2 * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.common.actor;
10 import static org.mockito.Mockito.never;
11 import static org.mockito.Mockito.timeout;
12 import static org.mockito.Mockito.verify;
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.remote.ThisActorSystemQuarantinedEvent;
22 import akka.testkit.javadsl.TestKit;
23 import org.junit.After;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.mockito.Mock;
28 import org.mockito.junit.MockitoJUnitRunner;
31 @RunWith(MockitoJUnitRunner.StrictStubs.class)
32 public class QuarantinedMonitorActorTest {
34 private static final Address LOCAL = Address.apply("http", "local");
35 private static final Address REMOTE = Address.apply("http", "remote");
38 private Effect callback;
39 private ActorSystem system;
40 private ActorRef actor;
44 system = ActorSystem.apply();
45 actor = system.actorOf(QuarantinedMonitorActor.props(callback));
49 public void tearDown() {
50 TestKit.shutdownActorSystem(system);
54 public void testOnReceiveQuarantined() throws Exception {
55 final Throwable t = new RuntimeException("Remote has quarantined this system");
56 final InvalidAssociation cause = InvalidAssociation.apply(LOCAL, REMOTE, t, Option.apply(null));
57 final ThisActorSystemQuarantinedEvent event = new ThisActorSystemQuarantinedEvent(LOCAL, REMOTE);
58 actor.tell(event, ActorRef.noSender());
59 verify(callback, timeout(1000)).apply();
63 public void testOnReceiveQuarantinedAsAssociation() throws Exception {
64 for (int i = 0; i < 9; i++) {
66 new RuntimeException("The remote system has a UID that has been quarantined. Association aborted.");
67 final InvalidAssociation cause = InvalidAssociation.apply(LOCAL, REMOTE, t, Option.apply(null));
68 final AssociationErrorEvent event =
69 new AssociationErrorEvent(cause, LOCAL, REMOTE, true, Logging.ErrorLevel());
70 actor.tell(event, ActorRef.noSender());
73 final Address local1 = Address.apply("http", "local1");
74 final Address remote1 = Address.apply("http", "remote1");
76 new RuntimeException("The remote system has a UID that has been quarantined. Association aborted.");
77 final InvalidAssociation cause1 = InvalidAssociation.apply(local1, remote1, t1, Option.apply(null));
78 final AssociationErrorEvent event1 =
79 new AssociationErrorEvent(cause1, local1, remote1, true, Logging.ErrorLevel());
80 actor.tell(event1, ActorRef.noSender());
81 verify(callback, timeout(1000)).apply();
85 public void testOnReceiveAnother() throws Exception {
86 final Address local = Address.apply("http", "local");
87 final Address remote = Address.apply("http", "remote");
88 final Throwable t = new RuntimeException("Another exception");
89 final InvalidAssociation cause = InvalidAssociation.apply(local, remote, t, Option.apply(null));
90 final AssociationErrorEvent event = new AssociationErrorEvent(cause, local, remote, true, Logging.ErrorLevel());
91 actor.tell(event, ActorRef.noSender());
92 verify(callback, never()).apply();