Ejemplo n.º 1
0
        public override long TimeoutFor(Message message)
        {
            long?timeout = _timeouts[message.MessageType];

            if (timeout == null)
            {
                return(@delegate.TimeoutFor(message));
            }
            else
            {
                return(timeout.Value);
            }
        }
Ejemplo n.º 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldLogFirstHeartbeatAfterTimeout()
        public virtual void ShouldLogFirstHeartbeatAfterTimeout()
        {
            // given
            InstanceId           instanceId    = new InstanceId(1);
            InstanceId           otherInstance = new InstanceId(2);
            ClusterConfiguration configuration = new ClusterConfiguration("whatever", NullLogProvider.Instance, "cluster://1", "cluster://2");

            configuration.Members[otherInstance] = URI.create("cluster://2");
            AssertableLogProvider internalLog     = new AssertableLogProvider(true);
            TimeoutStrategy       timeoutStrategy = mock(typeof(TimeoutStrategy));
            Timeouts timeouts = new Timeouts(timeoutStrategy);

            Config config = mock(typeof(Config));

            when(config.Get(ClusterSettings.max_acceptors)).thenReturn(10);

            MultiPaxosContext context = new MultiPaxosContext(instanceId, iterable(new ElectionRole("coordinator")), configuration, mock(typeof(Executor)), internalLog, mock(typeof(ObjectInputStreamFactory)), mock(typeof(ObjectOutputStreamFactory)), mock(typeof(AcceptorInstanceStore)), timeouts, mock(typeof(ElectionCredentialsProvider)), config);

            StateMachines stateMachines = new StateMachines(internalLog, mock(typeof(StateMachines.Monitor)), mock(typeof(MessageSource)), mock(typeof(MessageSender)), timeouts, mock(typeof(DelayedDirectExecutor)), ThreadStart.run, instanceId);

            stateMachines.AddStateMachine(new StateMachine(context.HeartbeatContext, typeof(HeartbeatMessage), HeartbeatState.Start, internalLog));

            timeouts.Tick(0);
            when(timeoutStrategy.TimeoutFor(any(typeof(Message)))).thenReturn(5L);

            // when
            stateMachines.Process(Message.@internal(HeartbeatMessage.Join));
            stateMachines.Process(Message.@internal(HeartbeatMessage.IAmAlive, new HeartbeatMessage.IAmAliveState(otherInstance)).setHeader(Message.HEADER_CREATED_BY, otherInstance.ToString()));
            for (int i = 1; i <= 15; i++)
            {
                timeouts.Tick(i);
            }

            // then
            verify(timeoutStrategy, times(3)).timeoutTriggered(argThat(new MessageArgumentMatcher <>()
                                                                       .onMessageType(HeartbeatMessage.TimedOut)));
            internalLog.AssertExactly(inLog(typeof(HeartbeatState)).debug("Received timed out for server 2"), inLog(typeof(HeartbeatContext)).info("1(me) is now suspecting 2"), inLog(typeof(HeartbeatState)).debug("Received timed out for server 2"), inLog(typeof(HeartbeatState)).debug("Received timed out for server 2"));
            internalLog.Clear();

            // when
            stateMachines.Process(Message.@internal(HeartbeatMessage.IAmAlive, new HeartbeatMessage.IAmAliveState(otherInstance)).setHeader(Message.HEADER_CREATED_BY, otherInstance.ToString()));

            // then
            internalLog.AssertExactly(inLog(typeof(HeartbeatState)).debug("Received i_am_alive[2] after missing 3 (15ms)"));
        }