Search in sources :

Example 11 with RawIterator

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

the class OperationsFacade method callProcedure.

private RawIterator<Object[], ProcedureException> callProcedure(QualifiedName name, Object[] input, final AccessMode override) throws ProcedureException {
    statement.assertOpen();
    final SecurityContext procedureSecurityContext = tx.securityContext().withMode(override);
    final RawIterator<Object[], ProcedureException> procedureCall;
    try (KernelTransaction.Revertable ignore = tx.overrideWith(procedureSecurityContext)) {
        BasicContext ctx = new BasicContext();
        ctx.put(Context.KERNEL_TRANSACTION, tx);
        ctx.put(Context.THREAD, Thread.currentThread());
        ctx.put(Context.SECURITY_CONTEXT, procedureSecurityContext);
        procedureCall = procedures.callProcedure(ctx, name, input);
    }
    return new RawIterator<Object[], ProcedureException>() {

        @Override
        public boolean hasNext() throws ProcedureException {
            try (KernelTransaction.Revertable ignore = tx.overrideWith(procedureSecurityContext)) {
                return procedureCall.hasNext();
            }
        }

        @Override
        public Object[] next() throws ProcedureException {
            try (KernelTransaction.Revertable ignore = tx.overrideWith(procedureSecurityContext)) {
                return procedureCall.next();
            }
        }
    };
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) BasicContext(org.neo4j.kernel.api.proc.BasicContext) SecurityContext(org.neo4j.kernel.api.security.SecurityContext) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) RawIterator(org.neo4j.collection.RawIterator)

Example 12 with RawIterator

use of org.neo4j.collection.RawIterator 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();
        }
    });
}
Also used : Context(org.neo4j.kernel.api.procedure.Context) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) 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) GlobalProcedures(org.neo4j.kernel.api.procedure.GlobalProcedures)

Example 13 with RawIterator

use of org.neo4j.collection.RawIterator 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());
}
Also used : AnyValue(org.neo4j.values.AnyValue) Arrays(java.util.Arrays) Label(org.neo4j.graphdb.Label) RawIterator(org.neo4j.collection.RawIterator) GraphDatabaseSettings(org.neo4j.configuration.GraphDatabaseSettings) Iterators.asList(org.neo4j.internal.helpers.collection.Iterators.asList) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Config(org.neo4j.configuration.Config) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) ProcedureSignature.procedureName(org.neo4j.internal.kernel.api.procs.ProcedureSignature.procedureName) Public(org.neo4j.annotations.Public) Values(org.neo4j.values.storable.Values) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) CapabilitiesRegistry(org.neo4j.capabilities.CapabilitiesRegistry) Capability(org.neo4j.capabilities.Capability) CapabilitiesSettings(org.neo4j.capabilities.CapabilitiesSettings) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) FALSE(org.neo4j.configuration.SettingValueParsers.FALSE) CapabilityProviderContext(org.neo4j.capabilities.CapabilityProviderContext) INTEGER(org.neo4j.capabilities.Type.INTEGER) DOUBLE(org.neo4j.capabilities.Type.DOUBLE) CapabilityProvider(org.neo4j.capabilities.CapabilityProvider) Name(org.neo4j.capabilities.Name) DBMSCapabilities(org.neo4j.capabilities.DBMSCapabilities) BooleanValue(org.neo4j.values.storable.BooleanValue) BOOLEAN(org.neo4j.capabilities.Type.BOOLEAN) TextValue(org.neo4j.values.storable.TextValue) Label.label(org.neo4j.graphdb.Label.label) Values.stringValue(org.neo4j.values.storable.Values.stringValue) Collectors(java.util.stream.Collectors) QualifiedName(org.neo4j.internal.kernel.api.procs.QualifiedName) Test(org.junit.jupiter.api.Test) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) List(java.util.List) ProcedureCallContext(org.neo4j.internal.kernel.api.procs.ProcedureCallContext) ArrayUtils.toArray(org.apache.commons.lang3.ArrayUtils.toArray) Description(org.neo4j.configuration.Description) KernelException(org.neo4j.exceptions.KernelException) Matchers.contains(org.hamcrest.Matchers.contains) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CapabilityDeclaration(org.neo4j.capabilities.CapabilityDeclaration) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest) TextValue(org.neo4j.values.storable.TextValue) QualifiedName(org.neo4j.internal.kernel.api.procs.QualifiedName) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

