use of io.atomix.protocols.raft.protocol.PublishRequest in project atomix by atomix.
the class RaftProxySequencerTest method testSequenceEventBeforeCommand.
/**
* Tests sequencing an event that arrives before a command response.
*/
@Test
public void testSequenceEventBeforeCommand() throws Throwable {
RaftProxySequencer sequencer = new RaftProxySequencer(new RaftProxyState("test", SessionId.from(1), UUID.randomUUID().toString(), new TestPrimitiveType(), 1000));
long sequence = sequencer.nextRequest();
PublishRequest request = PublishRequest.builder().withSession(1).withEventIndex(1).withPreviousIndex(0).withEvents(Collections.emptyList()).build();
CommandResponse response = CommandResponse.builder().withStatus(RaftResponse.Status.OK).withIndex(2).withEventIndex(1).build();
AtomicInteger run = new AtomicInteger();
sequencer.sequenceEvent(request, () -> assertEquals(run.getAndIncrement(), 0));
sequencer.sequenceResponse(sequence, response, () -> assertEquals(run.getAndIncrement(), 1));
assertEquals(run.get(), 2);
}
use of io.atomix.protocols.raft.protocol.PublishRequest in project atomix by atomix.
the class RaftProxySequencerTest method testSequenceEventAfterAllCommands.
/**
* Tests sequencing an event that arrives before a command response.
*/
@Test
public void testSequenceEventAfterAllCommands() throws Throwable {
RaftProxySequencer sequencer = new RaftProxySequencer(new RaftProxyState("test", SessionId.from(1), UUID.randomUUID().toString(), new TestPrimitiveType(), 1000));
long sequence = sequencer.nextRequest();
PublishRequest request1 = PublishRequest.builder().withSession(1).withEventIndex(2).withPreviousIndex(0).withEvents(Collections.emptyList()).build();
PublishRequest request2 = PublishRequest.builder().withSession(1).withEventIndex(3).withPreviousIndex(2).withEvents(Collections.emptyList()).build();
CommandResponse response = CommandResponse.builder().withStatus(RaftResponse.Status.OK).withIndex(2).withEventIndex(2).build();
AtomicInteger run = new AtomicInteger();
sequencer.sequenceEvent(request1, () -> assertEquals(run.getAndIncrement(), 0));
sequencer.sequenceEvent(request2, () -> assertEquals(run.getAndIncrement(), 2));
sequencer.sequenceResponse(sequence, response, () -> assertEquals(run.getAndIncrement(), 1));
assertEquals(run.get(), 3);
}
use of io.atomix.protocols.raft.protocol.PublishRequest in project atomix by atomix.
the class RaftProxySequencerTest method testSequenceEventAfterCommand.
/**
* Tests sequencing an event that arrives before a command response.
*/
@Test
public void testSequenceEventAfterCommand() throws Throwable {
RaftProxySequencer sequencer = new RaftProxySequencer(new RaftProxyState("test", SessionId.from(1), UUID.randomUUID().toString(), new TestPrimitiveType(), 1000));
long sequence = sequencer.nextRequest();
PublishRequest request = PublishRequest.builder().withSession(1).withEventIndex(1).withPreviousIndex(0).withEvents(Collections.emptyList()).build();
CommandResponse response = CommandResponse.builder().withStatus(RaftResponse.Status.OK).withIndex(2).withEventIndex(1).build();
AtomicInteger run = new AtomicInteger();
sequencer.sequenceResponse(sequence, response, () -> assertEquals(run.getAndIncrement(), 0));
sequencer.sequenceEvent(request, () -> assertEquals(run.getAndIncrement(), 1));
assertEquals(run.get(), 2);
}
use of io.atomix.protocols.raft.protocol.PublishRequest in project atomix by atomix.
the class RaftProxySequencerTest method testSequenceEventAtCommand.
/**
* Tests sequencing an event that arrives before a command response.
*/
@Test
public void testSequenceEventAtCommand() throws Throwable {
RaftProxySequencer sequencer = new RaftProxySequencer(new RaftProxyState("test", SessionId.from(1), UUID.randomUUID().toString(), new TestPrimitiveType(), 1000));
long sequence = sequencer.nextRequest();
PublishRequest request = PublishRequest.builder().withSession(1).withEventIndex(2).withPreviousIndex(0).withEvents(Collections.emptyList()).build();
CommandResponse response = CommandResponse.builder().withStatus(RaftResponse.Status.OK).withIndex(2).withEventIndex(2).build();
AtomicInteger run = new AtomicInteger();
sequencer.sequenceResponse(sequence, response, () -> assertEquals(run.getAndIncrement(), 1));
sequencer.sequenceEvent(request, () -> assertEquals(run.getAndIncrement(), 0));
assertEquals(run.get(), 2);
}
use of io.atomix.protocols.raft.protocol.PublishRequest in project atomix by atomix.
the class RaftProxySequencerTest method testSequenceEventAbsentCommand.
/**
* Tests sequencing an event that arrives before a command response.
*/
@Test
public void testSequenceEventAbsentCommand() throws Throwable {
RaftProxySequencer sequencer = new RaftProxySequencer(new RaftProxyState("test", SessionId.from(1), UUID.randomUUID().toString(), new TestPrimitiveType(), 1000));
PublishRequest request1 = PublishRequest.builder().withSession(1).withEventIndex(2).withPreviousIndex(0).withEvents(Collections.emptyList()).build();
PublishRequest request2 = PublishRequest.builder().withSession(1).withEventIndex(3).withPreviousIndex(2).withEvents(Collections.emptyList()).build();
AtomicInteger run = new AtomicInteger();
sequencer.sequenceEvent(request1, () -> assertEquals(run.getAndIncrement(), 0));
sequencer.sequenceEvent(request2, () -> assertEquals(run.getAndIncrement(), 1));
assertEquals(run.get(), 2);
}
Aggregations