Beispiel #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void testPermutation(byte[] unfragmented, io.netty.buffer.ByteBuf[] fragments) throws Exception
        private void TestPermutation(sbyte[] unfragmented, ByteBuf[] fragments)
        {
            // Given
            _channel = new EmbeddedChannel();
            BoltChannel boltChannel = NewBoltChannel(_channel);

            BoltStateMachine          machine        = mock(typeof(BoltStateMachine));
            SynchronousBoltConnection boltConnection = new SynchronousBoltConnection(machine);
            NullLogService            logging        = NullLogService.Instance;
            BoltProtocol boltProtocol = new BoltProtocolV1(boltChannel, (ch, s) => boltConnection, (v, ch) => machine, logging);

            boltProtocol.Install();

            // When data arrives split up according to the current permutation
            foreach (ByteBuf fragment in fragments)
            {
                _channel.writeInbound(fragment.readerIndex(0).retain());
            }

            // Then the session should've received the specified messages, and the protocol should be in a nice clean state
            try
            {
                RequestMessage run = new RunMessage("Mjölnir", EMPTY_MAP);
                verify(machine).process(eq(run), any(typeof(BoltResponseHandler)));
            }
            catch (AssertionError e)
            {
                throw new AssertionError("Failed to handle fragmented delivery.\n" + "Messages: " + Arrays.ToString(_messages) + "\n" + "Chunk size: " + _chunkSize + "\n" + "Serialized data delivered in fragments: " + DescribeFragments(fragments) + "\n" + "Unfragmented data: " + HexPrinter.hex(unfragmented) + "\n", e);
            }
        }
Beispiel #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCallExternalErrorOnInitWithDuplicateKeys() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCallExternalErrorOnInitWithDuplicateKeys()
        {
            BoltStateMachine          stateMachine = mock(typeof(BoltStateMachine));
            SynchronousBoltConnection connection   = new SynchronousBoltConnection(stateMachine);

            _channel = new EmbeddedChannel(NewDecoder(connection));

            // Generate INIT message with duplicate keys
            PackedOutputArray @out = new PackedOutputArray();

            Org.Neo4j.Bolt.messaging.Neo4jPack_Packer packer = PackerUnderTest.newPacker(@out);
            packer.PackStructHeader(2, InitMessage.SIGNATURE);
            packer.Pack("Test/User Agent 1.0");
            packer.PackMapHeader(3);
            packer.Pack("scheme");
            packer.Pack("basic");
            packer.Pack("principal");
            packer.Pack("user");
            packer.Pack("scheme");
            packer.Pack("password");

            _channel.writeInbound(Unpooled.wrappedBuffer(@out.Bytes()));
            _channel.finishAndReleaseAll();

            verify(stateMachine).handleExternalFailure(eq(Neo4jError.from(Org.Neo4j.Kernel.Api.Exceptions.Status_Request.Invalid, "Duplicate map key `scheme`.")), any());
        }
        public override BoltConnection NewConnection(BoltChannel channel, BoltStateMachine stateMachine)
        {
            requireNonNull(channel);
            requireNonNull(stateMachine);

            BoltScheduler              scheduler              = _schedulerProvider.get(channel);
            BoltConnectionReadLimiter  readLimiter            = CreateReadLimiter(_config, _logService);
            BoltConnectionQueueMonitor connectionQueueMonitor = new BoltConnectionQueueMonitorAggregate(scheduler, readLimiter);
            ChunkedOutput              chunkedOutput          = new ChunkedOutput(channel.RawChannel(), _throttleGroup);

            BoltConnection connection;

            if (_monitors.hasListeners(typeof(BoltConnectionMetricsMonitor)))
            {
                connection = new MetricsReportingBoltConnection(channel, chunkedOutput, stateMachine, _logService, scheduler, connectionQueueMonitor, _metricsMonitor, _clock);
            }
            else
            {
                connection = new DefaultBoltConnection(channel, chunkedOutput, stateMachine, _logService, scheduler, connectionQueueMonitor);
            }

            connection.Start();

            return(connection);
        }
