VisibilityFence { public static TransactionAware create(byte[] fenceId) { return new ReadFence(fenceId); } private  VisibilityFence(); static TransactionAware create(byte[] fenceId); static FenceWait prepareWait(byte[] fenceId, TransactionSystemClient txClient);  }
@Test public void testFence1() throws Exception { byte[] fenceId = "test_table".getBytes(Charsets.UTF_8); 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(); 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(); writeTxContext.finish(); TransactionAware readFenceCase21 = VisibilityFence.create(fenceId); TransactionContext readTxContextCase21 = new TransactionContext(new InMemoryTxSystemClient(txManager), readFenceCase21); readTxContextCase21.start(); assertTxnConflict(readTxContextCase18); readTxContextCase20.finish(); readTxContextCase21.finish(); }
@Test public void testFence2() throws Exception { byte[] fenceId = "test_table".getBytes(Charsets.UTF_8); TransactionAware readFence1 = VisibilityFence.create(fenceId); TransactionContext readTxContext1 = new TransactionContext(new InMemoryTxSystemClient(txManager), readFence1); readTxContext1.start(); TransactionAware readFence2 = VisibilityFence.create(fenceId); TransactionContext readTxContext2 = new TransactionContext(new InMemoryTxSystemClient(txManager), readFence2); readTxContext2.start(); TransactionAware readFence3 = VisibilityFence.create(fenceId); TransactionContext readTxContext3 = new TransactionContext(new InMemoryTxSystemClient(txManager), readFence3); readTxContext3.start(); TransactionAware writeFence = new WriteFence(fenceId); TransactionContext writeTxContext = new TransactionContext(new InMemoryTxSystemClient(txManager), writeFence); writeTxContext.start(); readTxContext1.finish(); try { writeTxContext.finish(); Assert.fail("Expected transaction to fail"); } catch (TransactionConflictException e) { writeTxContext.abort(); } writeTxContext.start(); readTxContext3.finish(); try { writeTxContext.finish(); Assert.fail("Expected transaction to fail"); } catch (TransactionConflictException e) { writeTxContext.abort(); } writeTxContext.start(); writeTxContext.finish(); try { readTxContext2.finish(); Assert.fail("Expected transaction to fail"); } catch (TransactionConflictException e) { readTxContext2.abort(); } readTxContext2 = new TransactionContext(new InMemoryTxSystemClient(txManager), readFence2); readTxContext2.start(); readTxContext2.finish(); }