Exemplo n.º 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldIgnoreSuspicionsForOurselves() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldIgnoreSuspicionsForOurselves()
        {
            // Given
            InstanceId           instanceId    = new InstanceId(1);
            HeartbeatState       heartbeat     = HeartbeatState.Heartbeat;
            ClusterConfiguration configuration = new ClusterConfiguration("whatever", NullLogProvider.Instance, "cluster://1", "cluster://2");

            configuration.Joined(instanceId, URI.create("cluster://1"));
            configuration.Joined(new InstanceId(2), URI.create("cluster://2"));

            Config config = mock(typeof(Config));

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

            MultiPaxosContext context = new MultiPaxosContext(instanceId, iterable(new ElectionRole("coordinator")), configuration, Mockito.mock(typeof(Executor)), NullLogProvider.Instance, Mockito.mock(typeof(ObjectInputStreamFactory)), Mockito.mock(typeof(ObjectOutputStreamFactory)), Mockito.mock(typeof(AcceptorInstanceStore)), Mockito.mock(typeof(Timeouts)), mock(typeof(ElectionCredentialsProvider)), config);

            HeartbeatContext heartbeatContext = context.HeartbeatContext;
            Message          received         = Message.@internal(HeartbeatMessage.Suspicions, new HeartbeatMessage.SuspicionsState(asSet(iterable(instanceId))));

            received.setHeader(Message.HEADER_FROM, "cluster://2").SetHeader(Message.HEADER_INSTANCE_ID, "2");

            // When
            heartbeat.handle(heartbeatContext, received, mock(typeof(MessageHolder)));

            // Then
            assertThat(heartbeatContext.GetSuspicionsOf(instanceId).Count, equalTo(0));
        }
Exemplo n.º 2
0
    IEnumerator UpdateSession(HeartbeatState hs)
    {
        while (true)
        {
            yield return(new WaitForSeconds(hs.IntervalSec));

            // Update the interval for the next time around.
            hs.IntervalSec = _intervalCalculator(_initialInterval, hs.IntervalSec, hs.ProgressPct, (float)hs.Elapsed.TotalSeconds);

            // Progress beyond 100% is not allowed.  100% will be reported by End().
            if (hs.ProgressPct < 100)
            {
                hs.ProgressPct++;
                SplytAnalytics.Session.UpdateProgress(hs.ProgressPct);
            }
        }
    }
Exemplo n.º 3
0
    public void Begin()
    {
        lock (_sessionLock)
        {
            if (_sessionStarted)
            {
                throw new InvalidOperationException("A session is already in progress.");
            }

            _sessionStarted = true;
            SplytAnalytics.Error error = SplytAnalytics.Session.Begin();

            if (error == SplytAnalytics.Error.Success)
            {
                _heartbeatState = new HeartbeatState(0, _initialInterval);
                StartCoroutine("UpdateSession", _heartbeatState);
            }
        }
    }
    public void Begin()
    {
        lock (_sessionLock)
        {
            if (_sessionStarted)
            {
                throw new InvalidOperationException("A session is already in progress.");
            }

            _sessionStarted = true;
            SplytAnalytics.Error error = SplytAnalytics.Session.Begin();

            if (error == SplytAnalytics.Error.Success)
            {
                _heartbeatState = new HeartbeatState(0, _initialInterval);
                StartCoroutine("UpdateSession", _heartbeatState);
            }
        }
    }
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 shouldAddInstanceIdHeaderInCatchUpMessages() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAddInstanceIdHeaderInCatchUpMessages()
        {
            // Given
            InstanceId           instanceId    = new InstanceId(1);
            HeartbeatState       heartbeat     = HeartbeatState.Heartbeat;
            ClusterConfiguration configuration = new ClusterConfiguration("whatever", NullLogProvider.Instance, "cluster://1", "cluster://2");

            configuration.Joined(instanceId, URI.create("cluster://1"));
            InstanceId otherInstance = new InstanceId(2);

            configuration.Joined(otherInstance, URI.create("cluster://2"));

            Config config = mock(typeof(Config));

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

            MultiPaxosContext context = new MultiPaxosContext(instanceId, iterable(new ElectionRole("coordinator")), configuration, Mockito.mock(typeof(Executor)), NullLogProvider.Instance, Mockito.mock(typeof(ObjectInputStreamFactory)), Mockito.mock(typeof(ObjectOutputStreamFactory)), Mockito.mock(typeof(AcceptorInstanceStore)), Mockito.mock(typeof(Timeouts)), mock(typeof(ElectionCredentialsProvider)), config);

            int lastDeliveredInstanceId = 100;

            context.LearnerContext.LastDeliveredInstanceId = lastDeliveredInstanceId;
            // This gap will trigger the catchUp message that we'll test against
            lastDeliveredInstanceId += 20;

            HeartbeatContext heartbeatContext = context.HeartbeatContext;
            Message          received         = Message.@internal(HeartbeatMessage.IAmAlive, new HeartbeatMessage.IAmAliveState(otherInstance));

            received.setHeader(Message.HEADER_FROM, "cluster://2").SetHeader(Message.HEADER_INSTANCE_ID, "2").setHeader("last-learned", Convert.ToString(lastDeliveredInstanceId));

            // When
            MessageHolder holder = mock(typeof(MessageHolder));

            heartbeat.handle(heartbeatContext, received, holder);

            // Then
            verify(holder, times(1)).offer(ArgumentMatchers.argThat(new MessageArgumentMatcher <LearnerMessage>()
                                                                    .onMessageType(LearnerMessage.catchUp).withHeader(Message.HEADER_INSTANCE_ID, "2")));
        }
    IEnumerator UpdateSession(HeartbeatState hs)
    {
        while (true)
        {
            yield return new WaitForSeconds(hs.IntervalSec);

            // Update the interval for the next time around.
            hs.IntervalSec = _intervalCalculator(_initialInterval, hs.IntervalSec, hs.ProgressPct, (float) hs.Elapsed.TotalSeconds);

            // Progress beyond 100% is not allowed.  100% will be reported by End().
            if (hs.ProgressPct < 100)
            {
                hs.ProgressPct++;
                SplytAnalytics.Session.UpdateProgress(hs.ProgressPct);
            }
        }
    }