Search in sources :

Example 1 with Config

use of org.neo4j.driver.Config in project beam by apache.

the class Neo4jIOTest method testDriverConfigurationWith.

@Test
public void testDriverConfigurationWith() throws Exception {
    Neo4jIO.DriverConfiguration driverConfiguration = Neo4jIO.DriverConfiguration.create();
    Config config = Config.builder().withEncryption().withConnectionAcquisitionTimeout(54321L, TimeUnit.MILLISECONDS).withConnectionTimeout(43210L, TimeUnit.MILLISECONDS).withConnectionLivenessCheckTimeout(32109L, TimeUnit.MILLISECONDS).withMaxConnectionLifetime(21098L, TimeUnit.MILLISECONDS).withMaxConnectionPoolSize(101).build();
    driverConfiguration = driverConfiguration.withConfig(config);
    Config configVerify = driverConfiguration.getConfig();
    Assert.assertNotNull(configVerify);
    Assert.assertEquals(true, configVerify.encrypted());
    Assert.assertEquals(54321L, configVerify.connectionAcquisitionTimeoutMillis());
    Assert.assertEquals(43210L, configVerify.connectionTimeoutMillis());
    Assert.assertEquals(32109L, configVerify.idleTimeBeforeConnectionTest());
    Assert.assertEquals(21098L, configVerify.maxConnectionLifetimeMillis());
    Assert.assertEquals(101, configVerify.maxConnectionPoolSize());
    driverConfiguration = driverConfiguration.withUrl("url1");
    Assert.assertEquals("url1", driverConfiguration.getUrl().get());
    // URL and URLs can be set independently but are both used
    driverConfiguration = driverConfiguration.withUrls(Arrays.asList("url2", "url3", "url4"));
    Assert.assertEquals(3, driverConfiguration.getUrls().get().size());
    driverConfiguration = driverConfiguration.withUsername("username");
    Assert.assertEquals("username", driverConfiguration.getUsername().get());
    driverConfiguration = driverConfiguration.withPassword("password");
    Assert.assertEquals("password", driverConfiguration.getPassword().get());
}
Also used : Config(org.neo4j.driver.Config) Test(org.junit.Test)

Example 2 with Config

use of org.neo4j.driver.Config in project spring-boot by spring-projects.

the class Neo4jAutoConfiguration method mapDriverConfig.

Config mapDriverConfig(Neo4jProperties properties, List<ConfigBuilderCustomizer> customizers) {
    Config.ConfigBuilder builder = Config.builder();
    configurePoolSettings(builder, properties.getPool());
    URI uri = properties.getUri();
    String scheme = (uri != null) ? uri.getScheme() : "bolt";
    configureDriverSettings(builder, properties, isSimpleScheme(scheme));
    builder.withLogging(new Neo4jSpringJclLogging());
    customizers.forEach((customizer) -> customizer.customize(builder));
    return builder.build();
}
Also used : Config(org.neo4j.driver.Config) URI(java.net.URI)

Example 3 with Config

use of org.neo4j.driver.Config in project jmeter by apache.

the class BoltConnectionElement method testStarted.

@Override
public void testStarted() {
    this.setRunningVersion(true);
    TestBeanHelper.prepare(this);
    JMeterVariables variables = getThreadContext().getVariables();
    if (variables.getObject(BOLT_CONNECTION) != null) {
        log.error("Bolt connection already exists");
    } else {
        synchronized (this) {
            Config config = Config.builder().withMaxConnectionPoolSize(getMaxConnectionPoolSize()).build();
            driver = GraphDatabase.driver(getBoltUri(), AuthTokens.basic(getUsername(), getPassword()), config);
            variables.putObject(BOLT_CONNECTION, driver);
        }
    }
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables) Config(org.neo4j.driver.Config)

Example 4 with Config

use of org.neo4j.driver.Config in project spring-boot by spring-projects.

the class Neo4jPropertiesTests method driverSettingsHaveConsistentDefaults.

@Test
void driverSettingsHaveConsistentDefaults() {
    Config defaultConfig = Config.defaultConfig();
    Neo4jProperties properties = new Neo4jProperties();
    assertDuration(properties.getConnectionTimeout(), defaultConfig.connectionTimeoutMillis());
    assertDuration(properties.getMaxTransactionRetryTime(), RetrySettings.DEFAULT.maxRetryTimeMs());
}
Also used : Config(org.neo4j.driver.Config) Test(org.junit.jupiter.api.Test)

Example 5 with Config

use of org.neo4j.driver.Config in project spring-boot by spring-projects.

the class Neo4jPropertiesTests method securitySettingsHaveConsistentDefaults.

@Test
void securitySettingsHaveConsistentDefaults() {
    Config defaultConfig = Config.defaultConfig();
    Neo4jProperties properties = new Neo4jProperties();
    assertThat(properties.getSecurity().isEncrypted()).isEqualTo(defaultConfig.encrypted());
    assertThat(properties.getSecurity().getTrustStrategy().name()).isEqualTo(defaultConfig.trustStrategy().strategy().name());
    assertThat(properties.getSecurity().isHostnameVerificationEnabled()).isEqualTo(defaultConfig.trustStrategy().isHostnameVerificationEnabled());
}
Also used : Config(org.neo4j.driver.Config) Test(org.junit.jupiter.api.Test)

Aggregations

Config (org.neo4j.driver.Config)8 Test (org.junit.jupiter.api.Test)3 URI (java.net.URI)2 AuthToken (org.neo4j.driver.AuthToken)2 JMeterVariables (org.apache.jmeter.threads.JMeterVariables)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Test (org.junit.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 SessionConfig (org.neo4j.driver.SessionConfig)1 ConnectionConfig (org.neo4j.shell.ConnectionConfig)1 FakeDriver (org.neo4j.shell.test.bolt.FakeDriver)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 Pool (org.springframework.boot.autoconfigure.neo4j.Neo4jProperties.Pool)1 Bean (org.springframework.context.annotation.Bean)1