Search in sources :

Example 1 with Driver

use of org.neo4j.ogm.driver.Driver in project LinkAgent by shulieTech.

the class Neo4jSessionOperationCutOffInterceptor method cutoff0.

@Override
public CutOffResult cutoff0(Advice advice) {
    Object[] args = advice.getParameterArray();
    String methodName = advice.getBehaviorName();
    Object target = advice.getTarget();
    /**
     * 压测状态为关闭,如果当前为压测流量则直接报错
     */
    if (!PradarSwitcher.isClusterTestEnabled()) {
        if (Pradar.isClusterTest()) {
            throw new PressureMeasureError(PradarSwitcher.PRADAR_SWITCHER_OFF + ":" + AppNameUtils.appName());
        }
        return CutOffResult.passed();
    }
    if (!Pradar.isClusterTest()) {
        // 非压测流量
        return CutOffResult.passed();
    }
    if (target instanceof Neo4JSessionExt) {
        // 影子配置session回调
        return CutOffResult.passed();
    }
    // 避免因配置重新生效而导致使用旧配置
    Driver driver1 = Reflect.on(target).get(Neo4JConstants.DYNAMIC_FIELD_DRIVER);
    DriverConfiguration configuration = driver1.getConfiguration();
    String uri = configuration.getURI();
    Credentials credentials = configuration.getCredentials();
    String username = null;
    if (credentials instanceof AuthTokenCredentials) {
        username = ((AuthTokenCredentials) credentials).credentials();
    } else if (credentials instanceof UsernamePasswordCredentials) {
        username = ((UsernamePasswordCredentials) credentials).getUsername();
    }
    DataSourceMeta<Neo4jSession> neo4jSessionDataSourceMeta = new DataSourceMeta<Neo4jSession>(uri, username, (Neo4jSession) target);
    DataSourceWrapUtil.wrap(neo4jSessionDataSourceMeta);
    // 压测流量转发影子库
    if (!DataSourceWrapUtil.pressureDataSources.containsKey(neo4jSessionDataSourceMeta) || null == DataSourceWrapUtil.pressureDataSources.get(neo4jSessionDataSourceMeta)) {
        ErrorReporter.buildError().setErrorType(ErrorTypeEnum.DataSource).setErrorCode("datasource-0002").setMessage("没有配置对应的影子库!").setDetail("Neo4J").closePradar(ConfigNames.SHADOW_DATABASE_CONFIGS).report();
        throw new PressureMeasureError("Neo4J-002:影子库配置不存在!");
    }
    DbMediatorDataSource<?> dbMediatorDataSource = DataSourceWrapUtil.pressureDataSources.get(neo4jSessionDataSourceMeta);
    Neo4JSessionExt dataSourcePerformanceTest = (Neo4JSessionExt) dbMediatorDataSource.getDataSourcePerformanceTest();
    Operation operation = Neo4JSessionOperation.of(methodName);
    PradarSwitcher.httpPassPrefix.set(dataSourcePerformanceTest.getDriver().getConfiguration().getURI());
    return CutOffResult.cutoff(operation.invoke(dataSourcePerformanceTest, args));
}
Also used : Neo4JSessionExt(com.pamirs.attach.plugin.neo4j.config.Neo4JSessionExt) AuthTokenCredentials(org.neo4j.ogm.authentication.AuthTokenCredentials) DriverConfiguration(org.neo4j.ogm.config.DriverConfiguration) Driver(org.neo4j.ogm.driver.Driver) Operation(com.pamirs.attach.plugin.neo4j.operation.Operation) Neo4JSessionOperation(com.pamirs.attach.plugin.neo4j.config.Neo4JSessionOperation) DataSourceMeta(com.pamirs.pradar.pressurement.agent.shared.service.DataSourceMeta) UsernamePasswordCredentials(org.neo4j.ogm.authentication.UsernamePasswordCredentials) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) Neo4jSession(org.neo4j.ogm.session.Neo4jSession) AuthTokenCredentials(org.neo4j.ogm.authentication.AuthTokenCredentials) Credentials(org.neo4j.ogm.authentication.Credentials) UsernamePasswordCredentials(org.neo4j.ogm.authentication.UsernamePasswordCredentials)

Example 2 with Driver

use of org.neo4j.ogm.driver.Driver in project neo4j-ogm by neo4j.

the class BoltCypherExceptionTest method initSessionFactory.

