@Before public void before() { t1 = new OtherThreadExecutor<>( "T1", null ); t2 = new OtherThreadExecutor<>( "T2", null ); }
newIndexPopulationJob( populator, index, storeView, NullLogProvider.getInstance(), EntityType.NODE, indexDescriptor( FIRST, name, false ) ); OtherThreadExecutor<Void> populationJobRunner = cleanup.add( new OtherThreadExecutor<>( "Population job test runner", null ) ); Future<Void> runFuture = populationJobRunner
@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 ); }
final CountDownLatch triggerExternalAccess = new CountDownLatch( 1 ); OtherThreadExecutor<Void> flippingThread = cleanup.add( new OtherThreadExecutor<>( "Flipping thread", null ) ); OtherThreadExecutor<Void> dropIndexThread = cleanup.add( new OtherThreadExecutor<>( "Drop index thread", null ) );
final AtomicBoolean stoppedCompleted = new AtomicBoolean(); final DoubleLatch checkPointerLatch = new DoubleLatch( 1 ); OtherThreadExecutor<Void> otherThreadExecutor = new OtherThreadExecutor<>( "scheduler stopper", null ); CheckPointer checkPointer = new CheckPointer()
try ( OtherThreadExecutor<Void> closer = new OtherThreadExecutor<>( "closer", null ) )
@Override public void evaluate() throws Throwable { String threadName = name != null ? name + "-" + description.getDisplayName() : description.getDisplayName(); executor = new OtherThreadExecutor<>( threadName, timeout, unit, initialState() ); try { base.evaluate(); } finally { try { executor.close(); } finally { executor = null; } } } };
@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(); } }
@Test public void nestedTransactionCanAcquireLocksFromTransactionObject() throws Exception { // given Node resource = createNode(); try ( Transaction outerTx = db.beginTx(); Transaction nestedTx = db.beginTx() ) { assertNotSame( outerTx, nestedTx ); try ( OtherThreadExecutor<Void> otherThread = new OtherThreadExecutor<>( "other thread", null ) ) { // when Lock lock = nestedTx.acquireWriteLock( resource ); Future<Lock> future = tryToAcquireSameLockOnAnotherThread( resource, otherThread ); // then acquireOnOtherThreadTimesOut( future ); // and when lock.release(); //then assertNotNull( future.get() ); } } }
OtherThreadExecutor<Void> executor = cleanup.add( new OtherThreadExecutor<>( "Deferred", null ) ); executor.execute( (WorkerCommand<Void,Void>) state ->
@Test public void concurrently_creating_same_property_key_in_different_transactions_should_end_up_with_same_key_id() throws Exception { // GIVEN GraphDatabaseAPI db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabase(); OtherThreadExecutor<WorkerState> worker1 = new OtherThreadExecutor<>( "w1", new WorkerState( db ) ); OtherThreadExecutor<WorkerState> worker2 = new OtherThreadExecutor<>( "w2", new WorkerState( db ) ); worker1.execute( new BeginTx() ); worker2.execute( new BeginTx() ); // WHEN String key = "mykey"; worker1.execute( new CreateNodeAndSetProperty( key ) ); worker2.execute( new CreateNodeAndSetProperty( key ) ); worker1.execute( new FinishTx() ); worker2.execute( new FinishTx() ); worker1.close(); worker2.close(); // THEN assertEquals( 1, propertyKeyCount( db ) ); db.shutdown(); }