Search in sources :

Example 1 with ClientException

use of org.neo4j.driver.v1.exceptions.ClientException in project neo4j by neo4j.

the class BoltCausalClusteringIT method shouldNotBeAbleToWriteOnAReadSession.

@Test
public void shouldNotBeAbleToWriteOnAReadSession() throws Exception {
    // given
    cluster = clusterRule.withNumberOfReadReplicas(0).startCluster();
    assertEventually("Failed to execute write query on read server", () -> {
        switchLeader(cluster.awaitLeader());
        CoreClusterMember leader = cluster.awaitLeader();
        Driver driver = GraphDatabase.driver(leader.routingURI(), AuthTokens.basic("neo4j", "neo4j"));
        try (Session session = driver.session(AccessMode.READ)) {
            // when
            session.run("CREATE (n:Person {name: 'Jim'})").consume();
            return false;
        } catch (ClientException ex) {
            assertEquals("Write queries cannot be performed in READ access mode.", ex.getMessage());
            return true;
        } finally {
            driver.close();
        }
    }, is(true), 30, SECONDS);
}
Also used : CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Driver(org.neo4j.driver.v1.Driver) ClientException(org.neo4j.driver.v1.exceptions.ClientException) Session(org.neo4j.driver.v1.Session) RoutingNetworkSession(org.neo4j.driver.internal.RoutingNetworkSession) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 CoreClusterMember (org.neo4j.causalclustering.discovery.CoreClusterMember)1 RoutingNetworkSession (org.neo4j.driver.internal.RoutingNetworkSession)1 Driver (org.neo4j.driver.v1.Driver)1 Session (org.neo4j.driver.v1.Session)1 ClientException (org.neo4j.driver.v1.exceptions.ClientException)1