use of io.atomix.primitive.operation.PrimitiveOperation in project atomix by atomix.
the class RaftProxyInvokerTest method testResequenceCommand.
/**
* Test resequencing a command response.
*/
@Test
public void testResequenceCommand() throws Throwable {
CompletableFuture<CommandResponse> future1 = new CompletableFuture<>();
CompletableFuture<CommandResponse> future2 = new CompletableFuture<>();
RaftProxyConnection connection = mock(RaftProxyConnection.class);
Mockito.when(connection.command(any(CommandRequest.class))).thenReturn(future1).thenReturn(future2);
RaftProxyState state = new RaftProxyState("test", SessionId.from(1), UUID.randomUUID().toString(), new TestPrimitiveType(), 1000);
RaftProxyManager manager = mock(RaftProxyManager.class);
ThreadContext threadContext = new TestContext();
RaftProxyInvoker submitter = new RaftProxyInvoker(connection, mock(RaftProxyConnection.class), state, new RaftProxySequencer(state), manager, threadContext);
CompletableFuture<byte[]> result1 = submitter.invoke(new PrimitiveOperation(COMMAND, HeapBytes.EMPTY));
CompletableFuture<byte[]> result2 = submitter.invoke(new PrimitiveOperation(COMMAND, HeapBytes.EMPTY));
future2.complete(CommandResponse.builder().withStatus(RaftResponse.Status.OK).withIndex(10).withResult("Hello world again!".getBytes()).build());
assertEquals(state.getCommandRequest(), 2);
assertEquals(state.getCommandResponse(), 0);
assertEquals(state.getResponseIndex(), 1);
assertFalse(result1.isDone());
assertFalse(result2.isDone());
future1.complete(CommandResponse.builder().withStatus(RaftResponse.Status.OK).withIndex(9).withResult("Hello world!".getBytes()).build());
assertTrue(result1.isDone());
assertTrue(Arrays.equals(result1.get(), "Hello world!".getBytes()));
assertTrue(result2.isDone());
assertTrue(Arrays.equals(result2.get(), "Hello world again!".getBytes()));
assertEquals(state.getCommandRequest(), 2);
assertEquals(state.getCommandResponse(), 2);
assertEquals(state.getResponseIndex(), 10);
}
use of io.atomix.primitive.operation.PrimitiveOperation in project atomix by atomix.
the class RaftProxyInvokerTest method testResequenceQuery.
/**
* Tests resequencing a query response.
*/
@Test
public void testResequenceQuery() throws Throwable {
CompletableFuture<QueryResponse> future1 = new CompletableFuture<>();
CompletableFuture<QueryResponse> future2 = new CompletableFuture<>();
RaftProxyConnection connection = mock(RaftProxyConnection.class);
Mockito.when(connection.query(any(QueryRequest.class))).thenReturn(future1).thenReturn(future2);
RaftProxyState state = new RaftProxyState("test", SessionId.from(1), UUID.randomUUID().toString(), new TestPrimitiveType(), 1000);
RaftProxyManager manager = mock(RaftProxyManager.class);
ThreadContext threadContext = new TestContext();
RaftProxyInvoker submitter = new RaftProxyInvoker(mock(RaftProxyConnection.class), connection, state, new RaftProxySequencer(state), manager, threadContext);
CompletableFuture<byte[]> result1 = submitter.invoke(new PrimitiveOperation(QUERY, HeapBytes.EMPTY));
CompletableFuture<byte[]> result2 = submitter.invoke(new PrimitiveOperation(QUERY, HeapBytes.EMPTY));
future2.complete(QueryResponse.builder().withStatus(RaftResponse.Status.OK).withIndex(10).withResult("Hello world again!".getBytes()).build());
assertEquals(state.getResponseIndex(), 1);
assertFalse(result1.isDone());
assertFalse(result2.isDone());
future1.complete(QueryResponse.builder().withStatus(RaftResponse.Status.OK).withIndex(9).withResult("Hello world!".getBytes()).build());
assertTrue(result1.isDone());
assertTrue(Arrays.equals(result1.get(), "Hello world!".getBytes()));
assertTrue(result2.isDone());
assertTrue(Arrays.equals(result2.get(), "Hello world again!".getBytes()));
assertEquals(state.getResponseIndex(), 10);
}
Aggregations