private IndexReference createIndexReference( WritableIndexReferenceFactory indexReferenceFactory ) throws Exception { IndexReference indexReference = indexReferenceFactory.createIndexReference( indexIdentifier ); cleanupRule.add( indexReference ); return indexReference; }
private GraphDatabaseService createDatabase() { return cleanup.add( builder.newGraphDatabase() ); }
private GraphDatabaseAPI createDatabase() { return (GraphDatabaseAPI) cleanup.add( builder.newGraphDatabase() ); }
@Test public void shouldCleanupMultipleObjectsInReverseAddedOrder() throws Throwable { // GIVEN CleanupRule rule = new CleanupRule(); AutoCloseable closeable = rule.add( mock( AutoCloseable.class ) ); Dirt dirt = rule.add( mock( Dirt.class ) ); // WHEN simulateTestExecution( rule ); // THEN InOrder inOrder = inOrder( dirt, closeable ); inOrder.verify( dirt, times( 1 ) ).shutdown(); inOrder.verify( closeable, times( 1 ) ).close(); }
public <T> T add( T toClose ) { Class<?> cls = toClose.getClass(); for ( String methodName : COMMON_CLOSE_METHOD_NAMES ) { try { Method method = cls.getMethod( methodName ); method.setAccessible( true ); add( closeable( method, toClose ) ); return toClose; } catch ( NoSuchMethodException e ) { // ignore } catch ( SecurityException e ) { throw new RuntimeException( e ); } } throw new IllegalArgumentException( "No suitable close method found on " + toClose + ", which is a " + cls ); }
@Test public void shouldCleanupAutoCloseable() throws Throwable { // GIVEN CleanupRule rule = new CleanupRule(); AutoCloseable toClose = rule.add( mock( AutoCloseable.class ) ); // WHEN simulateTestExecution( rule ); // THEN verify( toClose ).close(); }
@Test public void shouldCleanupObjectWithAppropriateCloseMethod() throws Throwable { // GIVEN CleanupRule rule = new CleanupRule(); Dirt toClose = rule.add( mock( Dirt.class ) ); // WHEN simulateTestExecution( rule ); // THEN verify( toClose ).shutdown(); }
@Test public void shouldTellUserIllegalArgumentIfSo() { // GIVEN CleanupRule rule = new CleanupRule(); try { rule.add( new Object() ); fail( "Should not accept this object" ); } catch ( IllegalArgumentException e ) { // OK, good } }
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
ExecutorService executor = cleanup.add( Executors.newCachedThreadPool() ); for ( int i = 0; i < 10; i++ )
@Test public void refreshReadOnlyIndexReference() throws Exception { ReadOnlyIndexReferenceFactory indexReferenceFactory = getReadOnlyIndexReferenceFactory(); IndexReference indexReference = indexReferenceFactory.createIndexReference( indexIdentifier ); cleanupRule.add( indexReference ); IndexReference refreshedIndex = indexReferenceFactory.refresh( indexReference ); assertSame("Refreshed instance should be the same.", indexReference, refreshedIndex); }
@Test public void createReadOnlyIndexReference() throws Exception { ReadOnlyIndexReferenceFactory indexReferenceFactory = getReadOnlyIndexReferenceFactory(); IndexReference indexReference = indexReferenceFactory.createIndexReference( indexIdentifier ); cleanupRule.add( indexReference ); expectedException.expect( UnsupportedOperationException.class ); indexReference.getWriter(); }
@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 ); }
@Test public void refreshChangedWritableIndexReference() throws Exception { WritableIndexReferenceFactory indexReferenceFactory = createFactory(); IndexReference indexReference = createIndexReference( indexReferenceFactory ); writeSomething( indexReference ); IndexReference refreshedIndexReference = indexReferenceFactory.refresh( indexReference ); cleanupRule.add( refreshedIndexReference ); assertNotSame( "Should return new refreshed index reference.", indexReference, refreshedIndexReference ); }
@Test public void concurrentCreatingAndAwaitingIndexesOnline() throws Exception { ExecutorService executor = cleanupRule.add( Executors.newSingleThreadExecutor() ); Future<?> indexCreate = executor.submit( () -> { try ( Transaction tx = db.beginTx() ) { db.schema().indexFor( label( 0 ) ).on( KEY ).create(); tx.success(); } } ); while ( !indexCreate.isDone() ) { try ( Transaction tx = db.beginTx() ) { db.schema().awaitIndexesOnline( 1, TimeUnit.MINUTES ); tx.success(); } } indexCreate.get(); }
@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(); }
OtherThreadExecutor<Void> executor = cleanup.add( new OtherThreadExecutor<>( "Deferred", null ) ); executor.execute( (WorkerCommand<Void,Void>) state ->
relIds.add( rel.getId() ); ExecutorService executor = cleanup.add( Executors.newSingleThreadExecutor() ); executor.submit( () ->
@Test public void shouldSeeExpectedDiagnostics() { AssertableLogProvider logProvider = new AssertableLogProvider(); GraphDatabaseService db = new TestGraphDatabaseFactory().setInternalLogProvider( logProvider ) .newImpermanentDatabaseBuilder() .setConfig( GraphDatabaseSettings.dump_configuration, Settings.TRUE ) .setConfig( GraphDatabaseSettings.pagecache_memory, "4M" ) .newGraphDatabase(); cleanupRule.add( db ); // THEN we should have logged logProvider.assertContainsMessageContaining( "Network information" ); logProvider.assertContainsMessageContaining( "Disk space on partition" ); logProvider.assertContainsMessageContaining( "Local timezone" ); // page cache info logProvider.assertContainsMessageContaining( "Page cache: 4M" ); // neostore records for ( MetaDataStore.Position position : MetaDataStore.Position.values() ) { logProvider.assertContainsMessageContaining( position.name() ); } // transaction log info logProvider.assertContainsMessageContaining( "Transaction log" ); logProvider.assertContainsMessageContaining( "TimeZone version: " ); } }