Beispiel #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void ifProposingWithClosedInstanceThenRetryWithNextInstance() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void IfProposingWithClosedInstanceThenRetryWithNextInstance()
        {
            ProposerContext context = Mockito.mock(typeof(ProposerContext));

            when(context.GetLog(any(typeof(Type)))).thenReturn(NullLog.Instance);

            Org.Neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId instanceId = new Org.Neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId(42);
            PaxosInstanceStore paxosInstanceStore = new PaxosInstanceStore();

            // The instance is closed
            PaxosInstance paxosInstance = new PaxosInstance(paxosInstanceStore, instanceId); // the instance

            paxosInstance.Closed(instanceId, "1/15#");                                       // is closed for that conversation, not really important
            when(context.UnbookInstance(instanceId)).thenReturn(Message.@internal(ProposerMessage.Accepted, "the closed payload"));

            when(context.GetPaxosInstance(instanceId)).thenReturn(paxosInstance);                     // required for

            // But in the meantime it was reused and has now (of course) timed out
            string  theTimedoutPayload = "the timed out payload";
            Message message            = Message.@internal(ProposerMessage.Phase1Timeout, theTimedoutPayload);

            message.setHeader(Org.Neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId.INSTANCE, instanceId.ToString());

            // Handle it
            MessageHolder mockHolder = mock(typeof(MessageHolder));

            ProposerState.Proposer.handle(context, message, mockHolder);

            // Verify it was resent as a propose with the same value
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: verify(mockHolder, times(1)).offer(org.mockito.ArgumentMatchers.argThat<org.neo4j.cluster.com.message.Message<? extends org.neo4j.cluster.com.message.MessageType>>(new org.neo4j.cluster.protocol.MessageArgumentMatcher().onMessageType(ProposerMessage.propose).withPayload(theTimedoutPayload)));
            verify(mockHolder, times(1)).offer(ArgumentMatchers.argThat <Message <MessageType> >((new MessageArgumentMatcher()).onMessageType(ProposerMessage.Propose).withPayload(theTimedoutPayload)));
            verify(context, times(1)).unbookInstance(instanceId);
        }
Beispiel #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void something() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void Something()
        {
            object acceptorValue = new object();
            object bookedValue   = new object();

            Org.Neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId instanceId = new Org.Neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId(42);

            PaxosInstanceStore paxosInstanceStore = new PaxosInstanceStore();

            ProposerContext context = Mockito.mock(typeof(ProposerContext));

            when(context.GetPaxosInstance(instanceId)).thenReturn(paxosInstanceStore.GetPaxosInstance(instanceId));
            when(context.GetMinimumQuorumSize(Mockito.anyList())).thenReturn(2);

            // The instance is closed
            PaxosInstance paxosInstance = new PaxosInstance(paxosInstanceStore, instanceId);                 // the instance

            paxosInstance.Propose(2001, Iterables.asList(Iterables.iterable(create("http://something1"), create("http://something2"), create("http://something3"))));

            Message message = Message.to(ProposerMessage.Promise, create("http://something1"), new ProposerMessage.PromiseState(2001, acceptorValue));

            message.setHeader(Org.Neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId.INSTANCE, instanceId.ToString());

            MessageHolder mockHolder = mock(typeof(MessageHolder));

            ProposerState.Proposer.handle(context, message, mockHolder);
        }