use of org.apache.ratis.protocol.exceptions.ReconfigurationInProgressException in project incubator-ratis by apache.
the class RaftReconfigurationBaseTest method runTestOverlappedSetConfRequests.
void runTestOverlappedSetConfRequests(CLUSTER cluster) throws Exception {
try {
RaftTestUtil.waitForLeader(cluster);
final RaftPeerId leaderId = cluster.getLeader().getId();
RaftPeer[] newPeers = cluster.addNewPeers(2, true).allPeersInNewConf;
// delay every peer's logSync so that the setConf request is delayed
cluster.getPeers().forEach(peer -> logSyncDelay.setDelayMs(peer.getId().toString(), 1000));
final CountDownLatch latch = new CountDownLatch(1);
final RaftPeer[] peersInRequest2 = cluster.getPeers().toArray(new RaftPeer[0]);
AtomicBoolean caughtException = new AtomicBoolean(false);
new Thread(() -> {
try (final RaftClient client2 = cluster.createClient(leaderId)) {
latch.await();
LOG.info("client2 starts to change conf");
final RaftClientRpc sender2 = client2.getClientRpc();
sender2.sendRequest(cluster.newSetConfigurationRequest(client2.getId(), leaderId, peersInRequest2));
} catch (ReconfigurationInProgressException e) {
caughtException.set(true);
} catch (Exception e) {
LOG.warn("Got unexpected exception when client2 changes conf", e);
}
}).start();
AtomicBoolean confChanged = new AtomicBoolean(false);
new Thread(() -> {
try (final RaftClient client1 = cluster.createClient(leaderId)) {
LOG.info("client1 starts to change conf");
confChanged.set(client1.admin().setConfiguration(newPeers).isSuccess());
} catch (IOException e) {
LOG.warn("Got unexpected exception when client1 changes conf", e);
}
}).start();
Thread.sleep(100);
latch.countDown();
for (int i = 0; i < 10 && !confChanged.get(); i++) {
Thread.sleep(1000);
}
Assert.assertTrue(confChanged.get());
Assert.assertTrue(caughtException.get());
} finally {
logSyncDelay.clear();
}
}
Aggregations