Search in sources :

Example 1 with Driver

use of org.h2.Driver in project sonarqube by SonarSource.

the class DdlUtilsTest method shouldCreateSchema_without_schema_migrations.

@Test
public void shouldCreateSchema_without_schema_migrations() throws SQLException {
    DriverManager.registerDriver(new Driver());
    try (Connection connection = DriverManager.getConnection("jdbc:h2:mem:sonar_test2")) {
        try (Statement statement = connection.createStatement()) {
            statement.execute("create table schema_migrations (version varchar(255) not null)");
        }
        DdlUtils.createSchema(connection, "h2", false);
        verifySchemaMigrations(connection);
    }
}
Also used : Statement(java.sql.Statement) Connection(java.sql.Connection) Driver(org.h2.Driver) Test(org.junit.Test)

Example 2 with Driver

use of org.h2.Driver in project sonarqube by SonarSource.

the class DdlUtilsTest method shouldCreateSchema_with_schema_migrations.

@Test
public void shouldCreateSchema_with_schema_migrations() throws SQLException {
    DriverManager.registerDriver(new Driver());
    try (Connection connection = DriverManager.getConnection("jdbc:h2:mem:sonar_test")) {
        DdlUtils.createSchema(connection, "h2", true);
        int tableCount = countTables(connection);
        assertThat(tableCount).isGreaterThan(30);
        verifySchemaMigrations(connection);
    }
}
Also used : Connection(java.sql.Connection) Driver(org.h2.Driver) Test(org.junit.Test)

Example 3 with Driver

use of org.h2.Driver in project neo4j by neo4j.

the class ProcedureTest method calls_simplistic_procedure.

@Test
public void calls_simplistic_procedure() {
    try (Driver driver = GraphDatabase.driver(graphDb.boltURI(), configuration());
        Session session = driver.session()) {
        StatementResult result = session.run("CALL " + procedureNamespace + ".theAnswer()");
        assertThat(result.single().get("value").asLong()).isEqualTo(42L);
    }
}
Also used : StatementResult(org.neo4j.driver.v1.StatementResult) Driver(org.neo4j.driver.v1.Driver) Session(org.neo4j.driver.v1.Session) Test(org.junit.Test)

Example 4 with Driver

use of org.h2.Driver in project neo4j by neo4j.

the class BoltCausalClusteringIT method sessionShouldExpireOnLeaderSwitch.

@Test
public void sessionShouldExpireOnLeaderSwitch() throws Exception {
    // given
    cluster = clusterRule.withNumberOfReadReplicas(0).startCluster();
    CoreClusterMember leader = cluster.awaitLeader();
    Driver driver = GraphDatabase.driver(leader.routingURI(), AuthTokens.basic("neo4j", "neo4j"));
    try (Session session = driver.session()) {
        session.run("CREATE (n:Person {name: 'Jim'})").consume();
        // when
        switchLeader(leader);
        session.run("CREATE (n:Person {name: 'Mark'})").consume();
        fail("Should have thrown exception");
    } catch (SessionExpiredException sep) {
        // then
        assertEquals(String.format("Server at %s no longer accepts writes", leader.boltAdvertisedAddress()), sep.getMessage());
    } finally {
        driver.close();
    }
}
Also used : CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Driver(org.neo4j.driver.v1.Driver) SessionExpiredException(org.neo4j.driver.v1.exceptions.SessionExpiredException) Session(org.neo4j.driver.v1.Session) RoutingNetworkSession(org.neo4j.driver.internal.RoutingNetworkSession) Test(org.junit.Test)

Example 5 with Driver

use of org.h2.Driver in project neo4j by neo4j.

the class BoltCausalClusteringIT method shouldSendRequestsToNewlyAddedReadReplicas.

@Test
public void shouldSendRequestsToNewlyAddedReadReplicas() throws Throwable {
    // given
    cluster = clusterRule.withNumberOfReadReplicas(1).withSharedCoreParams(stringMap(CausalClusteringSettings.cluster_routing_ttl.name(), "1s")).startCluster();
    CoreClusterMember leader = cluster.awaitLeader();
    Driver driver = GraphDatabase.driver(leader.routingURI(), AuthTokens.basic("neo4j", "neo4j"));
    String bookmark = inExpirableSession(driver, (d) -> d.session(AccessMode.WRITE), (session) -> {
        try (Transaction tx = session.beginTransaction()) {
            tx.run("CREATE (p:Person {name: {name} })", Values.parameters("name", "Jim"));
            tx.success();
        }
        return session.lastBookmark();
    });
    // when
    Set<String> readReplicas = new HashSet<>();
    for (ReadReplica readReplica : cluster.readReplicas()) {
        readReplicas.add(readReplica.boltAdvertisedAddress());
    }
    for (int i = 10; i <= 13; i++) {
        ReadReplica newReadReplica = cluster.addReadReplicaWithId(i);
        readReplicas.add(newReadReplica.boltAdvertisedAddress());
        newReadReplica.start();
    }
    assertEventually("Failed to send requests to all servers", () -> {
        for (// don't care about cores
        int i = 0; // don't care about cores
        i < cluster.readReplicas().size(); // don't care about cores
        i++) {
            try (Session session = driver.session(AccessMode.READ)) {
                BoltServerAddress boltServerAddress = ((RoutingNetworkSession) session).address();
                executeReadQuery(bookmark, session);
                readReplicas.remove(boltServerAddress.toString());
            } catch (Throwable throwable) {
                return false;
            }
        }
        // have sent something to all replicas
        return readReplicas.size() == 0;
    }, is(true), 30, SECONDS);
}
Also used : ReadReplica(org.neo4j.causalclustering.discovery.ReadReplica) Transaction(org.neo4j.driver.v1.Transaction) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Driver(org.neo4j.driver.v1.Driver) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) RoutingNetworkSession(org.neo4j.driver.internal.RoutingNetworkSession) HashSet(java.util.HashSet) Session(org.neo4j.driver.v1.Session) RoutingNetworkSession(org.neo4j.driver.internal.RoutingNetworkSession) BoltServerAddress(org.neo4j.driver.internal.net.BoltServerAddress) Test(org.junit.Test)

Aggregations

Driver (org.neo4j.driver.v1.Driver)40 Test (org.junit.Test)36 Session (org.neo4j.driver.v1.Session)29 Connection (java.sql.Connection)22 StatementResult (org.neo4j.driver.v1.StatementResult)16 Statement (java.sql.Statement)14 SQLException (java.sql.SQLException)11 CoreClusterMember (org.neo4j.causalclustering.discovery.CoreClusterMember)10 Record (org.neo4j.driver.v1.Record)10 RoutingNetworkSession (org.neo4j.driver.internal.RoutingNetworkSession)9 IOException (java.io.IOException)8 Driver (org.h2.Driver)8 PreparedStatement (java.sql.PreparedStatement)7 ResultSet (java.sql.ResultSet)7 HashSet (java.util.HashSet)5 PrintStream (java.io.PrintStream)4 Server (org.h2.tools.Server)4 SessionExpiredException (org.neo4j.driver.v1.exceptions.SessionExpiredException)4 PathInfoData (org.openkilda.messaging.info.event.PathInfoData)4 Flow (org.openkilda.messaging.model.Flow)4