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.Matchers.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;
19 public class DispatchersTest {
22 public void testGetDefaultDispatcherPath() {
23 akka.dispatch.Dispatchers mockDispatchers = mock(akka.dispatch.Dispatchers.class);
24 doReturn(false).when(mockDispatchers).hasDispatcher(anyString());
25 Dispatchers dispatchers = new Dispatchers(mockDispatchers);
27 for (Dispatchers.DispatcherType type : Dispatchers.DispatcherType.values()) {
28 assertEquals(Dispatchers.DEFAULT_DISPATCHER_PATH,
29 dispatchers.getDispatcherPath(type));
35 public void testGetDefaultDispatcher() {
36 akka.dispatch.Dispatchers mockDispatchers = mock(akka.dispatch.Dispatchers.class);
37 MessageDispatcher mockGlobalDispatcher = mock(MessageDispatcher.class);
38 doReturn(false).when(mockDispatchers).hasDispatcher(anyString());
39 doReturn(mockGlobalDispatcher).when(mockDispatchers).defaultGlobalDispatcher();
40 Dispatchers dispatchers = new Dispatchers(mockDispatchers);
42 for (Dispatchers.DispatcherType type : Dispatchers.DispatcherType.values()) {
43 assertEquals(mockGlobalDispatcher,
44 dispatchers.getDispatcher(type));
50 public void testGetDispatcherPath() {
51 akka.dispatch.Dispatchers mockDispatchers = mock(akka.dispatch.Dispatchers.class);
52 doReturn(true).when(mockDispatchers).hasDispatcher(anyString());
53 Dispatchers dispatchers = new Dispatchers(mockDispatchers);
55 assertEquals(Dispatchers.CLIENT_DISPATCHER_PATH,
56 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Client));
58 assertEquals(Dispatchers.TXN_DISPATCHER_PATH,
59 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Transaction));
61 assertEquals(Dispatchers.SHARD_DISPATCHER_PATH,
62 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Shard));
64 assertEquals(Dispatchers.NOTIFICATION_DISPATCHER_PATH,
65 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Notification));
70 public void testGetDispatcher() {
71 akka.dispatch.Dispatchers mockDispatchers = mock(akka.dispatch.Dispatchers.class);
72 MessageDispatcher mockDispatcher = mock(MessageDispatcher.class);
73 doReturn(true).when(mockDispatchers).hasDispatcher(anyString());
74 doReturn(mockDispatcher).when(mockDispatchers).lookup(anyString());
75 Dispatchers dispatchers = new Dispatchers(mockDispatchers);
77 assertEquals(Dispatchers.CLIENT_DISPATCHER_PATH,
78 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Client));
80 assertEquals(Dispatchers.TXN_DISPATCHER_PATH,
81 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Transaction));
83 assertEquals(Dispatchers.SHARD_DISPATCHER_PATH,
84 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Shard));
86 assertEquals(Dispatchers.NOTIFICATION_DISPATCHER_PATH,
87 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Notification));