Search in sources :

Example 1 with QueryExecutionException

use of org.neo4j.graphdb.QueryExecutionException in project neo4j by neo4j.

the class EmbeddedBuiltInProceduresInteractionTest method shouldNotKillQueryIfNotAuthenticated.

@Test
public void shouldNotKillQueryIfNotAuthenticated() throws Throwable {
    EnterpriseSecurityContext authy = createFakeAnonymousEnterpriseSecurityContext();
    GraphDatabaseFacade graph = neo.getLocalGraph();
    DoubleLatch latch = new DoubleLatch(2);
    ThreadedTransaction<EnterpriseSecurityContext> read = new ThreadedTransaction<>(neo, latch);
    String query = read.execute(threading, authy, "UNWIND [1,2,3] AS x RETURN x");
    latch.startAndWaitForAllToStart();
    String id = extractQueryId(query);
    try (InternalTransaction tx = graph.beginTransaction(KernelTransaction.Type.explicit, AnonymousContext.none())) {
        graph.execute(tx, "CALL dbms.killQuery('" + id + "')", Collections.emptyMap());
        throw new AssertionError("Expected exception to be thrown");
    } catch (QueryExecutionException e) {
        assertThat(e.getMessage(), containsString(PERMISSION_DENIED));
    }
    latch.finishAndWaitForAllToFinish();
    read.closeAndAssertSuccess();
}
Also used : EnterpriseSecurityContext(org.neo4j.kernel.enterprise.api.security.EnterpriseSecurityContext) QueryExecutionException(org.neo4j.graphdb.QueryExecutionException) DoubleLatch(org.neo4j.test.DoubleLatch) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Test(org.junit.Test)

Example 2 with QueryExecutionException

use of org.neo4j.graphdb.QueryExecutionException in project neo4j by neo4j.

the class TestFabricTransaction method execute.

@Override
public Result execute(String query, Map<String, Object> parameters) throws QueryExecutionException {
    var ctx = new TestFabricTransactionalContext(kernelInternalTransaction);
    var params = ValueUtils.asParameterMapValue(parameters);
    var result = new ResultSubscriber(ctx, ctx.valueMapper());
    try {
        BoltQueryExecution boltQueryExecution = fabricTransaction.executeQuery(query, params, false, result);
        result.init(boltQueryExecution.getQueryExecution());
    } catch (FabricException e) {
        if (e.getCause() instanceof RuntimeException) {
            throw (RuntimeException) e.getCause();
        } else {
            throw new QueryExecutionException(e.getMessage(), e, e.status().code().serialize());
        }
    } catch (QueryExecutionKernelException | Neo4jException e) {
        throw new QueryExecutionException(e.getMessage(), e, e.status().code().serialize());
    }
    return result;
}
Also used : BoltQueryExecution(org.neo4j.bolt.dbapi.BoltQueryExecution) QueryExecutionException(org.neo4j.graphdb.QueryExecutionException) QueryExecutionKernelException(org.neo4j.kernel.impl.query.QueryExecutionKernelException) ResultSubscriber(org.neo4j.cypher.internal.javacompat.ResultSubscriber) FabricException(org.neo4j.fabric.executor.FabricException) Neo4jException(org.neo4j.exceptions.Neo4jException)

Example 3 with QueryExecutionException

use of org.neo4j.graphdb.QueryExecutionException in project neo4j by neo4j.

the class NotificationAcceptanceTest method shouldGetErrorWhenUsingCreateUniqueWhenCypherVersionIs3_5.

@Test
void shouldGetErrorWhenUsingCreateUniqueWhenCypherVersionIs3_5() {
    // when
    QueryExecutionException exception = assertThrows(QueryExecutionException.class, () -> db.executeTransactionally("CYPHER 3.5 MATCH (b) WITH b LIMIT 1 CREATE UNIQUE (b)-[:REL]->()"));
    assertThat(exception.getStatusCode(), containsString("SyntaxError"));
}
Also used : QueryExecutionException(org.neo4j.graphdb.QueryExecutionException) Test(org.junit.jupiter.api.Test)

Example 4 with QueryExecutionException

