Beispiel #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldPrioritiseCorrectly()
        public virtual void ShouldPrioritiseCorrectly()
        {
            BatchingMessageHandler batchHandler = new BatchingMessageHandler(_downstreamHandler, _inQueueConfig, _batchConfig, _jobSchedulerFactory, NullLogProvider.Instance);

            NewEntry.Request      newEntry    = new NewEntry.Request(null, Content(""));
            AppendEntries.Request append      = new AppendEntries.Request(_leader, 1, -1, -1, Entries(0, 0, 0), 0);
            AppendEntries.Request emptyAppend = new AppendEntries.Request(_leader, 1, -1, -1, RaftLogEntry.empty, 0);
            Heartbeat             heartbeat   = new Heartbeat(null, 0, 0, 0);

            batchHandler.Handle(Wrap(newEntry));
            batchHandler.Handle(Wrap(append));
            batchHandler.Handle(Wrap(heartbeat));
            batchHandler.Handle(Wrap(emptyAppend));
            verifyZeroInteractions(_downstreamHandler);

            // when
            batchHandler.Run();
            batchHandler.Run();
            batchHandler.Run();
            batchHandler.Run();

            // then
            InOrder inOrder = Mockito.inOrder(_downstreamHandler);

            inOrder.verify(_downstreamHandler).handle(Wrap(heartbeat));
            inOrder.verify(_downstreamHandler).handle(Wrap(emptyAppend));
            inOrder.verify(_downstreamHandler).handle(Wrap(append));
            inOrder.verify(_downstreamHandler).handle(Wrap(new NewEntry.BatchRequest(singletonList(Content("")))));
        }
Beispiel #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBatchNewEntriesAndHandleOtherMessagesFirst()
        public virtual void ShouldBatchNewEntriesAndHandleOtherMessagesFirst()
        {
            // given
            BatchingMessageHandler batchHandler = new BatchingMessageHandler(_downstreamHandler, _inQueueConfig, _batchConfig, _jobSchedulerFactory, NullLogProvider.Instance);

            ReplicatedString contentA = new ReplicatedString("A");
            ReplicatedString contentC = new ReplicatedString("C");

            NewEntry.Request newEntryA  = new NewEntry.Request(null, contentA);
            Heartbeat        heartbeatA = new Heartbeat(null, 0, 0, 0);

            NewEntry.Request newEntryB  = new NewEntry.Request(null, contentC);
            Heartbeat        heartbeatB = new Heartbeat(null, 1, 1, 1);

            batchHandler.Handle(Wrap(newEntryA));
            batchHandler.Handle(Wrap(heartbeatA));
            batchHandler.Handle(Wrap(newEntryB));
            batchHandler.Handle(Wrap(heartbeatB));
            verifyZeroInteractions(_downstreamHandler);

            // when
            batchHandler.Run();               // heartbeatA
            batchHandler.Run();               // heartbeatB
            batchHandler.Run();               // batchRequest

            // then
            NewEntry.BatchRequest batchRequest = new NewEntry.BatchRequest(asList(contentA, contentC));

            verify(_downstreamHandler).handle(Wrap(heartbeatA));
            verify(_downstreamHandler).handle(Wrap(heartbeatB));
            verify(_downstreamHandler).handle(Wrap(batchRequest));
        }
Beispiel #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotBatchAppendEntriesDifferentLeaderTerms()
        public virtual void ShouldNotBatchAppendEntriesDifferentLeaderTerms()
        {
            BatchingMessageHandler batchHandler = new BatchingMessageHandler(_downstreamHandler, _inQueueConfig, _batchConfig, _jobSchedulerFactory, NullLogProvider.Instance);

            long leaderTerm   = 1;
            long prevLogIndex = -1;
            long prevLogTerm  = -1;
            long leaderCommit = 0;

            RaftLogEntry[] entriesA = Entries(0, 0, 2);
            RaftLogEntry[] entriesB = Entries(1, 3, 3);

            AppendEntries.Request appendA = new AppendEntries.Request(_leader, leaderTerm, prevLogIndex, prevLogTerm, entriesA, leaderCommit);

            prevLogIndex += appendA.entries().length;
            prevLogTerm   = lastOf(appendA.entries()).term();

            AppendEntries.Request appendB = new AppendEntries.Request(_leader, leaderTerm + 1, prevLogIndex, prevLogTerm, entriesB, leaderCommit);

            batchHandler.Handle(Wrap(appendA));
            batchHandler.Handle(Wrap(appendB));
            verifyZeroInteractions(_downstreamHandler);

            // when
            batchHandler.Run();
            batchHandler.Run();

            // then
            verify(_downstreamHandler).handle(Wrap(appendA));
            verify(_downstreamHandler).handle(Wrap(appendB));
        }
