Exemplo n.º 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldProcessDiscardAllMessage() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldProcessDiscardAllMessage()
        {
            BoltStateMachineState newState = _state.process(DiscardAllMessage.INSTANCE, _context);

            assertEquals(_state, newState);                 // remains in failed state
            assertTrue(_connectionState.hasPendingIgnore());
        }
Exemplo n.º 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @ParameterizedTest @ValueSource(strings = {"rollback", "ROLLBACK", "   rollback   ", "   RoLlBaCk ;   "}) void shouldRollbackTransaction(String statement) throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldRollbackTransaction(string statement)
        {
            BoltStateMachineState newState = _state.process(new RunMessage(statement), _context);

            assertEquals(_streamingState, newState);
            verify(_statementProcessor).rollbackTransaction();
        }
Exemplo n.º 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldHandleFailureDuringResetMessageProcessing() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldHandleFailureDuringResetMessageProcessing()
        {
            when(_context.resetMachine()).thenReturn(false);                 // reset failed
            BoltStateMachineState newState = _state.process(ResetMessage.INSTANCE, _context);

            assertEquals(_failedState, newState);
        }
Exemplo n.º 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldProcessRunMessage() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldProcessRunMessage()
        {
            BoltStateMachineState newState = _state.process(new RunMessage("RETURN 1", EMPTY_MAP), _context);

            assertEquals(_state, newState);                 // remains in failed state
            assertTrue(_connectionState.hasPendingIgnore());
        }
Exemplo n.º 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldBeginTransactionWithoutBookmark() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldBeginTransactionWithoutBookmark()
        {
            BoltStateMachineState newState = _state.process(new RunMessage("BEGIN", EMPTY_MAP), _context);

            assertEquals(_streamingState, newState);
            verify(_statementProcessor).beginTransaction(null);
        }
Exemplo n.º 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldProcessResetMessage() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldProcessResetMessage()
        {
            when(_context.resetMachine()).thenReturn(true);                 // reset successful
            BoltStateMachineState newState = _state.process(ResetMessage.INSTANCE, _context);

            assertEquals(_readyState, newState);
        }
Exemplo n.º 7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldNotProcessUnsupportedMessage() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldNotProcessUnsupportedMessage()
        {
            RequestMessage unsupportedMessage = mock(typeof(RequestMessage));

            BoltStateMachineState newState = _state.process(unsupportedMessage, _context);

            assertNull(newState);
        }
Exemplo n.º 8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldBeginTransactionWithMultipleBookmarks() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldBeginTransactionWithMultipleBookmarks()
        {
            IDictionary <string, object> @params = map("bookmarks", asList("neo4j:bookmark:v1:tx7", "neo4j:bookmark:v1:tx1", "neo4j:bookmark:v1:tx92", "neo4j:bookmark:v1:tx39"));

            BoltStateMachineState newState = _state.process(new RunMessage("BEGIN", asMapValue(@params)), _context);

            assertEquals(_streamingState, newState);
            verify(_statementProcessor).beginTransaction(new Bookmark(92));
        }
Exemplo n.º 9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldProcessAckFailureMessageWithPendingIgnore() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldProcessAckFailureMessageWithPendingIgnore()
        {
            _connectionState.markIgnored();
            assertTrue(_connectionState.hasPendingIgnore());

            BoltStateMachineState newState = _state.process(AckFailureMessage.INSTANCE, _context);

            assertEquals(_readyState, newState);
            assertFalse(_connectionState.hasPendingIgnore());
        }
Exemplo n.º 10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldProcessResetMessageWithPerndingIgnore() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldProcessResetMessageWithPerndingIgnore()
        {
            when(_context.resetMachine()).thenReturn(true);                 // reset successful
            _connectionState.markIgnored();
            assertTrue(_connectionState.hasPendingIgnore());

            BoltStateMachineState newState = _state.process(ResetMessage.INSTANCE, _context);

            assertEquals(_readyState, newState);
            assertFalse(_connectionState.hasPendingIgnore());
        }
Exemplo n.º 11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldProcessDiscardAllMessage() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldProcessDiscardAllMessage()
        {
            StatementProcessor statementProcessor = mock(typeof(StatementProcessor));

            _connectionState.StatementProcessor = statementProcessor;

            BoltStateMachineState nextState = _state.process(DiscardAllMessage.INSTANCE, _context);

            assertEquals(_readyState, nextState);
            verify(statementProcessor).streamResult(any());
        }
