Beispiel #1
0
 private ProposerContextImpl(Org.Neo4j.cluster.InstanceId me, CommonContextState commonState, LogProvider logging, Timeouts timeouts, Deque <Message> pendingValues, IDictionary <InstanceId, Message> bookedInstances, PaxosInstanceStore paxosInstances, HeartbeatContext heartbeatContext) : base(me, commonState, logging, timeouts)
 {
     this._pendingValues    = pendingValues;
     this._bookedInstances  = bookedInstances;
     this._paxosInstances   = paxosInstances;
     this._heartbeatContext = heartbeatContext;
 }
Beispiel #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldProperlyHandleConflictingMasterAvailableMessage()
        public virtual void ShouldProperlyHandleConflictingMasterAvailableMessage()
        {
            /*
             * If the instance is currently in TO_MASTER and a masterIsAvailable comes for another instance, then
             * this instance should transition to PENDING and ask for an election.
             */
            // Given
            InstanceId rogue = new InstanceId(2);

            // sanity check of starting state
            assertThat(_stateMachine.CurrentState, equalTo(HighAvailabilityMemberState.Pending));

            // when
            // It receives available master without having gone through TO_MASTER
            _memberListener.coordinatorIsElected(_me);

            // then
            // sanity check it transitioned to TO_MASTER
            assertThat(_stateMachine.CurrentState, equalTo(HighAvailabilityMemberState.ToMaster));

            // when
            // it receives a masterIsAvailable for another instance
            _memberListener.memberIsAvailable(MASTER, rogue, URI.create("ha://someUri"), StoreId.DEFAULT);

            // then
            AssertPendingStateAndElectionsAsked();
        }
Beispiel #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldProperlyHandleNonElectedMasterBecomingAvailableWhenInToSlave()
        public virtual void ShouldProperlyHandleNonElectedMasterBecomingAvailableWhenInToSlave()
        {
            /*
             * If the instance is in TO_SLAVE and a masterIsAvailable comes that does not refer to the elected master,
             * the instance should go to PENDING and ask for elections
             */
            // Given
            InstanceId other       = new InstanceId(2);
            InstanceId rogueMaster = new InstanceId(3);

            // sanity check of starting state
            assertThat(_stateMachine.CurrentState, equalTo(HighAvailabilityMemberState.Pending));

            // when
            // It becomes available master without having gone through TO_MASTER
            _memberListener.memberIsAvailable(MASTER, other, URI.create("ha://whatever"), StoreId.DEFAULT);

            // sanity check it is TO_SLAVE
            assertThat(_stateMachine.CurrentState, equalTo(HighAvailabilityMemberState.ToSlave));

            // when
            // it receives that another master became master but which is different than the currently elected one
            _memberListener.memberIsAvailable(MASTER, rogueMaster, URI.create("ha://fromNowhere"), StoreId.DEFAULT);

            // then
            AssertPendingStateAndElectionsAsked();
        }
Beispiel #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleLocalLearnMessagesWithoutInstanceIdInTheMessageHeaderWhenCatchingUp() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldHandleLocalLearnMessagesWithoutInstanceIdInTheMessageHeaderWhenCatchingUp()
        {
            // Given
            LearnerState learner = LearnerState.Learner;

            Org.Neo4j.cluster.InstanceId instanceId = new Org.Neo4j.cluster.InstanceId(42);
            long payload = 12L;

            LearnerContext context = mock(typeof(LearnerContext));

            when(context.MyId).thenReturn(instanceId);
            when(context.LastKnownLearnedInstanceInCluster).thenReturn(11L);
            when(context.LastLearnedInstanceId).thenReturn(payload);

//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") org.neo4j.cluster.com.message.Message<LearnerMessage> message = mock(org.neo4j.cluster.com.message.Message.class);
            Message <LearnerMessage> message = mock(typeof(Message));

            when(message.MessageType).thenReturn(LearnerMessage.CatchUp);
            when(message.HasHeader(Message.HEADER_INSTANCE_ID)).thenReturn(false);
            when(message.GetHeader(Message.HEADER_INSTANCE_ID)).thenThrow(new System.ArgumentException());
            when(message.Payload).thenReturn(payload);

            // When
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.cluster.statemachine.State<?,?> state = learner.handle(context, message, mock(org.neo4j.cluster.com.message.MessageHolder.class));
            State <object, ?> state = learner.handle(context, message, mock(typeof(MessageHolder)));

            // Then
            assertSame(state, learner);
            verify(context, times(1)).setLastKnownLearnedInstanceInCluster(payload, instanceId);
        }
