Exemple #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void failedThenAliveMemberShowsAsAlive()
        public virtual void FailedThenAliveMemberShowsAsAlive()
        {
            // given
            Cluster             cluster      = mock(typeof(Cluster));
            Heartbeat           heartbeat    = mock(typeof(Heartbeat));
            ClusterMemberEvents memberEvents = mock(typeof(ClusterMemberEvents));

            ObservedClusterMembers members = new ObservedClusterMembers(_logProvider, cluster, heartbeat, memberEvents, null);

            ArgumentCaptor <ClusterListener> listener = ArgumentCaptor.forClass(typeof(ClusterListener));

            verify(cluster).addClusterListener(listener.capture());
            listener.Value.enteredCluster(ClusterConfiguration(_clusterUri1, _clusterUri2, _clusterUri3));

            ArgumentCaptor <HeartbeatListener> heartBeatListener = ArgumentCaptor.forClass(typeof(HeartbeatListener));

            verify(heartbeat).addHeartbeatListener(heartBeatListener.capture());

            // when
            heartBeatListener.Value.failed(_clusterId1);
            heartBeatListener.Value.alive(_clusterId1);

            // then
            assertThat(members.Members, hasItem(sameMemberAs(new ClusterMember(_clusterId1))));
        }
Exemple #2
0
 public ClusterListenerAnonymousInnerClass(ClusterNetworkIT outerInstance, URI uri, Org.Neo4j.cluster.protocol.cluster.Cluster cluster, AtomicReference <ClusterConfiguration> config)
 {
     this.outerInstance = outerInstance;
     this._uri          = uri;
     this._cluster      = cluster;
     this._config       = config;
 }
