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