use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class BoltChannelAutoReadLimiterIT 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").in("data", Neo4jTypes.NTString).out(ProcedureSignature.VOID).build()) {
@Override
public RawIterator<AnyValue[], ProcedureException> apply(Context context, AnyValue[] objects, ResourceTracker resourceTracker) throws ProcedureException {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
throw new ProcedureException(Status.General.UnknownError, e, "Interrupted");
}
return RawIterator.empty();
}
});
}
use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class BuiltInDbmsProceduresIT method listCapabilitiesShouldReturnDynamicValues.
@Test
void listCapabilitiesShouldReturnDynamicValues() throws KernelException {
QualifiedName procedureName = procedureName("dbms", "listCapabilities");
int procedureId = procs().procedureGet(procedureName).id();
// first call
RawIterator<AnyValue[], ProcedureException> callResult = procs().procedureCallDbms(procedureId, new AnyValue[] {}, ProcedureCallContext.EMPTY);
List<AnyValue[]> capabilities = asList(callResult);
// should return false
assertThat(capabilities).contains(new AnyValue[] { Values.stringValue(TestCapabilities.my_dynamic_capability.name().fullName()), Values.stringValue(TestCapabilities.my_dynamic_capability.description()), Values.booleanValue(false) });
try (var txc = db.beginTx()) {
txc.createNode(label("my_dynamic_capability"));
txc.commit();
}
// second call
callResult = procs().procedureCallDbms(procedureId, new AnyValue[] {}, ProcedureCallContext.EMPTY);
capabilities = asList(callResult);
// should return true
assertThat(capabilities).contains(new AnyValue[] { Values.stringValue(TestCapabilities.my_dynamic_capability.name().fullName()), Values.stringValue(TestCapabilities.my_dynamic_capability.description()), Values.booleanValue(true) });
}
use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class BuiltInDbmsProceduresIT method listCapabilities.
@Test
void listCapabilities() throws KernelException {
QualifiedName procedureName = procedureName("dbms", "listCapabilities");
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(TestCapabilities.my_custom_capability.name().fullName(), TestCapabilities.my_dynamic_capability.name().fullName());
}
use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class BuiltInDbmsProceduresIT method listCapabilitiesShouldNotReturnBlocked.
@Test
void listCapabilitiesShouldNotReturnBlocked() throws KernelException {
// set blocked capabilities
Config config = dependencyResolver.resolveDependency(Config.class);
config.set(CapabilitiesSettings.dbms_capabilities_blocked, List.of("my.**"));
QualifiedName procedureName = procedureName("dbms", "listCapabilities");
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).doesNotContain(TestCapabilities.my_custom_capability.name().fullName());
}
use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class MapValue method ternaryEquals.
@Override
public Equality ternaryEquals(AnyValue other) {
assert other != null : "null values are not supported, use NoValue.NO_VALUE instead";
if (other == NO_VALUE) {
return Equality.UNDEFINED;
} else if (!(other instanceof MapValue)) {
return Equality.FALSE;
}
MapValue otherMap = (MapValue) other;
int size = size();
if (size != otherMap.size()) {
return Equality.FALSE;
}
String[] thisKeys = StreamSupport.stream(keySet().spliterator(), false).toArray(String[]::new);
Arrays.sort(thisKeys, String::compareTo);
String[] thatKeys = StreamSupport.stream(otherMap.keySet().spliterator(), false).toArray(String[]::new);
Arrays.sort(thatKeys, String::compareTo);
for (int i = 0; i < size; i++) {
if (thisKeys[i].compareTo(thatKeys[i]) != 0) {
return Equality.FALSE;
}
}
Equality equalityResult = Equality.TRUE;
for (int i = 0; i < size; i++) {
String key = thisKeys[i];
AnyValue thisValue = get(key);
AnyValue otherValue = otherMap.get(key);
Equality equality = thisValue.ternaryEquals(otherValue);
if (equality == Equality.UNDEFINED) {
equalityResult = Equality.UNDEFINED;
} else if (equality == Equality.FALSE) {
return Equality.FALSE;
}
}
return equalityResult;
}
Aggregations