@BeforeClass
public static void initSessionFactory() {
    Driver driver = new BoltDriver(GraphDatabase.driver(serverControls.boltURI(), Config.builder().withoutEncryption().build()));
    sessionFactory = new SessionFactory(driver, DOMAIN_PACKAGE);
}
Also used : SessionFactory(org.neo4j.ogm.session.SessionFactory) Driver(org.neo4j.ogm.driver.Driver) BeforeClass(org.junit.BeforeClass)

Example 3 with Driver

use of org.neo4j.ogm.driver.Driver in project neo4j-ogm by neo4j.

the class BoltDriverServiceTest method loadBoltDriver.

@Test
public void loadBoltDriver() {
    String uri = new Configuration.Builder(new ClasspathConfigurationSource("ogm.properties")).build().getURI();
    Configuration driverConfiguration = new Configuration.Builder().uri(uri).build();
    SessionFactory sf = new SessionFactory(driverConfiguration, "org.neo4j.ogm.domain.social.User");
    Driver driver = sf.unwrap(Driver.class);
    assertThat(driver).isNotNull();
    sf.close();
}
Also used : SessionFactory(org.neo4j.ogm.session.SessionFactory) ClasspathConfigurationSource(org.neo4j.ogm.config.ClasspathConfigurationSource) Configuration(org.neo4j.ogm.config.Configuration) Driver(org.neo4j.ogm.driver.Driver) Test(org.junit.Test)

Example 4 with Driver

use of org.neo4j.ogm.driver.Driver in project neo4j-ogm by neo4j.

the class EmbeddedCypherExceptionTest method initSessionFactory.

@BeforeClass
public static void initSessionFactory() {
    Driver driver = new EmbeddedDriver(serverControls.defaultDatabaseService(), new Configuration.Builder().build());
    sessionFactory = new SessionFactory(driver, DOMAIN_PACKAGE);
}
Also used : SessionFactory(org.neo4j.ogm.session.SessionFactory) Driver(org.neo4j.ogm.driver.Driver) BeforeClass(org.junit.BeforeClass)

Example 5 with Driver

use of org.neo4j.ogm.driver.Driver in project neo4j-ogm by neo4j.

the class CypherModificationSPITest method driverShouldNotProvideModificationWithoutConfiguration.

@Test
public void driverShouldNotProvideModificationWithoutConfiguration() {
    Driver driver = new TestDriver();
    assertThatExceptionOfType(IllegalStateException.class).isThrownBy(driver::getCypherModification).withMessage("Driver is not configured and cannot load Cypher modifications.").withNoCause();
}
Also used : AbstractConfigurableDriver(org.neo4j.ogm.driver.AbstractConfigurableDriver) Driver(org.neo4j.ogm.driver.Driver) Test(org.junit.Test)

Aggregations

Driver (org.neo4j.ogm.driver.Driver)15 SessionFactory (org.neo4j.ogm.session.SessionFactory)8 Test (org.junit.Test)6 Configuration (org.neo4j.ogm.config.Configuration)6 BeforeClass (org.junit.BeforeClass)5 Neo4JSessionExt (com.pamirs.attach.plugin.neo4j.config.Neo4JSessionExt)3 DriverConfiguration (org.neo4j.ogm.config.DriverConfiguration)3 AbstractConfigurableDriver (org.neo4j.ogm.driver.AbstractConfigurableDriver)3 HttpDriver (org.neo4j.ogm.drivers.http.driver.HttpDriver)3 BoltDriver (org.neo4j.ogm.drivers.bolt.driver.BoltDriver)2 Neo4jSession (org.neo4j.ogm.session.Neo4jSession)2 DriverConfig (com.pamirs.attach.plugin.neo4j.config.DriverConfig)1 Neo4JSessionOperation (com.pamirs.attach.plugin.neo4j.config.Neo4JSessionOperation)1 Operation (com.pamirs.attach.plugin.neo4j.operation.Operation)1 PressureMeasureError (com.pamirs.pradar.exception.PressureMeasureError)1 ShadowDatabaseConfig (com.pamirs.pradar.internal.config.ShadowDatabaseConfig)1 DataSourceMeta (com.pamirs.pradar.pressurement.agent.shared.service.DataSourceMeta)1 AuthTokenCredentials (org.neo4j.ogm.authentication.AuthTokenCredentials)1 Credentials (org.neo4j.ogm.authentication.Credentials)1 UsernamePasswordCredentials (org.neo4j.ogm.authentication.UsernamePasswordCredentials)1