@Test
public void testWrite() throws Exception {

  ExecutorService executeService = Executors.newFixedThreadPool(2);
  ReaderWriterLock lock = new ReaderWriterLock();
  Writer writer1 = spy(new Writer("Writer 1", lock.writeLock()));
  Writer writer2 = spy(new Writer("Writer 2", lock.writeLock()));
  executeService.submit(writer1);
  // Let write1 execute first
  Thread.sleep(150);
  executeService.submit(writer2);
  executeService.shutdown();
  try {
    executeService.awaitTermination(10, TimeUnit.SECONDS);
  } catch (InterruptedException e) {
    LOGGER.error("Error waiting for ExecutorService shutdown", e);
  }
  // Write operation will hold the write lock 250 milliseconds, so here we verify that when two
  // writer execute concurrently, the second writer can only writes only when the first one is
  // finished.
  assertTrue(appender.logContains("Writer 1 begin"));
  assertTrue(appender.logContains("Writer 1 finish"));
  assertTrue(appender.logContains("Writer 2 begin"));
  assertTrue(appender.logContains("Writer 2 finish"));
}