bf5b9fca5269e3d5bb390d99d9ba585fc5507fb7
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / test / java / org / opendaylight / controller / cluster / common / actor / QuarantinedMonitorActorTest.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.common.actor;
9
10 import static org.mockito.Mockito.never;
11 import static org.mockito.Mockito.timeout;
12 import static org.mockito.Mockito.verify;
13
14 import akka.actor.ActorRef;
15 import akka.actor.ActorSystem;
16 import akka.actor.Address;
17 import akka.event.Logging;
18 import akka.japi.Effect;
19 import akka.remote.AssociationErrorEvent;
20 import akka.remote.InvalidAssociation;
21 import akka.testkit.JavaTestKit;
22 import org.junit.After;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.mockito.Mock;
26 import org.mockito.MockitoAnnotations;
27 import scala.Option;
28
29 public class QuarantinedMonitorActorTest {
30
31     private static final Address LOCAL = Address.apply("http", "local");
32     private static final Address REMOTE = Address.apply("http", "remote");
33
34     @Mock
35     private Effect callback;
36     private ActorSystem system;
37     private ActorRef actor;
38
39     @Before
40     public void setUp() throws Exception {
41         MockitoAnnotations.initMocks(this);
42         system = ActorSystem.apply();
43         actor = system.actorOf(QuarantinedMonitorActor.props(callback));
44     }
45
46     @After
47     public void tearDown() throws Exception {
48         JavaTestKit.shutdownActorSystem(system);
49     }
50
51     @Test
52     public void testOnReceiveQuarantined() throws Exception {
53         final Throwable t = new RuntimeException("Remote has quarantined this system");
54         final InvalidAssociation cause = InvalidAssociation.apply(LOCAL, REMOTE, t, Option.apply(null));
55         final AssociationErrorEvent event = new AssociationErrorEvent(cause, LOCAL, REMOTE, true, Logging.ErrorLevel());
56         actor.tell(event, ActorRef.noSender());
57         verify(callback, timeout(1000)).apply();
58     }
59
60     @Test
61     public void testOnReceiveAnother() throws Exception {
62         final Address local = Address.apply("http", "local");
63         final Address remote = Address.apply("http", "remote");
64         final Throwable t = new RuntimeException("Another exception");
65         final InvalidAssociation cause = InvalidAssociation.apply(local, remote, t, Option.apply(null));
66         final AssociationErrorEvent event = new AssociationErrorEvent(cause, local, remote, true, Logging.ErrorLevel());
67         actor.tell(event, ActorRef.noSender());
68         verify(callback, never()).apply();
69     }
70
71 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.