示例#1
0
        /// <summary>
        /// Register a new procedure.
        /// </summary>
        /// <param name="proc"> the procedure. </param>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void register(org.neo4j.kernel.api.proc.CallableProcedure proc, boolean overrideCurrentImplementation) throws org.neo4j.internal.kernel.api.exceptions.ProcedureException
        public virtual void Register(CallableProcedure proc, bool overrideCurrentImplementation)
        {
            ProcedureSignature signature = proc.Signature();
            QualifiedName      name      = signature.Name();

            string descriptiveName = signature.ToString();

            ValidateSignature(descriptiveName, signature.InputSignature(), "input");
            ValidateSignature(descriptiveName, signature.OutputSignature(), "output");

            if (!signature.Void && signature.OutputSignature().Count == 0)
            {
                throw new ProcedureException(Org.Neo4j.Kernel.Api.Exceptions.Status_Procedure.ProcedureRegistrationFailed, "Procedures with zero output fields must be declared as VOID");
            }

            CallableProcedure oldImplementation = _procedures.get(name);

            if (oldImplementation == null)
            {
                _procedures.put(name, proc, signature.CaseInsensitive());
            }
            else
            {
                if (overrideCurrentImplementation)
                {
                    _procedures.put(name, proc, signature.CaseInsensitive());
                }
                else
                {
                    throw new ProcedureException(Org.Neo4j.Kernel.Api.Exceptions.Status_Procedure.ProcedureRegistrationFailed, "Unable to register procedure, because the name `%s` is already in use.", name);
                }
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowNonStaticOutput() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAllowNonStaticOutput()
        {
            // When
            CallableProcedure proc = Compile(typeof(ProcedureWithNonStaticOutputRecord))[0];

            // Then
            assertEquals(1, proc.Signature().outputSignature().size());
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowOverridingProcedureNameWithoutNamespace() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAllowOverridingProcedureNameWithoutNamespace()
        {
            // When
            CallableProcedure proc = Compile(typeof(ProcedureWithSingleName))[0];

            // Then
            assertEquals("singleName", proc.Signature().name().ToString());
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowOverridingProcedureName() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAllowOverridingProcedureName()
        {
            // When
            CallableProcedure proc = Compile(typeof(ProcedureWithOverriddenName))[0];

            // Then
            assertEquals("org.mystuff.thisisActuallyTheName", proc.Signature().name().ToString());
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowVoidOutput() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAllowVoidOutput()
        {
            // When
            CallableProcedure proc = Compile(typeof(ProcedureWithVoidOutput))[0];

            // Then
            assertEquals(0, proc.Signature().outputSignature().size());
            assertFalse(proc.Apply(null, new object[0], _resourceTracker).hasNext());
        }
示例#6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.neo4j.collection.RawIterator<Object[],org.neo4j.internal.kernel.api.exceptions.ProcedureException> callProcedure(org.neo4j.kernel.api.proc.Context ctx, org.neo4j.internal.kernel.api.procs.QualifiedName name, Object[] input, org.neo4j.kernel.api.ResourceTracker resourceTracker) throws org.neo4j.internal.kernel.api.exceptions.ProcedureException
        public virtual RawIterator <object[], ProcedureException> CallProcedure(Context ctx, QualifiedName name, object[] input, ResourceTracker resourceTracker)
        {
            CallableProcedure proc = _procedures.get(name);

            if (proc == null)
            {
                throw NoSuchProcedure(name);
            }
            return(proc.Apply(ctx, input, resourceTracker));
        }
示例#7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.neo4j.internal.kernel.api.procs.ProcedureHandle procedure(org.neo4j.internal.kernel.api.procs.QualifiedName name) throws org.neo4j.internal.kernel.api.exceptions.ProcedureException
        public virtual ProcedureHandle Procedure(QualifiedName name)
        {
            CallableProcedure proc = _procedures.get(name);

            if (proc == null)
            {
                throw NoSuchProcedure(name);
            }
            return(new ProcedureHandle(proc.Signature(), _procedures.idOf(name)));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRunSimpleReadOnlyProcedure() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRunSimpleReadOnlyProcedure()
        {
            // Given
            CallableProcedure proc = Compile(typeof(SingleReadOnlyProcedure))[0];

            // When
            RawIterator <object[], ProcedureException> @out = proc.Apply(new BasicContext(), new object[0], _resourceTracker);

            // Then
            assertThat(asList(@out), contains(new object[] { "Bonnie" }, new object[] { "Clyde" }));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldGiveHelpfulErrorOnNullMessageException() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldGiveHelpfulErrorOnNullMessageException()
        {
            // Given
            CallableProcedure proc = Compile(typeof(ProcedureThatThrowsNullMsgExceptionAtInvocation))[0];

            // Expect
            Exception.expect(typeof(ProcedureException));
            Exception.expectMessage("Failed to invoke procedure `org.neo4j.kernel.impl.proc.throwsAtInvocation`: " + "Caused by: java.lang.IndexOutOfBoundsException");

            // When
            proc.Apply(new BasicContext(), new object[0], _resourceTracker);
        }
示例#10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCompileAndRunProcedure() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCompileAndRunProcedure()
        {
            // Given
            CallableProcedure proc = _compiler.compileProcedure(typeof(ProcedureWithInjectedAPI), null, true)[0];

            // Then
            IList <object[]> @out = Iterators.asList(proc.Apply(new BasicContext(), new object[0], _resourceTracker));

            // Then
            assertThat(@out[0], equalTo(new object[] { "Bonnie" }));
            assertThat(@out[1], equalTo(new object[] { "Clyde" }));
        }
示例#11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCompileAndRunUnsafeProcedureUnsafeMode() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCompileAndRunUnsafeProcedureUnsafeMode()
        {
            // Given
            CallableProcedure proc = _compiler.compileProcedure(typeof(ProcedureWithUnsafeAPI), null, true)[0];

            // Then
            IList <object[]> @out = Iterators.asList(proc.Apply(new BasicContext(), new object[0], _resourceTracker));

            // Then
            assertThat(@out[0], equalTo(new object[] { "Morpheus" }));
            assertThat(@out[1], equalTo(new object[] { "Trinity" }));
            assertThat(@out[2], equalTo(new object[] { "Neo" }));
            assertThat(@out[3], equalTo(new object[] { "Emil" }));
        }
示例#12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldIgnoreWhiteListingIfFullAccess() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldIgnoreWhiteListingIfFullAccess()
        {
            // Given
            ProcedureConfig             config            = new ProcedureConfig(Config.defaults(procedure_whitelist, "empty"));
            Log                         log               = mock(typeof(Log));
            ReflectiveProcedureCompiler procedureCompiler = new ReflectiveProcedureCompiler(new TypeMappers(), _components, _components, log, config);

            // When
            CallableProcedure proc = procedureCompiler.CompileProcedure(typeof(SingleReadOnlyProcedure), null, true)[0];
            // Then
            RawIterator <object[], ProcedureException> result = proc.Apply(new BasicContext(), new object[0], _resourceTracker);

            assertEquals(result.Next()[0], "Bonnie");
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRunSimpleProcedure() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRunSimpleProcedure()
        {
            // Given
            CallableProcedure procedure = Compile(typeof(ClassWithProcedureWithSimpleArgs))[0];

            // When
            RawIterator <object[], ProcedureException> @out = procedure.Apply(new BasicContext(), new object[] { "Pontus", 35L }, _resourceTracker);

            // Then
            IList <object[]> collect = new IList <object[]> {
                @out
            };

            assertThat(collect[0][0], equalTo("Pontus is 35 years old."));
        }
示例#14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldLoadWhiteListedProcedure() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldLoadWhiteListedProcedure()
        {
            // Given
            ProcedureConfig config = new ProcedureConfig(Config.defaults(procedure_whitelist, "org.neo4j.kernel.impl.proc.listCoolPeople"));

            Log log = mock(typeof(Log));
            ReflectiveProcedureCompiler procedureCompiler = new ReflectiveProcedureCompiler(new TypeMappers(), _components, _components, log, config);

            // When
            CallableProcedure proc = procedureCompiler.CompileProcedure(typeof(SingleReadOnlyProcedure), null, false)[0];
            // When
            RawIterator <object[], ProcedureException> result = proc.Apply(new BasicContext(), new object[0], _resourceTracker);

            // Then
            assertEquals(result.Next()[0], "Bonnie");
        }
示例#15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRunClassWithMultipleProceduresDeclared() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRunClassWithMultipleProceduresDeclared()
        {
            // Given
            IList <CallableProcedure> compiled     = Compile(typeof(MultiProcedureProcedure));
            CallableProcedure         bananaPeople = compiled[0];
            CallableProcedure         coolPeople   = compiled[1];

            // When
            RawIterator <object[], ProcedureException> coolOut   = coolPeople.Apply(new BasicContext(), new object[0], _resourceTracker);
            RawIterator <object[], ProcedureException> bananaOut = bananaPeople.Apply(new BasicContext(), new object[0], _resourceTracker);

            // Then
            assertThat(asList(coolOut), contains(new object[] { "Bonnie" }, new object[] { "Clyde" }));

            assertThat(asList(bananaOut), contains(new object[] { "Jake", 18L }, new object[] { "Pontus", 2L }));
        }
示例#16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldInjectLogging() throws org.neo4j.internal.kernel.api.exceptions.KernelException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldInjectLogging()
        {
            // Given
            Log log = spy(typeof(Log));

            _components.register(typeof(Log), ctx => log);
            CallableProcedure procedure = _procedureCompiler.compileProcedure(typeof(LoggingProcedure), null, true)[0];

            // When
            procedure.Apply(new BasicContext(), new object[0], _resourceTracker);

            // Then
            verify(log).debug("1");
            verify(log).info("2");
            verify(log).warn("3");
            verify(log).error("4");
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRunGenericProcedure() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRunGenericProcedure()
        {
            // Given
            CallableProcedure procedure = Compile(typeof(ClassWithProcedureWithGenericArgs))[0];

            // When
            RawIterator <object[], ProcedureException> @out = procedure.Apply(new BasicContext(), new object[] { Arrays.asList("Roland", "Eddie", "Susan", "Jake"), Arrays.asList(1000L, 23L, 29L, 12L) }, _resourceTracker);

            // Then
            IList <object[]> collect = new IList <object[]> {
                @out
            };

            assertThat(collect[0][0], equalTo("Roland is 1000 years old."));
            assertThat(collect[1][0], equalTo("Eddie is 23 years old."));
            assertThat(collect[2][0], equalTo("Susan is 29 years old."));
            assertThat(collect[3][0], equalTo("Jake is 12 years old."));
        }
示例#18
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCloseResourcesAndGiveHelpfulErrorOnMidStreamException() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCloseResourcesAndGiveHelpfulErrorOnMidStreamException()
        {
            // Given
            CallableProcedure proc = Compile(typeof(ProcedureThatThrowsNullMsgExceptionMidStream))[0];

            // Expect
            Exception.expect(typeof(ProcedureException));
            Exception.expectMessage("Failed to invoke procedure `org.neo4j.kernel.impl.proc.throwsInStream`: " + "Caused by: java.lang.IndexOutOfBoundsException");

            // Expect that we get a suppressed exception from Stream.onClose (which also verifies that we actually call
            // onClose on the first exception)
            Exception.expect(new BaseMatcherAnonymousInnerClass(this));

            // When
            RawIterator <object[], ProcedureException> stream = proc.Apply(new BasicContext(), new object[0], _resourceTracker);

            if (stream.HasNext())
            {
                stream.Next();
            }
        }
示例#19
0
        /// <summary>
        /// Register a new procedure. This method must not be called concurrently with <seealso cref="procedure(QualifiedName)"/>. </summary>
        /// <param name="proc"> the procedure. </param>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void register(org.neo4j.kernel.api.proc.CallableProcedure proc) throws org.neo4j.internal.kernel.api.exceptions.ProcedureException
        public virtual void Register(CallableProcedure proc)
        {
            Register(proc, false);
        }
示例#20
0
        /// <summary>
        /// Register a new procedure. This method must not be called concurrently with <seealso cref="procedure(QualifiedName)"/>. </summary>
        /// <param name="proc"> the procedure. </param>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void register(org.neo4j.kernel.api.proc.CallableProcedure proc, boolean overrideCurrentImplementation) throws org.neo4j.internal.kernel.api.exceptions.ProcedureException
        public virtual void Register(CallableProcedure proc, bool overrideCurrentImplementation)
        {
            _registry.register(proc, overrideCurrentImplementation);
        }
示例#21
0
 public virtual void Add(CallableProcedure proc)
 {
     ProceduresConflict.Add(proc);
 }