public void testConcurrentCreate() throws Exception { tm().begin(); AtomicMapLookup.getAtomicMap(cache, KEY); final AtomicBoolean gotTimeoutException = new AtomicBoolean(); fork(() -> { try { tm().begin(); try { AtomicMapLookup.getAtomicMap(cache, KEY); } catch (TimeoutException e) { // this is the exception we were expecting gotTimeoutException.set(true); } finally { tm().rollback(); } } catch (Exception e) { log.error("Unexpected error performing transaction", e); } }).get(10, TimeUnit.SECONDS); assert gotTimeoutException.get(); }
public void testConcurrentPut() throws Exception { final CountDownLatch readLatch = new CountDownLatch(1); final CountDownLatch commitLatch = new CountDownLatch(1); AtomicMap<Integer, String> atomicMap = AtomicMapLookup.getAtomicMap(cache, KEY); tm().begin(); atomicMap.put(1, "value1"); Future<Object> future = fork(() -> { try { tm().begin(); AtomicMap<Integer, String> otMap = AtomicMapLookup.getAtomicMap(cache, KEY); assertEquals(0, otMap.size()); readLatch.countDown(); otMap.put(2, "value2"); commitLatch.await(10, TimeUnit.SECONDS); tm().commit(); } catch (Exception e) { tm().rollback(); throw e; } return null; }); readLatch.await(10, TimeUnit.SECONDS); tm().commit(); commitLatch.countDown(); future.get(10, TimeUnit.SECONDS); assertEquals(new HashSet<>(Arrays.asList(1, 2)), atomicMap.keySet()); }
public void testLockTimeout() throws Exception { AtomicMap<Integer, String> atomicMap = AtomicMapLookup.getAtomicMap(cache, KEY); tm().begin(); atomicMap.put(1, ""); Future<Object> future = fork(() -> { tm().begin(); try { AtomicMap<Integer, String> otMap = AtomicMapLookup.getAtomicMap(cache, KEY); otMap.put(1, "val"); } finally { tm().rollback(); } return null; }); try { future.get(10, TimeUnit.SECONDS); fail("Should have failed with a TimeoutException"); } catch (ExecutionException e) { assertTrue(e.getCause() instanceof TimeoutException); } }
tm().begin(); atomicMap.put(1, "value1"); atomicMap.put(2, "value2"); atomicMap.put(3, "value3"); tm().commit(); tm().begin(); atomicMap.remove(1); Future<Object> future = fork(() -> { try { tm().begin(); AtomicMap<Integer, String> otMap = AtomicMapLookup.getAtomicMap(cache, KEY); commitLatch.await(10, TimeUnit.SECONDS); tm().commit(); } catch (Exception e) { tm().rollback(); throw e; tm().commit(); commitLatch.countDown();
public void testReadAfterTxStarted() throws Exception { AtomicMap<Integer, String> atomicMap = AtomicMapLookup.getAtomicMap(cache, KEY); atomicMap.put(1, "existing"); tm().begin(); atomicMap.put(1, "newVal"); final CountDownLatch commitLatch = new CountDownLatch(1); Future<Object> future = fork(() -> { tm().begin(); tm().rollback(); tm().commit(); commitLatch.countDown();