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();
}
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
}
}
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"));
}
}
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"));
}
}
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!
}
}
Aggregations