Search in sources :

Example 1 with PublishRequest

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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CommandResponse(io.atomix.protocols.raft.protocol.CommandResponse) PublishRequest(io.atomix.protocols.raft.protocol.PublishRequest) Test(org.junit.Test)

Example 2 with PublishRequest

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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CommandResponse(io.atomix.protocols.raft.protocol.CommandResponse) PublishRequest(io.atomix.protocols.raft.protocol.PublishRequest) Test(org.junit.Test)

Example 3 with PublishRequest

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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CommandResponse(io.atomix.protocols.raft.protocol.CommandResponse) PublishRequest(io.atomix.protocols.raft.protocol.PublishRequest) Test(org.junit.Test)

Example 4 with PublishRequest

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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CommandResponse(io.atomix.protocols.raft.protocol.CommandResponse) PublishRequest(io.atomix.protocols.raft.protocol.PublishRequest) Test(org.junit.Test)

Example 5 with PublishRequest

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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PublishRequest(io.atomix.protocols.raft.protocol.PublishRequest) Test(org.junit.Test)

Aggregations

PublishRequest (io.atomix.protocols.raft.protocol.PublishRequest)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 Test (org.junit.Test)5 CommandResponse (io.atomix.protocols.raft.protocol.CommandResponse)4