Merge "BUG 2676 : Introduce API for accessing akka dispatchers"
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / utils / DispatchersTest.java
1 package org.opendaylight.controller.cluster.datastore.utils;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.mockito.Matchers.anyString;
5 import static org.mockito.Mockito.doReturn;
6 import static org.mockito.Mockito.mock;
7 import akka.dispatch.MessageDispatcher;
8 import org.junit.Test;
9
10 public class DispatchersTest {
11
12     @Test
13     public void testGetDefaultDispatcherPath(){
14         akka.dispatch.Dispatchers mockDispatchers = mock(akka.dispatch.Dispatchers.class);
15         doReturn(false).when(mockDispatchers).hasDispatcher(anyString());
16         Dispatchers dispatchers = new Dispatchers(mockDispatchers);
17
18         for(Dispatchers.DispatcherType type : Dispatchers.DispatcherType.values()) {
19             assertEquals(Dispatchers.DEFAULT_DISPATCHER_PATH,
20                     dispatchers.getDispatcherPath(type));
21         }
22
23     }
24
25     @Test
26     public void testGetDefaultDispatcher(){
27         akka.dispatch.Dispatchers mockDispatchers = mock(akka.dispatch.Dispatchers.class);
28         MessageDispatcher mockGlobalDispatcher = mock(MessageDispatcher.class);
29         doReturn(false).when(mockDispatchers).hasDispatcher(anyString());
30         doReturn(mockGlobalDispatcher).when(mockDispatchers).defaultGlobalDispatcher();
31         Dispatchers dispatchers = new Dispatchers(mockDispatchers);
32
33         for(Dispatchers.DispatcherType type : Dispatchers.DispatcherType.values()) {
34             assertEquals(mockGlobalDispatcher,
35                     dispatchers.getDispatcher(type));
36         }
37
38     }
39
40     @Test
41     public void testGetDispatcherPath(){
42         akka.dispatch.Dispatchers mockDispatchers = mock(akka.dispatch.Dispatchers.class);
43         doReturn(true).when(mockDispatchers).hasDispatcher(anyString());
44         Dispatchers dispatchers = new Dispatchers(mockDispatchers);
45
46         assertEquals(Dispatchers.CLIENT_DISPATCHER_PATH,
47                 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Client));
48
49         assertEquals(Dispatchers.TXN_DISPATCHER_PATH,
50                 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Transaction));
51
52         assertEquals(Dispatchers.SHARD_DISPATCHER_PATH,
53                 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Shard));
54
55         assertEquals(Dispatchers.NOTIFICATION_DISPATCHER_PATH,
56                 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Notification));
57
58     }
59
60     @Test
61     public void testGetDispatcher(){
62         akka.dispatch.Dispatchers mockDispatchers = mock(akka.dispatch.Dispatchers.class);
63         MessageDispatcher mockDispatcher = mock(MessageDispatcher.class);
64         doReturn(true).when(mockDispatchers).hasDispatcher(anyString());
65         doReturn(mockDispatcher).when(mockDispatchers).lookup(anyString());
66         Dispatchers dispatchers = new Dispatchers(mockDispatchers);
67
68         assertEquals(Dispatchers.CLIENT_DISPATCHER_PATH,
69                 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Client));
70
71         assertEquals(Dispatchers.TXN_DISPATCHER_PATH,
72                 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Transaction));
73
74         assertEquals(Dispatchers.SHARD_DISPATCHER_PATH,
75                 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Shard));
76
77         assertEquals(Dispatchers.NOTIFICATION_DISPATCHER_PATH,
78                 dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Notification));
79
80     }
81 }

©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.