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 shouldNotCloseTheGapIfItsTheCoordinatorAndTheGapIsSmallerThanTheThreshold() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotCloseTheGapIfItsTheCoordinatorAndTheGapIsSmallerThanTheThreshold()
        {
            // Given
            // A coordinator that knows that the last Paxos instance delivered is 3
            long         lastDelivered = 3L;
            LearnerState learner       = LearnerState.Learner;

            Org.Neo4j.cluster.InstanceId memberId = new Org.Neo4j.cluster.InstanceId(42);

            LearnerContext context = mock(typeof(LearnerContext));

            when(context.IsMe(any())).thenReturn(true);
            when(context.Coordinator).thenReturn(memberId);                   // so it's the coordinator
            when(context.LastDeliveredInstanceId).thenReturn(lastDelivered);
            // and has this list of pending instances (up to id 14)
            IList <PaxosInstance> pendingInstances = new LinkedList <PaxosInstance>();

            for (int i = 1; i < 12; i++)                 // start at 1 because instance 3 is already delivered
            {
                InstanceId    instanceId = new InstanceId(lastDelivered + i);
                PaxosInstance value      = new PaxosInstance(mock(typeof(PaxosInstanceStore)), instanceId);
                value.Closed("", "");
                when(context.GetPaxosInstance(instanceId)).thenReturn(value);
                pendingInstances.Add(value);
            }
            when(context.GetLog(any())).thenReturn(mock(typeof(Log)));

            Message <LearnerMessage> incomingInstance = Message.to(LearnerMessage.Learn, URI.create("c:/1"), new LearnerMessage.LearnState(new object())).setHeader(Message.HEADER_FROM, "c:/2").setHeader(Message.HEADER_CONVERSATION_ID, "conversation-id").setHeader(InstanceId.INSTANCE, "" + (lastDelivered + LearnerContext_Fields.LEARN_GAP_THRESHOLD));

            // When
            // it receives a message with Paxos instance id at the threshold
            learner.handle(context, incomingInstance, mock(typeof(MessageHolder)));

            // Then
            // it waits and doesn't deliver anything
            foreach (PaxosInstance pendingInstance in pendingInstances)
            {
                assertFalse(pendingInstance.IsState(PaxosInstance.State.Delivered));
            }
            verify(context, times(0)).LastDeliveredInstanceId = anyLong();
        }