Search in sources :

Example 6 with RawIterator

use of org.neo4j.collection.RawIterator in project neo4j by neo4j.

the class CsvInputTest method shouldNotReportNoRelationshipTypeIfDecorated.

@Test
public void shouldNotReportNoRelationshipTypeIfDecorated() {
    // given
    String sourceDescription = "source";
    Supplier<CharReadable> headerSource = () -> wrap(dataWithSourceDescription(":START_ID,:END_ID", sourceDescription), 3);
    Iterable<DataFactory> data = datas(config -> new Data() {

        @Override
        public RawIterator<CharReadable, IOException> stream() {
            return asRawIterator(iterator(headerSource.get()));
        }

        @Override
        public Decorator decorator() {
            return defaultRelationshipType("MyType");
        }
    });
    CsvInput.Monitor monitor = mock(CsvInput.Monitor.class);
    // when
    new CsvInput(datas(), defaultFormatNodeFileHeader(), data, defaultFormatRelationshipFileHeader(), IdType.INTEGER, COMMAS, monitor, INSTANCE);
    // then
    verify(monitor, never()).noRelationshipTypeSpecified(sourceDescription);
}
Also used : CharReadable(org.neo4j.csv.reader.CharReadable) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RawIterator(org.neo4j.collection.RawIterator) Iterators.asRawIterator(org.neo4j.internal.helpers.collection.Iterators.asRawIterator) Test(org.junit.Test)

Example 7 with RawIterator

use of org.neo4j.collection.RawIterator in project neo4j by neo4j.

the class CsvInputTest method shouldNotReportNoNodeLabelsIfDecorated.

@Test
public void shouldNotReportNoNodeLabelsIfDecorated() {
    // given
    String sourceDescription = "source";
    Supplier<CharReadable> headerSource = () -> wrap(dataWithSourceDescription(":ID", sourceDescription), 3);
    Iterable<DataFactory> data = datas(config -> new Data() {

        @Override
        public RawIterator<CharReadable, IOException> stream() {
            return asRawIterator(iterator(headerSource.get()));
        }

        @Override
        public Decorator decorator() {
            return additiveLabels(new String[] { "MyLabel" });
        }
    });
    CsvInput.Monitor monitor = mock(CsvInput.Monitor.class);
    // when
    new CsvInput(data, defaultFormatNodeFileHeader(), datas(), defaultFormatRelationshipFileHeader(), IdType.INTEGER, COMMAS, monitor, INSTANCE);
    // then
    verify(monitor, never()).noRelationshipTypeSpecified(sourceDescription);
}
Also used : CharReadable(org.neo4j.csv.reader.CharReadable) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RawIterator(org.neo4j.collection.RawIterator) Iterators.asRawIterator(org.neo4j.internal.helpers.collection.Iterators.asRawIterator) Test(org.junit.Test)

Example 8 with RawIterator

use of org.neo4j.collection.RawIterator in project neo4j by neo4j.

the class CsvInputTest method shouldReportNoRelationshipType.

@Test
public void shouldReportNoRelationshipType() {
    // given
    String sourceDescription = "source";
    Supplier<CharReadable> headerSource = () -> wrap(dataWithSourceDescription(":START_ID,:END_ID", sourceDescription), 3);
    Iterable<DataFactory> data = datas(config -> new Data() {

        @Override
        public RawIterator<CharReadable, IOException> stream() {
            return asRawIterator(iterator(headerSource.get()));
        }

        @Override
        public Decorator decorator() {
            return NO_DECORATOR;
        }
    });
    CsvInput.Monitor monitor = mock(CsvInput.Monitor.class);
    // when
    new CsvInput(datas(), defaultFormatNodeFileHeader(), data, defaultFormatRelationshipFileHeader(), IdType.INTEGER, COMMAS, monitor, INSTANCE);
    // then
    verify(monitor).noRelationshipTypeSpecified(sourceDescription);
}
Also used : CharReadable(org.neo4j.csv.reader.CharReadable) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RawIterator(org.neo4j.collection.RawIterator) Iterators.asRawIterator(org.neo4j.internal.helpers.collection.Iterators.asRawIterator) Test(org.junit.Test)

Example 9 with RawIterator

use of org.neo4j.collection.RawIterator in project neo4j by neo4j.

the class ProceduresTest method shouldMakeContextAvailable.