Beispiel #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBatchSingleEntryAppendEntries()
        public virtual void ShouldBatchSingleEntryAppendEntries()
        {
            BatchingMessageHandler batchHandler = new BatchingMessageHandler(_downstreamHandler, _inQueueConfig, _batchConfig, _jobSchedulerFactory, NullLogProvider.Instance);

            long leaderTerm   = 1;
            long prevLogIndex = -1;
            long prevLogTerm  = -1;
            long leaderCommit = 0;

            RaftLogEntry entryA = new RaftLogEntry(0, Content("A"));
            RaftLogEntry entryB = new RaftLogEntry(0, Content("B"));

            AppendEntries.Request appendA = new AppendEntries.Request(_leader, leaderTerm, prevLogIndex, prevLogTerm, new RaftLogEntry[] { entryA }, leaderCommit);

            AppendEntries.Request appendB = new AppendEntries.Request(_leader, leaderTerm, prevLogIndex + 1, 0, new RaftLogEntry[] { entryB }, leaderCommit);

            batchHandler.Handle(Wrap(appendA));
            batchHandler.Handle(Wrap(appendB));
            verifyZeroInteractions(_downstreamHandler);

            // when
            batchHandler.Run();

            // then
            AppendEntries.Request expected = new AppendEntries.Request(_leader, leaderTerm, prevLogIndex, prevLogTerm, new RaftLogEntry[] { entryA, entryB }, leaderCommit);

            verify(_downstreamHandler).handle(Wrap(expected));
        }
Beispiel #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDropMessagesAfterBeingStopped() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldDropMessagesAfterBeingStopped()
        {
            // given
            AssertableLogProvider  logProvider  = new AssertableLogProvider();
            BatchingMessageHandler batchHandler = new BatchingMessageHandler(_downstreamHandler, _inQueueConfig, _batchConfig, _jobSchedulerFactory, logProvider);

            NewEntry.Request message = new NewEntry.Request(null, null);
            batchHandler.Stop();

            // when
            batchHandler.Handle(Wrap(message));
            batchHandler.Run();

            // then
            verify(_downstreamHandler, never()).handle(ArgumentMatchers.any(typeof(RaftMessages_ReceivedInstantClusterIdAwareMessage)));
            logProvider.AssertAtLeastOnce(AssertableLogProvider.inLog(typeof(BatchingMessageHandler)).debug("This handler has been stopped, dropping the message: %s", Wrap(message)));
        }
Beispiel #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldInvokeInnerHandlerWhenRun()
        public virtual void ShouldInvokeInnerHandlerWhenRun()
        {
            // given
            BatchingMessageHandler batchHandler = new BatchingMessageHandler(_downstreamHandler, _inQueueConfig, _batchConfig, _jobSchedulerFactory, NullLogProvider.Instance);

            NewEntry.Request message = new NewEntry.Request(null, Content("dummy"));

            batchHandler.Handle(Wrap(message));
            verifyZeroInteractions(_downstreamHandler);

            // when
            batchHandler.Run();

            // then
            NewEntry.BatchRequest expected = new NewEntry.BatchRequest(singletonList(new ReplicatedString("dummy")));
            verify(_downstreamHandler).handle(Wrap(expected));
        }
