use of org.apache.ignite.raft.jraft.rpc.impl.RaftException in project ignite-3 by apache.
the class ItJraftCounterServerTest method testCreateSnapshotAbnormalFailure.
@Test
public void testCreateSnapshotAbnormalFailure() throws Exception {
listenerFactory = () -> new CounterListener() {
@Override
public void onSnapshotSave(Path path, Consumer<Throwable> doneClo) {
doneClo.accept(new IgniteInternalException("Very bad"));
}
};
startCluster();
RaftGroupService client1 = clients.get(0);
RaftGroupService client2 = clients.get(1);
client1.refreshLeader().get();
client2.refreshLeader().get();
long val = applyIncrements(client1, 1, 10);
assertEquals(sum(10), val);
Peer peer = servers.get(0).localPeer(COUNTER_GROUP_0);
try {
client1.snapshot(peer).get();
fail();
} catch (Exception e) {
assertTrue(e.getCause() instanceof RaftException);
}
}
use of org.apache.ignite.raft.jraft.rpc.impl.RaftException in project ignite-3 by apache.
the class ItJraftCounterServerTest method testCreateSnapshotGracefulFailure.
@Test
public void testCreateSnapshotGracefulFailure() throws Exception {
listenerFactory = () -> new CounterListener() {
@Override
public void onSnapshotSave(Path path, Consumer<Throwable> doneClo) {
doneClo.accept(new IgniteInternalException("Very bad"));
}
};
startCluster();
RaftGroupService client1 = clients.get(0);
RaftGroupService client2 = clients.get(1);
client1.refreshLeader().get();
client2.refreshLeader().get();
RaftServer server = servers.get(0);
Peer peer = server.localPeer(COUNTER_GROUP_0);
long val = applyIncrements(client1, 1, 10);
assertEquals(sum(10), val);
try {
client1.snapshot(peer).get();
fail();
} catch (Exception e) {
assertTrue(e.getCause() instanceof RaftException);
}
}
use of org.apache.ignite.raft.jraft.rpc.impl.RaftException in project ignite-3 by apache.
the class ItJraftCounterServerTest method testApplyWithFailure.
/**
* Tests if a raft group become unavailable in case of a critical error.
*/
@Test
public void testApplyWithFailure() throws Exception {
listenerFactory = () -> new CounterListener() {
@Override
public void onWrite(Iterator<CommandClosure<WriteCommand>> iterator) {
Iterator<CommandClosure<WriteCommand>> wrapper = new Iterator<>() {
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@Override
public CommandClosure<WriteCommand> next() {
CommandClosure<WriteCommand> cmd = iterator.next();
IncrementAndGetCommand command = (IncrementAndGetCommand) cmd.command();
if (command.delta() == 10) {
throw new IgniteInternalException("Very bad");
}
return cmd;
}
};
super.onWrite(wrapper);
}
};
startCluster();
RaftGroupService client1 = clients.get(0);
RaftGroupService client2 = clients.get(1);
client1.refreshLeader().get();
client2.refreshLeader().get();
NodeImpl leader = servers.stream().map(s -> ((NodeImpl) s.raftGroupService(COUNTER_GROUP_0).getRaftNode())).filter(n -> n.getState() == STATE_LEADER).findFirst().orElse(null);
assertNotNull(leader);
long val1 = applyIncrements(client1, 1, 5);
long val2 = applyIncrements(client2, 1, 7);
assertEquals(sum(5), val1);
assertEquals(sum(7), val2);
long val3 = applyIncrements(client1, 6, 9);
assertEquals(sum(9), val3);
try {
client1.<Long>run(new IncrementAndGetCommand(10)).get();
fail();
} catch (Exception e) {
// Expected.
Throwable cause = e.getCause();
assertTrue(cause instanceof RaftException);
}
NodeImpl finalLeader = leader;
waitForCondition(() -> finalLeader.getState() == STATE_ERROR, 5_000);
// Client can't switch to new leader, because only one peer in the list.
try {
client1.<Long>run(new IncrementAndGetCommand(11)).get();
} catch (Exception e) {
boolean isValid = e.getCause() instanceof TimeoutException;
if (!isValid) {
LOG.error("Got unexpected exception", e);
}
assertTrue(isValid, "Expecting the timeout");
}
}
use of org.apache.ignite.raft.jraft.rpc.impl.RaftException in project ignite-3 by apache.
the class RaftGroupServiceTest method testSnapshotExecutionFailedResponse.
/**
* @throws Exception If failed.
*/
@Test
public void testSnapshotExecutionFailedResponse() throws Exception {
String groupId = "test";
mockSnapshotRequest(0);
RaftGroupService service = RaftGroupServiceImpl.start(groupId, cluster, FACTORY, TIMEOUT, NODES, false, DELAY, executor).get(3, TimeUnit.SECONDS);
var addr = new NetworkAddress("localhost", 8082);
CompletableFuture<Void> fut = service.snapshot(new Peer(addr));
try {
fut.get();
fail();
} catch (ExecutionException e) {
assertTrue(e.getCause() instanceof RaftException);
}
}
Aggregations