Beispiel #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReceiveBookmarkOnCommitAndPullAll() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReceiveBookmarkOnCommitAndPullAll()
        {
            // Given
            BoltResponseRecorder recorder = new BoltResponseRecorder();
            BoltStateMachine     machine  = Env.newMachine(_boltChannel);

            machine.Process(new InitMessage(USER_AGENT, emptyMap()), nullResponseHandler());

            // When
            machine.Process(new RunMessage("BEGIN", EMPTY_MAP), recorder);
            machine.Process(DiscardAllMessage.INSTANCE, recorder);

            machine.Process(new RunMessage("CREATE (a:Person)", EMPTY_MAP), recorder);
            machine.Process(DiscardAllMessage.INSTANCE, recorder);

            machine.Process(new RunMessage("COMMIT", EMPTY_MAP), recorder);
            machine.Process(PullAllMessage.INSTANCE, recorder);

            // Then
            assertThat(recorder.NextResponse(), succeeded());
            assertThat(recorder.NextResponse(), succeeded());
            assertThat(recorder.NextResponse(), succeeded());
            assertThat(recorder.NextResponse(), succeeded());
            assertThat(recorder.NextResponse(), succeeded());
            assertThat(recorder.NextResponse(), succeededWithMetadata("bookmark", _bookmarkPattern));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setup()
        public virtual void Setup()
        {
            _boltChannel  = new BoltChannel("bolt-1", "bolt", _channel);
            _stateMachine = mock(typeof(BoltStateMachine));
            when(_stateMachine.shouldStickOnThread()).thenReturn(false);
            when(_stateMachine.hasOpenStatement()).thenReturn(false);
        }
Beispiel #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCloseAutoCommitTransactionAndRespondToNextStatementWhenStreamingFails() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCloseAutoCommitTransactionAndRespondToNextStatementWhenStreamingFails()
        {
            // Given
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.bolt.runtime.BoltStateMachine machine = env.newMachine(BOLT_CHANNEL);
            BoltStateMachine machine = Env.newMachine(_boltChannel);

            machine.Process(new InitMessage(USER_AGENT, emptyMap()), nullResponseHandler());
            BoltResponseRecorder recorder = new BoltResponseRecorder();

            // When
            machine.Process(new RunMessage("UNWIND [1, 0] AS x RETURN 1 / x", EMPTY_MAP), recorder);
            machine.Process(PullAllMessage.INSTANCE, recorder);
            machine.Process(AckFailureMessage.INSTANCE, recorder);
            machine.Process(new RunMessage("RETURN 2", EMPTY_MAP), recorder);
            machine.Process(PullAllMessage.INSTANCE, recorder);

            // Then
            assertThat(recorder.NextResponse(), succeeded());
            assertThat(recorder.NextResponse(), allOf(containsRecord(1L), failedWithStatus(Org.Neo4j.Kernel.Api.Exceptions.Status_Statement.ArithmeticError)));
            assertThat(recorder.NextResponse(), succeeded());
            assertThat(recorder.NextResponse(), succeeded());
            assertThat(recorder.NextResponse(), succeededWithRecord(2L));
            assertEquals(0, recorder.ResponseCount());
        }
 public BoltStateMachineV1Context(BoltStateMachine machine, BoltChannel boltChannel, BoltStateMachineSPI spi, MutableConnectionState connectionState, Clock clock)
 {
     this._machine         = machine;
     this._boltChannel     = boltChannel;
     this._spi             = spi;
     this._connectionState = connectionState;
     this._clock           = clock;
 }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldCreateBoltStateMachinesV3()
        internal virtual void ShouldCreateBoltStateMachinesV3()
        {
            BoltStateMachineFactoryImpl factory = NewBoltFactory();

            BoltStateMachine boltStateMachine = factory.NewStateMachine(3L, _channel);

            assertNotNull(boltStateMachine);
            assertThat(boltStateMachine, instanceOf(typeof(BoltStateMachineV3)));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @ParameterizedTest(name = "V{0}") @ValueSource(longs = {org.neo4j.bolt.v1.BoltProtocolV1.VERSION, org.neo4j.bolt.v2.BoltProtocolV2.VERSION}) void shouldCreateBoltStateMachinesV1(long protocolVersion)
        internal virtual void ShouldCreateBoltStateMachinesV1(long protocolVersion)
        {
            BoltStateMachineFactoryImpl factory = NewBoltFactory();

            BoltStateMachine boltStateMachine = factory.NewStateMachine(protocolVersion, _channel);

            assertNotNull(boltStateMachine);
            assertThat(boltStateMachine, instanceOf(typeof(BoltStateMachineV1)));
        }
Beispiel #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldResetMachine() throws org.neo4j.bolt.runtime.BoltConnectionFatality
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldResetMachine()
        {
            BoltStateMachine          machine = mock(typeof(BoltStateMachine));
            BoltStateMachineV1Context context = NewContext(machine, mock(typeof(BoltStateMachineSPI)));

            context.ResetMachine();

            verify(machine).reset();
        }
Beispiel #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReadYourOwnWrites() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReadYourOwnWrites()
        {
            using (Transaction tx = Env.graph().beginTx())
            {
                Node node = Env.graph().createNode(Label.label("A"));
                node.SetProperty("prop", "one");
                tx.Success();
            }

            BinaryLatch latch = new BinaryLatch();

            long   dbVersion = Env.lastClosedTxId();
            Thread thread    = new Thread(() =>
            {
                try
                {
                    using (BoltStateMachine machine = Env.newMachine(_boltChannel))
                    {
                        machine.process(new InitMessage(USER_AGENT, emptyMap()), nullResponseHandler());
                        latch.Await();
                        machine.process(new RunMessage("MATCH (n:A) SET n.prop = 'two'", EMPTY_MAP), nullResponseHandler());
                        machine.process(PullAllMessage.INSTANCE, nullResponseHandler());
                    }
                }
                catch (BoltConnectionFatality connectionFatality)
                {
                    throw new Exception(connectionFatality);
                }
            });

            thread.Start();

            long dbVersionAfterWrite = dbVersion + 1;

            using (BoltStateMachine machine = Env.newMachine(_boltChannel))
            {
                BoltResponseRecorder recorder = new BoltResponseRecorder();
                machine.process(new InitMessage(USER_AGENT, emptyMap()), nullResponseHandler());
                latch.Release();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final String bookmark = "neo4j:bookmark:v1:tx" + dbVersionAfterWrite;
                string bookmark = "neo4j:bookmark:v1:tx" + dbVersionAfterWrite;
                machine.process(new RunMessage("BEGIN", ValueUtils.asMapValue(singletonMap("bookmark", bookmark))), nullResponseHandler());
                machine.process(PullAllMessage.INSTANCE, recorder);
                machine.process(new RunMessage("MATCH (n:A) RETURN n.prop", EMPTY_MAP), nullResponseHandler());
                machine.process(PullAllMessage.INSTANCE, recorder);
                machine.process(new RunMessage("COMMIT", EMPTY_MAP), nullResponseHandler());
                machine.process(PullAllMessage.INSTANCE, recorder);

                assertThat(recorder.NextResponse(), succeeded());
                assertThat(recorder.NextResponse(), succeededWithRecord("two"));
                assertThat(recorder.NextResponse(), succeededWithMetadata("bookmark", _bookmarkPattern));
            }

            thread.Join();
        }
Beispiel #12
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void unpack(byte[] input) throws java.io.IOException
        private void Unpack(sbyte[] input)
        {
            BoltStateMachine          stateMachine = mock(typeof(BoltStateMachine));
            SynchronousBoltConnection connection   = new SynchronousBoltConnection(stateMachine);

            _channel = new EmbeddedChannel(NewDecoder(connection));

            _channel.writeInbound(Unpooled.wrappedBuffer(input));
            _channel.finishAndReleaseAll();
        }
Beispiel #13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldHandleFailure() throws org.neo4j.bolt.runtime.BoltConnectionFatality
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldHandleFailure()
        {
            BoltStateMachine          machine = mock(typeof(BoltStateMachine));
            BoltStateMachineV1Context context = NewContext(machine, mock(typeof(BoltStateMachineSPI)));

            Exception cause = new Exception();

            context.HandleFailure(cause, true);

            verify(machine).handleFailure(cause, true);
        }
Beispiel #14
0
        public virtual BoltStateMachine NewMachine(long version, BoltChannel boltChannel)
        {
            if (_boltFactory == null)
            {
                throw new System.InvalidOperationException("Cannot access test environment before test is running.");
            }
            BoltStateMachine machine = _boltFactory.newStateMachine(version, boltChannel);

            _runningMachines.Add(machine);
            return(machine);
        }
Beispiel #15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDispatchPullAll() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldDispatchPullAll()
        {
            BoltStateMachine          stateMachine = mock(typeof(BoltStateMachine));
            SynchronousBoltConnection connection   = new SynchronousBoltConnection(stateMachine);

            _channel = new EmbeddedChannel(NewDecoder(connection));

            _channel.writeInbound(Unpooled.wrappedBuffer(serialize(PackerUnderTest, PullAllMessage.INSTANCE)));
            _channel.finishAndReleaseAll();

            verify(stateMachine).process(eq(PullAllMessage.INSTANCE), any());
        }
 public DefaultBoltConnection(BoltChannel channel, PackOutput output, BoltStateMachine machine, LogService logService, BoltConnectionLifetimeListener listener, BoltConnectionQueueMonitor queueMonitor, int maxBatchSize)
 {
     this._id           = channel.Id();
     this._channel      = channel;
     this._output       = output;
     this._machine      = machine;
     this._listener     = listener;
     this._queueMonitor = queueMonitor;
     this._log          = logService.GetInternalLog(this.GetType());
     this._userLog      = logService.GetUserLog(this.GetType());
     this._maxBatchSize = maxBatchSize;
     this._batch        = new List <Job>(maxBatchSize);
 }
Beispiel #17
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDispatchInit() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldDispatchInit()
        {
            BoltStateMachine          stateMachine = mock(typeof(BoltStateMachine));
            SynchronousBoltConnection connection   = new SynchronousBoltConnection(stateMachine);

            _channel = new EmbeddedChannel(NewDecoder(connection));

            string userAgent = "Test/User Agent 1.0";
            IDictionary <string, object> authToken = MapUtil.map("scheme", "basic", "principal", "user", "credentials", "password");

            _channel.writeInbound(Unpooled.wrappedBuffer(serialize(PackerUnderTest, new InitMessage(userAgent, authToken))));
            _channel.finishAndReleaseAll();

            verify(stateMachine).process(refEq(new InitMessage(userAgent, authToken), "authToken"), any());
        }
Beispiel #18
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDispatchRun() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldDispatchRun()
        {
            BoltStateMachine          stateMachine = mock(typeof(BoltStateMachine));
            SynchronousBoltConnection connection   = new SynchronousBoltConnection(stateMachine);

            _channel = new EmbeddedChannel(NewDecoder(connection));

            string   statement  = "RETURN 1";
            MapValue parameters = ValueUtils.asMapValue(MapUtil.map("param1", 1, "param2", "2", "param3", true, "param4", 5.0));

            _channel.writeInbound(Unpooled.wrappedBuffer(serialize(PackerUnderTest, new RunMessage(statement, parameters))));
            _channel.finishAndReleaseAll();

            verify(stateMachine).process(eq(new RunMessage(statement, parameters)), any());
        }
Beispiel #19
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCallExternalErrorOnInitWithNullKeys() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCallExternalErrorOnInitWithNullKeys()
        {
            BoltStateMachine          stateMachine = mock(typeof(BoltStateMachine));
            SynchronousBoltConnection connection   = new SynchronousBoltConnection(stateMachine);

            _channel = new EmbeddedChannel(NewDecoder(connection));

            string userAgent = "Test/User Agent 1.0";
            IDictionary <string, object> authToken = MapUtil.map("scheme", "basic", null, "user", "credentials", "password");

            _channel.writeInbound(Unpooled.wrappedBuffer(serialize(PackerUnderTest, new InitMessage(userAgent, authToken))));
            _channel.finishAndReleaseAll();

            verify(stateMachine).handleExternalFailure(eq(Neo4jError.from(Org.Neo4j.Kernel.Api.Exceptions.Status_Request.Invalid, "Value `null` is not supported as key in maps, must be a non-nullable string.")), any());
        }
Beispiel #20
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void testUnpackableStructParametersWithKnownType(org.neo4j.bolt.messaging.Neo4jPack packerForSerialization, org.neo4j.values.AnyValue parameterValue, String expectedMessage) throws Exception
        private void TestUnpackableStructParametersWithKnownType(Neo4jPack packerForSerialization, AnyValue parameterValue, string expectedMessage)
        {
            string   statement  = "RETURN $x";
            MapValue parameters = VirtualValues.map(new string[] { "x" }, new AnyValue[] { parameterValue });

            BoltStateMachine          stateMachine = mock(typeof(BoltStateMachine));
            SynchronousBoltConnection connection   = new SynchronousBoltConnection(stateMachine);

            _channel = new EmbeddedChannel(NewDecoder(connection));

            _channel.writeInbound(Unpooled.wrappedBuffer(serialize(packerForSerialization, new RunMessage(statement, parameters))));
            _channel.finishAndReleaseAll();

            verify(stateMachine).handleExternalFailure(eq(Neo4jError.from(Org.Neo4j.Kernel.Api.Exceptions.Status_Statement.TypeError, expectedMessage)), any());
        }
Beispiel #21
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void testMessageDecoding(org.neo4j.bolt.messaging.RequestMessage message) throws Exception
        private static void TestMessageDecoding(RequestMessage message)
        {
            Neo4jPack neo4jPack = newNeo4jPack();

            BoltStateMachine         stateMachine = mock(typeof(BoltStateMachine));
            BoltRequestMessageReader reader       = requestMessageReader(stateMachine);

            PackedInputArray input = new PackedInputArray(encode(neo4jPack, message));

            Org.Neo4j.Bolt.messaging.Neo4jPack_Unpacker unpacker = neo4jPack.NewUnpacker(input);

            reader.Read(unpacker);

            verify(stateMachine).process(eq(message), any());
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleErrorThatCausesFailureMessage() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldHandleErrorThatCausesFailureMessage()
        {
            Neo4jPack_Unpacker unpacker = mock(typeof(Neo4jPack_Unpacker));
            BoltIOException    error    = new BoltIOException(Org.Neo4j.Kernel.Api.Exceptions.Status_General.UnknownError, "Hello");

            when(unpacker.UnpackStructHeader()).thenThrow(error);

            BoltStateMachine stateMachine = mock(typeof(BoltStateMachine));
            BoltConnection   connection   = new SynchronousBoltConnection(stateMachine);

            BoltResponseHandler      externalErrorResponseHandler = ResponseHandlerMock();
            BoltRequestMessageReader reader = new TestBoltRequestMessageReader(connection, externalErrorResponseHandler, emptyList());

            reader.Read(unpacker);

            verify(stateMachine).handleExternalFailure(Neo4jError.from(error), externalErrorResponseHandler);
        }
Beispiel #23
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotFailWhenOutOfOrderRollbackInAutoCommitMode() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotFailWhenOutOfOrderRollbackInAutoCommitMode()
        {
            // Given
            BoltResponseRecorder runRecorder     = new BoltResponseRecorder();
            BoltResponseRecorder pullAllRecorder = new BoltResponseRecorder();
            BoltStateMachine     machine         = Env.newMachine(_boltChannel);

            machine.Process(new InitMessage(USER_AGENT, emptyMap()), nullResponseHandler());

            // When
            machine.Process(new RunMessage("ROLLBACK", EMPTY_MAP), runRecorder);
            machine.Process(PullAllMessage.INSTANCE, pullAllRecorder);

            // Then
            assertThat(runRecorder.NextResponse(), succeeded());
            assertThat(pullAllRecorder.NextResponse(), succeeded());
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDecodeKnownMessage() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldDecodeKnownMessage()
        {
            Neo4jPack_Unpacker unpacker = mock(typeof(Neo4jPack_Unpacker));

            when(unpacker.UnpackStructSignature()).thenReturn('a');

            RequestMessage        message         = mock(typeof(RequestMessage));
            BoltResponseHandler   responseHandler = ResponseHandlerMock();
            RequestMessageDecoder decoder         = new TestRequestMessageDecoder('a', responseHandler, message);

            BoltStateMachine stateMachine = mock(typeof(BoltStateMachine));
            BoltConnection   connection   = new SynchronousBoltConnection(stateMachine);

            BoltRequestMessageReader reader = new TestBoltRequestMessageReader(connection, ResponseHandlerMock(), singletonList(decoder));

            reader.Read(unpacker);

            verify(stateMachine).process(message, responseHandler);
        }
Beispiel #25
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldInterpretEmptyStatementAsReuseLastStatementInAutocommitTransaction() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldInterpretEmptyStatementAsReuseLastStatementInAutocommitTransaction()
        {
            // Given
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.bolt.runtime.BoltStateMachine machine = env.newMachine(BOLT_CHANNEL);
            BoltStateMachine machine = Env.newMachine(_boltChannel);

            machine.Process(new InitMessage(USER_AGENT, emptyMap()), nullResponseHandler());
            BoltResponseRecorder recorder = new BoltResponseRecorder();

            // When
            machine.Process(new RunMessage("RETURN 1", EMPTY_MAP), nullResponseHandler());
            machine.Process(PullAllMessage.INSTANCE, recorder);
            machine.Process(new RunMessage("", EMPTY_MAP), nullResponseHandler());
            machine.Process(PullAllMessage.INSTANCE, recorder);

            // Then
            assertThat(recorder.NextResponse(), succeededWithRecord(1L));
            assertThat(recorder.NextResponse(), succeededWithRecord(1L));
        }
Beispiel #26
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleBeginCommit() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldHandleBeginCommit()
        {
            // Given
            BoltResponseRecorder recorder = new BoltResponseRecorder();
            BoltStateMachine     machine  = Env.newMachine(_boltChannel);

            machine.Process(new InitMessage(USER_AGENT, emptyMap()), nullResponseHandler());

            // When
            machine.Process(new RunMessage("BEGIN", EMPTY_MAP), recorder);
            machine.Process(DiscardAllMessage.INSTANCE, nullResponseHandler());

            machine.Process(new RunMessage("CREATE (n:InTx)", EMPTY_MAP), recorder);
            machine.Process(DiscardAllMessage.INSTANCE, nullResponseHandler());

            machine.Process(new RunMessage("COMMIT", EMPTY_MAP), recorder);
            machine.Process(DiscardAllMessage.INSTANCE, nullResponseHandler());

            // Then
            assertThat(recorder.NextResponse(), succeeded());
            assertThat(recorder.NextResponse(), succeeded());
            assertThat(recorder.NextResponse(), succeeded());
        }
Beispiel #27
0
 internal MetricsReportingBoltConnection(BoltChannel channel, PackOutput output, BoltStateMachine machine, LogService logService, BoltConnectionLifetimeListener listener, BoltConnectionQueueMonitor queueMonitor, int maxBatchSize, BoltConnectionMetricsMonitor metricsMonitor, Clock clock) : base(channel, output, machine, logService, listener, queueMonitor, maxBatchSize)
 {
     this._metricsMonitor = metricsMonitor;
     this._clock          = clock;
 }
Beispiel #28
0
 internal MetricsReportingBoltConnection(BoltChannel channel, PackOutput output, BoltStateMachine machine, LogService logService, BoltConnectionLifetimeListener listener, BoltConnectionQueueMonitor queueMonitor, BoltConnectionMetricsMonitor metricsMonitor, Clock clock) : this(channel, output, machine, logService, listener, queueMonitor, DefaultMaxBatchSize, metricsMonitor, clock)
 {
 }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private <T extends org.neo4j.bolt.messaging.RequestMessage> T unpack(RecordingByteChannel channel) throws Exception
        private T Unpack <T>(RecordingByteChannel channel) where T : Org.Neo4j.Bolt.messaging.RequestMessage
        {
            IList <RequestMessage> messages     = new List <RequestMessage>();
            BoltStateMachine       stateMachine = mock(typeof(BoltStateMachine));

            doAnswer(new AnswerAnonymousInnerClass(this, messages)) BoltRequestMessageReader reader = new BoltRequestMessageReaderV1(new SynchronousBoltConnection(stateMachine), mock(typeof(BoltResponseMessageWriter)), NullLogService.Instance);
Beispiel #30
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldTerminateQueriesEvenIfUsingPeriodicCommit() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldTerminateQueriesEvenIfUsingPeriodicCommit()
        {
            // Spawns a throttled HTTP server, runs a PERIODIC COMMIT that fetches data from this server,
            // and checks that the query able to be terminated

            // We start with 3, because that is how many actors we have -
            // 1. the http server
            // 2. the running query
            // 3. the one terminating 2
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.test.DoubleLatch latch = new org.neo4j.test.DoubleLatch(3, true);
            DoubleLatch latch = new DoubleLatch(3, true);

            // This is used to block the http server between the first and second batch
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.test.Barrier_Control barrier = new org.neo4j.test.Barrier_Control();
            Org.Neo4j.Test.Barrier_Control barrier = new Org.Neo4j.Test.Barrier_Control();

            // Serve CSV via local web server, let Jetty find a random port for us
            Server server = CreateHttpServer(latch, barrier, 20, 30);

            server.start();
            int localPort = GetLocalPort(server);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.bolt.runtime.BoltStateMachine[] machine = {null};
            BoltStateMachine[] machine = new BoltStateMachine[] { null };

            Thread thread = new Thread(() =>
            {
                try
                {
                    using (BoltStateMachine stateMachine = Env.newMachine(_boltChannel))
                    {
                        machine[0] = stateMachine;
                        stateMachine.process(new InitMessage(USER_AGENT, emptyMap()), nullResponseHandler());
                        string query = format("USING PERIODIC COMMIT 10 LOAD CSV FROM 'http://localhost:%d' AS line " + "CREATE (n:A {id: line[0], square: line[1]}) " + "WITH count(*) as number " + "CREATE (n:ShouldNotExist)", localPort);
                        try
                        {
                            latch.Start();
                            stateMachine.process(new RunMessage(query, EMPTY_MAP), nullResponseHandler());
                            stateMachine.process(PullAllMessage.INSTANCE, nullResponseHandler());
                        }
                        finally
                        {
                            latch.Finish();
                        }
                    }
                }
                catch (BoltConnectionFatality connectionFatality)
                {
                    throw new Exception(connectionFatality);
                }
            });

            thread.Name = "query runner";
            thread.Start();

            // We block this thread here, waiting for the http server to spin up and the running query to get started
            latch.StartAndWaitForAllToStart();
            Thread.Sleep(1000);

            // This is the call that RESETs the Bolt connection and will terminate the running query
            machine[0].Process(ResetMessage.INSTANCE, nullResponseHandler());

            barrier.Release();

            // We block again here, waiting for the running query to have been terminated, and for the server to have
            // wrapped up and finished streaming http results
            latch.FinishAndWaitForAllToFinish();

            // And now we check that the last node did not get created
            using (Transaction ignored = Env.graph().beginTx())
            {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertFalse("Query was not terminated in time - nodes were created!", Env.graph().findNodes(Label.label("ShouldNotExist")).hasNext());
            }
        }