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;
15 import akka.dispatch.MessageDispatcher;
16 import org.junit.Test;
18 public class DispatchersTest {
21 public void testGetDefaultDispatcherPath(){
22 akka.dispatch.Dispatchers mockDispatchers = mock(akka.dispatch.Dispatchers.class);
23 doReturn(false).when(mockDispatchers).hasDispatcher(anyString());
24 Dispatchers dispatchers = new Dispatchers(mockDispatchers);
26 for(Dispatchers.DispatcherType type : Dispatchers.DispatcherType.values()) {
27 assertEquals(Dispatchers.DEFAULT_DISPATCHER_PATH,
28 dispatchers.getDispatcherPath(type));
34 public void testGetDefaultDispatcher(){
35 akka.dispatch.Dispatchers mockDispatchers = mock(akka.dispatch.Dispatchers.class);
36 MessageDispatcher mockGlobalDispatcher = mock(MessageDispatcher.class);
37 doReturn(false).when(mockDispatchers).hasDispatcher(anyString());
38 doReturn(mockGlobalDispatcher).when(mockDispatchers).defaultGlobalDispatcher();
39 Dispatchers dispatchers = new Dispatchers(mockDispatchers);
41 for(Dispatchers.DispatcherType type : Dispatchers.DispatcherType.values()) {
42 assertEquals(mockGlobalDispatcher,
43 dispatchers.getDispatcher(type));
49 public void testGetDispatcherPath(){
50 akka.dispatch.Dispatchers mockDispatchers = mock(akka.dispatch.Dispatchers.class);
51 doReturn(true).when(mockDispatchers).hasDispatcher(anyString());
52 Dispatchers dispatchers = new Dispatchers(mockDispatchers);
54 assertEquals(Dispatchers.CLIENT_DISPATCHER_PATH,
55 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Client));
57 assertEquals(Dispatchers.TXN_DISPATCHER_PATH,
58 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Transaction));
60 assertEquals(Dispatchers.SHARD_DISPATCHER_PATH,
61 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Shard));
63 assertEquals(Dispatchers.NOTIFICATION_DISPATCHER_PATH,
64 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Notification));
69 public void testGetDispatcher(){
70 akka.dispatch.Dispatchers mockDispatchers = mock(akka.dispatch.Dispatchers.class);
71 MessageDispatcher mockDispatcher = mock(MessageDispatcher.class);
72 doReturn(true).when(mockDispatchers).hasDispatcher(anyString());
73 doReturn(mockDispatcher).when(mockDispatchers).lookup(anyString());
74 Dispatchers dispatchers = new Dispatchers(mockDispatchers);
76 assertEquals(Dispatchers.CLIENT_DISPATCHER_PATH,
77 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Client));
79 assertEquals(Dispatchers.TXN_DISPATCHER_PATH,
80 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Transaction));
82 assertEquals(Dispatchers.SHARD_DISPATCHER_PATH,
83 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Shard));
85 assertEquals(Dispatchers.NOTIFICATION_DISPATCHER_PATH,
86 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Notification));