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());
}
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);
}
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));
}
}
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)) })));
}
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)))) })));
}
Aggregations