Exemplo n.º 12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldHandleFailureDuringRunMessageProcessing() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldHandleFailureDuringRunMessageProcessing()
        {
            Exception error = new Exception("Hello");

            when(_statementProcessor.run(any(), any())).thenThrow(error);

            BoltStateMachineState nextState = _state.process(new RunMessage("RETURN 1", EMPTY_MAP), _context);

            assertEquals(_failedState, nextState);
            verify(_context).handleFailure(error, false);
        }
Exemplo n.º 13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldProcessAckFailureMessageWithPendingError() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldProcessAckFailureMessageWithPendingError()
        {
            Neo4jError error = Neo4jError.from(new Exception());

            _connectionState.markFailed(error);
            assertEquals(error, _connectionState.PendingError);

            BoltStateMachineState newState = _state.process(AckFailureMessage.INSTANCE, _context);

            assertEquals(_readyState, newState);
            assertNull(_connectionState.PendingError);
        }
Exemplo n.º 14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldProcessResetMessageWhenInterrupted() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldProcessResetMessageWhenInterrupted()
        {
            _connectionState.incrementInterruptCounter();
            _connectionState.incrementInterruptCounter();
            assertTrue(_connectionState.Interrupted);
            assertFalse(_connectionState.hasPendingIgnore());

            BoltStateMachineState newState = _state.process(ResetMessage.INSTANCE, _context);

            assertEquals(_state, newState);                 // remains in interrupted state
            assertTrue(_connectionState.hasPendingIgnore());
        }
Exemplo n.º 15
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void nextState(org.neo4j.bolt.messaging.RequestMessage message, org.neo4j.bolt.runtime.StateMachineContext context) throws org.neo4j.bolt.runtime.BoltConnectionFatality
        private void NextState(RequestMessage message, StateMachineContext context)
        {
            BoltStateMachineState preState = _state;

            _state = _state.process(message, context);
            if (_state == null)
            {
                string msg = "Message '" + message + "' cannot be handled by a session in the " + preState.Name() + " state.";
                Fail(Neo4jError.fatalFrom(Org.Neo4j.Kernel.Api.Exceptions.Status_Request.Invalid, msg));
                throw new BoltProtocolBreachFatality(msg);
            }
        }
Exemplo n.º 16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldProcessResetMessageWithPerndingError() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldProcessResetMessageWithPerndingError()
        {
            when(_context.resetMachine()).thenReturn(true);                 // reset successful
            Neo4jError error = Neo4jError.from(new Exception());

            _connectionState.markFailed(error);
            assertEquals(error, _connectionState.PendingError);

            BoltStateMachineState newState = _state.process(ResetMessage.INSTANCE, _context);

            assertEquals(_readyState, newState);
            assertNull(_connectionState.PendingError);
        }
Exemplo n.º 17
0
        public BoltStateMachineV1(BoltStateMachineSPI spi, BoltChannel boltChannel, Clock clock)
        {
            this._id                     = boltChannel.Id();
            this._boltChannel            = boltChannel;
            this._spi                    = spi;
            this.ConnectionStateConflict = new MutableConnectionState();
            this._context                = new BoltStateMachineV1Context(this, boltChannel, spi, ConnectionStateConflict, clock);

            States states = BuildStates();

            this._state       = states.Initial;
            this._failedState = states.Failed;
        }
Exemplo n.º 18
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldHandleErrorWhenProcessingDiscardAllMessage() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldHandleErrorWhenProcessingDiscardAllMessage()
        {
            Exception error = new Exception("Hello");

            StatementProcessor statementProcessor = mock(typeof(StatementProcessor));

            doThrow(error).when(statementProcessor).streamResult(any());
            _connectionState.StatementProcessor = statementProcessor;

            BoltStateMachineState nextState = _state.process(DiscardAllMessage.INSTANCE, _context);

            assertEquals(_failedState, nextState);
            verify(_context).handleFailure(error, false);
        }