use of org.neo4j.graphdb.QueryExecutionException in project neo4j by neo4j.

the class PropertyConstraintsStressIT method createPropertyExistenceConstraintCommand.

private static WorkerCommand<Object, Boolean> createPropertyExistenceConstraintCommand(final GraphDatabaseService db, final String query) {
    return new WorkerCommand<Object, Boolean>() {

        @Override
        public Boolean doWork(Object state) throws Exception {
            boolean constraintCreationFailed = false;
            try (Transaction tx = db.beginTx()) {
                db.execute(query);
                tx.success();
            } catch (QueryExecutionException e) {
                System.out.println("Constraint failed: " + e.getMessage());
                if (Exceptions.rootCause(e) instanceof ConstraintValidationException) {
                    // Unable to create constraint since it is not consistent with existing data
                    constraintCreationFailed = true;
                } else {
                    throw e;
                }
            }
            if (!constraintCreationFailed) {
                System.out.println("Constraint created: " + query);
            }
            return constraintCreationFailed;
        }
    };
}
Also used : WorkerCommand(org.neo4j.test.OtherThreadExecutor.WorkerCommand) QueryExecutionException(org.neo4j.graphdb.QueryExecutionException) Transaction(org.neo4j.graphdb.Transaction) ConstraintValidationException(org.neo4j.kernel.api.exceptions.schema.ConstraintValidationException)

Example 5 with QueryExecutionException

use of org.neo4j.graphdb.QueryExecutionException in project neo4j by neo4j.

the class AbstractConstraintCreationIT method shouldNotLeaveAnyStateBehindAfterFailingToCreateConstraint.

@Test
public void shouldNotLeaveAnyStateBehindAfterFailingToCreateConstraint() throws Exception {
    // given
    try (Transaction tx = db.beginTx()) {
        createOffendingDataInRunningTx(db);
        tx.success();
    }
    // when
    try (Transaction tx = db.beginTx()) {
        createConstraintInRunningTx(db, KEY, PROP);
        tx.success();
        fail("expected failure");
    } catch (QueryExecutionException e) {
        assertThat(e.getMessage(), startsWith("Unable to create CONSTRAINT"));
    }
    // then
    try (Transaction tx = db.beginTx()) {
        assertEquals(Collections.<ConstraintDefinition>emptyList(), Iterables.asList(db.schema().getConstraints()));
        assertEquals(Collections.<IndexDefinition, Schema.IndexState>emptyMap(), indexesWithState(db.schema()));
        tx.success();
    }
}
Also used : QueryExecutionException(org.neo4j.graphdb.QueryExecutionException) Transaction(org.neo4j.graphdb.Transaction) Schema(org.neo4j.graphdb.schema.Schema) Test(org.junit.Test)

Aggregations

QueryExecutionException (org.neo4j.graphdb.QueryExecutionException)9 Transaction (org.neo4j.graphdb.Transaction)4 Test (org.junit.Test)3 Test (org.junit.jupiter.api.Test)3 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)3 Path (java.nio.file.Path)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 BoltQueryExecution (org.neo4j.bolt.dbapi.BoltQueryExecution)1 ResultSubscriber (org.neo4j.cypher.internal.javacompat.ResultSubscriber)1 DatabaseManagementException (org.neo4j.dbms.api.DatabaseManagementException)1 KernelException (org.neo4j.exceptions.KernelException)1 Neo4jException (org.neo4j.exceptions.Neo4jException)1 FabricException (org.neo4j.fabric.executor.FabricException)1 Schema (org.neo4j.graphdb.schema.Schema)1 SchemaWriteOperations (org.neo4j.kernel.api.SchemaWriteOperations)1 ConstraintValidationException (org.neo4j.kernel.api.exceptions.schema.ConstraintValidationException)1 EnterpriseSecurityContext (org.neo4j.kernel.enterprise.api.security.EnterpriseSecurityContext)1 GraphDatabaseFacade (org.neo4j.kernel.impl.factory.GraphDatabaseFacade)1 QueryExecutionKernelException (org.neo4j.kernel.impl.query.QueryExecutionKernelException)1 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)1