2 * Copyright (c) 2014, 2015 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
9 package org.opendaylight.controller.cluster.datastore.utils;
11 import static org.junit.Assert.assertEquals;
12 import static org.mockito.ArgumentMatchers.anyString;
13 import static org.mockito.Mockito.doReturn;
14 import static org.mockito.Mockito.mock;
16 import akka.dispatch.MessageDispatcher;
17 import org.junit.Test;
18 import org.opendaylight.controller.cluster.common.actor.Dispatchers;
20 public class DispatchersTest {
23 public void testGetDefaultDispatcherPath() {
24 akka.dispatch.Dispatchers mockDispatchers = mock(akka.dispatch.Dispatchers.class);
25 doReturn(false).when(mockDispatchers).hasDispatcher(anyString());
26 Dispatchers dispatchers = new Dispatchers(mockDispatchers);
28 for (Dispatchers.DispatcherType type : Dispatchers.DispatcherType.values()) {
29 assertEquals(Dispatchers.DEFAULT_DISPATCHER_PATH,
30 dispatchers.getDispatcherPath(type));
36 public void testGetDefaultDispatcher() {
37 akka.dispatch.Dispatchers mockDispatchers = mock(akka.dispatch.Dispatchers.class);
38 MessageDispatcher mockGlobalDispatcher = mock(MessageDispatcher.class);
39 doReturn(false).when(mockDispatchers).hasDispatcher(anyString());
40 doReturn(mockGlobalDispatcher).when(mockDispatchers).defaultGlobalDispatcher();
41 Dispatchers dispatchers = new Dispatchers(mockDispatchers);
43 for (Dispatchers.DispatcherType type : Dispatchers.DispatcherType.values()) {
44 assertEquals(mockGlobalDispatcher,
45 dispatchers.getDispatcher(type));
51 public void testGetDispatcherPath() {
52 akka.dispatch.Dispatchers mockDispatchers = mock(akka.dispatch.Dispatchers.class);
53 doReturn(true).when(mockDispatchers).hasDispatcher(anyString());
54 Dispatchers dispatchers = new Dispatchers(mockDispatchers);
56 assertEquals(Dispatchers.CLIENT_DISPATCHER_PATH,
57 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Client));
59 assertEquals(Dispatchers.TXN_DISPATCHER_PATH,
60 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Transaction));
62 assertEquals(Dispatchers.SHARD_DISPATCHER_PATH,
63 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Shard));
65 assertEquals(Dispatchers.NOTIFICATION_DISPATCHER_PATH,
66 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Notification));
71 public void testGetDispatcher() {
72 akka.dispatch.Dispatchers mockDispatchers = mock(akka.dispatch.Dispatchers.class);
73 MessageDispatcher mockDispatcher = mock(MessageDispatcher.class);
74 doReturn(true).when(mockDispatchers).hasDispatcher(anyString());
75 doReturn(mockDispatcher).when(mockDispatchers).lookup(anyString());
76 Dispatchers dispatchers = new Dispatchers(mockDispatchers);
78 assertEquals(Dispatchers.CLIENT_DISPATCHER_PATH,
79 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Client));
81 assertEquals(Dispatchers.TXN_DISPATCHER_PATH,
82 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Transaction));
84 assertEquals(Dispatchers.SHARD_DISPATCHER_PATH,
85 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Shard));
87 assertEquals(Dispatchers.NOTIFICATION_DISPATCHER_PATH,
88 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Notification));