public URI boltURI() { if ( controls == null ) { throw new IllegalStateException( "Cannot access instance URI before or after the test runs." ); } return controls.boltURI(); }
@Test public void shouldOpenBoltPort() throws Throwable { // given try ( ServerControls controls = getTestServerBuilder( testDir.directory() ).newServer() ) { URI uri = controls.boltURI(); // when new SocketConnection().connect( new HostnamePort( uri.getHost(), uri.getPort() ) ); // then no exception } }
@Test public void shouldReturnBoltUriWhenDefaultBoltConnectorOffAndOtherConnectorConfigured() { TestServerBuilder serverBuilder = newInProcessBuilder( testDir.directory() ) .withConfig( "dbms.connector.bolt.enabled", "false" ) .withConfig( "dbms.connector.another_bolt.type", "BOLT" ) .withConfig( "dbms.connector.another_bolt.enabled", "true" ) .withConfig( "dbms.connector.another_bolt.listen_address", ":0" ); try ( ServerControls server = serverBuilder.newServer() ) { HostnamePort boltHostPort = connectorAddress( server.graph(), "bolt" ); HostnamePort anotherBoltHostPort = connectorAddress( server.graph(), "another_bolt" ); assertNull( boltHostPort ); assertNotNull( anotherBoltHostPort ); URI boltUri = server.boltURI(); assertEquals( "bolt", boltUri.getScheme() ); assertEquals( anotherBoltHostPort.getHost(), boltUri.getHost() ); assertEquals( anotherBoltHostPort.getPort(), boltUri.getPort() ); } }
@Test public void shouldReturnBoltUriWhenMultipleBoltConnectorsConfigured() { TestServerBuilder serverBuilder = newInProcessBuilder( testDir.directory() ) .withConfig( "dbms.connector.another_bolt.type", "BOLT" ) .withConfig( "dbms.connector.another_bolt.enabled", "true" ) .withConfig( "dbms.connector.another_bolt.listen_address", ":0" ) .withConfig( "dbms.connector.bolt.enabled", "true" ) .withConfig( "dbms.connector.bolt.listen_address", ":0" ); try ( ServerControls server = serverBuilder.newServer() ) { HostnamePort boltHostPort = connectorAddress( server.graph(), "bolt" ); HostnamePort anotherBoltHostPort = connectorAddress( server.graph(), "another_bolt" ); assertNotNull( boltHostPort ); assertNotNull( anotherBoltHostPort ); assertNotEquals( boltHostPort, anotherBoltHostPort ); URI boltUri = server.boltURI(); assertEquals( "bolt", boltUri.getScheme() ); assertEquals( boltHostPort.getHost(), boltUri.getHost() ); assertEquals( boltHostPort.getPort(), boltUri.getPort() ); } }
@BeforeClass public static void setUp() throws Exception { server = TestServerBuilders.newInProcessBuilder().withFixture(setup) .withConfig("dbms.security.auth_enabled", "false").newServer(); BOLT_URL = "'"+server.boltURI().toString()+"'"; db = new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().newGraphDatabase(); TestUtil.registerProcedure(db, Bolt.class); }
@Override public String getBoltHost() { return serverControls.boltURI().getHost(); }
@Override public String getBoltHost() { return serverControls.boltURI().getHost(); }
public URI boltURI() { if ( controls == null ) { throw new IllegalStateException( "Cannot access instance URI before or after the test runs." ); } return controls.boltURI(); }
@Override public String getBoltHost() { return serverControls.boltURI().getHost(); }
@Override public String getBoltHost() { return serverControls.boltURI().getHost(); }
@Override public String getBoltPort() { return String.valueOf(serverControls.boltURI().getPort()); } }
@Override public String getBoltPort() { return String.valueOf(serverControls.boltURI().getPort()); } }
@Override public String getBoltPort() { return String.valueOf(serverControls.boltURI().getPort()); } }
@Override public String getBoltPort() { return String.valueOf(serverControls.boltURI().getPort()); } }
.newServer(); this.uri = controls.boltURI().toString(); } else { TestServerBuilder builder = newInProcessBuilder()
@BeforeClass public static void initializeNeo4j() throws IOException { serverControls = TestServerBuilders.newInProcessBuilder().withProcedure(ApocLovesSwitch.class) .newServer(); boltURI = serverControls.boltURI(); }
@BeforeClass public static void initSessionFactory() { Driver driver = new BoltDriver( GraphDatabase.driver(serverControls.boltURI(), Config.build().withoutEncryption().toConfig())); sessionFactory = new SessionFactory(driver, DOMAIN_PACKAGE); }
@BeforeClass public static void startServer() { serverControls = TestServerBuilders.newInProcessBuilder().newServer(); Driver driver = GraphDatabase.driver(serverControls.boltURI(), Config.build().withoutEncryption().toConfig()); supportsBytePacking = ServerVersion.version(driver).greaterThanOrEqual(ServerVersion.v3_2_0); sessionFactory = new SessionFactory(new BoltDriver(driver), DOMAIN_PACKAGE); }
@Test public void translatesServiceUnavailabeException() { try (ServerControls serverControls = TestServerBuilders.newInProcessBuilder().newServer()) { BoltDriver driver = new BoltDriver(); Configuration ogmConfiguration = new Configuration.Builder().uri(serverControls.boltURI().toString()) .verifyConnection(true).build(); driver.configure(ogmConfiguration); SessionFactory sessionFactory = new SessionFactory(driver, DOMAIN_PACKAGE); Session session = sessionFactory.openSession(); serverControls.close(); assertThatExceptionOfType(ConnectionException.class).isThrownBy(() -> { session.loadAll(ConstraintedNode.class); }).withCauseInstanceOf(ServiceUnavailableException.class); } } }