use of org.neo4j.kernel.api.proc.Context in project neo4j by neo4j.
the class UserFunctionsTest method shouldMakeContextAvailable.
@Test
public void shouldMakeContextAvailable() throws Throwable {
// Given
Key<String> someKey = key("someKey", String.class);
procs.register(new CallableUserFunction.BasicUserFunction(signature) {
@Override
public Object apply(Context ctx, Object[] input) throws ProcedureException {
return ctx.get(someKey);
}
});
BasicContext ctx = new BasicContext();
ctx.put(someKey, "hello, world");
// When
Object result = procs.callFunction(ctx, signature.name(), new Object[0]);
// Then
assertThat(result, equalTo("hello, world"));
}
use of org.neo4j.kernel.api.proc.Context 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.kernel.api.proc.Context in project neo4j by neo4j.
the class ClusterOverviewProcedure method apply.
@Override
public RawIterator<Object[], ProcedureException> apply(Context ctx, Object[] input) throws ProcedureException {
List<ReadWriteEndPoint> endpoints = new ArrayList<>();
CoreTopology coreTopology = topologyService.coreServers();
Set<MemberId> coreMembers = coreTopology.members().keySet();
MemberId leader = null;
try {
leader = leaderLocator.getLeader();
} catch (NoLeaderFoundException e) {
log.debug("No write server found. This can happen during a leader switch.");
}
for (MemberId memberId : coreMembers) {
Optional<CoreServerInfo> coreServerInfo = coreTopology.find(memberId);
if (coreServerInfo.isPresent()) {
Role role = memberId.equals(leader) ? Role.LEADER : Role.FOLLOWER;
endpoints.add(new ReadWriteEndPoint(coreServerInfo.get().connectors(), role, memberId.getUuid(), asList(coreServerInfo.get().groups())));
} else {
log.debug("No Address found for " + memberId);
}
}
for (Map.Entry<MemberId, ReadReplicaInfo> readReplica : topologyService.readReplicas().members().entrySet()) {
ReadReplicaInfo readReplicaInfo = readReplica.getValue();
endpoints.add(new ReadWriteEndPoint(readReplicaInfo.connectors(), Role.READ_REPLICA, readReplica.getKey().getUuid(), asList(readReplicaInfo.groups())));
}
endpoints.sort(comparing(o -> o.addresses().toString()));
return map((endpoint) -> new Object[] { endpoint.memberId().toString(), endpoint.addresses().uriList().stream().map(URI::toString).toArray(), endpoint.role().name(), endpoint.groups() }, asRawIterator(endpoints.iterator()));
}
Aggregations