{
Assert.assertNotNull(bundleContext);
ExecutorService executor = new ThreadPoolExecutor(1, 5, 100, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
ScheduledExecutorService scheduledExecutor = new ScheduledThreadPoolExecutor(2);
EventAdminImpl eventAdmin = new EventAdminImpl(bundleContext, executor, scheduledExecutor);
eventAdmin.start();
Dictionary<String, Object> properties = new Hashtable<String, Object>();
properties.put(EventConstants.EVENT_TOPIC, "a/b/c/d");
final CountDownLatch latch = new CountDownLatch(1);
final AtomicInteger count = new AtomicInteger();
ServiceRegistration sr = bundleContext.registerService(EventHandler.class.getName(), new EventHandler()
{
public void handleEvent(Event event)
{
try
{
Thread.sleep(100);
}
catch (InterruptedException ie)
{
Thread.currentThread().interrupt();
}
finally
{
count.incrementAndGet();
latch.countDown();
}
}
}, properties);
try
{
eventAdmin.postEvent(new Event("a/b/c/d", (Dictionary) null));
latch.await();
assertEquals(1, count.get());
eventAdmin.sendEvent(new Event("a/b/c/d", (Dictionary) null));
eventAdmin.sendEvent(new Event("a/b/c/d/e", (Dictionary) null));
eventAdmin.sendEvent(new Event("z/b/c/d", (Dictionary) null));
eventAdmin.sendEvent(new Event("a/b/c", (Dictionary) null));
assertEquals(2, count.get());
}
finally
{
sr.unregister();
eventAdmin.stop();
executor.shutdown();
scheduledExecutor.shutdown();
}
}