Exemplo n.º 1
0
        /*
         * This test ensures that an instance that is marked as failed has its elector version reset. This means that
         * the instance, once it comes back, will still be able to do elections even if it lost state
         */
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void nonElectorFailingMustNotCauseElectorVersionToBeReset()
        public virtual void NonElectorFailingMustNotCauseElectorVersionToBeReset()
        {
            // Given
            InstanceId me      = new InstanceId(1);
            InstanceId elector = new InstanceId(2);

            CommonContextState commonContextState = mock(typeof(CommonContextState), RETURNS_MOCKS);
            Timeouts           timeouts           = mock(typeof(Timeouts));
            Executor           executor           = mock(typeof(Executor));

            HeartbeatContext heartbeatContext = mock(typeof(HeartbeatContext));

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

            ClusterContext context = new ClusterContextImpl(me, commonContextState, NullLogProvider.Instance, timeouts, executor, mock(typeof(ObjectOutputStreamFactory)), mock(typeof(ObjectInputStreamFactory)), mock(typeof(LearnerContext)), heartbeatContext, mock(typeof(Config)));

            verify(heartbeatContext).addHeartbeatListener(listenerCaptor.capture());

            HeartbeatListener theListener = listenerCaptor.Value;

            // This means instance 2 was the elector at version 8
            context.LastElector        = elector;
            context.LastElectorVersion = 8;

            // When
            theListener.Failed(new InstanceId(3));

            // Then
            assertEquals(context.LastElector, elector);
            assertEquals(context.LastElectorVersion, 8);
        }
Exemplo n.º 2
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))));
        }
Exemplo n.º 3
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
                }
            }
        }
Exemplo n.º 4
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));
        }
Exemplo n.º 5
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))));
        }
Exemplo n.º 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void readsEnterpriseStoreVersionCorrectly() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ReadsEnterpriseStoreVersionCorrectly()
        {
            PrepareNeoStoreFile(HighLimitV3_0_0.RECORD_FORMATS.storeVersion());

            Execute(_databaseDirectory.ToString());

            verify(@out, times(3)).accept(_outCaptor.capture());

            assertEquals(Arrays.asList("Store format version:         vE.H.0", "Store format introduced in:   3.0.0", "Store format superseded in:   3.0.6"), _outCaptor.AllValues);
        }
Exemplo n.º 7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldManageChannelsInChannelInitializer()
        internal virtual void ShouldManageChannelsInChannelInitializer()
        {
            NetworkConnectionTracker connectionTracker = mock(typeof(NetworkConnectionTracker));
            SocketTransport          socketTransport   = NewSocketTransport(connectionTracker, NO_THROTTLE);

            EmbeddedChannel channel = new EmbeddedChannel(socketTransport.ChannelInitializer());

            ArgumentCaptor <TrackedNetworkConnection> captor = ArgumentCaptor.forClass(typeof(TrackedNetworkConnection));

            verify(connectionTracker).add(captor.capture());
            verify(connectionTracker, never()).remove(any());

            channel.close();

            verify(connectionTracker).remove(captor.Value);
        }
Exemplo n.º 8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void retrieveStoreDelegatesToStoreCopyService() throws org.neo4j.causalclustering.catchup.storecopy.StoreCopyFailedException, org.neo4j.causalclustering.catchup.CatchupAddressResolutionException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void RetrieveStoreDelegatesToStoreCopyService()
        {
            // given
            StoreId        storeId        = new StoreId(92, 5, 7, 32);
            DatabaseLayout databaseLayout = DatabaseLayout.of(new File("."));

            // when
            Subject.copy(_anyAddress, storeId, databaseLayout);

            // then
            ArgumentCaptor <CatchupAddressProvider> argumentCaptor = ArgumentCaptor.forClass(typeof(CatchupAddressProvider));

            verify(_remoteStore).copy(argumentCaptor.capture(), eq(storeId), eq(databaseLayout), eq(true));

            //and
            assertEquals(_anyAddress, argumentCaptor.Value.primary());
        }
Exemplo n.º 9
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))));
        }
Exemplo n.º 10
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)))));
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
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
                }
            }
        }
Exemplo n.º 13
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))));
        }