Exemplo n.º 19
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldIgnoreMessagesOtherThanInterruptAndReset() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldIgnoreMessagesOtherThanInterruptAndReset()
        {
            IList <RequestMessage> messages = new IList <RequestMessage> {
                AckFailureMessage.INSTANCE, PullAllMessage.INSTANCE, DiscardAllMessage.INSTANCE, new RunMessage("RETURN 1", EMPTY_MAP), new InitMessage("Driver", emptyMap())
            };

            foreach (RequestMessage message in messages)
            {
                _connectionState.resetPendingFailedAndIgnored();

                BoltStateMachineState newState = _state.process(message, _context);

                assertEquals(_state, newState);                           // remains in interrupted state
                assertTrue(_connectionState.hasPendingIgnore());
            }
        }
Exemplo n.º 20
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void handleExternalFailure(org.neo4j.bolt.runtime.Neo4jError error, org.neo4j.bolt.runtime.BoltResponseHandler handler) throws org.neo4j.bolt.runtime.BoltConnectionFatality
        public override void HandleExternalFailure(Neo4jError error, BoltResponseHandler handler)
        {
            Before(handler);
            try
            {
                if (ConnectionStateConflict.canProcessMessage())
                {
                    Fail(error);
                    _state = _failedState;
                }
            }
            finally
            {
                After();
            }
        }
Exemplo n.º 21
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldProcessRunMessage() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldProcessRunMessage()
        {
            StatementMetadata statementMetadata = mock(typeof(StatementMetadata));

            when(statementMetadata.FieldNames()).thenReturn(new string[] { "foo", "bar", "baz" });
            when(_statementProcessor.run(any(), any())).thenReturn(statementMetadata);

            BoltResponseHandler responseHandler = mock(typeof(BoltResponseHandler));

            _connectionState.ResponseHandler = responseHandler;

            BoltStateMachineState nextState = _state.process(new RunMessage("RETURN 1", EMPTY_MAP), _context);

            assertEquals(_streamingState, nextState);
            verify(_statementProcessor).run("RETURN 1", EMPTY_MAP);
            verify(responseHandler).onMetadata("fields", stringArray("foo", "bar", "baz"));
            verify(responseHandler).onMetadata(eq("result_available_after"), any());
        }
Exemplo n.º 22
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldAddServerVersionMetadataOnHelloMessage() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldAddServerVersionMetadataOnHelloMessage()
        {
            // Given
            // hello message
            IDictionary <string, object> meta = map("user_agent", "3.0", PRINCIPAL, "neo4j", CREDENTIALS, "password");
            HelloMessage helloMessage         = new HelloMessage(meta);

            // setup state machine
            ConnectedState        state      = new ConnectedState();
            BoltStateMachineState readyState = mock(typeof(BoltStateMachineState));

            StateMachineContext    context         = mock(typeof(StateMachineContext));
            BoltStateMachineSPI    boltSpi         = mock(typeof(BoltStateMachineSPI), RETURNS_MOCKS);
            MutableConnectionState connectionState = new MutableConnectionState();

            state.ReadyState = readyState;

            when(context.BoltSpi()).thenReturn(boltSpi);
            when(context.ConnectionState()).thenReturn(connectionState);

            when(boltSpi.Version()).thenReturn("42.42.42");
            MutableConnectionState connectionStateMock = mock(typeof(MutableConnectionState));

            when(context.ConnectionState()).thenReturn(connectionStateMock);
            when(context.ConnectionId()).thenReturn("connection-uuid");

            when(boltSpi.Authenticate(meta)).thenReturn(AuthenticationResult.AUTH_DISABLED);

            // When
            BoltStateMachineState newState = state.Process(helloMessage, context);

            // Then
            assertEquals(readyState, newState);
            verify(connectionStateMock).onMetadata("server", stringValue("42.42.42"));
            verify(connectionStateMock).onMetadata(eq("connection_id"), any(typeof(StringValue)));
        }
Exemplo n.º 23
0
 public override void MarkFailed(Neo4jError error)
 {
     Fail(error);
     _state = _failedState;
 }
Exemplo n.º 24
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldProcessInterruptMessage() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldProcessInterruptMessage()
        {
            BoltStateMachineState newState = _state.process(InterruptSignal.INSTANCE, _context);

            assertEquals(_interruptedState, newState);
        }
Exemplo n.º 25
0
 public States(BoltStateMachineState initial, BoltStateMachineState failed)
 {
     this.Initial = initial;
     this.Failed  = failed;
 }