Search in sources :

Example 21 with ProcedureException

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

the class AwaitIndexProcedureTest method shouldThrowAnExceptionIfTheIndexDoesNotExist.

@Test
void shouldThrowAnExceptionIfTheIndexDoesNotExist() {
    when(schemaRead.indexGetForName(anyString())).thenReturn(IndexDescriptor.NO_INDEX);
    ProcedureException exception = assertThrows(ProcedureException.class, () -> procedure.awaitIndexByName("index", TIMEOUT, TIME_UNIT));
    assertThat(exception.status()).isEqualTo(Status.Schema.IndexNotFound);
}
Also used : ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Example 22 with ProcedureException

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

the class AwaitIndexProcedureTest method shouldThrowAnExceptionIfTheIndexHasFailed.

@Test
void shouldThrowAnExceptionIfTheIndexHasFailed() throws IndexNotFoundKernelException {
    when(schemaRead.indexGetForName(anyString())).thenReturn(anyIndex);
    when(schemaRead.indexGetState(any(IndexDescriptor.class))).thenReturn(FAILED);
    when(schemaRead.indexGetFailure(any(IndexDescriptor.class))).thenReturn(Exceptions.stringify(new Exception("Kilroy was here")));
    ProcedureException exception = assertThrows(ProcedureException.class, () -> procedure.awaitIndexByName("index", TIMEOUT, TIME_UNIT));
    assertThat(exception.status()).isEqualTo(Status.Schema.IndexCreationFailed);
    assertThat(exception.getMessage()).contains("Kilroy was here");
    assertThat(exception.getMessage()).contains("Index 'index' is in failed state.: Cause of failure:");
}
Also used : ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) PropertyKeyIdNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) LabelNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.LabelNotFoundKernelException) Test(org.junit.jupiter.api.Test)

Example 23 with ProcedureException

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

the class AwaitIndexProcedureTest method shouldBlockUntilTheIndexIsOnline.

@Test
void shouldBlockUntilTheIndexIsOnline() throws IndexNotFoundKernelException, InterruptedException {
    when(schemaRead.index(any(SchemaDescriptor.class))).thenReturn(Iterators.iterator(anyIndex));
    when(schemaRead.indexGetForName(anyString())).thenReturn(anyIndex);
    AtomicReference<InternalIndexState> state = new AtomicReference<>(POPULATING);
    when(schemaRead.indexGetState(any(IndexDescriptor.class))).then(invocationOnMock -> state.get());
    AtomicBoolean done = new AtomicBoolean(false);
    var thread = new Thread(() -> {
        try {
            procedure.awaitIndexByName("index", TIMEOUT, TIME_UNIT);
        } catch (ProcedureException e) {
            throw new RuntimeException(e);
        }
        done.set(true);
    });
    thread.start();
    assertThat(done.get()).isFalse();
    state.set(ONLINE);
    thread.join();
    assertThat(done.get()).isTrue();
}
Also used : InternalIndexState(org.neo4j.internal.kernel.api.InternalIndexState) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) AtomicReference(java.util.concurrent.atomic.AtomicReference) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 24 with ProcedureException

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

the class JmxQueryProcedureTest method shouldHandleCompositeAttributes.

@Test
void shouldHandleCompositeAttributes() throws Throwable {
    // given
    ObjectName beanName = new ObjectName("org.neo4j:chevyMakesTheTruck=bobMcCoshMakesTheDifference");
    when(jmxServer.queryNames(new ObjectName("*:*"), null)).thenReturn(asSet(beanName));
    when(jmxServer.getMBeanInfo(beanName)).thenReturn(new MBeanInfo("org.neo4j.SomeMBean", "This is a description", new MBeanAttributeInfo[] { new MBeanAttributeInfo("name", "differenceMaker", "Who makes the difference?", true, false, false) }, null, null, null));
    when(jmxServer.getAttribute(beanName, "name")).thenReturn(new CompositeDataSupport(new CompositeType("myComposite", "Composite description", new String[] { "key1", "key2" }, new String[] { "Can't be empty", "Also can't be empty" }, new OpenType<?>[] { SimpleType.STRING, SimpleType.INTEGER }), map("key1", "Hello", "key2", 123)));
    JmxQueryProcedure procedure = new JmxQueryProcedure(ProcedureSignature.procedureName("bob"), jmxServer);
    // when
    RawIterator<AnyValue[], ProcedureException> result = procedure.apply(null, new AnyValue[] { stringValue("*:*") }, EMPTY_RESOURCE_TRACKER);
    // then
    assertThat(asList(result)).contains(new AnyValue[] { stringValue("org.neo4j:chevyMakesTheTruck=bobMcCoshMakesTheDifference"), stringValue("This is a description"), ValueUtils.of(map(attributeName, map("description", "Who makes the difference?", "value", map("description", "Composite description", "properties", map("key1", "Hello", "key2", 123))))) });
}
Also used : MBeanInfo(javax.management.MBeanInfo) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) CompositeType(javax.management.openmbean.CompositeType) Test(org.junit.jupiter.api.Test)

Example 25 with ProcedureException

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

the class JmxQueryProcedureTest method shouldConvertAllStandardBeansWithoutError.

@Test
void shouldConvertAllStandardBeansWithoutError() throws Throwable {
    // given
    MBeanServer jmxServer = ManagementFactory.getPlatformMBeanServer();
    JmxQueryProcedure procedure = new JmxQueryProcedure(ProcedureSignature.procedureName("bob"), jmxServer);
    // when
    RawIterator<AnyValue[], ProcedureException> result = procedure.apply(null, new AnyValue[] { stringValue("*:*") }, EMPTY_RESOURCE_TRACKER);
    // then we verify that we respond with the expected number of beans without error
    // .. we don't assert more than this, this is more of a smoke test to ensure
    // that independent of platform, we never throw exceptions even when converting every
    // single MBean into Neo4j types, and we always get the correct number of MBeans out.
    assertThat(asList(result)).hasSize(jmxServer.getMBeanCount());
}
Also used : ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) MBeanServer(javax.management.MBeanServer) Test(org.junit.jupiter.api.Test)

Aggregations

ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)124 Test (org.junit.jupiter.api.Test)95 CallableProcedure (org.neo4j.kernel.api.procedure.CallableProcedure)21 AnyValue (org.neo4j.values.AnyValue)19 QualifiedName (org.neo4j.internal.kernel.api.procs.QualifiedName)14 KernelException (org.neo4j.exceptions.KernelException)10 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)10 KernelIntegrationTest (org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)9 Arrays (java.util.Arrays)8 List (java.util.List)8 RawIterator (org.neo4j.collection.RawIterator)8 UserFunctionSignature (org.neo4j.internal.kernel.api.procs.UserFunctionSignature)8 CallableUserFunction (org.neo4j.kernel.api.procedure.CallableUserFunction)8 Collectors (java.util.stream.Collectors)7 ProcedureSignature (org.neo4j.internal.kernel.api.procs.ProcedureSignature)7 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)7 Method (java.lang.reflect.Method)6 ArrayList (java.util.ArrayList)6 FieldSignature (org.neo4j.internal.kernel.api.procs.FieldSignature)6 CallableUserAggregationFunction (org.neo4j.kernel.api.procedure.CallableUserAggregationFunction)6