use of org.neo4j.graphdb.security.WriteOperationsNotAllowedException in project neo4j by neo4j.
the class ReadOnlySlaveTest method givenClusterWithReadOnlySlaveWhenWriteTxOnSlaveThenCommitFails.
@Test
public void givenClusterWithReadOnlySlaveWhenWriteTxOnSlaveThenCommitFails() throws Throwable {
// When
ManagedCluster cluster = clusterRule.startCluster();
HighlyAvailableGraphDatabase readOnlySlave = cluster.getMemberByServerId(new InstanceId(2));
try (Transaction tx = readOnlySlave.beginTx()) {
readOnlySlave.createNode();
tx.success();
fail("Should have thrown exception");
} catch (WriteOperationsNotAllowedException ex) {
// Then
}
}
use of org.neo4j.graphdb.security.WriteOperationsNotAllowedException in project neo4j by neo4j.
the class ReadOnlySlaveTest method givenClusterWithReadOnlySlaveWhenAddNewRelTypeOnSlaveThenThrowException.
@Test
public void givenClusterWithReadOnlySlaveWhenAddNewRelTypeOnSlaveThenThrowException() throws Throwable {
// Given
ManagedCluster cluster = clusterRule.startCluster();
Node node;
Node node2;
HighlyAvailableGraphDatabase master = cluster.getMaster();
try (Transaction tx = master.beginTx()) {
node = master.createNode();
node2 = master.createNode();
tx.success();
}
// When
HighlyAvailableGraphDatabase readOnlySlave = cluster.getMemberByServerId(new InstanceId(2));
try (Transaction tx = readOnlySlave.beginTx()) {
Node slaveNode = readOnlySlave.getNodeById(node.getId());
Node slaveNode2 = readOnlySlave.getNodeById(node2.getId());
// Then
slaveNode.createRelationshipTo(slaveNode2, RelationshipType.withName("KNOWS"));
tx.success();
fail("Should have thrown exception");
} catch (WriteOperationsNotAllowedException ex) {
// Ok!
}
}
use of org.neo4j.graphdb.security.WriteOperationsNotAllowedException in project neo4j by neo4j.
the class TransactionHandle method executeStatements.
private void executeStatements(StatementDeserializer statements, ExecutionResultSerializer output, List<Neo4jError> errors, HttpServletRequest request) {
try {
boolean hasPrevious = false;
while (statements.hasNext()) {
Statement statement = statements.next();
try {
boolean hasPeriodicCommit = engine.isPeriodicCommit(statement.statement());
if ((statements.hasNext() || hasPrevious) && hasPeriodicCommit) {
throw new QueryExecutionKernelException(new InvalidSemanticsException("Cannot execute another statement after executing " + "PERIODIC COMMIT statement in the same transaction"));
}
if (!hasPrevious && hasPeriodicCommit) {
context.closeTransactionForPeriodicCommit();
}
hasPrevious = true;
TransactionalContext tc = txManagerFacade.create(request, queryService, type, securityContext, statement.statement(), statement.parameters());
Result result = safelyExecute(statement, hasPeriodicCommit, tc);
output.statementResult(result, statement.includeStats(), statement.resultDataContents());
output.notifications(result.getNotifications());
} catch (KernelException | CypherException | AuthorizationViolationException | WriteOperationsNotAllowedException e) {
errors.add(new Neo4jError(e.status(), e));
break;
} catch (DeadlockDetectedException e) {
errors.add(new Neo4jError(Status.Transaction.DeadlockDetected, e));
} catch (IOException e) {
errors.add(new Neo4jError(Status.Network.CommunicationError, e));
break;
} catch (Exception e) {
Throwable cause = e.getCause();
if (cause instanceof Status.HasStatus) {
errors.add(new Neo4jError(((Status.HasStatus) cause).status(), cause));
} else {
errors.add(new Neo4jError(Status.Statement.ExecutionFailed, e));
}
break;
}
}
addToCollection(statements.errors(), errors);
} catch (Throwable e) {
errors.add(new Neo4jError(Status.General.UnknownError, e));
}
}
use of org.neo4j.graphdb.security.WriteOperationsNotAllowedException in project neo4j by neo4j.
the class ReadReplicaReplicationIT method shouldNotBeAbleToWriteToReadReplica.
@Test
public void shouldNotBeAbleToWriteToReadReplica() throws Exception {
// given
Cluster cluster = clusterRule.startCluster();
ReadReplicaGraphDatabase readReplica = cluster.findAnyReadReplica().database();
// when
try (Transaction tx = readReplica.beginTx()) {
Node node = readReplica.createNode();
node.setProperty("foobar", "baz_bat");
node.addLabel(Label.label("Foo"));
tx.success();
fail("should have thrown");
} catch (WriteOperationsNotAllowedException e) {
// then all good
}
}
use of org.neo4j.graphdb.security.WriteOperationsNotAllowedException in project neo4j by neo4j.
the class RestartIT method restartWhileDoingTransactions.
@Test
public void restartWhileDoingTransactions() throws Exception {
// given
Cluster cluster = clusterRule.startCluster();
// when
final GraphDatabaseService coreDB = cluster.getCoreMemberById(0).database();
ExecutorService executor = Executors.newCachedThreadPool();
final AtomicBoolean done = new AtomicBoolean(false);
executor.execute(() -> {
while (!done.get()) {
try (Transaction tx = coreDB.beginTx()) {
Node node = coreDB.createNode(label("boo"));
node.setProperty("foobar", "baz_bat");
tx.success();
} catch (AcquireLockTimeoutException | WriteOperationsNotAllowedException e) {
// expected sometimes
}
}
});
Thread.sleep(500);
cluster.removeCoreMemberWithMemberId(1);
cluster.addCoreMemberWithId(1).start();
Thread.sleep(500);
// then
done.set(true);
executor.shutdown();
}
Aggregations