Beispiel #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void snapshotListPrunesOtherMemberWithSameMasterRole() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void SnapshotListPrunesOtherMemberWithSameMasterRole()
        {
            // GIVEN
            // -- a snapshot containing one member with a role
            PaxosClusterMemberEvents.ClusterMembersSnapshot snapshot = new PaxosClusterMemberEvents.ClusterMembersSnapshot(new HANewSnapshotFunction());
            URI               clusterUri = new URI(URI);
            InstanceId        instanceId = new InstanceId(1);
            MemberIsAvailable @event     = new MemberIsAvailable(MASTER, instanceId, clusterUri, new URI(URI + "?something1"), DEFAULT);

            snapshot.AvailableMember(@event);

            // WHEN
            // -- another member, but with same role, gets added to the snapshot
            URI               otherClusterUri = new URI(URI);
            InstanceId        otherInstanceId = new InstanceId(2);
            MemberIsAvailable otherEvent      = new MemberIsAvailable(MASTER, otherInstanceId, otherClusterUri, new URI(URI + "?something2"), DEFAULT);

            snapshot.AvailableMember(otherEvent);

            // THEN
            // -- getting the snapshot list should only reveal the last member added, as it had the same role
            assertEquals(1, Iterables.count(snapshot.GetCurrentAvailable(otherInstanceId)));
            assertThat(snapshot.GetCurrentAvailable(otherInstanceId), hasItems(MemberIsAvailable(otherEvent)));
            assertEquals(1, Iterables.count(snapshot.CurrentAvailableMembers));
            assertThat(snapshot.CurrentAvailableMembers, hasItems(MemberIsAvailable(otherEvent)));
        }
Beispiel #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldUseLastKnownOnlineClusterMemberAndSetTimeoutForCatchup() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldUseLastKnownOnlineClusterMemberAndSetTimeoutForCatchup()
        {
            // Given
            LearnerState   state    = LearnerState.Learner;
            LearnerContext ctx      = mock(typeof(LearnerContext));
            MessageHolder  outgoing = mock(typeof(MessageHolder));

            Org.Neo4j.cluster.InstanceId upToDateClusterMember = new Org.Neo4j.cluster.InstanceId(1);

            // What we know
            when(ctx.LastLearnedInstanceId).thenReturn(0L);
            when(ctx.GetPaxosInstance(new Org.Neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId(1L))).thenReturn(new PaxosInstance(null, new Org.Neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId(1L)));
            when(ctx.LastKnownAliveUpToDateInstance).thenReturn(upToDateClusterMember);
            when(ctx.GetUriForId(upToDateClusterMember)).thenReturn(new URI("c:/1"));

            // What we know the cluster knows
            when(ctx.LastKnownLearnedInstanceInCluster).thenReturn(1L);

            // When
            Message <LearnerMessage> message = Message.to(LearnerMessage.CatchUp, new URI("c:/2"), 2L).setHeader(Message.HEADER_FROM, "c:/2").setHeader(Message.HEADER_INSTANCE_ID, "2");
            State newState = state.handle(ctx, message, outgoing);

            // Then

            assertThat(newState, equalTo(LearnerState.Learner));
            verify(outgoing).offer(Message.to(LearnerMessage.LearnRequest, new URI("c:/1"), new LearnerMessage.LearnRequestState()).setHeader(Org.Neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId.INSTANCE, Convert.ToString(1L)));
            verify(ctx).setTimeout("learn", Message.timeout(LearnerMessage.LearnTimedout, message));
        }
