Search in sources :

Example 46 with ProcedureException

use of org.neo4j.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.

the class ResampleIndexProcedureTest method shouldThrowAnExceptionIfTheIndexDoesNotExist.

@Test
public void shouldThrowAnExceptionIfTheIndexDoesNotExist() throws SchemaRuleNotFoundException, IndexNotFoundKernelException {
    when(operations.labelGetForName(anyString())).thenReturn(0);
    when(operations.propertyKeyGetForName(anyString())).thenReturn(0);
    when(operations.indexGetForLabelAndPropertyKey(any())).thenThrow(new SchemaRuleNotFoundException(INDEX_RULE, SchemaDescriptorFactory.forLabel(0, 0)));
    try {
        procedure.resampleIndex(":Person(name)");
        fail("Expected an exception");
    } catch (ProcedureException e) {
        assertThat(e.status(), is(Status.Schema.IndexNotFound));
    }
}
Also used : SchemaRuleNotFoundException(org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Test(org.junit.Test)

Example 47 with ProcedureException

use of org.neo4j.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.

the class BuiltInProceduresIT method listAllIndexes.

@Test
public void listAllIndexes() throws Throwable {
    // Given
    Statement statement = statementInNewTransaction(SecurityContext.AUTH_DISABLED);
    int labelId1 = statement.tokenWriteOperations().labelGetOrCreateForName("Person");
    int labelId2 = statement.tokenWriteOperations().labelGetOrCreateForName("Age");
    int propertyKeyId = statement.tokenWriteOperations().propertyKeyGetOrCreateForName("foo");
    //TODO: Add test support for composite indexes
    statement.schemaWriteOperations().indexCreate(SchemaDescriptorFactory.forLabel(labelId1, propertyKeyId));
    statement.schemaWriteOperations().uniquePropertyConstraintCreate(forLabel(labelId2, propertyKeyId));
    commit();
    //let indexes come online
    try (Transaction tx = db.beginTx()) {
        db.schema().awaitIndexOnline(db.schema().getIndexes().iterator().next(), 20, SECONDS);
        tx.success();
    }
    // When
    RawIterator<Object[], ProcedureException> stream = procedureCallOpsInNewTx().procedureCallRead(procedureName("db", "indexes"), new Object[0]);
    Set<Object[]> result = new HashSet<>();
    while (stream.hasNext()) {
        result.add(stream.next());
    }
    // Then
    assertThat(result, containsInAnyOrder(new Object[] { "INDEX ON :Age(foo)", "ONLINE", "node_unique_property" }, new Object[] { "INDEX ON :Person(foo)", "ONLINE", "node_label_property" }));
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Statement(org.neo4j.kernel.api.Statement) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 48 with ProcedureException

use of org.neo4j.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.

the class BuiltInProceduresIT method listPropertyKeys.

@Test
public void listPropertyKeys() throws Throwable {
    // Given
    TokenWriteOperations ops = tokenWriteOperationsInNewTransaction();
    ops.propertyKeyGetOrCreateForName("MyProp");
    commit();
    // When
    RawIterator<Object[], ProcedureException> stream = procedureCallOpsInNewTx().procedureCallRead(procedureName("db", "propertyKeys"), new Object[0]);
    // Then
    assertThat(asList(stream), contains(equalTo(new Object[] { "MyProp" })));
}
Also used : TokenWriteOperations(org.neo4j.kernel.api.TokenWriteOperations) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Test(org.junit.Test)

Example 49 with ProcedureException

use of org.neo4j.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.

the class ReflectiveProcedureWithArgumentsTest method shouldRunGenericProcedure.

@Test
public void shouldRunGenericProcedure() throws Throwable {
    // Given
    CallableProcedure procedure = compile(ClassWithProcedureWithGenericArgs.class).get(0);
    // When
    RawIterator<Object[], ProcedureException> out = procedure.apply(new BasicContext(), new Object[] { Arrays.asList("Roland", "Eddie", "Susan", "Jake"), Arrays.asList(1000L, 23L, 29L, 12L) });
    // Then
    List<Object[]> collect = asList(out);
    assertThat(collect.get(0)[0], equalTo("Roland is 1000 years old."));
    assertThat(collect.get(1)[0], equalTo("Eddie is 23 years old."));
    assertThat(collect.get(2)[0], equalTo("Susan is 29 years old."));
    assertThat(collect.get(3)[0], equalTo("Jake is 12 years old."));
}
Also used : BasicContext(org.neo4j.kernel.api.proc.BasicContext) CallableProcedure(org.neo4j.kernel.api.proc.CallableProcedure) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Test(org.junit.Test)

Aggregations

ProcedureException (org.neo4j.kernel.api.exceptions.ProcedureException)49 Test (org.junit.Test)28 CallableProcedure (org.neo4j.kernel.api.proc.CallableProcedure)14 BasicContext (org.neo4j.kernel.api.proc.BasicContext)10 MethodHandle (java.lang.invoke.MethodHandle)8 ArrayList (java.util.ArrayList)8 CallableUserFunction (org.neo4j.kernel.api.proc.CallableUserFunction)8 FieldSignature (org.neo4j.kernel.api.proc.FieldSignature)8 QualifiedName (org.neo4j.kernel.api.proc.QualifiedName)8 ComponentInjectionException (org.neo4j.kernel.api.exceptions.ComponentInjectionException)7 UserFunctionSignature (org.neo4j.kernel.api.proc.UserFunctionSignature)7 RawIterator (org.neo4j.collection.RawIterator)6 Context (org.neo4j.kernel.api.proc.Context)6 Log (org.neo4j.logging.Log)6 List (java.util.List)5 Statement (org.neo4j.kernel.api.Statement)5 ProcedureSignature (org.neo4j.kernel.api.proc.ProcedureSignature)5 Procedure (org.neo4j.procedure.Procedure)5 Method (java.lang.reflect.Method)4 Comparator (java.util.Comparator)4