Пример #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldUpdateDiscoveryHeaderWithContactingInstances()
        public virtual void ShouldUpdateDiscoveryHeaderWithContactingInstances()
        {
            // Given
            InstanceId me         = new InstanceId(1);
            InstanceId joiningOne = new InstanceId(2);
            InstanceId joiningTwo = new InstanceId(3);

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

            HeartbeatContext heartbeatContext = mock(typeof(HeartbeatContext));

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

            ClusterMessage.ConfigurationRequestState requestOne = mock(typeof(ClusterMessage.ConfigurationRequestState));
            when(requestOne.JoiningId).thenReturn(joiningOne);

            ClusterMessage.ConfigurationRequestState requestTwo = mock(typeof(ClusterMessage.ConfigurationRequestState));
            when(requestTwo.JoiningId).thenReturn(joiningTwo);

            // When
            // Instance 2 contacts us twice and Instance 3 contacts us once
            context.AddContactingInstance(requestOne, "4, 5");                 // discovery headers are random here
            context.AddContactingInstance(requestOne, "4, 5");
            context.AddContactingInstance(requestTwo, "2, 5");

            // Then
            // The discovery header we generate should still contain one copy of each instance
            assertEquals("2,3", context.GenerateDiscoveryHeader());
        }
Пример #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldGracefullyHandleEmptyDiscoveryHeader()
        public virtual void ShouldGracefullyHandleEmptyDiscoveryHeader()
        {
            // Given
            InstanceId me      = new InstanceId(1);
            InstanceId joining = 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));

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

            ClusterMessage.ConfigurationRequestState request = mock(typeof(ClusterMessage.ConfigurationRequestState));
            when(request.JoiningId).thenReturn(joining);

            // When
            // Instance 2 contacts us with a request but it is empty
            context.AddContactingInstance(request, "");

            // Then
            // The discovery header we generate should still contain that instance
            assertEquals("2", context.GenerateDiscoveryHeader());
        }