Example 14 with RawIterator

use of org.neo4j.collection.RawIterator 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());
}
Also used : AnyValue(org.neo4j.values.AnyValue) Arrays(java.util.Arrays) Label(org.neo4j.graphdb.Label) RawIterator(org.neo4j.collection.RawIterator) GraphDatabaseSettings(org.neo4j.configuration.GraphDatabaseSettings) Iterators.asList(org.neo4j.internal.helpers.collection.Iterators.asList) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Config(org.neo4j.configuration.Config) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) ProcedureSignature.procedureName(org.neo4j.internal.kernel.api.procs.ProcedureSignature.procedureName) Public(org.neo4j.annotations.Public) Values(org.neo4j.values.storable.Values) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) CapabilitiesRegistry(org.neo4j.capabilities.CapabilitiesRegistry) Capability(org.neo4j.capabilities.Capability) CapabilitiesSettings(org.neo4j.capabilities.CapabilitiesSettings) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) FALSE(org.neo4j.configuration.SettingValueParsers.FALSE) CapabilityProviderContext(org.neo4j.capabilities.CapabilityProviderContext) INTEGER(org.neo4j.capabilities.Type.INTEGER) DOUBLE(org.neo4j.capabilities.Type.DOUBLE) CapabilityProvider(org.neo4j.capabilities.CapabilityProvider) Name(org.neo4j.capabilities.Name) DBMSCapabilities(org.neo4j.capabilities.DBMSCapabilities) BooleanValue(org.neo4j.values.storable.BooleanValue) BOOLEAN(org.neo4j.capabilities.Type.BOOLEAN) TextValue(org.neo4j.values.storable.TextValue) Label.label(org.neo4j.graphdb.Label.label) Values.stringValue(org.neo4j.values.storable.Values.stringValue) Collectors(java.util.stream.Collectors) QualifiedName(org.neo4j.internal.kernel.api.procs.QualifiedName) Test(org.junit.jupiter.api.Test) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) List(java.util.List) ProcedureCallContext(org.neo4j.internal.kernel.api.procs.ProcedureCallContext) ArrayUtils.toArray(org.apache.commons.lang3.ArrayUtils.toArray) Description(org.neo4j.configuration.Description) KernelException(org.neo4j.exceptions.KernelException) Matchers.contains(org.hamcrest.Matchers.contains) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CapabilityDeclaration(org.neo4j.capabilities.CapabilityDeclaration) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest) Config(org.neo4j.configuration.Config) TextValue(org.neo4j.values.storable.TextValue) QualifiedName(org.neo4j.internal.kernel.api.procs.QualifiedName) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

Example 15 with RawIterator

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

the class CsvInputTest method shouldReportDuplicateSourceFileUsedAsBothNodeAndRelationshipSourceFile.

@Test
public void shouldReportDuplicateSourceFileUsedAsBothNodeAndRelationshipSourceFile() {
    // given
    String sourceDescription = "The single data source";
    Supplier<CharReadable> nodeHeaderSource = () -> wrap(dataWithSourceDescription(":ID", "node source"), 3);
    Supplier<CharReadable> relationshipHeaderSource = () -> wrap(dataWithSourceDescription(":START_ID,:END_ID,:TYPE", "relationship source"), 10);
    Supplier<CharReadable> source = () -> wrap(dataWithSourceDescription("1,2,3", sourceDescription), 6);
    Iterable<DataFactory> nodeData = datas(config -> new Data() {

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

        @Override
        public Decorator decorator() {
            return NO_DECORATOR;
        }
    });
    Iterable<DataFactory> relationshipData = datas(config -> new Data() {

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

        @Override
        public Decorator decorator() {
            return NO_DECORATOR;
        }
    });
    CsvInput.Monitor monitor = mock(CsvInput.Monitor.class);
    // when
    new CsvInput(nodeData, defaultFormatNodeFileHeader(), relationshipData, defaultFormatRelationshipFileHeader(), IdType.INTEGER, COMMAS, monitor, INSTANCE);
    // then
    verify(monitor).duplicateSourceFile(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)

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