use of org.neo4j.collection.RawIterator in project neo4j by neo4j.
the class ProceduresTest method shouldMakeContextAvailable.
@Test
public void shouldMakeContextAvailable() throws Throwable {
// Given
Key<String> someKey = key("someKey", String.class);
procs.register(new CallableProcedure.BasicProcedure(signature) {
@Override
public RawIterator<Object[], ProcedureException> apply(Context ctx, Object[] input) throws ProcedureException {
return RawIterator.<Object[], ProcedureException>of(new Object[] { ctx.get(someKey) });
}
});
BasicContext ctx = new BasicContext();
ctx.put(someKey, "hello, world");
// When
RawIterator<Object[], ProcedureException> result = procs.callProcedure(ctx, signature.name(), new Object[0]);
// Then
assertThat(asList(result), contains(equalTo(new Object[] { "hello, world" })));
}
use of org.neo4j.collection.RawIterator in project neo4j by neo4j.
the class BuiltInDbmsProceduresIT method listAllCapabilitiesShouldNotReturnBlocked.
@Test
void listAllCapabilitiesShouldNotReturnBlocked() throws KernelException {
// set blocked capabilities
Config config = dependencyResolver.resolveDependency(Config.class);
config.set(CapabilitiesSettings.dbms_capabilities_blocked, List.of("my.custom.**"));
QualifiedName procedureName = procedureName("dbms", "listAllCapabilities");
int procedureId = procs().procedureGet(procedureName).id();
RawIterator<AnyValue[], ProcedureException> callResult = procs().procedureCallDbms(procedureId, new AnyValue[] {}, ProcedureCallContext.EMPTY);
List<AnyValue[]> capabilities = asList(callResult);
List<String> capabilityNames = capabilities.stream().map(c -> ((TextValue) c[0]).stringValue()).collect(Collectors.toList());
assertThat(capabilityNames).containsExactlyInAnyOrder(DBMSCapabilities.dbms_instance_version.name().fullName(), DBMSCapabilities.dbms_instance_kernel_version.name().fullName(), DBMSCapabilities.dbms_instance_edition.name().fullName(), DBMSCapabilities.dbms_instance_operational_mode.name().fullName(), TestCapabilities.my_dynamic_capability.name().fullName(), TestCapabilities.my_internal_capability.name().fullName());
}
use of org.neo4j.collection.RawIterator in project neo4j by neo4j.
the class BuiltInDbmsProceduresIT method listAllCapabilities.
@Test
void listAllCapabilities() throws KernelException {
QualifiedName procedureName = procedureName("dbms", "listAllCapabilities");
int procedureId = procs().procedureGet(procedureName).id();
RawIterator<AnyValue[], ProcedureException> callResult = procs().procedureCallDbms(procedureId, new AnyValue[] {}, ProcedureCallContext.EMPTY);
List<AnyValue[]> capabilities = asList(callResult);
List<String> capabilityNames = capabilities.stream().map(c -> ((TextValue) c[0]).stringValue()).collect(Collectors.toList());
assertThat(capabilityNames).containsExactlyInAnyOrder(DBMSCapabilities.dbms_instance_version.name().fullName(), DBMSCapabilities.dbms_instance_kernel_version.name().fullName(), DBMSCapabilities.dbms_instance_edition.name().fullName(), DBMSCapabilities.dbms_instance_operational_mode.name().fullName(), TestCapabilities.my_custom_capability.name().fullName(), TestCapabilities.my_internal_capability.name().fullName(), TestCapabilities.my_dynamic_capability.name().fullName());
}
use of org.neo4j.collection.RawIterator in project neo4j by neo4j.
the class BoltKeepAliveSchedulingIT method installSleepProcedure.
private static void installSleepProcedure(GraphDatabaseService db) throws ProcedureException {
GraphDatabaseAPI dbApi = (GraphDatabaseAPI) db;
dbApi.getDependencyResolver().resolveDependency(GlobalProcedures.class).register(new CallableProcedure.BasicProcedure(procedureSignature("boltissue", "sleep").out(ProcedureSignature.VOID).build()) {
@Override
public RawIterator<AnyValue[], ProcedureException> apply(Context context, AnyValue[] objects, ResourceTracker resourceTracker) throws ProcedureException {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
throw new ProcedureException(Status.General.UnknownError, e, "Interrupted");
}
return RawIterator.empty();
}
});
}
use of org.neo4j.collection.RawIterator in project neo4j by neo4j.
the class CommunityProcedureITBase method listProcedures.
@Test
void listProcedures() throws Throwable {
// When
ProcedureHandle procedures = procs().procedureGet(procedureName("dbms", "procedures"));
RawIterator<AnyValue[], ProcedureException> stream = procs().procedureCallRead(procedures.id(), new AnyValue[0], ProcedureCallContext.EMPTY);
// Then
List<AnyValue[]> actual = asList(stream);
List<Object[]> expected = getExpectedCommunityProcs();
Map<String, AnyValue[]> resultMap = actual.stream().collect(toMap(row -> ((StringValue) row[0]).stringValue(), Function.identity()));
Map<String, Object[]> expectedMap = expected.stream().collect(toMap(row -> ((StringValue) row[0]).stringValue(), Function.identity()));
assertThat(resultMap.keySet(), containsInAnyOrder(expectedMap.keySet().toArray()));
for (String procName : resultMap.keySet()) {
AnyValue[] actualArray = resultMap.get(procName);
Object[] expectedArray = expectedMap.get(procName);
assertNotNull(expectedArray, "Got an unexpected entry for " + procName + " =>\n" + printElementsOfArray(actualArray));
assertEquals(expectedArray.length, actualArray.length, "Count of columns for " + procName + " does not match");
for (int i = 1; i < actualArray.length; i++) {
Matcher matcher;
if (expectedArray[i] instanceof TextArray) {
// this has to be a list of roles, we ignore those in community and expect a null here
matcher = equalTo(NO_VALUE);
} else if (expectedArray[i] instanceof Matcher) {
matcher = (Matcher) expectedArray[i];
} else {
matcher = equalTo(expectedArray[i]);
}
assertThat("Column " + i + " for " + procName + " does not match", actualArray[i], matcher);
}
}
commit();
}
Aggregations