Beispiel #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBatchMultipleEntryAppendEntries()
        public virtual void ShouldBatchMultipleEntryAppendEntries()
        {
            BatchingMessageHandler batchHandler = new BatchingMessageHandler(_downstreamHandler, _inQueueConfig, _batchConfig, _jobSchedulerFactory, NullLogProvider.Instance);

            long leaderTerm   = 1;
            long prevLogIndex = -1;
            long prevLogTerm  = -1;
            long leaderCommit = 0;

            RaftLogEntry[] entriesA = Entries(0, 0, 2);
            RaftLogEntry[] entriesB = Entries(1, 3, 3);
            RaftLogEntry[] entriesC = Entries(2, 4, 8);
            RaftLogEntry[] entriesD = Entries(3, 9, 15);

            AppendEntries.Request appendA = new AppendEntries.Request(_leader, leaderTerm, prevLogIndex, prevLogTerm, entriesA, leaderCommit);

            prevLogIndex += appendA.entries().length;
            prevLogTerm   = lastOf(appendA.entries()).term();
            leaderCommit += 2;               // arbitrary

            AppendEntries.Request appendB = new AppendEntries.Request(_leader, leaderTerm, prevLogIndex, prevLogTerm, entriesB, leaderCommit);

            prevLogIndex += appendB.entries().length;
            prevLogTerm   = lastOf(appendB.entries()).term();
            leaderCommit += 5;               // arbitrary

            AppendEntries.Request appendC = new AppendEntries.Request(_leader, leaderTerm, prevLogIndex, prevLogTerm, ArrayUtil.concat(entriesC, entriesD), leaderCommit);

            batchHandler.Handle(Wrap(appendA));
            batchHandler.Handle(Wrap(appendB));
            batchHandler.Handle(Wrap(appendC));
            verifyZeroInteractions(_downstreamHandler);

            // when
            batchHandler.Run();

            // then
            AppendEntries.Request expected = new AppendEntries.Request(_leader, leaderTerm, -1, -1, ArrayUtil.concatArrays(entriesA, entriesB, entriesC, entriesD), leaderCommit);

            verify(_downstreamHandler).handle(Wrap(expected));
        }
Beispiel #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBatchUsingReceivedInstantOfFirstReceivedMessage()
        public virtual void ShouldBatchUsingReceivedInstantOfFirstReceivedMessage()
        {
            // given
            BatchingMessageHandler batchHandler = new BatchingMessageHandler(_downstreamHandler, _inQueueConfig, _batchConfig, _jobSchedulerFactory, NullLogProvider.Instance);
            ReplicatedString       content      = new ReplicatedString("A");

            NewEntry.Request messageA = new NewEntry.Request(null, content);

            Instant firstReceived  = Instant.ofEpochMilli(1L);
            Instant secondReceived = firstReceived.plusMillis(1L);

            batchHandler.Handle(Wrap(firstReceived, messageA));
            batchHandler.Handle(Wrap(secondReceived, messageA));

            // when
            batchHandler.Run();

            // then
            NewEntry.BatchRequest batchRequest = new NewEntry.BatchRequest(asList(content, content));
            verify(_downstreamHandler).handle(Wrap(firstReceived, batchRequest));
        }
Beispiel #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBatchRequests()
        public virtual void ShouldBatchRequests()
        {
            // given
            BatchingMessageHandler batchHandler = new BatchingMessageHandler(_downstreamHandler, _inQueueConfig, _batchConfig, _jobSchedulerFactory, NullLogProvider.Instance);
            ReplicatedString       contentA     = new ReplicatedString("A");
            ReplicatedString       contentB     = new ReplicatedString("B");

            NewEntry.Request messageA = new NewEntry.Request(null, contentA);
            NewEntry.Request messageB = new NewEntry.Request(null, contentB);

            batchHandler.Handle(Wrap(messageA));
            batchHandler.Handle(Wrap(messageB));
            verifyZeroInteractions(_downstreamHandler);

            // when
            batchHandler.Run();

            // then
            NewEntry.BatchRequest expected = new NewEntry.BatchRequest(asList(contentA, contentB));
            verify(_downstreamHandler).handle(Wrap(expected));
        }