@Test
public void testSubscribeAndClose() throws IOException, InterruptedException {

	final TestNotificationListener listener = new TestNotificationListener();
	final AtomicReference<Throwable> error = new AtomicReference<Throwable>();
	final CountDownLatch sync = new CountDownLatch(1);
	addRequest();
	addRequest();
	writer.registerAllRequestsProcessedListener(listener);
	final Thread asyncCloseThread = new Thread(new Runnable() {
		@Override
		public void run() {
			try {
				writer.close();
			}
			catch (Throwable t) {
				error.set(t);
			}
			finally {
				sync.countDown();
			}
		}
	});
	asyncCloseThread.start();
	handleRequest();
	handleRequest();
	sync.await();
	assertEquals("Listener was not notified.", 1, listener.getNumberOfNotifications());
}