Search in sources :

Example 1 with ReconfigurationInProgressException

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();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RaftPeerId(org.apache.ratis.protocol.RaftPeerId) IOException(java.io.IOException) RaftPeer(org.apache.ratis.protocol.RaftPeer) CountDownLatch(java.util.concurrent.CountDownLatch) ReconfigurationInProgressException(org.apache.ratis.protocol.exceptions.ReconfigurationInProgressException) RaftClient(org.apache.ratis.client.RaftClient) LeaderNotReadyException(org.apache.ratis.protocol.exceptions.LeaderNotReadyException) TimeoutException(java.util.concurrent.TimeoutException) ReconfigurationInProgressException(org.apache.ratis.protocol.exceptions.ReconfigurationInProgressException) ReconfigurationTimeoutException(org.apache.ratis.protocol.exceptions.ReconfigurationTimeoutException) IOException(java.io.IOException) RaftClientRpc(org.apache.ratis.client.RaftClientRpc)

Aggregations

IOException (java.io.IOException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 TimeoutException (java.util.concurrent.TimeoutException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 RaftClient (org.apache.ratis.client.RaftClient)1 RaftClientRpc (org.apache.ratis.client.RaftClientRpc)1 RaftPeer (org.apache.ratis.protocol.RaftPeer)1 RaftPeerId (org.apache.ratis.protocol.RaftPeerId)1 LeaderNotReadyException (org.apache.ratis.protocol.exceptions.LeaderNotReadyException)1 ReconfigurationInProgressException (org.apache.ratis.protocol.exceptions.ReconfigurationInProgressException)1 ReconfigurationTimeoutException (org.apache.ratis.protocol.exceptions.ReconfigurationTimeoutException)1