Search in sources :

Example 11 with WriteOperationsNotAllowedException

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

the class CoreReplicationIT method shouldNotAllowTokenCreationFromAFollowerWithNoInitialTokens.

@Test
public void shouldNotAllowTokenCreationFromAFollowerWithNoInitialTokens() throws Exception {
    // given
    CoreClusterMember leader = cluster.coreTx((db, tx) -> {
        db.createNode();
        tx.success();
    });
    awaitForDataToBeApplied(leader);
    dataMatchesEventually(leader, cluster.coreMembers());
    CoreGraphDatabase follower = cluster.getDbWithRole(Role.FOLLOWER).database();
    // when
    try (Transaction tx = follower.beginTx()) {
        follower.getAllNodes().iterator().next().setProperty("name", "Mark");
        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) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) CoreGraphDatabase(org.neo4j.causalclustering.core.CoreGraphDatabase) WriteOperationsNotAllowedException(org.neo4j.graphdb.security.WriteOperationsNotAllowedException) Test(org.junit.Test)

Example 12 with WriteOperationsNotAllowedException

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

the class ReadOnlySlaveTest method givenClusterWithReadOnlySlaveWhenChangePropertyOnSlaveThenThrowException.

@Test
public void givenClusterWithReadOnlySlaveWhenChangePropertyOnSlaveThenThrowException() 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.setProperty("foo", "bar");
        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