Search in sources :

Example 41 with ProcedureException

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

the class ClusterOverviewProcedureTest method shouldProvideOverviewOfCoreServersAndReadReplicas.

@Test
public void shouldProvideOverviewOfCoreServersAndReadReplicas() throws Exception {
    // given
    final CoreTopologyService topologyService = mock(CoreTopologyService.class);
    Map<MemberId, CoreServerInfo> coreMembers = new HashMap<>();
    MemberId theLeader = new MemberId(UUID.randomUUID());
    MemberId follower1 = new MemberId(UUID.randomUUID());
    MemberId follower2 = new MemberId(UUID.randomUUID());
    coreMembers.put(theLeader, adressesForCore(0));
    coreMembers.put(follower1, adressesForCore(1));
    coreMembers.put(follower2, adressesForCore(2));
    Map<MemberId, ReadReplicaInfo> replicaMembers = new HashMap<>();
    MemberId replica4 = new MemberId(UUID.randomUUID());
    MemberId replica5 = new MemberId(UUID.randomUUID());
    replicaMembers.put(replica4, addressesForReadReplica(4));
    replicaMembers.put(replica5, addressesForReadReplica(5));
    when(topologyService.coreServers()).thenReturn(new CoreTopology(null, false, coreMembers));
    when(topologyService.readReplicas()).thenReturn(new ReadReplicaTopology(replicaMembers));
    LeaderLocator leaderLocator = mock(LeaderLocator.class);
    when(leaderLocator.getLeader()).thenReturn(theLeader);
    ClusterOverviewProcedure procedure = new ClusterOverviewProcedure(topologyService, leaderLocator, NullLogProvider.getInstance());
    // when
    final RawIterator<Object[], ProcedureException> members = procedure.apply(null, new Object[0]);
    assertThat(members.next(), new IsRecord(theLeader.getUuid(), 5000, Role.LEADER, asSet("core", "core0")));
    assertThat(members.next(), new IsRecord(follower1.getUuid(), 5001, Role.FOLLOWER, asSet("core", "core1")));
    assertThat(members.next(), new IsRecord(follower2.getUuid(), 5002, Role.FOLLOWER, asSet("core", "core2")));
    assertThat(members.next(), new IsRecord(replica4.getUuid(), 6004, Role.READ_REPLICA, asSet("replica", "replica4")));
    assertThat(members.next(), new IsRecord(replica5.getUuid(), 6005, Role.READ_REPLICA, asSet("replica", "replica5")));
    assertFalse(members.hasNext());
}
Also used : ReadReplicaInfo(org.neo4j.causalclustering.discovery.ReadReplicaInfo) HashMap(java.util.HashMap) CoreTopology(org.neo4j.causalclustering.discovery.CoreTopology) MemberId(org.neo4j.causalclustering.identity.MemberId) LeaderLocator(org.neo4j.causalclustering.core.consensus.LeaderLocator) CoreTopologyService(org.neo4j.causalclustering.discovery.CoreTopologyService) CoreServerInfo(org.neo4j.causalclustering.discovery.CoreServerInfo) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) ReadReplicaTopology(org.neo4j.causalclustering.discovery.ReadReplicaTopology) Test(org.junit.Test)

Example 42 with ProcedureException

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

the class AwaitIndexProcedureTest method shouldBlockUntilTheIndexIsOnline.

@Test
public void shouldBlockUntilTheIndexIsOnline() throws SchemaRuleNotFoundException, IndexNotFoundKernelException, InterruptedException {
    when(operations.labelGetForName(anyString())).thenReturn(0);
    when(operations.propertyKeyGetForName(anyString())).thenReturn(0);
    when(operations.indexGetForLabelAndPropertyKey(anyObject())).thenReturn(anyIndex);
    AtomicReference<InternalIndexState> state = new AtomicReference<>(POPULATING);
    when(operations.indexGetState(any(NewIndexDescriptor.class))).then(new Answer<InternalIndexState>() {

        @Override
        public InternalIndexState answer(InvocationOnMock invocationOnMock) throws Throwable {
            return state.get();
        }
    });
    AtomicBoolean done = new AtomicBoolean(false);
    new Thread(() -> {
        try {
            procedure.awaitIndex(":Person(name)", timeout, timeoutUnits);
        } catch (ProcedureException e) {
            throw new RuntimeException(e);
        }
        done.set(true);
    }).start();
    assertThat(done.get(), is(false));
    state.set(ONLINE);
    assertEventually("Procedure did not return after index was online", done::get, is(true), 10, TimeUnit.SECONDS);
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) InternalIndexState(org.neo4j.kernel.api.index.InternalIndexState) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Test(org.junit.Test)

Example 43 with ProcedureException

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

the class AwaitIndexProcedureTest method shouldThrowAnExceptionIfTheIndexDoesNotExist.

@Test
public void shouldThrowAnExceptionIfTheIndexDoesNotExist() throws SchemaRuleNotFoundException, IndexNotFoundKernelException {
    when(operations.propertyKeyGetForName(anyString())).thenReturn(0);
    when(operations.labelGetForName(anyString())).thenReturn(0);
    when(operations.indexGetForLabelAndPropertyKey(any())).thenThrow(new SchemaRuleNotFoundException(INDEX_RULE, SchemaDescriptorFactory.forLabel(0, 0)));
    try {
        procedure.awaitIndex(":Person(name)", timeout, timeoutUnits);
        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 44 with ProcedureException

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

the class JmxQueryProcedureTest method shouldHandleMBeanThatThrowsOnGetAttribute.

@Test
public void shouldHandleMBeanThatThrowsOnGetAttribute() throws Throwable {
    // given some JVM MBeans do not allow accessing their attributes, despite marking
    // then as readable
    when(jmxServer.getAttribute(beanName, "name")).thenThrow(new RuntimeMBeanException(new UnsupportedOperationException("Haha, screw discoverable services!")));
    JmxQueryProcedure procedure = new JmxQueryProcedure(ProcedureSignature.procedureName("bob"), jmxServer);
    // when
    RawIterator<Object[], ProcedureException> result = procedure.apply(null, new Object[] { "*:*" });
    // then
    assertThat(asList(result), contains(equalTo(new Object[] { "org.neo4j:chevyMakesTheTruck=bobMcCoshMakesTheDifference", "This is a description", map(attributeName, map("description", "This is the attribute desc.", "value", null)) })));
}
Also used : RuntimeMBeanException(javax.management.RuntimeMBeanException) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Test(org.junit.Test)

Example 45 with ProcedureException

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

the class JmxQueryProcedureTest method shouldHandleCompositeAttributes.

@Test
public 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<Object[], ProcedureException> result = procedure.apply(null, new Object[] { "*:*" });
    // then
    assertThat(asList(result), contains(equalTo(new Object[] { "org.neo4j:chevyMakesTheTruck=bobMcCoshMakesTheDifference", "This is a description", 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.kernel.api.exceptions.ProcedureException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) CompositeType(javax.management.openmbean.CompositeType) 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