2 * Copyright (c) 2017 Inocybe Technologies and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.cluster.raft;
10 import static org.opendaylight.controller.cluster.raft.utils.MessageCollectorActor.expectMatching;
12 import com.google.common.collect.ImmutableMap;
13 import java.util.List;
14 import org.junit.Test;
15 import org.opendaylight.controller.cluster.raft.MockRaftActorContext.MockPayload;
16 import org.opendaylight.controller.cluster.raft.base.messages.ApplyState;
19 * Tests end-to-end replication of sliced log entry payloads, ie entries whose size exceeds the maximum size for a
20 * single AppendEntries message.
22 * @author Thomas Pantelis
24 public class ReplicationWithSlicedPayloadIntegrationTest extends AbstractRaftActorIntegrationTest {
27 public void runTest() {
28 testLog.info("ReplicationWithSlicedPayloadIntegrationTest starting");
30 // Create the leader and 2 follower actors.
32 snapshotChunkSize = 20;
34 DefaultConfigParamsImpl followerConfigParams = newFollowerConfigParams();
35 followerConfigParams.setSnapshotBatchCount(snapshotBatchCount);
36 follower1Actor = newTestRaftActor(follower1Id, ImmutableMap.of(leaderId, testActorPath(leaderId),
37 follower2Id, testActorPath(follower2Id)), followerConfigParams);
39 follower2Actor = newTestRaftActor(follower2Id, ImmutableMap.of(leaderId, testActorPath(leaderId),
40 follower1Id, testActorPath(follower1Id)), followerConfigParams);
42 peerAddresses = ImmutableMap.<String, String>builder()
43 .put(follower1Id, follower1Actor.path().toString())
44 .put(follower2Id, follower2Actor.path().toString()).build();
46 leaderConfigParams = newLeaderConfigParams();
47 leaderActor = newTestRaftActor(leaderId, peerAddresses, leaderConfigParams);
49 follower1CollectorActor = follower1Actor.underlyingActor().collectorActor();
50 follower2CollectorActor = follower2Actor.underlyingActor().collectorActor();
51 leaderCollectorActor = leaderActor.underlyingActor().collectorActor();
53 leaderContext = leaderActor.underlyingActor().getRaftActorContext();
55 waitUntilLeader(leaderActor);
57 currentTerm = leaderContext.getTermInformation().getCurrentTerm();
59 // Send a large payload that exceeds the size threshold and needs to be sliced.
61 MockPayload largePayload = sendPayloadData(leaderActor, "large", snapshotChunkSize + 1);
63 // Then send a small payload that does not need to be sliced.
65 MockPayload smallPayload = sendPayloadData(leaderActor, "normal", snapshotChunkSize - 1);
67 final List<ApplyState> leaderApplyState = expectMatching(leaderCollectorActor, ApplyState.class, 2);
68 verifyApplyState(leaderApplyState.get(0), leaderCollectorActor,
69 largePayload.toString(), currentTerm, 0, largePayload);
70 verifyApplyState(leaderApplyState.get(1), leaderCollectorActor,
71 smallPayload.toString(), currentTerm, 1, smallPayload);
73 final List<ApplyState> follower1ApplyState = expectMatching(follower1CollectorActor, ApplyState.class, 2);
74 verifyApplyState(follower1ApplyState.get(0), null, null, currentTerm, 0, largePayload);
75 verifyApplyState(follower1ApplyState.get(1), null, null, currentTerm, 1, smallPayload);
77 final List<ApplyState> follower2ApplyState = expectMatching(follower2CollectorActor, ApplyState.class, 2);
78 verifyApplyState(follower2ApplyState.get(0), null, null, currentTerm, 0, largePayload);
79 verifyApplyState(follower2ApplyState.get(1), null, null, currentTerm, 1, smallPayload);
81 testLog.info("ReplicationWithSlicedPayloadIntegrationTest ending");