Exemple #3
0
        /// <summary>
        /// Sets up the supporting infrastructure and communication hooks for our state machines. This is here to support
        /// an external requirement for assembling protocol servers given an existing set of state machines (used to prove
        /// correctness).
        /// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("rawtypes") public ProtocolServer constructSupportingInfrastructureFor(InstanceId me, org.neo4j.cluster.com.message.MessageSource input, org.neo4j.cluster.com.message.MessageSender output, DelayedDirectExecutor executor, org.neo4j.cluster.timeout.Timeouts timeouts, java.util.concurrent.Executor stateMachineExecutor, final org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext context, org.neo4j.cluster.statemachine.StateMachine[] machines)
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
        public virtual ProtocolServer ConstructSupportingInfrastructureFor(InstanceId me, MessageSource input, MessageSender output, DelayedDirectExecutor executor, Timeouts timeouts, Executor stateMachineExecutor, MultiPaxosContext context, StateMachine[] machines)
        {
            StateMachines stateMachines = new StateMachines(_logging, _stateMachinesMonitor, input, output, timeouts, executor, stateMachineExecutor, me);

            foreach (StateMachine machine in machines)
            {
                stateMachines.AddStateMachine(machine);
            }

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final ProtocolServer server = new ProtocolServer(me, stateMachines, logging);
            ProtocolServer server = new ProtocolServer(me, stateMachines, _logging);

            server.AddBindingListener(me1 => context.ClusterContext.setBoundAt(me1));

            stateMachines.AddMessageProcessor(new HeartbeatRefreshProcessor(stateMachines.Outgoing, context.ClusterContext));
            input.AddMessageProcessor(new HeartbeatIAmAliveProcessor(stateMachines.Outgoing, context.ClusterContext));

            Cluster cluster = server.NewClient(typeof(Cluster));

            cluster.AddClusterListener(new HeartbeatJoinListener(stateMachines.Outgoing));
            cluster.AddClusterListener(new HeartbeatLeftListener(context.HeartbeatContext, _logging));

            context.HeartbeatContext.addHeartbeatListener(new HeartbeatReelectionListener(server.NewClient(typeof(Election)), _logging));
            context.ClusterContext.addClusterListener(new ClusterLeaveReelectionListener(server.NewClient(typeof(Election)), _logging));

            StateMachineRules rules = (new StateMachineRules(stateMachines.Outgoing)).rule(ClusterState.start, ClusterMessage.create, ClusterState.entered, @internal(AtomicBroadcastMessage.entered), @internal(ProposerMessage.join), @internal(AcceptorMessage.join), @internal(LearnerMessage.join), @internal(HeartbeatMessage.join), @internal(ElectionMessage.created), @internal(SnapshotMessage.join)).rule(ClusterState.discovery, ClusterMessage.configurationResponse, ClusterState.joining, @internal(AcceptorMessage.join), @internal(LearnerMessage.join), @internal(AtomicBroadcastMessage.join)).rule(ClusterState.discovery, ClusterMessage.configurationResponse, ClusterState.entered, @internal(AtomicBroadcastMessage.entered), @internal(ProposerMessage.join), @internal(AcceptorMessage.join), @internal(LearnerMessage.join), @internal(HeartbeatMessage.join), @internal(ElectionMessage.join), @internal(SnapshotMessage.join)).rule(ClusterState.joining, ClusterMessage.configurationChanged, ClusterState.entered, @internal(AtomicBroadcastMessage.entered), @internal(ProposerMessage.join), @internal(AcceptorMessage.join), @internal(LearnerMessage.join), @internal(HeartbeatMessage.join), @internal(ElectionMessage.join), @internal(SnapshotMessage.join)).rule(ClusterState.joining, ClusterMessage.joinFailure, ClusterState.start, @internal(AtomicBroadcastMessage.leave), @internal(AcceptorMessage.leave), @internal(LearnerMessage.leave), @internal(ProposerMessage.leave)).rule(ClusterState.entered, ClusterMessage.leave, ClusterState.start, @internal(AtomicBroadcastMessage.leave), @internal(AcceptorMessage.leave), @internal(LearnerMessage.leave), @internal(HeartbeatMessage.leave), @internal(SnapshotMessage.leave), @internal(ElectionMessage.leave), @internal(ProposerMessage.leave)).rule(ClusterState.entered, ClusterMessage.leave, ClusterState.start, @internal(AtomicBroadcastMessage.leave), @internal(AcceptorMessage.leave), @internal(LearnerMessage.leave), @internal(HeartbeatMessage.leave), @internal(ElectionMessage.leave), @internal(SnapshotMessage.leave), @internal(ProposerMessage.leave)).rule(ClusterState.leaving, ClusterMessage.configurationChanged, ClusterState.start, @internal(AtomicBroadcastMessage.leave), @internal(AcceptorMessage.leave), @internal(LearnerMessage.leave), @internal(HeartbeatMessage.leave), @internal(ElectionMessage.leave), @internal(SnapshotMessage.leave), @internal(ProposerMessage.leave)).rule(ClusterState.leaving, ClusterMessage.leaveTimedout, ClusterState.start, @internal(AtomicBroadcastMessage.leave), @internal(AcceptorMessage.leave), @internal(LearnerMessage.leave), @internal(HeartbeatMessage.leave), @internal(ElectionMessage.leave), @internal(SnapshotMessage.leave), @internal(ProposerMessage.leave));

            stateMachines.AddStateTransitionListener(rules);

            return(server);
        }
