X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-akka-raft%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fraft%2FRaftActorServerConfigurationSupportTest.java;h=884b16c11e8aceed093dfa2f063e7c5499c9a854;hb=HEAD;hp=54ba69ec84025a05496f9b761dc8da407ded1e60;hpb=20733d0406fb31b701e32ee74ee13dc8769a256c;p=controller.git diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorServerConfigurationSupportTest.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorServerConfigurationSupportTest.java index 54ba69ec84..8edb5fb68d 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorServerConfigurationSupportTest.java +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorServerConfigurationSupportTest.java @@ -22,19 +22,14 @@ import akka.dispatch.Dispatchers; import akka.testkit.TestActorRef; import akka.testkit.javadsl.TestKit; import com.google.common.base.Stopwatch; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; import com.google.common.io.ByteSource; import com.google.common.util.concurrent.MoreExecutors; import java.io.OutputStream; import java.time.Duration; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.Set; import java.util.concurrent.TimeUnit; import org.apache.commons.lang3.SerializationUtils; import org.junit.After; @@ -156,7 +151,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { followerActorContext.setCurrentBehavior(follower); TestActorRef leaderActor = actorFactory.createTestActor( - MockLeaderRaftActor.props(ImmutableMap.of(FOLLOWER_ID, followerActor.path().toString()), + MockLeaderRaftActor.props(Map.of(FOLLOWER_ID, followerActor.path().toString()), followerActorContext).withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId(LEADER_ID)); @@ -177,7 +172,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { AddServerReply addServerReply = testKit.expectMsgClass(Duration.ofSeconds(5), AddServerReply.class); assertEquals("getStatus", ServerChangeStatus.OK, addServerReply.getStatus()); - assertEquals("getLeaderHint", LEADER_ID, addServerReply.getLeaderHint().get()); + assertEquals("getLeaderHint", LEADER_ID, addServerReply.getLeaderHint().orElseThrow()); // Verify ServerConfigurationPayload entry in leader's log @@ -203,10 +198,9 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { // Verify new server config was applied in both followers - assertEquals("Follower peers", Sets.newHashSet(LEADER_ID, NEW_SERVER_ID), followerActorContext.getPeerIds()); + assertEquals("Follower peers", Set.of(LEADER_ID, NEW_SERVER_ID), followerActorContext.getPeerIds()); - assertEquals("New follower peers", Sets.newHashSet(LEADER_ID, FOLLOWER_ID), - newFollowerActorContext.getPeerIds()); + assertEquals("New follower peers", Set.of(LEADER_ID, FOLLOWER_ID), newFollowerActorContext.getPeerIds()); assertEquals("Follower commit index", 3, followerActorContext.getCommitIndex()); assertEquals("Follower last applied index", 3, followerActorContext.getLastApplied()); @@ -238,8 +232,8 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { 0, 2, 1).build()); TestActorRef leaderActor = actorFactory.createTestActor( - MockLeaderRaftActor.props(ImmutableMap.of(), - initialActorContext).withDispatcher(Dispatchers.DefaultDispatcherId()), + MockLeaderRaftActor.props(Map.of(), initialActorContext) + .withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId(LEADER_ID)); MockLeaderRaftActor leaderRaftActor = leaderActor.underlyingActor(); @@ -257,7 +251,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { AddServerReply addServerReply = testKit.expectMsgClass(Duration.ofSeconds(5), AddServerReply.class); assertEquals("getStatus", ServerChangeStatus.OK, addServerReply.getStatus()); - assertEquals("getLeaderHint", LEADER_ID, addServerReply.getLeaderHint().get()); + assertEquals("getLeaderHint", LEADER_ID, addServerReply.getLeaderHint().orElseThrow()); // Verify ServerConfigurationPayload entry in leader's log @@ -277,7 +271,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { // Verify new server config was applied in the new follower - assertEquals("New follower peers", Sets.newHashSet(LEADER_ID), newFollowerActorContext.getPeerIds()); + assertEquals("New follower peers", Set.of(LEADER_ID), newFollowerActorContext.getPeerIds()); LOG.info("testAddServerWithNoExistingFollower ending"); } @@ -290,8 +284,8 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { RaftActorContext initialActorContext = new MockRaftActorContext(); TestActorRef leaderActor = actorFactory.createTestActor( - MockLeaderRaftActor.props(ImmutableMap.of(), - initialActorContext).withDispatcher(Dispatchers.DefaultDispatcherId()), + MockLeaderRaftActor.props(Map.of(), initialActorContext) + .withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId(LEADER_ID)); MockLeaderRaftActor leaderRaftActor = leaderActor.underlyingActor(); @@ -303,7 +297,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { AddServerReply addServerReply = testKit.expectMsgClass(Duration.ofSeconds(5), AddServerReply.class); assertEquals("getStatus", ServerChangeStatus.OK, addServerReply.getStatus()); - assertEquals("getLeaderHint", LEADER_ID, addServerReply.getLeaderHint().get()); + assertEquals("getLeaderHint", LEADER_ID, addServerReply.getLeaderHint().orElseThrow()); // Verify ServerConfigurationPayload entry in leader's log @@ -324,7 +318,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { // Verify new server config was applied in the new follower - assertEquals("New follower peers", Sets.newHashSet(LEADER_ID), newFollowerActorContext.getPeerIds()); + assertEquals("New follower peers", Set.of(LEADER_ID), newFollowerActorContext.getPeerIds()); assertNoneMatching(newFollowerCollectorActor, InstallSnapshot.class, 500); @@ -360,8 +354,8 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { RaftActorContext initialActorContext = new MockRaftActorContext(); TestActorRef leaderActor = actorFactory.createTestActor( - MockLeaderRaftActor.props(ImmutableMap.of(), - initialActorContext).withDispatcher(Dispatchers.DefaultDispatcherId()), + MockLeaderRaftActor.props(Map.of(), initialActorContext) + .withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId(LEADER_ID)); MockLeaderRaftActor leaderRaftActor = leaderActor.underlyingActor(); @@ -409,8 +403,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { // Verify ServerConfigurationPayload entry in the new follower expectMatching(newFollowerCollectorActor, ApplyState.class, 2); - assertEquals("New follower peers", Sets.newHashSet(LEADER_ID, NEW_SERVER_ID2), - newFollowerActorContext.getPeerIds()); + assertEquals("New follower peers", Set.of(LEADER_ID, NEW_SERVER_ID2), newFollowerActorContext.getPeerIds()); LOG.info("testAddServerWithOperationInProgress ending"); } @@ -423,8 +416,8 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { RaftActorContext initialActorContext = new MockRaftActorContext(); TestActorRef leaderActor = actorFactory.createTestActor( - MockLeaderRaftActor.props(ImmutableMap.of(), - initialActorContext).withDispatcher(Dispatchers.DefaultDispatcherId()), + MockLeaderRaftActor.props(Map.of(), initialActorContext) + .withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId(LEADER_ID)); MockLeaderRaftActor leaderRaftActor = leaderActor.underlyingActor(); @@ -446,7 +439,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { AddServerReply addServerReply = testKit.expectMsgClass(Duration.ofSeconds(5), AddServerReply.class); assertEquals("getStatus", ServerChangeStatus.OK, addServerReply.getStatus()); - assertEquals("getLeaderHint", LEADER_ID, addServerReply.getLeaderHint().get()); + assertEquals("getLeaderHint", LEADER_ID, addServerReply.getLeaderHint().orElseThrow()); expectFirstMatching(newFollowerCollectorActor, ApplySnapshot.class); @@ -470,8 +463,8 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { RaftActorContext initialActorContext = new MockRaftActorContext(); TestActorRef leaderActor = actorFactory.createTestActor( - MockLeaderRaftActor.props(ImmutableMap.of(), - initialActorContext).withDispatcher(Dispatchers.DefaultDispatcherId()), + MockLeaderRaftActor.props(Map.of(), initialActorContext) + .withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId(LEADER_ID)); MockLeaderRaftActor leaderRaftActor = leaderActor.underlyingActor(); @@ -502,8 +495,8 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { RaftActorContext initialActorContext = new MockRaftActorContext(); TestActorRef leaderActor = actorFactory.createTestActor( - MockLeaderRaftActor.props(ImmutableMap.of(), - initialActorContext).withDispatcher(Dispatchers.DefaultDispatcherId()), + MockLeaderRaftActor.props(Map.of(), initialActorContext) + .withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId(LEADER_ID)); MockLeaderRaftActor leaderRaftActor = leaderActor.underlyingActor(); @@ -551,8 +544,8 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { RaftActorContext initialActorContext = new MockRaftActorContext(); TestActorRef leaderActor = actorFactory.createTestActor( - MockLeaderRaftActor.props(ImmutableMap.of(), - initialActorContext).withDispatcher(Dispatchers.DefaultDispatcherId()), + MockLeaderRaftActor.props(Map.of(), initialActorContext) + .withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId(LEADER_ID)); MockLeaderRaftActor leaderRaftActor = leaderActor.underlyingActor(); @@ -596,8 +589,8 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { RaftActorContext initialActorContext = new MockRaftActorContext(); TestActorRef leaderActor = actorFactory.createTestActor( - MockLeaderRaftActor.props(ImmutableMap.of(), - initialActorContext).withDispatcher(Dispatchers.DefaultDispatcherId()), + MockLeaderRaftActor.props(Map.of(), initialActorContext) + .withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId(LEADER_ID)); MockLeaderRaftActor leaderRaftActor = leaderActor.underlyingActor(); @@ -630,7 +623,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { configParams.setHeartBeatInterval(new FiniteDuration(1, TimeUnit.DAYS)); TestActorRef noLeaderActor = actorFactory.createTestActor( - MockRaftActor.builder().id(LEADER_ID).peerAddresses(ImmutableMap.of(FOLLOWER_ID, + MockRaftActor.builder().id(LEADER_ID).peerAddresses(Map.of(FOLLOWER_ID, followerActor.path().toString())).config(configParams).persistent(Optional.of(false)) .props().withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId(LEADER_ID)); @@ -652,8 +645,8 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { RaftActorContext initialActorContext = new MockRaftActorContext(); TestActorRef leaderActor = actorFactory.createTestActor( - MockLeaderRaftActor.props(ImmutableMap.of(), - initialActorContext).withDispatcher(Dispatchers.DefaultDispatcherId()), + MockLeaderRaftActor.props(Map.of(), initialActorContext) + .withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId(LEADER_ID)); MockLeaderRaftActor leaderRaftActor = leaderActor.underlyingActor(); @@ -687,7 +680,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { // The first AddServer should succeed with OK even though consensus wasn't reached AddServerReply addServerReply = testKit.expectMsgClass(Duration.ofSeconds(5), AddServerReply.class); assertEquals("getStatus", ServerChangeStatus.OK, addServerReply.getStatus()); - assertEquals("getLeaderHint", LEADER_ID, addServerReply.getLeaderHint().get()); + assertEquals("getLeaderHint", LEADER_ID, addServerReply.getLeaderHint().orElseThrow()); // Verify ServerConfigurationPayload entry in leader's log verifyServerConfigurationPayloadEntry(leaderActorContext.getReplicatedLog(), votingServer(LEADER_ID), @@ -712,7 +705,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { RaftActorContext initialActorContext = new MockRaftActorContext(); TestActorRef leaderActor = actorFactory.createTestActor( - MockLeaderRaftActor.props(ImmutableMap.of(FOLLOWER_ID, followerActor.path().toString()), + MockLeaderRaftActor.props(Map.of(FOLLOWER_ID, followerActor.path().toString()), initialActorContext).withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId(LEADER_ID)); @@ -736,14 +729,13 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { MessageCollectorActor.props(), actorFactory.generateActorId(LEADER_ID)); TestActorRef followerRaftActor = actorFactory.createTestActor( - MockRaftActor.builder().id(FOLLOWER_ID).peerAddresses(ImmutableMap.of(LEADER_ID, + MockRaftActor.builder().id(FOLLOWER_ID).peerAddresses(Map.of(LEADER_ID, leaderActor.path().toString())).config(configParams).persistent(Optional.of(false)) .props().withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId(FOLLOWER_ID)); followerRaftActor.underlyingActor().waitForInitializeBehaviorComplete(); - followerRaftActor.tell(new AppendEntries(1, LEADER_ID, 0, 1, Collections.emptyList(), - -1, -1, (short)0), leaderActor); + followerRaftActor.tell(new AppendEntries(1, LEADER_ID, 0, 1, List.of(), -1, -1, (short)0), leaderActor); followerRaftActor.tell(new AddServer(NEW_SERVER_ID, newFollowerRaftActor.path().toString(), true), testKit.getRef()); @@ -759,7 +751,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { DefaultConfigParamsImpl configParams = new DefaultConfigParamsImpl(); configParams.setHeartBeatInterval(new FiniteDuration(1, TimeUnit.DAYS)); TestActorRef noLeaderActor = actorFactory.createTestActor( - MockRaftActor.builder().id(LEADER_ID).peerAddresses(ImmutableMap.of(FOLLOWER_ID, + MockRaftActor.builder().id(LEADER_ID).peerAddresses(Map.of(FOLLOWER_ID, followerActor.path().toString())).config(configParams).persistent(Optional.of(false)) .props().withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId(LEADER_ID)); @@ -768,7 +760,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { noLeaderActor.underlyingActor()); ReplicatedLogEntry serverConfigEntry = new SimpleReplicatedLogEntry(1, 1, - new ServerConfigurationPayload(Collections.emptyList())); + new ServerConfigurationPayload(List.of())); boolean handled = support.handleMessage(new ApplyState(null, null, serverConfigEntry), ActorRef.noSender()); assertEquals("Message handled", true, handled); @@ -788,7 +780,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { configParams.setHeartBeatInterval(new FiniteDuration(1, TimeUnit.DAYS)); TestActorRef leaderActor = actorFactory.createTestActor( - MockRaftActor.builder().id(LEADER_ID).peerAddresses(ImmutableMap.of(FOLLOWER_ID, + MockRaftActor.builder().id(LEADER_ID).peerAddresses(Map.of(FOLLOWER_ID, followerActor.path().toString())).config(configParams).persistent(Optional.of(false)) .props().withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId(LEADER_ID)); @@ -808,7 +800,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { RaftActorContext initialActorContext = new MockRaftActorContext(); TestActorRef leaderActor = actorFactory.createTestActor( - MockLeaderRaftActor.props(ImmutableMap.of(FOLLOWER_ID, followerActor.path().toString()), + MockLeaderRaftActor.props(Map.of(FOLLOWER_ID, followerActor.path().toString()), initialActorContext).withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId(LEADER_ID)); @@ -830,14 +822,13 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { MessageCollectorActor.props(), actorFactory.generateActorId(LEADER_ID)); TestActorRef followerRaftActor = actorFactory.createTestActor( - MockRaftActor.builder().id(FOLLOWER_ID).peerAddresses(ImmutableMap.of(LEADER_ID, + MockRaftActor.builder().id(FOLLOWER_ID).peerAddresses(Map.of(LEADER_ID, leaderActor.path().toString())).config(configParams).persistent(Optional.of(false)) .props().withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId(FOLLOWER_ID)); followerRaftActor.underlyingActor().waitForInitializeBehaviorComplete(); - followerRaftActor.tell(new AppendEntries(1, LEADER_ID, 0, 1, Collections.emptyList(), - -1, -1, (short)0), leaderActor); + followerRaftActor.tell(new AppendEntries(1, LEADER_ID, 0, 1, List.of(), -1, -1, (short)0), leaderActor); followerRaftActor.tell(new RemoveServer(FOLLOWER_ID), testKit.getRef()); expectFirstMatching(leaderActor, RemoveServer.class); @@ -861,7 +852,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { final String downNodeId = "downNode"; TestActorRef leaderActor = actorFactory.createTestActor(MockLeaderRaftActor.props( - ImmutableMap.of(FOLLOWER_ID, follower1ActorPath, FOLLOWER_ID2, follower2ActorPath, downNodeId, ""), + Map.of(FOLLOWER_ID, follower1ActorPath, FOLLOWER_ID2, follower2ActorPath, downNodeId, ""), initialActorContext).withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId(LEADER_ID)); @@ -870,14 +861,14 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { ActorRef follower1Collector = actorFactory.createActor( MessageCollectorActor.props(), actorFactory.generateActorId("collector")); final TestActorRef follower1Actor = actorFactory.createTestActor( - CollectingMockRaftActor.props(FOLLOWER_ID, ImmutableMap.of(LEADER_ID, leaderActor.path().toString(), + CollectingMockRaftActor.props(FOLLOWER_ID, Map.of(LEADER_ID, leaderActor.path().toString(), FOLLOWER_ID2, follower2ActorPath, downNodeId, ""), configParams, NO_PERSISTENCE, follower1Collector).withDispatcher(Dispatchers.DefaultDispatcherId()), follower1ActorId); ActorRef follower2Collector = actorFactory.createActor( MessageCollectorActor.props(), actorFactory.generateActorId("collector")); final TestActorRef follower2Actor = actorFactory.createTestActor( - CollectingMockRaftActor.props(FOLLOWER_ID2, ImmutableMap.of(LEADER_ID, leaderActor.path().toString(), + CollectingMockRaftActor.props(FOLLOWER_ID2, Map.of(LEADER_ID, leaderActor.path().toString(), FOLLOWER_ID, follower1ActorPath, downNodeId, ""), configParams, NO_PERSISTENCE, follower2Collector).withDispatcher(Dispatchers.DefaultDispatcherId()), follower2ActorId); @@ -890,12 +881,12 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { assertEquals("getStatus", ServerChangeStatus.OK, removeServerReply.getStatus()); ApplyState applyState = MessageCollectorActor.expectFirstMatching(leaderCollector, ApplyState.class); - assertEquals(0L, applyState.getReplicatedLogEntry().getIndex()); + assertEquals(0L, applyState.getReplicatedLogEntry().index()); verifyServerConfigurationPayloadEntry(leaderActor.underlyingActor().getRaftActorContext().getReplicatedLog(), votingServer(LEADER_ID), votingServer(FOLLOWER_ID2), votingServer(downNodeId)); applyState = MessageCollectorActor.expectFirstMatching(follower2Collector, ApplyState.class); - assertEquals(0L, applyState.getReplicatedLogEntry().getIndex()); + assertEquals(0L, applyState.getReplicatedLogEntry().index()); verifyServerConfigurationPayloadEntry(leaderActor.underlyingActor().getRaftActorContext().getReplicatedLog(), votingServer(LEADER_ID), votingServer(FOLLOWER_ID2), votingServer(downNodeId)); @@ -921,7 +912,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { RaftActorContext initialActorContext = new MockRaftActorContext(); TestActorRef leaderActor = actorFactory.createTestActor( - MockLeaderRaftActor.props(ImmutableMap.of(FOLLOWER_ID, followerActorPath), + MockLeaderRaftActor.props(Map.of(FOLLOWER_ID, followerActorPath), initialActorContext).withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId(LEADER_ID)); @@ -930,7 +921,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { final ActorRef followerCollector = actorFactory.createActor(MessageCollectorActor.props(), actorFactory.generateActorId("collector")); actorFactory.createTestActor( - CollectingMockRaftActor.props(FOLLOWER_ID, ImmutableMap.of(LEADER_ID, leaderActor.path().toString()), + CollectingMockRaftActor.props(FOLLOWER_ID, Map.of(LEADER_ID, leaderActor.path().toString()), configParams, NO_PERSISTENCE, followerCollector) .withDispatcher(Dispatchers.DefaultDispatcherId()), followerActorId); @@ -940,7 +931,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { assertEquals("getStatus", ServerChangeStatus.OK, removeServerReply.getStatus()); final ApplyState applyState = MessageCollectorActor.expectFirstMatching(followerCollector, ApplyState.class); - assertEquals(0L, applyState.getReplicatedLogEntry().getIndex()); + assertEquals(0L, applyState.getReplicatedLogEntry().index()); verifyServerConfigurationPayloadEntry(leaderActor.underlyingActor().getRaftActorContext().getReplicatedLog(), votingServer(FOLLOWER_ID)); @@ -954,7 +945,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { LOG.info("testRemoveServerLeaderWithNoFollowers starting"); TestActorRef leaderActor = actorFactory.createTestActor( - MockLeaderRaftActor.props(Collections.emptyMap(), + MockLeaderRaftActor.props(Map.of(), new MockRaftActorContext()).withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId(LEADER_ID)); @@ -979,7 +970,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { final String follower2ActorPath = actorFactory.createTestActorPath(follower2ActorId); TestActorRef leaderActor = actorFactory.createTestActor( - MockLeaderRaftActor.props(ImmutableMap.of(FOLLOWER_ID, follower1ActorPath, + MockLeaderRaftActor.props(Map.of(FOLLOWER_ID, follower1ActorPath, FOLLOWER_ID2, follower2ActorPath), new MockRaftActorContext()) .withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId(LEADER_ID)); ActorRef leaderCollector = newLeaderCollectorActor(leaderActor.underlyingActor()); @@ -987,26 +978,26 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { ActorRef follower1Collector = actorFactory.createActor( MessageCollectorActor.props(), actorFactory.generateActorId("collector")); final TestActorRef follower1RaftActor = actorFactory.createTestActor( - CollectingMockRaftActor.props(FOLLOWER_ID, ImmutableMap.of(LEADER_ID, leaderActor.path().toString(), + CollectingMockRaftActor.props(FOLLOWER_ID, Map.of(LEADER_ID, leaderActor.path().toString(), FOLLOWER_ID2, follower2ActorPath), configParams, NO_PERSISTENCE, follower1Collector) .withDispatcher(Dispatchers.DefaultDispatcherId()), follower1ActorId); ActorRef follower2Collector = actorFactory.createActor( MessageCollectorActor.props(), actorFactory.generateActorId("collector")); final TestActorRef follower2RaftActor = actorFactory.createTestActor( - CollectingMockRaftActor.props(FOLLOWER_ID2, ImmutableMap.of(LEADER_ID, leaderActor.path().toString(), + CollectingMockRaftActor.props(FOLLOWER_ID2, Map.of(LEADER_ID, leaderActor.path().toString(), FOLLOWER_ID, follower1ActorPath), configParams, NO_PERSISTENCE, follower2Collector) .withDispatcher(Dispatchers.DefaultDispatcherId()), follower2ActorId); // Send first ChangeServersVotingStatus message - leaderActor.tell(new ChangeServersVotingStatus(ImmutableMap.of(FOLLOWER_ID, false, FOLLOWER_ID2, false)), + leaderActor.tell(new ChangeServersVotingStatus(Map.of(FOLLOWER_ID, false, FOLLOWER_ID2, false)), testKit.getRef()); ServerChangeReply reply = testKit.expectMsgClass(Duration.ofSeconds(5), ServerChangeReply.class); assertEquals("getStatus", ServerChangeStatus.OK, reply.getStatus()); final ApplyState applyState = MessageCollectorActor.expectFirstMatching(leaderCollector, ApplyState.class); - assertEquals(0L, applyState.getReplicatedLogEntry().getIndex()); + assertEquals(0L, applyState.getReplicatedLogEntry().index()); verifyServerConfigurationPayloadEntry(leaderActor.underlyingActor().getRaftActorContext().getReplicatedLog(), votingServer(LEADER_ID), nonVotingServer(FOLLOWER_ID), nonVotingServer(FOLLOWER_ID2)); @@ -1026,7 +1017,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { // Send second ChangeServersVotingStatus message - leaderActor.tell(new ChangeServersVotingStatus(ImmutableMap.of(FOLLOWER_ID, true)), testKit.getRef()); + leaderActor.tell(new ChangeServersVotingStatus(Map.of(FOLLOWER_ID, true)), testKit.getRef()); reply = testKit.expectMsgClass(Duration.ofSeconds(5), ServerChangeReply.class); assertEquals("getStatus", ServerChangeStatus.OK, reply.getStatus()); @@ -1058,7 +1049,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { final String follower2ActorPath = actorFactory.createTestActorPath(follower2ActorId); TestActorRef leaderActor = actorFactory.createTestActor( - MockLeaderRaftActor.props(ImmutableMap.of(FOLLOWER_ID, follower1ActorPath, + MockLeaderRaftActor.props(Map.of(FOLLOWER_ID, follower1ActorPath, FOLLOWER_ID2, follower2ActorPath), new MockRaftActorContext()) .withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId(LEADER_ID)); ActorRef leaderCollector = newLeaderCollectorActor(leaderActor.underlyingActor()); @@ -1066,20 +1057,20 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { ActorRef follower1Collector = actorFactory.createActor( MessageCollectorActor.props(), actorFactory.generateActorId("collector")); final TestActorRef follower1RaftActor = actorFactory.createTestActor( - CollectingMockRaftActor.props(FOLLOWER_ID, ImmutableMap.of(LEADER_ID, leaderActor.path().toString(), + CollectingMockRaftActor.props(FOLLOWER_ID, Map.of(LEADER_ID, leaderActor.path().toString(), FOLLOWER_ID2, follower2ActorPath), configParams, NO_PERSISTENCE, follower1Collector) .withDispatcher(Dispatchers.DefaultDispatcherId()), follower1ActorId); ActorRef follower2Collector = actorFactory.createActor( MessageCollectorActor.props(), actorFactory.generateActorId("collector")); final TestActorRef follower2RaftActor = actorFactory.createTestActor( - CollectingMockRaftActor.props(FOLLOWER_ID2, ImmutableMap.of(LEADER_ID, leaderActor.path().toString(), + CollectingMockRaftActor.props(FOLLOWER_ID2, Map.of(LEADER_ID, leaderActor.path().toString(), FOLLOWER_ID, follower1ActorPath), configParams, NO_PERSISTENCE, follower2Collector) .withDispatcher(Dispatchers.DefaultDispatcherId()), follower2ActorId); // Send ChangeServersVotingStatus message - leaderActor.tell(new ChangeServersVotingStatus(ImmutableMap.of(LEADER_ID, false)), testKit.getRef()); + leaderActor.tell(new ChangeServersVotingStatus(Map.of(LEADER_ID, false)), testKit.getRef()); ServerChangeReply reply = testKit.expectMsgClass(Duration.ofSeconds(5), ServerChangeReply.class); assertEquals("getStatus", ServerChangeStatus.OK, reply.getStatus()); @@ -1108,10 +1099,10 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { LOG.info("testChangeLeaderToNonVotingInSingleNode starting"); TestActorRef leaderActor = actorFactory.createTestActor( - MockLeaderRaftActor.props(ImmutableMap.of(), new MockRaftActorContext()) + MockLeaderRaftActor.props(Map.of(), new MockRaftActorContext()) .withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId(LEADER_ID)); - leaderActor.tell(new ChangeServersVotingStatus(ImmutableMap.of(LEADER_ID, false)), testKit.getRef()); + leaderActor.tell(new ChangeServersVotingStatus(Map.of(LEADER_ID, false)), testKit.getRef()); ServerChangeReply reply = testKit.expectMsgClass(Duration.ofSeconds(5), ServerChangeReply.class); assertEquals("getStatus", ServerChangeStatus.INVALID_REQUEST, reply.getStatus()); @@ -1133,7 +1124,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { // via the server config. The server config will also contain 2 voting peers that are down (ie no // actors created). - ServerConfigurationPayload persistedServerConfig = new ServerConfigurationPayload(Arrays.asList( + ServerConfigurationPayload persistedServerConfig = new ServerConfigurationPayload(List.of( new ServerInfo(node1ID, false), new ServerInfo(node2ID, false), new ServerInfo("downNode1", true), new ServerInfo("downNode2", true))); SimpleReplicatedLogEntry persistedServerConfigEntry = new SimpleReplicatedLogEntry(0, 1, persistedServerConfig); @@ -1148,14 +1139,14 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { ActorRef node1Collector = actorFactory.createActor( MessageCollectorActor.props(), actorFactory.generateActorId("collector")); TestActorRef node1RaftActorRef = actorFactory.createTestActor( - CollectingMockRaftActor.props(node1ID, ImmutableMap.of(), configParams, + CollectingMockRaftActor.props(node1ID, Map.of(), configParams, PERSISTENT, node1Collector).withDispatcher(Dispatchers.DefaultDispatcherId()), node1ID); CollectingMockRaftActor node1RaftActor = node1RaftActorRef.underlyingActor(); ActorRef node2Collector = actorFactory.createActor( MessageCollectorActor.props(), actorFactory.generateActorId("collector")); TestActorRef node2RaftActorRef = actorFactory.createTestActor( - CollectingMockRaftActor.props(node2ID, ImmutableMap.of(), configParams, + CollectingMockRaftActor.props(node2ID, Map.of(), configParams, PERSISTENT, node2Collector).withDispatcher(Dispatchers.DefaultDispatcherId()), node2ID); CollectingMockRaftActor node2RaftActor = node2RaftActorRef.underlyingActor(); @@ -1182,7 +1173,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { // First send the message such that node1 has no peer address for node2 - should fail. - ChangeServersVotingStatus changeServers = new ChangeServersVotingStatus(ImmutableMap.of(node1ID, true, + ChangeServersVotingStatus changeServers = new ChangeServersVotingStatus(Map.of(node1ID, true, node2ID, true, "downNode1", false, "downNode2", false)); node1RaftActorRef.tell(changeServers, testKit.getRef()); ServerChangeReply reply = testKit.expectMsgClass(Duration.ofSeconds(5), ServerChangeReply.class); @@ -1193,7 +1184,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { long term = node1RaftActor.getRaftActorContext().getTermInformation().getCurrentTerm(); node1RaftActorRef.tell(new AppendEntries(term, "downNode1", -1L, -1L, - Collections.emptyList(), 0, -1, (short)1), ActorRef.noSender()); + List.of(), 0, -1, (short)1), ActorRef.noSender()); // Wait for the ElectionTimeout to clear the leaderId. The leaderId must be null so on the next // ChangeServersVotingStatus message, it will try to elect a leader. @@ -1240,7 +1231,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { ? actorFactory.createTestActorPath(node1ID) : peerId.equals(node2ID) ? actorFactory.createTestActorPath(node2ID) : null; - ServerConfigurationPayload persistedServerConfig = new ServerConfigurationPayload(Arrays.asList( + ServerConfigurationPayload persistedServerConfig = new ServerConfigurationPayload(List.of( new ServerInfo(node1ID, false), new ServerInfo(node2ID, true))); SimpleReplicatedLogEntry persistedServerConfigEntry = new SimpleReplicatedLogEntry(0, 1, persistedServerConfig); @@ -1256,7 +1247,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { ActorRef node1Collector = actorFactory.createActor( MessageCollectorActor.props(), actorFactory.generateActorId("collector")); TestActorRef node1RaftActorRef = actorFactory.createTestActor( - CollectingMockRaftActor.props(node1ID, ImmutableMap.of(), configParams1, + CollectingMockRaftActor.props(node1ID, Map.of(), configParams1, PERSISTENT, node1Collector).withDispatcher(Dispatchers.DefaultDispatcherId()), node1ID); final CollectingMockRaftActor node1RaftActor = node1RaftActorRef.underlyingActor(); @@ -1266,7 +1257,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { ActorRef node2Collector = actorFactory.createActor( MessageCollectorActor.props(), actorFactory.generateActorId("collector")); TestActorRef node2RaftActorRef = actorFactory.createTestActor( - CollectingMockRaftActor.props(node2ID, ImmutableMap.of(), configParams2, + CollectingMockRaftActor.props(node2ID, Map.of(), configParams2, PERSISTENT, node2Collector).withDispatcher(Dispatchers.DefaultDispatcherId()), node2ID); CollectingMockRaftActor node2RaftActor = node2RaftActorRef.underlyingActor(); @@ -1278,13 +1269,13 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { node2RaftActor.setDropMessageOfType(RequestVote.class); - ChangeServersVotingStatus changeServers = new ChangeServersVotingStatus(ImmutableMap.of(node1ID, true)); + ChangeServersVotingStatus changeServers = new ChangeServersVotingStatus(Map.of(node1ID, true)); node1RaftActorRef.tell(changeServers, testKit.getRef()); ServerChangeReply reply = testKit.expectMsgClass(Duration.ofSeconds(5), ServerChangeReply.class); assertEquals("getStatus", ServerChangeStatus.NO_LEADER, reply.getStatus()); - assertEquals("Server config", Sets.newHashSet(nonVotingServer(node1ID), votingServer(node2ID)), - Sets.newHashSet(node1RaftActor.getRaftActorContext().getPeerServerInfo(true).getServerConfig())); + assertEquals("Server config", Set.of(nonVotingServer(node1ID), votingServer(node2ID)), + Set.copyOf(node1RaftActor.getRaftActorContext().getPeerServerInfo(true).getServerConfig())); assertEquals("getRaftState", RaftState.Follower, node1RaftActor.getRaftState()); LOG.info("testChangeToVotingWithNoLeaderAndElectionTimeout ending"); @@ -1306,7 +1297,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { configParams.setElectionTimeoutFactor(3); configParams.setPeerAddressResolver(peerAddressResolver); - ServerConfigurationPayload persistedServerConfig = new ServerConfigurationPayload(Arrays.asList( + ServerConfigurationPayload persistedServerConfig = new ServerConfigurationPayload(List.of( new ServerInfo(node1ID, false), new ServerInfo(node2ID, false))); SimpleReplicatedLogEntry persistedServerConfigEntry = new SimpleReplicatedLogEntry(0, 1, persistedServerConfig); @@ -1321,14 +1312,14 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { ActorRef node1Collector = actorFactory.createActor( MessageCollectorActor.props(), actorFactory.generateActorId("collector")); TestActorRef node1RaftActorRef = actorFactory.createTestActor( - CollectingMockRaftActor.props(node1ID, ImmutableMap.of(), configParams, + CollectingMockRaftActor.props(node1ID, Map.of(), configParams, PERSISTENT, node1Collector).withDispatcher(Dispatchers.DefaultDispatcherId()), node1ID); final CollectingMockRaftActor node1RaftActor = node1RaftActorRef.underlyingActor(); ActorRef node2Collector = actorFactory.createActor( MessageCollectorActor.props(), actorFactory.generateActorId("collector")); TestActorRef node2RaftActorRef = actorFactory.createTestActor( - CollectingMockRaftActor.props(node2ID, ImmutableMap.of(), configParams, + CollectingMockRaftActor.props(node2ID, Map.of(), configParams, PERSISTENT, node2Collector).withDispatcher(Dispatchers.DefaultDispatcherId()), node2ID); final CollectingMockRaftActor node2RaftActor = node2RaftActorRef.underlyingActor(); @@ -1338,7 +1329,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { // forward the request to node2. ChangeServersVotingStatus changeServers = new ChangeServersVotingStatus( - ImmutableMap.of(node1ID, true, node2ID, true)); + Map.of(node1ID, true, node2ID, true)); node1RaftActorRef.tell(changeServers, testKit.getRef()); ServerChangeReply reply = testKit.expectMsgClass(Duration.ofSeconds(5), ServerChangeReply.class); assertEquals("getStatus", ServerChangeStatus.OK, reply.getStatus()); @@ -1372,7 +1363,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { ? actorFactory.createTestActorPath(node1ID) : peerId.equals(node2ID) ? actorFactory.createTestActorPath(node2ID) : null); - ServerConfigurationPayload persistedServerConfig = new ServerConfigurationPayload(Arrays.asList( + ServerConfigurationPayload persistedServerConfig = new ServerConfigurationPayload(List.of( new ServerInfo(node1ID, false), new ServerInfo(node2ID, true))); SimpleReplicatedLogEntry persistedServerConfigEntry = new SimpleReplicatedLogEntry(0, 1, persistedServerConfig); @@ -1384,14 +1375,14 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { ActorRef node1Collector = actorFactory.createActor( MessageCollectorActor.props(), actorFactory.generateActorId("collector")); TestActorRef node1RaftActorRef = actorFactory.createTestActor( - CollectingMockRaftActor.props(node1ID, ImmutableMap.of(), configParams, + CollectingMockRaftActor.props(node1ID, Map.of(), configParams, PERSISTENT, node1Collector).withDispatcher(Dispatchers.DefaultDispatcherId()), node1ID); final CollectingMockRaftActor node1RaftActor = node1RaftActorRef.underlyingActor(); ActorRef node2Collector = actorFactory.createActor( MessageCollectorActor.props(), actorFactory.generateActorId("collector")); TestActorRef node2RaftActorRef = actorFactory.createTestActor( - CollectingMockRaftActor.props(node2ID, ImmutableMap.of(), configParams, + CollectingMockRaftActor.props(node2ID, Map.of(), configParams, PERSISTENT, node2Collector).withDispatcher(Dispatchers.DefaultDispatcherId()), node2ID); CollectingMockRaftActor node2RaftActor = node2RaftActorRef.underlyingActor(); @@ -1402,7 +1393,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { node2RaftActor.setDropMessageOfType(RequestVote.class); - ChangeServersVotingStatus changeServers = new ChangeServersVotingStatus(ImmutableMap.of(node1ID, true, + ChangeServersVotingStatus changeServers = new ChangeServersVotingStatus(Map.of(node1ID, true, node2ID, true)); node1RaftActorRef.tell(changeServers, testKit.getRef()); @@ -1463,7 +1454,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { ReplicatedLogEntry logEntry = log.get(log.lastIndex()); assertEquals("Last log entry payload class", ServerConfigurationPayload.class, logEntry.getData().getClass()); ServerConfigurationPayload payload = (ServerConfigurationPayload)logEntry.getData(); - assertEquals("Server config", Sets.newHashSet(expected), Sets.newHashSet(payload.getServerConfig())); + assertEquals("Server config", Set.of(expected), Set.copyOf(payload.getServerConfig())); } private static RaftActorContextImpl newFollowerContext(final String id, @@ -1475,7 +1466,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { ElectionTermImpl termInfo = new ElectionTermImpl(noPersistence, id, LOG); termInfo.update(1, LEADER_ID); return new RaftActorContextImpl(actor, actor.underlyingActor().getContext(), - id, termInfo, -1, -1, ImmutableMap.of(LEADER_ID, ""), configParams, + id, termInfo, -1, -1, Map.of(LEADER_ID, ""), configParams, noPersistence, applyState -> actor.tell(applyState, actor), LOG, MoreExecutors.directExecutor()); } @@ -1485,7 +1476,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { AbstractMockRaftActor(final String id, final Map peerAddresses, final Optional config, final boolean persistent, final ActorRef collectorActor) { - super(builder().id(id).peerAddresses(peerAddresses).config(config.get()) + super(builder().id(id).peerAddresses(peerAddresses).config(config.orElseThrow()) .persistent(Optional.of(persistent))); this.collectorActor = collectorActor; } @@ -1572,9 +1563,9 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { @Override @SuppressWarnings("checkstyle:IllegalCatch") public void createSnapshot(final ActorRef actorRef, final Optional installSnapshotStream) { - MockSnapshotState snapshotState = new MockSnapshotState(new ArrayList<>(getState())); + MockSnapshotState snapshotState = new MockSnapshotState(List.copyOf(getState())); if (installSnapshotStream.isPresent()) { - SerializationUtils.serialize(snapshotState, installSnapshotStream.get()); + SerializationUtils.serialize(snapshotState, installSnapshotStream.orElseThrow()); } actorRef.tell(new CaptureSnapshotReply(snapshotState, installSnapshotStream), actorRef); @@ -1590,8 +1581,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { public static class MockNewFollowerRaftActor extends AbstractMockRaftActor { public MockNewFollowerRaftActor(final ConfigParams config, final ActorRef collectorActor) { - super(NEW_SERVER_ID, Maps.newHashMap(), Optional.of(config), NO_PERSISTENCE, - collectorActor); + super(NEW_SERVER_ID, Map.of(), Optional.of(config), NO_PERSISTENCE, collectorActor); setPersistence(false); }