public <R> R execute( WorkerCommand<T, R> cmd ) throws Exception { return executeDontWait( cmd ).get(); }
public <RESULT> Future<RESULT> execute( OtherThreadExecutor.WorkerCommand<STATE, RESULT> cmd ) { Future<RESULT> future = executor.executeDontWait( cmd ); try { executor.awaitStartExecuting(); } catch ( InterruptedException e ) { throw new RuntimeException( "Interrupted while awaiting start of execution.", e ); } return future; }
public <R> R execute( WorkerCommand<T, R> cmd, long timeout, TimeUnit unit ) throws Exception { Future<R> future = executeDontWait( cmd ); boolean success = false; try { awaitStartExecuting(); R result = future.get( timeout, unit ); success = true; return result; } finally { if ( !success ) { future.cancel( true ); } } }
private Future<Lock> tryToAcquireSameLockOnAnotherThread( Node resource, OtherThreadExecutor<Void> otherThread ) throws Exception { Future<Lock> future = otherThread.executeDontWait( acquireWriteLock( resource ) ); otherThread.waitUntilWaiting(); return future; }
@Test public void shouldMutexAccessBetweenInvalidateAndinstance() throws Exception { // GIVEN final CountDownLatch latch = new CountDownLatch( 1 ); final AtomicInteger initCalls = new AtomicInteger(); LazySingleReference<Integer> ref = new LazySingleReference<Integer>() { @Override protected Integer create() { awaitLatch( latch ); return initCalls.incrementAndGet(); } }; Future<Integer> t1Evaluate = t1.executeDontWait( evaluate( ref ) ); t1.waitUntilWaiting(); // WHEN Future<Void> t2Invalidate = t2.executeDontWait( invalidate( ref ) ); t2.waitUntilBlocked(); latch.countDown(); int e = t1Evaluate.get(); t2Invalidate.get(); // THEN assertEquals( "Evaluation", 1, e ); }
@Test public void shouldOnlyAllowSingleThreadToInitialize() throws Exception { // GIVEN final CountDownLatch latch = new CountDownLatch( 1 ); final AtomicInteger initCalls = new AtomicInteger(); LazySingleReference<Integer> ref = new LazySingleReference<Integer>() { @Override protected Integer create() { awaitLatch( latch ); return initCalls.incrementAndGet(); } }; Future<Integer> t1Evaluate = t1.executeDontWait( evaluate( ref ) ); t1.waitUntilWaiting(); // WHEN Future<Integer> t2Evaluate = t2.executeDontWait( evaluate( ref ) ); t2.waitUntilBlocked(); latch.countDown(); int e1 = t1Evaluate.get(); int e2 = t2Evaluate.get(); // THEN assertEquals( "T1 evaluation", 1, e1 ); assertEquals( "T2 evaluation", 1, e2 ); }
"Population job test runner", null ) ); Future<Void> runFuture = populationJobRunner .executeDontWait( state ->
@Test public void shouldAbortStoreScanWaitOnDrop() throws Exception { // given the proxy structure FakePopulatingIndexProxy delegate = new FakePopulatingIndexProxy(); FlippableIndexProxy flipper = new FlippableIndexProxy( delegate ); OtherThreadExecutor<Void> waiter = cleanup.add( new OtherThreadExecutor<>( "Waiter", null ) ); // and a thread stuck in the awaitStoreScanCompletion loop Future<Object> waiting = waiter.executeDontWait( state -> flipper.awaitStoreScanCompleted() ); while ( !delegate.awaitCalled ) { Thread.sleep( 10 ); } // when flipper.drop(); // then the waiting should quickly be over waiting.get( 10, SECONDS ); }
Future<Void> flipContextFuture = flippingThread.executeDontWait( startFlipAndWaitForLatchBeforeFinishing( flippable, triggerFinishFlip, triggerExternalAccess ) ); Future<Void> dropIndexFuture = dropIndexThread.executeDontWait( dropTheIndex( flippable ) ); dropIndexThread.waitUntilWaiting();
otherThreadExecutor.executeDontWait( (WorkerCommand<Void,Void>) state ->
Future<Void> shutdown = closer.executeDontWait( state ->
@Test public void shouldHaveOneThreadWaitForARemoval() throws Exception { // GIVEN IdOrderingQueue queue = new SynchronizedArrayIdOrderingQueue( 5 ); queue.offer( 3 ); queue.offer( 5 ); // WHEN another thread comes in and awaits 5 OtherThreadExecutor<Void> t2 = cleanup.add( new OtherThreadExecutor<Void>( "T2", null ) ); Future<Object> await5 = t2.executeDontWait( awaitHead( queue, 5 ) ); t2.waitUntilWaiting(); // ... and head (3) gets removed queue.removeChecked( 3 ); // THEN the other thread should be OK to continue await5.get(); }
@Test public void shouldApplyBackPressure() throws Exception { // given int backPressureThreshold = 10; BlockableMonitor monitor = new BlockableMonitor(); try ( OtherThreadExecutor<Void> t2 = new OtherThreadExecutor<>( "T2", null ); BadCollector badCollector = new BadCollector( NULL_OUTPUT_STREAM, UNLIMITED_TOLERANCE, COLLECT_ALL, backPressureThreshold, false, monitor ) ) { for ( int i = 0; i < backPressureThreshold; i++ ) { badCollector.collectDuplicateNode( i, i, "group" ); } // when Future<Object> enqueue = t2.executeDontWait( command( () -> badCollector.collectDuplicateNode( 999, 999, "group" ) ) ); t2.waitUntilWaiting( waitDetails -> waitDetails.isAt( BadCollector.class, "collect" ) ); monitor.unblock(); // then enqueue.get(); } }
node.setProperty( TEST_PROPERTY_NAME, "b" ); Future<Void> propertySetFuture = secondTransactionExecutor.executeDontWait( state ->
lockManger.newClient().acquireExclusive( LockTracer.NONE, ResourceTypes.LABEL, 1 ); Future<Void> propertySetFuture = secondTransactionExecutor.executeDontWait( state ->