Exemple #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void receivingInstanceFailureEventRemovesAllRolesForIt()
        public virtual void ReceivingInstanceFailureEventRemovesAllRolesForIt()
        {
            // given
            Cluster             cluster      = mock(typeof(Cluster));
            Heartbeat           heartbeat    = mock(typeof(Heartbeat));
            ClusterMemberEvents memberEvents = mock(typeof(ClusterMemberEvents));

            ObservedClusterMembers members = new ObservedClusterMembers(_logProvider, cluster, heartbeat, memberEvents, _clusterId1);
            // initialized with the members of the cluster
            ArgumentCaptor <ClusterListener> listener = ArgumentCaptor.forClass(typeof(ClusterListener));

            verify(cluster).addClusterListener(listener.capture());
            listener.Value.enteredCluster(ClusterConfiguration(_clusterUri1, _clusterUri2, _clusterUri3));

            ArgumentCaptor <ClusterMemberListener> memberListener = ArgumentCaptor.forClass(typeof(ClusterMemberListener));

            verify(memberEvents).addClusterMemberListener(memberListener.capture());

            // instance 2 is available as MASTER and BACKUP
            memberListener.Value.memberIsAvailable(OnlineBackupKernelExtension.BACKUP, _clusterId2, _clusterUri2, StoreId.DEFAULT);
            memberListener.Value.memberIsAvailable(MASTER, _clusterId2, _clusterUri2, StoreId.DEFAULT);

            // when - instance 2 becomes failed
            memberListener.Value.memberIsFailed(_clusterId2);

            // then - instance 2 should not be available as any roles
            foreach (ClusterMember clusterMember in members.Members)
            {
                if (clusterMember.InstanceId.Equals(_clusterId2))
                {
                    assertThat(count(clusterMember.Roles), equalTo(0L));
                    break;                              // that's the only member we care about
                }
            }
        }
Exemple #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void missingSlaveUnavailabilityEventDoesNotClobberState()
        public virtual void MissingSlaveUnavailabilityEventDoesNotClobberState()
        {
            // given
            Cluster             cluster      = mock(typeof(Cluster));
            Heartbeat           heartbeat    = mock(typeof(Heartbeat));
            ClusterMemberEvents memberEvents = mock(typeof(ClusterMemberEvents));

            ObservedClusterMembers members = new ObservedClusterMembers(_logProvider, cluster, heartbeat, memberEvents, _clusterId1);

            ArgumentCaptor <ClusterListener> listener = ArgumentCaptor.forClass(typeof(ClusterListener));

            verify(cluster).addClusterListener(listener.capture());
            listener.Value.enteredCluster(ClusterConfiguration(_clusterUri1, _clusterUri2, _clusterUri3));

            ArgumentCaptor <ClusterMemberListener> memberListener = ArgumentCaptor.forClass(typeof(ClusterMemberListener));

            verify(memberEvents).addClusterMemberListener(memberListener.capture());

            // when
            // first we are available as master
            memberListener.Value.memberIsAvailable(MASTER, _clusterId1, _haUri1, StoreId.DEFAULT);
            // and then for some reason as slave, without an unavailable message in between
            memberListener.Value.memberIsAvailable(SLAVE, _clusterId1, _haUri1, StoreId.DEFAULT);

            // then
            assertThat(members.CurrentMember.HARole, equalTo(SLAVE));
        }
Exemple #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void membersShowsAsUnavailableWhenNewMasterElectedBeforeTheyBecomeAvailable()
        public virtual void MembersShowsAsUnavailableWhenNewMasterElectedBeforeTheyBecomeAvailable()
        {
            // given
            Cluster             cluster      = mock(typeof(Cluster));
            Heartbeat           heartbeat    = mock(typeof(Heartbeat));
            ClusterMemberEvents memberEvents = mock(typeof(ClusterMemberEvents));

            ObservedClusterMembers members = new ObservedClusterMembers(_logProvider, cluster, heartbeat, memberEvents, null);

            ArgumentCaptor <ClusterListener> listener = ArgumentCaptor.forClass(typeof(ClusterListener));

            verify(cluster).addClusterListener(listener.capture());
            listener.Value.enteredCluster(ClusterConfiguration(_clusterUri1, _clusterUri2, _clusterUri3));

            ArgumentCaptor <ClusterMemberListener> memberListener = ArgumentCaptor.forClass(typeof(ClusterMemberListener));

            verify(memberEvents).addClusterMemberListener(memberListener.capture());
            memberListener.Value.memberIsAvailable(SLAVE, _clusterId1, _haUri1, StoreId.DEFAULT);

            // when
            memberListener.Value.coordinatorIsElected(_clusterId2);

            // then
            assertThat(members.Members, hasItem(sameMemberAs(new ClusterMember(_clusterId1))));
        }