Beispiel #7
0
 internal ProposerContextImpl(Org.Neo4j.cluster.InstanceId me, CommonContextState commonState, LogProvider logging, Timeouts timeouts, PaxosInstanceStore paxosInstances, HeartbeatContext heartbeatContext) : base(me, commonState, logging, timeouts)
 {
     this._paxosInstances   = paxosInstances;
     this._heartbeatContext = heartbeatContext;
     _pendingValues         = new LinkedList <Message>();
     _bookedInstances       = new Dictionary <InstanceId, Message>();
 }
Beispiel #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldProperlyHandleMasterIsAvailableWhenInMasterState()
        public virtual void ShouldProperlyHandleMasterIsAvailableWhenInMasterState()
        {
            /*
             * If the instance is in MASTER state and a masterIsAvailable is received for another instance, then
             * this instance should got to PENDING and ask for elections
             */
            // Given
            InstanceId rogue = new InstanceId(2);

            // sanity check of starting state
            assertThat(_stateMachine.CurrentState, equalTo(HighAvailabilityMemberState.Pending));

            // when
            // It receives available master without having gone through TO_MASTER
            _memberListener.coordinatorIsElected(_me);

            // then
            // sanity check it transitioned to TO_MASTER
            assertThat(_stateMachine.CurrentState, equalTo(HighAvailabilityMemberState.ToMaster));

            // when
            // it receives a masterIsAvailable for itself, completing the transition
            _memberListener.memberIsAvailable(MASTER, _me, URI.create("ha://someUri"), StoreId.DEFAULT);

            // then
            // it should move to MASTER
            assertThat(_stateMachine.CurrentState, equalTo(HighAvailabilityMemberState.Master));

            // when
            // it receives a slaveIsAvailable for itself while in the MASTER state
            _memberListener.memberIsAvailable(MASTER, rogue, URI.create("ha://someUri"), StoreId.DEFAULT);

            // then
            AssertPendingStateAndElectionsAsked();
        }
Beispiel #9
0
 internal LearnerContextImpl(Org.Neo4j.cluster.InstanceId me, CommonContextState commonState, LogProvider logging, Timeouts timeouts, PaxosInstanceStore paxosInstances, AcceptorInstanceStore instanceStore, ObjectInputStreamFactory objectInputStreamFactory, ObjectOutputStreamFactory objectOutputStreamFactory, HeartbeatContext heartbeatContext) : base(me, commonState, logging, timeouts)
 {
     this._heartbeatContext          = heartbeatContext;
     this._instanceStore             = instanceStore;
     this._objectInputStreamFactory  = objectInputStreamFactory;
     this._objectOutputStreamFactory = objectOutputStreamFactory;
     this._paxosInstances            = paxosInstances;
     this._learnMissLogger           = (new CappedLogger(logging.GetLog(typeof(LearnerState)))).setDuplicateFilterEnabled(true);
 }
