2 * Copyright (c) 2014 Cisco Systems, Inc. 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.remote.rpc.registry.gossip;
10 import akka.actor.ActorRef;
11 import akka.actor.ActorSystem;
12 import akka.actor.Props;
13 import akka.testkit.TestActorRef;
14 import akka.testkit.TestProbe;
15 import com.typesafe.config.ConfigFactory;
16 import org.junit.After;
17 import org.junit.AfterClass;
18 import org.junit.Assert;
19 import org.junit.Before;
20 import org.junit.BeforeClass;
21 import org.junit.Test;
22 import org.opendaylight.controller.remote.rpc.TerminationMonitor;
24 import static org.mockito.Mockito.reset;
25 import static org.mockito.Mockito.spy;
27 public class BucketStoreTest {
29 private static ActorSystem system;
30 private static BucketStore store;
32 private BucketStore mockStore;
35 public static void setup() {
37 system = ActorSystem.create("opendaylight-rpc", ConfigFactory.load().getConfig("unit-test"));
38 system.actorOf(Props.create(TerminationMonitor.class), "termination-monitor");
40 store = createStore();
44 public static void teardown() {
49 public void createMocks(){
50 mockStore = spy(store);
54 public void resetMocks(){
59 public void testReceiveUpdateBucket_WhenInputBucketShouldUpdateVersion(){
60 Bucket bucket = new BucketImpl();
61 Long expectedVersion = bucket.getVersion();
63 mockStore.receiveUpdateBucket(bucket);
65 Assert.assertEquals(bucket, mockStore.getLocalBucket());
66 Assert.assertEquals(expectedVersion, mockStore.getLocalBucket().getVersion());
70 * Create BucketStore actor and returns the underlying instance of BucketStore class.
72 * @return instance of BucketStore class
74 private static BucketStore createStore(){
75 TestProbe mockActor = new TestProbe(system);
76 ActorRef mockGossiper = mockActor.ref();
77 final Props props = Props.create(BucketStore.class, mockGossiper);
78 final TestActorRef<BucketStore> testRef = TestActorRef.create(system, props, "testStore");
80 return testRef.underlyingActor();