Exemple #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRegisterItselfOnListeners()
        public virtual void ShouldRegisterItselfOnListeners()
        {
            // given
            Cluster             cluster             = mock(typeof(Cluster));
            Heartbeat           heartbeat           = mock(typeof(Heartbeat));
            ClusterMemberEvents clusterMemberEvents = mock(typeof(ClusterMemberEvents));

            // when
            new ObservedClusterMembers(_logProvider, cluster, heartbeat, clusterMemberEvents, null);

            // then
            verify(cluster).addClusterListener(Mockito.any());
            verify(heartbeat).addHeartbeatListener(Mockito.any());
            verify(clusterMemberEvents).addClusterMemberListener(Mockito.any());
        }
Exemple #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldContainMemberListAfterEnteringCluster()
        public virtual void ShouldContainMemberListAfterEnteringCluster()
        {
            // given
            Cluster             cluster      = mock(typeof(Cluster));
            Heartbeat           heartbeat    = mock(typeof(Heartbeat));
            ClusterMemberEvents memberEvents = mock(typeof(ClusterMemberEvents));

            ObservedClusterMembers members = new ObservedClusterMembers(_logProvider, cluster, heartbeat, memberEvents, null);

            // when
            ArgumentCaptor <ClusterListener> listener = ArgumentCaptor.forClass(typeof(ClusterListener));

            verify(cluster).addClusterListener(listener.capture());
            listener.Value.enteredCluster(ClusterConfiguration(_clusterUri1, _clusterUri2, _clusterUri3));

            // then
            assertThat(members.Members, hasItems(sameMemberAs(new ClusterMember(_clusterId1)), sameMemberAs(new ClusterMember(_clusterId2)), sameMemberAs(new ClusterMember(_clusterId3))));
        }
Exemple #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void leftMemberDisappearsFromList()
        public virtual void LeftMemberDisappearsFromList()
        {
            // given
            Cluster             cluster      = mock(typeof(Cluster));
            Heartbeat           heartbeat    = mock(typeof(Heartbeat));
            ClusterMemberEvents memberEvents = mock(typeof(ClusterMemberEvents));

            ObservedClusterMembers members = new ObservedClusterMembers(_logProvider, cluster, heartbeat, memberEvents, null);

            ArgumentCaptor <ClusterListener> listener = ArgumentCaptor.forClass(typeof(ClusterListener));

            verify(cluster).addClusterListener(listener.capture());

            listener.Value.enteredCluster(ClusterConfiguration(_clusterUri1, _clusterUri2, _clusterUri3));

            // when
            listener.Value.leftCluster(_clusterId3, _clusterUri3);

            // then
            assertThat(members.Members, not(hasItems(sameMemberAs(new ClusterMember(_clusterId3)))));
        }
Exemple #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void iCanGetToMyself()
        public virtual void ICanGetToMyself()
        {
            // given
            Cluster             cluster      = mock(typeof(Cluster));
            Heartbeat           heartbeat    = mock(typeof(Heartbeat));
            ClusterMemberEvents memberEvents = mock(typeof(ClusterMemberEvents));

            ObservedClusterMembers members = new ObservedClusterMembers(_logProvider, cluster, heartbeat, memberEvents, _clusterId1);

            // when

            ArgumentCaptor <ClusterListener> listener = ArgumentCaptor.forClass(typeof(ClusterListener));

            verify(cluster).addClusterListener(listener.capture());

            listener.Value.enteredCluster(ClusterConfiguration(_clusterUri1, _clusterUri2));

            ClusterMember me = members.CurrentMember;

            assertNotNull(me);
            assertEquals(1, me.InstanceId.toIntegerIndex());
            assertEquals(_clusterId1, me.InstanceId);
        }
