public static <T, E extends Exception> void assertEventually( String reason, ThrowingSupplier<T, E> actual, Matcher<? super T> matcher, long timeout, TimeUnit timeUnit ) throws E, InterruptedException { assertEventually( ignored -> reason, actual, matcher, timeout, timeUnit ); }
} ).start(); assertEventually( "Wrapped was not started", running::get, is( true ), 10, TimeUnit.SECONDS ); assertThat( "Bootstrapper exited early", exited.get(), is( false ) ); assertEventually( "Wrapped was not stopped", running::get, is( false ), 10, TimeUnit.SECONDS ); assertEventually( "Bootstrapper did not exit", exited::get, is( true ), 10, TimeUnit.SECONDS ); assertThat( "Bootstrapper did not propagate exit status", status.get(), is( 0 ) );
@Test public void shouldBlockUntilTheIndexIsOnline() throws IndexNotFoundKernelException, InterruptedException { when( tokenRead.nodeLabel( anyString() ) ).thenReturn( 0 ); when( tokenRead.propertyKey( anyString() ) ).thenReturn( 0 ); when( schemaRead.index( anyInt(), any() ) ).thenReturn( anyIndex ); AtomicReference<InternalIndexState> state = new AtomicReference<>( POPULATING ); when( schemaRead.indexGetState( any( IndexReference.class ) ) ).then( invocationOnMock -> state.get() ); AtomicBoolean done = new AtomicBoolean( false ); new Thread( () -> { try { procedure.awaitIndexByPattern( ":Person(name)", TIMEOUT, TIME_UNIT ); } catch ( ProcedureException e ) { throw new RuntimeException( e ); } done.set( true ); } ).start(); assertThat( done.get(), is( false ) ); state.set( ONLINE ); assertEventually( "Procedure did not return after index was online", done::get, is( true ), TIMEOUT, TIME_UNIT ); }
} ).start(); assertEventually( "Blocked unexpectedly", exited::get, is( true ), 10, TimeUnit.SECONDS ); assertThat( "Bootstrapper did not propagate exit status", status.get(), is( 1 ) );
@Test public void shouldTimeoutIfTheIndexTakesTooLongToComeOnline() throws InterruptedException, IndexNotFoundKernelException { when( tokenRead.nodeLabel( anyString() ) ).thenReturn( 0 ); when( tokenRead.propertyKey( anyString() ) ).thenReturn( 0 ); when( schemaRead.index( anyInt(), anyInt() ) ).thenReturn( anyIndex ); when( schemaRead.indexGetState( any( IndexReference.class ) ) ).thenReturn( POPULATING ); AtomicReference<ProcedureException> exception = new AtomicReference<>(); new Thread( () -> { try { // We wait here, because we expect timeout procedure.awaitIndexByPattern( ":Person(name)", 0, TIME_UNIT ); } catch ( ProcedureException e ) { exception.set( e ); } } ).start(); assertEventually( "Procedure did not time out", exception::get, not( nullValue() ), TIMEOUT, TIME_UNIT ); //noinspection ThrowableResultOfMethodCallIgnored assertThat( exception.get().status(), is( Status.Procedure.ProcedureTimedOut ) ); } }
@Test public void shouldStartStopNeoServerWithoutAnyConfigFiles() throws Throwable { // When int resultCode = ServerBootstrapper.start( bootstrapper, withConnectorsOnRandomPortsConfig( "--home-dir", tempDir.newFolder( "home-dir" ).getAbsolutePath(), "-c", configOption( data_directory, tempDir.getRoot().getAbsolutePath() ), "-c", configOption( logs_directory, tempDir.getRoot().getAbsolutePath() ), "-c", "dbms.backup.enabled=false" ) ); // Then assertEquals( ServerBootstrapper.OK, resultCode ); assertEventually( "Server was not started", bootstrapper::isRunning, is( true ), 1, TimeUnit.MINUTES ); }
@Test public void shouldFailIfWrongCredentials() throws Throwable { // When connection.connect( address ) .send( util.defaultAcceptedVersions() ) .send( util.chunk( new InitMessage( "TestClient/1.1", map( "principal", "neo4j", "credentials", "wrong", "scheme", "basic" ) ) ) ); // Then assertThat( connection, util.eventuallyReceivesSelectedProtocolVersion() ); assertThat( connection, util.eventuallyReceives( msgFailure( Status.Security.Unauthorized, "The client is unauthorized due to authentication failure." ) ) ); assertThat( connection, eventuallyDisconnects() ); assertEventually( ignore -> "Matching log call not found in\n" + logProvider.serialize(), this::authFailureLoggedToUserLog, is( true ), 30, SECONDS ); }
private void testStartupWithConnectors( boolean httpEnabled, boolean httpsEnabled, boolean boltEnabled ) throws Exception { int resultCode = ServerBootstrapper.start( bootstrapper, "--home-dir", tempDir.newFolder( "home-dir" ).getAbsolutePath(), "-c", configOption( data_directory, tempDir.getRoot().getAbsolutePath() ), "-c", configOption( logs_directory, tempDir.getRoot().getAbsolutePath() ), "-c", "dbms.connector.http.enabled=" + httpEnabled, "-c", "dbms.connector.http.listen_address=:0", "-c", "dbms.connector.https.enabled=" + httpsEnabled, "-c", "dbms.connector.https.listen_address=:0", "-c", "dbms.connector.bolt.enabled=" + boltEnabled, "-c", "dbms.connector.bolt.listen_address=:0" ); assertEquals( ServerBootstrapper.OK, resultCode ); assertEventually( "Server was not started", bootstrapper::isRunning, is( true ), 1, TimeUnit.MINUTES ); assertDbAccessibleAsEmbedded(); verifyConnector( db(), "http", httpEnabled ); verifyConnector( db(), "https", httpsEnabled ); verifyConnector( db(), "bolt", boltEnabled ); }
@Test public void schemaStateShouldBeEvictedOnIndexComingOnline() throws Exception { // GIVEN schemaWriteInNewTransaction(); getOrCreateSchemaState( "my key", "my state" ); commit(); // WHEN createIndex( newTransaction( AUTH_DISABLED ) ); commit(); try ( Transaction tx = db.beginTx() ) { db.schema().awaitIndexesOnline( 20, SECONDS ); tx.success(); } // THEN schema state is eventually updated (clearing the schema cache is not atomic with respect to flipping // the new index to the ONLINE state, but happens as soon as possible *after* the index becomes ONLINE). assertEventually( "Schema state should have been updated", () -> schemaStateContains( "my key" ), is( false ), 1, TimeUnit.SECONDS ); }
@Test public void givenExplicitlyEnabledServerLoggingConfigurationShouldLogAccess() throws Exception { // given String directoryPrefix = testName.getMethodName(); File logDirectory = testDirectory.directory( directoryPrefix + "-logdir" ); final String query = "?explicitlyEnabled=" + randomString(); NeoServer server = serverOnRandomPorts().withDefaultDatabaseTuning().persistent() .withProperty( ServerSettings.http_logging_enabled.name(), Settings.TRUE ) .withProperty( GraphDatabaseSettings.logs_directory.name(), logDirectory.getAbsolutePath() ) .withProperty( new BoltConnector( "bolt" ).listen_address.name(), ":0" ) .usingDataDir( testDirectory.directory( directoryPrefix + "-dbdir" ).getAbsolutePath() ) .build(); try { server.start(); FunctionalTestHelper functionalTestHelper = new FunctionalTestHelper( server ); // when JaxRsResponse response = new RestRequest().get( functionalTestHelper.managementUri() + query ); assertThat( response.getStatus(), is( HttpStatus.SC_OK ) ); response.close(); // then File httpLog = new File( logDirectory, "http.log" ); assertEventually( "request appears in log", fileContentSupplier( httpLog ), containsString( query ), 5, TimeUnit.SECONDS ); } finally { server.stop(); } }
@Test public void shouldLogUserReadableLabelAndPropertyNames() throws Exception { //noinspection deprecation GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI(); String labelName = "User"; String property = "name"; // when createIndex( db, labelName, property ); // then LogMatcherBuilder match = inLog( IndexPopulationJob.class ); IndexProviderMap indexProviderMap = db.getDependencyResolver().resolveDependency( IndexProviderMap.class ); IndexProvider defaultProvider = indexProviderMap.getDefaultProvider(); IndexProviderDescriptor providerDescriptor = defaultProvider.getProviderDescriptor(); logProvider.assertAtLeastOnce( match.info( "Index population started: [%s]", ":User(name) [provider: {key=" + providerDescriptor.getKey() + ", version=" + providerDescriptor.getVersion() + "}]" ) ); assertEventually( (ThrowingSupplier<Object,Exception>) () -> null, new LogMessageMatcher( match, providerDescriptor ), 1, TimeUnit.MINUTES ); }