//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); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void proposer_rejectAcceptShouldCarryOnPayload() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ProposerRejectAcceptShouldCarryOnPayload() { // GIVEN string instanceId = "1"; PaxosInstance instance = new PaxosInstance(mock(typeof(PaxosInstanceStore)), new Org.Neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId(instanceId)); Serializable payload = "myPayload"; instance.Propose(1, new IList <java.net.URI> { create("http://some-guy") }); instance.Ready(payload, true); instance.Pending(); ProposerContext context = mock(typeof(ProposerContext)); when(context.GetLog(any(typeof(Type)))).thenReturn(NullLog.Instance); when(context.GetPaxosInstance(any(typeof(Org.Neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId)))).thenReturn(instance); when(context.MyId).thenReturn(new Org.Neo4j.cluster.InstanceId(parseInt(instanceId))); TrackingMessageHolder outgoing = new TrackingMessageHolder(); Message <ProposerMessage> message = to(rejectAccept, create("http://something"), new ProposerMessage.RejectAcceptState()).setHeader(INSTANCE, instanceId); // WHEN ProposerState.Proposer.handle(context, message, outgoing); // THEN verify(context).setTimeout(eq(new Org.Neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId(instanceId)), argThat((new MessageArgumentMatcher <>()).withPayload(payload))); }
//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); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldKeepAtMostGivenNumberOfInstances() public virtual void ShouldKeepAtMostGivenNumberOfInstances() { // Given const int instancesToKeep = 10; PaxosInstanceStore theStore = new PaxosInstanceStore(instancesToKeep); // Keeps the first instance inserted, which is the first to be removed PaxosInstance firstInstance = null; // When for (int i = 0; i < instancesToKeep + 1; i++) { InstanceId currentInstanceId = new InstanceId(i); PaxosInstance currentInstance = theStore.GetPaxosInstance(currentInstanceId); theStore.Delivered(currentInstance.Id); if (firstInstance == null) { firstInstance = currentInstance; } } // Then // The first instance must have been removed now PaxosInstance toTest = theStore.GetPaxosInstance(firstInstance.Id); assertNotSame(firstInstance, toTest); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldReturnSameObjectWhenAskedById() public virtual void ShouldReturnSameObjectWhenAskedById() { // Given PaxosInstanceStore theStore = new PaxosInstanceStore(); InstanceId currentInstanceId = new InstanceId(1); // When PaxosInstance currentInstance = theStore.GetPaxosInstance(currentInstanceId); // Then assertSame(currentInstance, theStore.GetPaxosInstance(currentInstanceId)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void leaveShouldClearStoredInstances() public virtual void LeaveShouldClearStoredInstances() { // Given PaxosInstanceStore theStore = new PaxosInstanceStore(); InstanceId currentInstanceId = new InstanceId(1); // When PaxosInstance currentInstance = theStore.GetPaxosInstance(currentInstanceId); theStore.Leave(); // Then assertNotSame(currentInstance, theStore.GetPaxosInstance(currentInstanceId)); }
public virtual PaxosInstance Snapshot(PaxosInstanceStore store) { PaxosInstance snap = new PaxosInstance(store, Id); snap.State = State; snap.BallotConflict = BallotConflict; snap.AcceptorsConflict = AcceptorsConflict == null ? null : new List <URI>(AcceptorsConflict); snap.Promises = Promises == null ? null : new List <ProposerMessage.PromiseState>(Promises); snap.Accepts = Accepts == null ? null : new List <ProposerMessage.AcceptedState>(Accepts); snap.RejectedAccepts = RejectedAccepts == null ? null : new List <ProposerMessage.RejectAcceptState>(RejectedAccepts); snap.Value_1 = Value_1; snap.Phase1Ballot = Phase1Ballot; snap.Value_2 = Value_2; snap.ClientValue = ClientValue; snap.ConversationIdHeader = ConversationIdHeader; return(snap); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void proposer_proposePhase1TimeoutShouldCarryOnPayload() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ProposerProposePhase1TimeoutShouldCarryOnPayload() { // GIVEN PaxosInstance instance = mock(typeof(PaxosInstance)); ProposerContext context = mock(typeof(ProposerContext)); when(context.GetPaxosInstance(any(typeof(Org.Neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId)))).thenReturn(instance); when(context.MyId).thenReturn(new Org.Neo4j.cluster.InstanceId(0)); TrackingMessageHolder outgoing = new TrackingMessageHolder(); string instanceId = "1"; Serializable payload = "myPayload"; Message <ProposerMessage> message = to(propose, create("http://something"), payload).setHeader(INSTANCE, instanceId); // WHEN ProposerState.Proposer.handle(context, message, outgoing); // THEN verify(context).setTimeout(eq(new Org.Neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId(instanceId)), argThat((new MessageArgumentMatcher <>()).withPayload(payload))); }
//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(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") @Test public void proposer_promiseShouldCarryOnPayloadToPhase2Timeout() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ProposerPromiseShouldCarryOnPayloadToPhase2Timeout() { // GIVEN string instanceId = "1"; Serializable payload = "myPayload"; PaxosInstance instance = new PaxosInstance(mock(typeof(PaxosInstanceStore)), new Org.Neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId(instanceId)); instance.Propose(1, new IList <java.net.URI> { create("http://some-guy") }); instance.Value_2 = payload; // don't blame me for making it package access. ProposerContext context = mock(typeof(ProposerContext)); when(context.GetPaxosInstance(any(typeof(Org.Neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId)))).thenReturn(instance); when(context.GetMinimumQuorumSize(anyList())).thenReturn(1); TrackingMessageHolder outgoing = new TrackingMessageHolder(); Message <ProposerMessage> message = to(promise, create("http://something"), new ProposerMessage.PromiseState(1, payload)).setHeader(INSTANCE, instanceId); // WHEN ProposerState.Proposer.handle(context, message, outgoing); // THEN verify(context).setTimeout(eq(new Org.Neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId(instanceId)), argThat((new MessageArgumentMatcher <>()).withPayload(payload))); }