Beispiel #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void learnerShouldAskAllAliveInstancesAndTheseOnlyForMissingValue() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void LearnerShouldAskAllAliveInstancesAndTheseOnlyForMissingValue()
        {
            // Given

            IList <URI> allMembers = new List <URI>(3);
            URI         instance1  = URI.create("c:/1");        // this one is failed
            URI         instance2  = URI.create("c:/2");        // this one is ok and will respond
            URI         instance3  = URI.create("c:/3");        // this one is the requesting instance
            URI         instance4  = URI.create("c:/4");        // and this one is ok and will respond too

            allMembers.Add(instance1);
            allMembers.Add(instance2);
            allMembers.Add(instance3);
            allMembers.Add(instance4);

            ISet <Org.Neo4j.cluster.InstanceId> aliveInstanceIds = new HashSet <Org.Neo4j.cluster.InstanceId>();

            Org.Neo4j.cluster.InstanceId id2 = new Org.Neo4j.cluster.InstanceId(2);
            Org.Neo4j.cluster.InstanceId id4 = new Org.Neo4j.cluster.InstanceId(4);
            aliveInstanceIds.Add(id2);
            aliveInstanceIds.Add(id4);

            LearnerState   state    = LearnerState.Learner;
            LearnerContext ctx      = mock(typeof(LearnerContext));
            MessageHolder  outgoing = mock(typeof(MessageHolder));
            InstanceId     paxosInstanceIdIAskedFor = new InstanceId(4);

            when(ctx.LastDeliveredInstanceId).thenReturn(3L);
            when(ctx.LastKnownLearnedInstanceInCluster).thenReturn(5L);
            when(ctx.MemberURIs).thenReturn(allMembers);
            when(ctx.Alive).thenReturn(aliveInstanceIds);
            when(ctx.GetUriForId(id2)).thenReturn(instance2);
            when(ctx.GetUriForId(id4)).thenReturn(instance4);
            when(ctx.GetPaxosInstance(paxosInstanceIdIAskedFor)).thenReturn(new PaxosInstance(mock(typeof(PaxosInstanceStore)), paxosInstanceIdIAskedFor));

            Message <LearnerMessage> theCause = Message.to(LearnerMessage.CatchUp, instance2);                // could be anything, really

            // When
            state.handle(ctx, Message.timeout(LearnerMessage.LearnTimedout, theCause), outgoing);

            // Then
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: verify(outgoing, 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()
            verify(outgoing, times(1)).offer(ArgumentMatchers.argThat <Message <MessageType> >(new MessageArgumentMatcher()
                                                                                               .onMessageType(LearnerMessage.LearnRequest).to(instance2)));
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: verify(outgoing, 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()
            verify(outgoing, times(1)).offer(ArgumentMatchers.argThat <Message <MessageType> >(new MessageArgumentMatcher()
                                                                                               .onMessageType(LearnerMessage.LearnRequest).to(instance4)));
            verifyNoMoreInteractions(outgoing);
        }
Beispiel #11
0
 public PullerFactory(RequestContextFactory requestContextFactory, Master master, LastUpdateTime lastUpdateTime, LogProvider logging, InstanceId serverId, InvalidEpochExceptionHandler invalidEpochHandler, long pullInterval, JobScheduler jobScheduler, DependencyResolver dependencyResolver, AvailabilityGuard availabilityGuard, HighAvailabilityMemberStateMachine memberStateMachine, Monitors monitors, Config config)
 {
     this._requestContextFactory = requestContextFactory;
     this._master              = master;
     this._lastUpdateTime      = lastUpdateTime;
     this._logging             = logging;
     this._serverId            = serverId;
     this._invalidEpochHandler = invalidEpochHandler;
     this._pullInterval        = pullInterval;
     this._jobScheduler        = jobScheduler;
     this._dependencyResolver  = dependencyResolver;
     this._availabilityGuard   = availabilityGuard;
     this._memberStateMachine  = memberStateMachine;
     this._monitors            = monitors;
     this._activeDatabaseName  = config.Get(GraphDatabaseSettings.active_database);
 }
Beispiel #12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testSlaveMasterIsElected()
        public virtual void TestSlaveMasterIsElected()
        {
            // CASE 1: It is me that got elected master - should switch to TO_MASTER
            HighAvailabilityMemberState newState = SLAVE.masterIsElected(_context, _myId);

            assertEquals(TO_MASTER, newState);

            InstanceId masterInstanceId = new InstanceId(2);

            when(_context.ElectedMasterId).thenReturn(masterInstanceId);
            // CASE 2: It is someone else that got elected master - should switch to PENDING
            HighAvailabilityMemberState newStateCase2 = SLAVE.masterIsElected(_context, new InstanceId(3));

            assertEquals(PENDING, newStateCase2);

            // CASE 3: It is the current master that got elected again - ignore
            HighAvailabilityMemberState newStateCase3 = SLAVE.masterIsElected(_context, masterInstanceId);

            assertEquals(SLAVE, newStateCase3);
        }
Beispiel #13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testSlaveMasterIsAvailable()
        public virtual void TestSlaveMasterIsAvailable()
        {
            // CASE 1: It is me who is available as master - i don't think so
            HighAvailabilityMemberState illegal = SLAVE.masterIsAvailable(_context, _myId, SampleUri);

            assertEquals(ILLEGAL, illegal);

            // CASE 2: It is someone else that is available as master and is not the master now - missed the election, fail
            InstanceId masterInstanceId = new InstanceId(2);

            when(_context.ElectedMasterId).thenReturn(masterInstanceId);
            HighAvailabilityMemberState moreIllegal = SLAVE.masterIsAvailable(_context, new InstanceId(3), SampleUri);

            assertEquals(ILLEGAL, moreIllegal);

            // CASE 3: It is the same master as now - it's ok, stay calm and carry on
            HighAvailabilityMemberState newState = SLAVE.masterIsAvailable(_context, masterInstanceId, SampleUri);

            assertEquals(SLAVE, newState);
        }
Beispiel #14
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();
        }
Beispiel #15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testToSlaveMasterIsAvailable()
        public virtual void TestToSlaveMasterIsAvailable()
        {
            // CASE 1: Got MasterIsAvailable for me - should fail, i am currently trying to become slave
            HighAvailabilityMemberState illegal = TO_SLAVE.masterIsAvailable(_context, _myId, SampleUri);

            assertEquals(ILLEGAL, illegal);

            // CASE 2: Got MasterIsAvailable for someone else who is already the master - should continue switching
            InstanceId currentMaster = new InstanceId(2);

            when(_context.ElectedMasterId).thenReturn(currentMaster);
            HighAvailabilityMemberState newState = TO_SLAVE.masterIsAvailable(_context, currentMaster, SampleUri);

            assertEquals(TO_SLAVE, newState);

            // CASE 3: Got MasterIsAvailable for someone else who is not the master - should fail
            InstanceId instanceId = new InstanceId(3);
            HighAvailabilityMemberState moreIllegal = TO_SLAVE.masterIsAvailable(_context, instanceId, SampleUri);

            assertEquals(ILLEGAL, moreIllegal);
        }
Beispiel #16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void snapshotListPrunesSameMemberOnIdenticalAvailabilityEvents() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void SnapshotListPrunesSameMemberOnIdenticalAvailabilityEvents()
        {
            // GIVEN
            // -- a snapshot containing one member with a role
            PaxosClusterMemberEvents.ClusterMembersSnapshot snapshot = new PaxosClusterMemberEvents.ClusterMembersSnapshot(new PaxosClusterMemberEvents.UniqueRoleFilter()
                                                                                                                           );
            URI               clusterUri        = new URI(URI);
            InstanceId        instanceId        = new InstanceId(1);
            MemberIsAvailable memberIsAvailable = new MemberIsAvailable(MASTER, instanceId, clusterUri, new URI(URI + "?something"), DEFAULT);

            snapshot.AvailableMember(memberIsAvailable);

            // WHEN
            // -- the same member and role gets added to the snapshot
            snapshot.AvailableMember(memberIsAvailable);

            // THEN
            // -- getting the snapshot list should only reveal the last one
            assertEquals(1, Iterables.count(snapshot.GetCurrentAvailable(instanceId)));
            assertThat(snapshot.GetCurrentAvailable(instanceId), hasItem(memberIsAvailable(memberIsAvailable)));
            assertEquals(1, Iterables.count(snapshot.CurrentAvailableMembers));
            assertThat(snapshot.CurrentAvailableMembers, hasItems(memberIsAvailable(memberIsAvailable)));
        }
Beispiel #17
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void snapshotListDoesNotPruneOtherMemberWithSlaveRole() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void SnapshotListDoesNotPruneOtherMemberWithSlaveRole()
        {
            // GIVEN
            // -- a snapshot containing one member with a role
            PaxosClusterMemberEvents.ClusterMembersSnapshot snapshot = new PaxosClusterMemberEvents.ClusterMembersSnapshot(new HANewSnapshotFunction());
            URI               clusterUri = new URI(URI);
            InstanceId        instanceId = new InstanceId(1);
            MemberIsAvailable @event     = new MemberIsAvailable(SLAVE, instanceId, clusterUri, new URI(URI + "?something1"), DEFAULT);

            snapshot.AvailableMember(@event);

            // WHEN
            // -- another member, but with same role, gets added to the snapshot
            URI               otherClusterUri = new URI(URI);
            InstanceId        otherInstanceId = new InstanceId(2);
            MemberIsAvailable otherEvent      = new MemberIsAvailable(SLAVE, otherInstanceId, otherClusterUri, new URI(URI + "?something2"), DEFAULT);

            snapshot.AvailableMember(otherEvent);

            // THEN
            assertEquals(2, Iterables.count(snapshot.CurrentAvailableMembers));
            assertThat(snapshot.CurrentAvailableMembers, hasItems(MemberIsAvailable(@event), MemberIsAvailable(otherEvent)));
        }
Beispiel #18
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldProperlyHandleMasterIsAvailableWhenInSlaveState()
        public virtual void ShouldProperlyHandleMasterIsAvailableWhenInSlaveState()
        {
            /*
             * If the instance is in SLAVE state and receives masterIsAvailable for an instance different than the
             * current master, it should revert to PENDING and ask for elections
             */
            // Given
            InstanceId master      = new InstanceId(2);
            InstanceId rogueMaster = new InstanceId(3);

            // sanity check of starting state
            assertThat(_stateMachine.CurrentState, equalTo(HighAvailabilityMemberState.Pending));

            // when
            // a master is elected normally
            _memberListener.coordinatorIsElected(master);
            _memberListener.memberIsAvailable(MASTER, master, URI.create("ha://someUri"), StoreId.DEFAULT);

            // then
            // sanity check it transitioned to TO_SLAVE
            assertThat(_stateMachine.CurrentState, equalTo(HighAvailabilityMemberState.ToSlave));

            // when
            _memberListener.memberIsAvailable(SLAVE, _me, URI.create("ha://myUri"), StoreId.DEFAULT);

            // then
            // we should be in SLAVE state
            assertThat(_stateMachine.CurrentState, equalTo(HighAvailabilityMemberState.Slave));

            // when
            // it receives a masterIsAvailable for an unelected master while in the slave state
            _memberListener.memberIsAvailable(MASTER, rogueMaster, URI.create("ha://someOtherUri"), StoreId.DEFAULT);

            // then
            AssertPendingStateAndElectionsAsked();
        }
Beispiel #19
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void snapshotListShouldContainOnlyOneEventForARoleWithTheSameIdWhenSwitchingFromMasterToSlave() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void SnapshotListShouldContainOnlyOneEventForARoleWithTheSameIdWhenSwitchingFromMasterToSlave()
        {
            // GIVEN
            // -- a snapshot containing one member with a role
            PaxosClusterMemberEvents.ClusterMembersSnapshot snapshot = new PaxosClusterMemberEvents.ClusterMembersSnapshot(new HANewSnapshotFunction());
            URI               clusterUri = new URI(URI);
            InstanceId        instanceId = new InstanceId(1);
            MemberIsAvailable event1     = new MemberIsAvailable(MASTER, instanceId, clusterUri, new URI(URI + "?something"), DEFAULT);

            snapshot.AvailableMember(event1);

            // WHEN
            // -- the same member, although different role, gets added to the snapshot
            MemberIsAvailable event2 = new MemberIsAvailable(SLAVE, instanceId, clusterUri, new URI(URI + "?something"), DEFAULT);

            snapshot.AvailableMember(event2);

            // THEN
            // -- getting the snapshot list should reveal both
            assertEquals(1, Iterables.count(snapshot.GetCurrentAvailable(instanceId)));
            assertThat(snapshot.GetCurrentAvailable(instanceId), hasItems(MemberIsAvailable(event2)));
            assertEquals(1, Iterables.count(snapshot.CurrentAvailableMembers));
            assertThat(snapshot.CurrentAvailableMembers, hasItems(MemberIsAvailable(event2)));
        }
Beispiel #20
0
 /// <summary>
 /// Logged when an instance is elected for a role, such as coordinator of a cluster.
 /// </summary>
 /// <param name="role"> </param>
 /// <param name="instanceId"> </param>
 /// <param name="electedMember"> </param>
 public override void Elected(string role, InstanceId instanceId, URI electedMember)
 {
     _log.info("Instance %s was elected as %s", PrintId(instanceId, electedMember), role);
 }
Beispiel #21
0
 public UpdatePullingTransactionObligationFulfiller(UpdatePuller updatePuller, HighAvailabilityMemberStateMachine memberStateMachine, InstanceId serverId, System.Func <TransactionIdStore> transactionIdStoreSupplier)
 {
     this._updatePuller               = updatePuller;
     this._memberStateMachine         = memberStateMachine;
     this._transactionIdStoreSupplier = transactionIdStoreSupplier;
     this._listener = new RoleListener(this, serverId);
 }
Beispiel #22
0
 public abstract HighAvailabilityMemberState slaveIsAvailable(HighAvailabilityMemberContext context, Org.Neo4j.cluster.InstanceId slaveId, java.net.URI slaveUri);
Beispiel #23
0
 public override void SetLastKnownLearnedInstanceInCluster(long lastKnownLearnedInstanceInCluster, Org.Neo4j.cluster.InstanceId instanceId)
 {
     CommonState.setLastKnownLearnedInstanceInCluster(lastKnownLearnedInstanceInCluster, instanceId);
 }
Beispiel #24
0
 public abstract HighAvailabilityMemberState masterIsAvailable(HighAvailabilityMemberContext context, Org.Neo4j.cluster.InstanceId masterId, java.net.URI masterHaURI);
Beispiel #25
0
 public abstract HighAvailabilityMemberState masterIsElected(HighAvailabilityMemberContext context, Org.Neo4j.cluster.InstanceId masterId);
Beispiel #26
0
 public SimpleHighAvailabilityMemberContext(InstanceId myId, bool slaveOnly)
 {
     this._myId      = myId;
     this._slaveOnly = slaveOnly;
 }
Beispiel #27
0
 /// <summary>
 /// Logged when another instance leaves the cluster
 /// </summary>
 /// <param name="instanceId"> </param>
 public override void LeftCluster(InstanceId instanceId, URI member)
 {
     _log.info("Instance %s has left the cluster", PrintId(instanceId, member));
 }
Beispiel #28
0
 internal RoleListener(UpdatePullingTransactionObligationFulfiller outerInstance, InstanceId myInstanceId)
 {
     this._outerInstance = outerInstance;
     this.MyInstanceId   = myInstanceId;
 }
Beispiel #29
0
 internal AtomicBroadcastContextImpl(Org.Neo4j.cluster.InstanceId me, CommonContextState commonState, LogProvider logging, Timeouts timeouts, Executor executor, HeartbeatContext heartbeatContext) : base(me, commonState, logging, timeouts)
 {
     this._executor         = executor;
     this._heartbeatContext = heartbeatContext;
 }
Beispiel #30
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setup()
        public virtual void Setup()
        {
            _myId    = new InstanceId(1);
            _context = mock(typeof(HighAvailabilityMemberContext));
            when(_context.MyId).thenReturn(_myId);
        }