Remove explicit default super-constructor calls
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / test / java / org / opendaylight / controller / cluster / raft / ReplicationWithSlicedPayloadIntegrationTest.java
1 /*
2  * Copyright (c) 2017 Inocybe Technologies and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.cluster.raft;
9
10 import static org.opendaylight.controller.cluster.raft.utils.MessageCollectorActor.expectMatching;
11
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;
17
18 /**
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.
21  *
22  * @author Thomas Pantelis
23  */
24 public class ReplicationWithSlicedPayloadIntegrationTest extends AbstractRaftActorIntegrationTest {
25
26     @Test
27     public void runTest() throws Exception {
28         testLog.info("ReplicationWithSlicedPayloadIntegrationTest starting");
29
30         // Create the leader and 2 follower actors.
31
32         snapshotChunkSize = 20;
33
34         DefaultConfigParamsImpl followerConfigParams = newFollowerConfigParams();
35         followerConfigParams.setSnapshotBatchCount(snapshotBatchCount);
36         follower1Actor = newTestRaftActor(follower1Id, ImmutableMap.of(leaderId, testActorPath(leaderId),
37                 follower2Id, testActorPath(follower2Id)), followerConfigParams);
38
39         follower2Actor = newTestRaftActor(follower2Id, ImmutableMap.of(leaderId, testActorPath(leaderId),
40                 follower1Id, testActorPath(follower1Id)), followerConfigParams);
41
42         peerAddresses = ImmutableMap.<String, String>builder()
43                 .put(follower1Id, follower1Actor.path().toString())
44                 .put(follower2Id, follower2Actor.path().toString()).build();
45
46         leaderConfigParams = newLeaderConfigParams();
47         leaderActor = newTestRaftActor(leaderId, peerAddresses, leaderConfigParams);
48
49         follower1CollectorActor = follower1Actor.underlyingActor().collectorActor();
50         follower2CollectorActor = follower2Actor.underlyingActor().collectorActor();
51         leaderCollectorActor = leaderActor.underlyingActor().collectorActor();
52
53         leaderContext = leaderActor.underlyingActor().getRaftActorContext();
54
55         waitUntilLeader(leaderActor);
56
57         currentTerm = leaderContext.getTermInformation().getCurrentTerm();
58
59         // Send a large payload that exceeds the size threshold and needs to be sliced.
60
61         MockPayload largePayload = sendPayloadData(leaderActor, "large", snapshotChunkSize + 1);
62
63         // Then send a small payload that does not need to be sliced.
64
65         MockPayload smallPayload = sendPayloadData(leaderActor, "normal", snapshotChunkSize - 1);
66
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);
72
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);
76
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);
80
81         testLog.info("ReplicationWithSlicedPayloadIntegrationTest ending");
82     }
83 }