2 * Copyright (c) 2016 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.cluster.access.client;
10 import static org.junit.Assert.assertSame;
12 import akka.actor.ActorSystem;
13 import akka.testkit.TestProbe;
14 import akka.testkit.javadsl.TestKit;
15 import com.google.common.base.Ticker;
16 import java.util.concurrent.TimeUnit;
17 import org.junit.After;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.junit.runner.RunWith;
21 import org.mockito.Mock;
22 import org.mockito.junit.MockitoJUnitRunner;
23 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
24 import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier;
25 import org.opendaylight.controller.cluster.access.concepts.FrontendType;
26 import org.opendaylight.controller.cluster.access.concepts.MemberName;
27 import scala.concurrent.duration.FiniteDuration;
29 @RunWith(MockitoJUnitRunner.class)
30 public class ClientActorContextTest {
31 private static final MemberName MEMBER_NAME = MemberName.forName("member-1");
32 private static final FrontendType FRONTEND_TYPE =
33 FrontendType.forName(ClientActorContextTest.class.getSimpleName());
34 private static final FrontendIdentifier FRONTEND_ID = FrontendIdentifier.create(MEMBER_NAME, FRONTEND_TYPE);
35 private static final ClientIdentifier CLIENT_ID = ClientIdentifier.create(FRONTEND_ID, 0);
36 private static final String PERSISTENCE_ID = ClientActorContextTest.class.getSimpleName();
39 private InternalCommand<? extends BackendInfo> command;
40 private ActorSystem system;
41 private TestProbe probe;
42 private ClientActorContext ctx;
46 system = ActorSystem.apply();
47 probe = new TestProbe(system);
48 ctx = new ClientActorContext(probe.ref(), PERSISTENCE_ID, system,
49 CLIENT_ID, AccessClientUtil.newMockClientActorConfig());
53 public void testMockingControl() {
54 assertSame(CLIENT_ID, ctx.getIdentifier());
55 assertSame(PERSISTENCE_ID, ctx.persistenceId());
56 assertSame(probe.ref(), ctx.self());
60 public void testTicker() {
61 assertSame(Ticker.systemTicker(), ctx.ticker());
65 public void testExecuteInActor() {
66 ctx.executeInActor(command);
67 probe.expectMsg(command);
71 public void testExecuteInActorScheduled() {
72 ctx.executeInActor(command, FiniteDuration.create(1, TimeUnit.SECONDS));
73 probe.expectMsg(command);
77 public void tearDown() {
78 TestKit.shutdownActorSystem(system);