@Test
public void testFence1() throws Exception {

  byte[] fenceId = "test_table".getBytes(Charsets.UTF_8);
  // Writer updates data here in a separate transaction (code not shown)
  // start tx
  // update
  // commit tx
  // Readers use fence to indicate that they are interested in changes to specific data
  TransactionAware readFenceCase16 = VisibilityFence.create(fenceId);
  TransactionContext readTxContextCase16 =
    new TransactionContext(new InMemoryTxSystemClient(txManager), readFenceCase16);
  readTxContextCase16.start();
  readTxContextCase16.finish();
  TransactionAware readFenceCase17 = VisibilityFence.create(fenceId);
  TransactionContext readTxContextCase17 =
    new TransactionContext(new InMemoryTxSystemClient(txManager), readFenceCase17);
  readTxContextCase17.start();
  TransactionAware readFenceCase18 = VisibilityFence.create(fenceId);
  TransactionContext readTxContextCase18 =
    new TransactionContext(new InMemoryTxSystemClient(txManager), readFenceCase18);
  readTxContextCase18.start();
  // Now writer needs to wait for in-progress readers to see the change, it uses write fence to do so
  // Start write fence txn
  TransactionAware writeFence = new WriteFence(fenceId);
  TransactionContext writeTxContext = new TransactionContext(new InMemoryTxSystemClient(txManager), writeFence);
  writeTxContext.start();
  TransactionAware readFenceCase20 = VisibilityFence.create(fenceId);
  TransactionContext readTxContextCase20 =
    new TransactionContext(new InMemoryTxSystemClient(txManager), readFenceCase20);
  readTxContextCase20.start();
  readTxContextCase17.finish();
  assertTxnConflict(writeTxContext);
  writeTxContext.start();
  // Commit write fence txn can commit without conflicts at this point
  writeTxContext.finish();
  TransactionAware readFenceCase21 = VisibilityFence.create(fenceId);
  TransactionContext readTxContextCase21 =
    new TransactionContext(new InMemoryTxSystemClient(txManager), readFenceCase21);
  readTxContextCase21.start();
  assertTxnConflict(readTxContextCase18);
  readTxContextCase20.finish();
  readTxContextCase21.finish();
}