@Test public void testAbort() throws Exception { monitor.start(); final int capacity = monitor.maxCapacity(); ArrayList<ReqId> reqIds = new ArrayList<>(); HashMap<ReqId, TransactionFuture> futures = new HashMap<>(); for (int i = 0; i < capacity; i++) { reqIds.add(new ReqId(0, i)); futures.put(new ReqId(0, i), monitor.register(new ReqId(0, i), context, timeout)); } int remaining = capacity; Collections.shuffle(reqIds); for (ReqId reqId : reqIds) { monitor.abort(reqId); remaining--; assertFalse(futures.get(reqId).get()); assertFalse(futures.get(reqId).isFlushed()); int pendingCount = 0; for (TransactionFuture future : futures.values()) { if (!future.isDone()) { pendingCount++; } } assertEquals(remaining, pendingCount); assertEquals(remaining, monitor.registeredCount()); } }
public void abort(ReqId reqId) { synchronized (this) { if (state != State.CLOSED) { TransactionFuture future = registered.get(reqId); if (future != null) { if (future.complete(false)) { numRegistered--; } notifyAll(); } } } }
TransactionMonitor { public void abort(ReqId reqId) { synchronized (this) { if (state != State.CLOSED) { TransactionFuture future = registered.get(reqId); if (future != null) { if (future.complete(false)) { numRegistered--; } notifyAll(); } } } } }
TransactionMonitor { public void abort(ReqId reqId) { synchronized (this) { if (state != State.CLOSED) { TransactionFuture future = registered.get(reqId); if (future != null) { if (future.complete(false)) { numRegistered--; } notifyAll(); } } } } TransactionMonitor(int maxConcurrentTransactions); }
TransactionMonitor { public void abort(ReqId reqId) { synchronized (this) { if (state != State.CLOSED) { TransactionFuture future = registered.get(reqId); if (future != null) { if (future.complete(false)) { numRegistered--; } notifyAll(); } } } } TransactionMonitor(int maxConcurrentTransactions); void close(); boolean start(); boolean stop(); boolean isStopped(); void clear(); int maxCapacity(); TransactionFuture register(ReqId reqId, TransactionContext context, long registrationTimeout); TransactionContext getTransactionContext(ReqId reqId); TransactionContext committed(ReqId reqId); void abort(ReqId reqId); void flush(ReqId reqId); TransactionFuture lastEnqueued(); long lastEnqueuedTime(); int registeredCount(); }
TransactionMonitor { public void abort(ReqId reqId) { synchronized (this) { if (state != State.CLOSED) { TransactionFuture future = registered.get(reqId); if (future != null) { if (future.complete(false)) { numRegistered--; } notifyAll(); } } } } TransactionMonitor(int maxConcurrentTransactions); void close(); boolean start(); boolean stop(); boolean isStopped(); void clear(); int maxCapacity(); TransactionFuture register(ReqId reqId, TransactionContext context, long registrationTimeout); TransactionContext getTransactionContext(ReqId reqId); TransactionContext committed(ReqId reqId); void abort(ReqId reqId); void flush(ReqId reqId); TransactionFuture lastEnqueued(); long lastEnqueuedTime(); int registeredCount();  }