Skip to content

Commit

Permalink
RATIS-2115. Fix flaky RetryCacheTests and InstallSnapshotFromLeaderTe…
Browse files Browse the repository at this point in the history
…sts.
  • Loading branch information
szetszwo committed Aug 2, 2024
1 parent a793e6c commit 6108df1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import org.apache.ratis.protocol.RaftGroupId;
import org.apache.ratis.protocol.RaftPeer;
import org.apache.ratis.protocol.RaftPeerId;
import org.apache.ratis.protocol.exceptions.RaftException;
import org.apache.ratis.protocol.exceptions.RaftRetryFailureException;
import org.apache.ratis.protocol.exceptions.ReconfigurationTimeoutException;
import org.apache.ratis.retry.RetryPolicies;
import org.apache.ratis.server.RaftServer;
import org.apache.ratis.server.RaftServerConfigKeys;
Expand Down Expand Up @@ -162,13 +164,16 @@ private void testInstallSnapshotDuringLeaderSwitch(CLUSTER cluster) throws Excep
final MiniRaftCluster.PeerChanges change = cluster.addNewPeers(2, true,
true);
try (final RaftClient client = cluster.createClient(leaderId, RetryPolicies.noRetry())) {
Assertions.assertThrows(RaftRetryFailureException.class,
final RaftException e = Assertions.assertThrows(RaftException.class,
() -> client.admin().setConfiguration(change.allPeersInNewConf));
Assertions.assertTrue( e instanceof RaftRetryFailureException
|| e instanceof ReconfigurationTimeoutException,
() -> "Unexpected exception: " + e);
}

final SnapshotInfo snapshotInfo = cluster.getDivision(change.newPeers[0].getId())
.getStateMachine().getLatestSnapshot();
Assertions.assertNotNull(snapshotInfo);
Assertions.assertNull(snapshotInfo);

// recover the old followers and isolate the leader to force leader switch
RaftTestUtil.isolate(cluster, leaderId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.slf4j.event.Level;

import java.util.Arrays;
import java.util.Collections;
import java.util.concurrent.TimeUnit;

import static java.util.Arrays.asList;
Expand Down Expand Up @@ -137,9 +138,8 @@ void runTestRetryOnNewLeader(CLUSTER cluster) throws Exception {
final long oldLastApplied = cluster.getLeader().getInfo().getLastAppliedIndex();

// trigger the reconfiguration, make sure the original leader is kicked out
PeerChanges change = cluster.addNewPeers(2, true);
RaftPeer[] allPeers = cluster.removePeers(2, true,
asList(change.newPeers)).allPeersInNewConf;
final PeerChanges change = cluster.removePeers(2, true, Collections.emptyList());
final RaftPeer[] allPeers = change.allPeersInNewConf;
// trigger setConfiguration
RaftServerTestUtil.runWithMinorityPeers(cluster, Arrays.asList(allPeers),
peers -> cluster.setConfiguration(peers.toArray(RaftPeer.emptyArray())));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
Expand All @@ -24,7 +24,7 @@
import java.util.Arrays;
import java.util.Collection;

public class TestLeaderInstallSnapshot
public class TestLeaderInstallSnapshotWithGrpc
extends InstallSnapshotFromLeaderTests<MiniRaftClusterWithGrpc>
implements MiniRaftClusterWithGrpc.FactoryGet {

Expand Down

0 comments on commit 6108df1

Please sign in to comment.