Search in sources :

Example 1 with WriteOperationsNotAllowedException

use of org.neo4j.graphdb.security.WriteOperationsNotAllowedException in project neo4j by neo4j.

the class TestReadOnlyNeo4j method testSimple.

@Test
public void testSimple() {
    DbRepresentation someData = createSomeData();
    GraphDatabaseService readGraphDb = new TestGraphDatabaseFactory().setFileSystem(new UncloseableDelegatingFileSystemAbstraction(fs.get())).newImpermanentDatabaseBuilder(PATH).setConfig(GraphDatabaseSettings.read_only, Settings.TRUE).newGraphDatabase();
    assertEquals(someData, DbRepresentation.of(readGraphDb));
    try (Transaction tx = readGraphDb.beginTx()) {
        readGraphDb.createNode();
        tx.success();
    } catch (WriteOperationsNotAllowedException e) {
    // good
    }
    readGraphDb.shutdown();
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) UncloseableDelegatingFileSystemAbstraction(org.neo4j.graphdb.mockfs.UncloseableDelegatingFileSystemAbstraction) DbRepresentation(org.neo4j.test.DbRepresentation) WriteOperationsNotAllowedException(org.neo4j.graphdb.security.WriteOperationsNotAllowedException) Test(org.junit.Test)

Example 2 with WriteOperationsNotAllowedException

use of org.neo4j.graphdb.security.WriteOperationsNotAllowedException in project neo4j by neo4j.

the class ClusterShutdownIT method shouldShutdownEvenThoughWaitingForLock.

@Test
public void shouldShutdownEvenThoughWaitingForLock() throws Exception {
    Cluster cluster = clusterRule.startCluster();
    try {
        for (int victimId = 0; victimId < cluster.numberOfCoreMembersReportedByTopology(); victimId++) {
            assertTrue(cluster.getCoreMemberById(victimId).database().isAvailable(1000));
            shouldShutdownEvenThoughWaitingForLock0(cluster, victimId, shutdownOrder);
            cluster.start();
        }
    } catch (WriteOperationsNotAllowedException e) {
    // expected
    }
}
Also used : Cluster(org.neo4j.causalclustering.discovery.Cluster) WriteOperationsNotAllowedException(org.neo4j.graphdb.security.WriteOperationsNotAllowedException) Test(org.junit.Test)

Example 3 with WriteOperationsNotAllowedException

use of org.neo4j.graphdb.security.WriteOperationsNotAllowedException in project neo4j by neo4j.

the class CoreReplicationIT method shouldNotAllowWritesFromAFollower.

@Test
public void shouldNotAllowWritesFromAFollower() throws Exception {
    // given
    cluster.awaitLeader();
    CoreGraphDatabase follower = cluster.getDbWithRole(Role.FOLLOWER).database();
    // when
    try (Transaction tx = follower.beginTx()) {
        follower.createNode();
        tx.success();
        fail("Should have thrown exception");
    } catch (WriteOperationsNotAllowedException ignored) {
        // expected
        assertThat(ignored.getMessage(), containsString("No write operations are allowed"));
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) CoreGraphDatabase(org.neo4j.causalclustering.core.CoreGraphDatabase) WriteOperationsNotAllowedException(org.neo4j.graphdb.security.WriteOperationsNotAllowedException) Test(org.junit.Test)

Example 4 with WriteOperationsNotAllowedException

use of org.neo4j.graphdb.security.WriteOperationsNotAllowedException in project neo4j by neo4j.

the class CoreReplicationIT method shouldNotAllowSchemaChangesFromAFollower.

@Test
public void shouldNotAllowSchemaChangesFromAFollower() throws Exception {
    // given
    cluster.awaitLeader();
    CoreGraphDatabase follower = cluster.getDbWithRole(Role.FOLLOWER).database();
    // when
    try (Transaction tx = follower.beginTx()) {
        follower.schema().constraintFor(Label.label("Foo")).assertPropertyIsUnique("name").create();
        tx.success();
        fail("Should have thrown exception");
    } catch (WriteOperationsNotAllowedException ignored) {
        // expected
        assertThat(ignored.getMessage(), containsString("No write operations are allowed"));
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) CoreGraphDatabase(org.neo4j.causalclustering.core.CoreGraphDatabase) WriteOperationsNotAllowedException(org.neo4j.graphdb.security.WriteOperationsNotAllowedException) Test(org.junit.Test)

Example 5 with WriteOperationsNotAllowedException

use of org.neo4j.graphdb.security.WriteOperationsNotAllowedException in project neo4j by neo4j.

the class ReadOnlySlaveTest method givenClusterWithReadOnlySlaveWhenAddNewLabelOnSlaveThenThrowException.

@Test
public void givenClusterWithReadOnlySlaveWhenAddNewLabelOnSlaveThenThrowException() throws Throwable {
    // Given
    ManagedCluster cluster = clusterRule.startCluster();
    Node node;
    HighlyAvailableGraphDatabase master = cluster.getMaster();
    try (Transaction tx = master.beginTx()) {
        node = master.createNode();
        tx.success();
    }
    // When
    HighlyAvailableGraphDatabase readOnlySlave = cluster.getMemberByServerId(new InstanceId(2));
    try (Transaction tx = readOnlySlave.beginTx()) {
        Node slaveNode = readOnlySlave.getNodeById(node.getId());
        // Then
        slaveNode.addLabel(Label.label("FOO"));
        tx.success();
        fail("Should have thrown exception");
    } catch (WriteOperationsNotAllowedException ex) {
    // Ok!
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) InstanceId(org.neo4j.cluster.InstanceId) ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) Node(org.neo4j.graphdb.Node) WriteOperationsNotAllowedException(org.neo4j.graphdb.security.WriteOperationsNotAllowedException) Test(org.junit.Test)

Aggregations

WriteOperationsNotAllowedException (org.neo4j.graphdb.security.WriteOperationsNotAllowedException)12 Test (org.junit.Test)11 Transaction (org.neo4j.graphdb.Transaction)10 Node (org.neo4j.graphdb.Node)5 InstanceId (org.neo4j.cluster.InstanceId)4 HighlyAvailableGraphDatabase (org.neo4j.kernel.ha.HighlyAvailableGraphDatabase)4 ManagedCluster (org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster)4 CoreGraphDatabase (org.neo4j.causalclustering.core.CoreGraphDatabase)3 Cluster (org.neo4j.causalclustering.discovery.Cluster)3 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)2 IOException (java.io.IOException)1 ExecutorService (java.util.concurrent.ExecutorService)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 CoreClusterMember (org.neo4j.causalclustering.discovery.CoreClusterMember)1 ReadReplicaGraphDatabase (org.neo4j.causalclustering.readreplica.ReadReplicaGraphDatabase)1 CypherException (org.neo4j.cypher.CypherException)1 InvalidSemanticsException (org.neo4j.cypher.InvalidSemanticsException)1 Result (org.neo4j.graphdb.Result)1 UncloseableDelegatingFileSystemAbstraction (org.neo4j.graphdb.mockfs.UncloseableDelegatingFileSystemAbstraction)1 AuthorizationViolationException (org.neo4j.graphdb.security.AuthorizationViolationException)1