Initial code/design for an Akka Raft implementation
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / test / java / org / opendaylight / controller / cluster / raft / RaftReplicatorTest.java
1 package org.opendaylight.controller.cluster.raft;
2
3 import akka.testkit.JavaTestKit;
4 import org.junit.Test;
5 import org.opendaylight.controller.cluster.raft.internal.messages.SendHeartBeat;
6
7 import java.util.concurrent.atomic.AtomicLong;
8
9 import static org.junit.Assert.assertEquals;
10
11 public class RaftReplicatorTest extends AbstractActorTest {
12
13     @Test
14     public void testThatHeartBeatIsGenerated () throws Exception {
15         new JavaTestKit(getSystem()) {{
16
17             new Within(duration("1 seconds")) {
18                 protected void run() {
19
20                     getSystem().actorOf(RaftReplicator.props(
21                         new FollowerLogInformationImpl("test",
22                             new AtomicLong(100), new AtomicLong(100)),
23                         getRef()));
24
25                     final String out = new ExpectMsg<String>(duration("1 seconds"), "match hint") {
26                         // do not put code outside this method, will run afterwards
27                         protected String match(Object in) {
28                             if (in instanceof SendHeartBeat) {
29                                 return "match";
30                             } else {
31                                 throw noMatch();
32                             }
33                         }
34                     }.get(); // this extracts the received message
35
36                     assertEquals("match", out);
37
38                 }
39
40
41             };
42         }};
43     }
44 }