Esempio n. 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAlwaysAddItsInstanceIdToOutgoingMessages()
        public virtual void ShouldAlwaysAddItsInstanceIdToOutgoingMessages()
        {
            InstanceId me = new InstanceId(42);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.List<org.neo4j.cluster.com.message.Message> sentOut = new java.util.LinkedList<>();
            IList <Message> sentOut = new LinkedList <Message>();

            /*
             * Lots of setup required. Must have a sender that keeps messages so we can see what the machine sent out.
             * We must have the StateMachines actually delegate the incoming message and retrieve the generated outgoing.
             * That means we need an actual StateMachine with a registered MessageType. And most of those are void
             * methods, which means lots of Answer objects.
             */
            // Given
            MessageSender sender = mock(typeof(MessageSender));

            // The sender, which adds messages outgoing to the list above.
            doAnswer(invocation =>
            {
                ((IList <Org.Neo4j.cluster.com.message.Message>)sentOut).AddRange(invocation.getArgument(0));
                return(null);
            }).when(sender).process(ArgumentMatchers.any <IList <Message <? extends MessageType> > >());

            StateMachines stateMachines = new StateMachines(NullLogProvider.Instance, mock(typeof(StateMachines.Monitor)), mock(typeof(MessageSource)), sender, mock(typeof(Timeouts)), mock(typeof(DelayedDirectExecutor)), ThreadStart.run, me);

            // The state machine, which has a TestMessage message type and simply adds a HEADER_TO header to the messages it
            // is handed to handle.
            StateMachine machine = mock(typeof(StateMachine));

            when(machine.MessageType).then((Answer <object>)invocation => typeof(TestMessage));
            doAnswer(invocation =>
            {
                Message message      = invocation.getArgument(0);
                MessageHolder holder = invocation.getArgument(1);
                message.setHeader(Message.HEADER_TO, "to://neverland");
                holder.offer(message);
                return(null);
            }).when(machine).handle(any(typeof(Message)), any(typeof(MessageHolder)));
            stateMachines.AddStateMachine(machine);

            // When
            stateMachines.Process(Message.@internal(TestMessage.Message1));

            // Then
            assertEquals("StateMachines should not make up messages from thin air", 1, sentOut.Count);
            Message sent = sentOut[0];

            assertTrue("StateMachines should add the instance-id header", sent.hasHeader(Message.HEADER_INSTANCE_ID));
            assertEquals("StateMachines should add instance-id header that has the correct value", me.ToString(), sent.getHeader(Message.HEADER_INSTANCE_ID));
        }
Esempio n. 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void whenMessageHandlingCausesNewMessagesThenEnsureCorrectOrder()
        public virtual void WhenMessageHandlingCausesNewMessagesThenEnsureCorrectOrder()
        {
            // Given
            StateMachines stateMachines = new StateMachines(NullLogProvider.Instance, mock(typeof(StateMachines.Monitor)), mock(typeof(MessageSource)), Mockito.mock(typeof(MessageSender)), Mockito.mock(typeof(Timeouts)), Mockito.mock(typeof(DelayedDirectExecutor)), ThreadStart.run, mock(typeof(InstanceId)));

            List <TestMessage> handleOrder  = new List <TestMessage>();
            StateMachine       stateMachine = new StateMachine(handleOrder, typeof(TestMessage), TestState.Test, NullLogProvider.Instance);

            stateMachines.AddStateMachine(stateMachine);

            // When
            stateMachines.Process(@internal(TestMessage.Message1));

            // Then
            assertThat(handleOrder.ToString(), equalTo("[message1, message2, message4, message5, message3]"));
        }