@Test
void shouldMakeContextAvailable() throws Throwable {
    // Given
    procs.register(new CallableProcedure.BasicProcedure(signature) {

        @Override
        public RawIterator<AnyValue[], ProcedureException> apply(Context ctx, AnyValue[] input, ResourceTracker resourceTracker) {
            return RawIterator.<AnyValue[], ProcedureException>of(new AnyValue[] { stringValue(ctx.thread().getName()) });
        }
    });
    Context ctx = prepareContext();
    ProcedureHandle procedureHandle = procs.procedure(signature.name());
    // When
    RawIterator<AnyValue[], ProcedureException> result = procs.callProcedure(ctx, procedureHandle.id(), new AnyValue[0], EMPTY_RESOURCE_TRACKER);
    // Then
    assertThat(asList(result)).contains(new AnyValue[] { stringValue(Thread.currentThread().getName()) });
}
Also used : BasicContext.buildContext(org.neo4j.kernel.api.procedure.BasicContext.buildContext) Context(org.neo4j.kernel.api.procedure.Context) ProcedureHandle(org.neo4j.internal.kernel.api.procs.ProcedureHandle) ResourceTracker(org.neo4j.kernel.api.ResourceTracker) AnyValue(org.neo4j.values.AnyValue) CallableProcedure(org.neo4j.kernel.api.procedure.CallableProcedure) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) RawIterator(org.neo4j.collection.RawIterator) Test(org.junit.jupiter.api.Test)

Example 10 with RawIterator

use of org.neo4j.collection.RawIterator 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()));
}
Also used : ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Neo4jTypes(org.neo4j.kernel.api.proc.Neo4jTypes) Log(org.neo4j.logging.Log) RawIterator(org.neo4j.collection.RawIterator) CallableProcedure(org.neo4j.kernel.api.proc.CallableProcedure) ClientConnectorAddresses(org.neo4j.causalclustering.discovery.ClientConnectorAddresses) LogProvider(org.neo4j.logging.LogProvider) ArrayList(java.util.ArrayList) Iterators.asRawIterator(org.neo4j.helpers.collection.Iterators.asRawIterator) Map(java.util.Map) MemberId(org.neo4j.causalclustering.identity.MemberId) URI(java.net.URI) ReadReplicaInfo(org.neo4j.causalclustering.discovery.ReadReplicaInfo) Comparator.comparing(java.util.Comparator.comparing) ProcedureSignature.procedureSignature(org.neo4j.kernel.api.proc.ProcedureSignature.procedureSignature) CoreServerInfo(org.neo4j.causalclustering.discovery.CoreServerInfo) LeaderLocator(org.neo4j.causalclustering.core.consensus.LeaderLocator) CoreTopology(org.neo4j.causalclustering.discovery.CoreTopology) Iterators.map(org.neo4j.helpers.collection.Iterators.map) TopologyService(org.neo4j.causalclustering.discovery.TopologyService) Set(java.util.Set) UUID(java.util.UUID) Iterables.asList(org.neo4j.helpers.collection.Iterables.asList) List(java.util.List) NoLeaderFoundException(org.neo4j.causalclustering.core.consensus.NoLeaderFoundException) QualifiedName(org.neo4j.kernel.api.proc.QualifiedName) Optional(java.util.Optional) Context(org.neo4j.kernel.api.proc.Context) NoLeaderFoundException(org.neo4j.causalclustering.core.consensus.NoLeaderFoundException) ReadReplicaInfo(org.neo4j.causalclustering.discovery.ReadReplicaInfo) ArrayList(java.util.ArrayList) URI(java.net.URI) CoreTopology(org.neo4j.causalclustering.discovery.CoreTopology) MemberId(org.neo4j.causalclustering.identity.MemberId) CoreServerInfo(org.neo4j.causalclustering.discovery.CoreServerInfo) Map(java.util.Map)

Aggregations

RawIterator (org.neo4j.collection.RawIterator)18 Test (org.junit.Test)8 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)8 AnyValue (org.neo4j.values.AnyValue)8 Matchers.containsString (org.hamcrest.Matchers.containsString)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 CharReadable (org.neo4j.csv.reader.CharReadable)7 Iterators.asRawIterator (org.neo4j.internal.helpers.collection.Iterators.asRawIterator)7 List (java.util.List)6 Test (org.junit.jupiter.api.Test)6 Arrays (java.util.Arrays)5 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)5 Iterators.asList (org.neo4j.internal.helpers.collection.Iterators.asList)5 ProcedureCallContext (org.neo4j.internal.kernel.api.procs.ProcedureCallContext)5 Collectors (java.util.stream.Collectors)4 ArrayUtils.toArray (org.apache.commons.lang3.ArrayUtils.toArray)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Matchers.contains (org.hamcrest.Matchers.contains)4 Assertions.assertArrayEquals (org.junit.jupiter.api.Assertions.assertArrayEquals)4 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)4