Exemple #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void missingMasterUnavailabilityEventForOtherInstanceStillRemovesBackupRole()
        public virtual void MissingMasterUnavailabilityEventForOtherInstanceStillRemovesBackupRole()
        {
            // given
            Cluster             cluster      = mock(typeof(Cluster));
            Heartbeat           heartbeat    = mock(typeof(Heartbeat));
            ClusterMemberEvents memberEvents = mock(typeof(ClusterMemberEvents));

            ObservedClusterMembers members = new ObservedClusterMembers(_logProvider, cluster, heartbeat, memberEvents, _clusterId1);
            // initialized with the members of the cluster
            ArgumentCaptor <ClusterListener> listener = ArgumentCaptor.forClass(typeof(ClusterListener));

            verify(cluster).addClusterListener(listener.capture());
            listener.Value.enteredCluster(ClusterConfiguration(_clusterUri1, _clusterUri2, _clusterUri3));

            ArgumentCaptor <ClusterMemberListener> memberListener = ArgumentCaptor.forClass(typeof(ClusterMemberListener));

            verify(memberEvents).addClusterMemberListener(memberListener.capture());

            // instance 2 is available as MASTER and BACKUP
            memberListener.Value.memberIsAvailable(OnlineBackupKernelExtension.BACKUP, _clusterId2, _clusterUri2, StoreId.DEFAULT);
            memberListener.Value.memberIsAvailable(MASTER, _clusterId2, _clusterUri2, StoreId.DEFAULT);

            // when - instance 2 becomes available as SLAVE
            memberListener.Value.memberIsAvailable(SLAVE, _clusterId2, _clusterUri2, StoreId.DEFAULT);

            // then - instance 2 should be available ONLY as SLAVE
            foreach (ClusterMember clusterMember in members.Members)
            {
                if (clusterMember.InstanceId.Equals(_clusterId2))
                {
                    assertThat(count(clusterMember.Roles), equalTo(1L));
                    assertThat(Iterables.single(clusterMember.Roles), equalTo(SLAVE));
                    break;                              // that's the only member we care about
                }
            }
        }
Exemple #12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void availableSlaveShowsProperInformation()
        public virtual void AvailableSlaveShowsProperInformation()
        {
            // given
            Cluster             cluster      = mock(typeof(Cluster));
            Heartbeat           heartbeat    = mock(typeof(Heartbeat));
            ClusterMemberEvents memberEvents = mock(typeof(ClusterMemberEvents));

            ObservedClusterMembers members = new ObservedClusterMembers(_logProvider, cluster, heartbeat, memberEvents, null);

            ArgumentCaptor <ClusterListener> listener = ArgumentCaptor.forClass(typeof(ClusterListener));

            verify(cluster).addClusterListener(listener.capture());
            listener.Value.enteredCluster(ClusterConfiguration(_clusterUri1, _clusterUri2, _clusterUri3));

            ArgumentCaptor <ClusterMemberListener> memberListener = ArgumentCaptor.forClass(typeof(ClusterMemberListener));

            verify(memberEvents).addClusterMemberListener(memberListener.capture());

            // when
            memberListener.Value.memberIsAvailable(SLAVE, _clusterId1, _haUri1, StoreId.DEFAULT);

            // then
            assertThat(members.Members, hasItem(sameMemberAs((new ClusterMember(_clusterId1)).availableAs(SLAVE, _haUri1, StoreId.DEFAULT))));
        }
Exemple #13
0
 public ClusterListenerAnonymousInnerClass(ClusterMockTest outerInstance, URI uri, Org.Neo4j.cluster.protocol.cluster.Cluster cluster)
 {
     this.outerInstance = outerInstance;
     this._uri          = uri;
     this._cluster      = cluster;
 }