Merge "Fixed for bug 1197"
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / jmx / mbeans / shard / ShardStatsTest.java
1 package org.opendaylight.controller.cluster.datastore.jmx.mbeans.shard;
2
3 import org.junit.After;
4 import org.junit.Assert;
5 import org.junit.Before;
6 import org.junit.Test;
7 import org.opendaylight.controller.cluster.datastore.jmx.mbeans.AbstractBaseMBean;
8
9 import javax.management.MBeanServer;
10 import javax.management.ObjectName;
11
12 public class ShardStatsTest {
13   private MBeanServer mbeanServer;
14  private  ShardStats  shardStats;
15   private ObjectName testMBeanName;
16
17   @Before
18   public void setUp() throws Exception {
19
20     shardStats = new ShardStats("shard-1");
21     shardStats.registerMBean();
22     mbeanServer= shardStats.getMBeanServer();
23     String objectName = AbstractBaseMBean.BASE_JMX_PREFIX + "type="+shardStats.getMBeanType()+",Category="+
24         shardStats.getMBeanCategory() + ",name="+
25         shardStats.getMBeanName();
26     testMBeanName = new ObjectName(objectName);
27   }
28
29   @After
30   public void tearDown() throws Exception {
31     shardStats.unregisterMBean();
32   }
33
34   @Test
35   public void testGetShardName() throws Exception {
36
37     Object attribute = mbeanServer.getAttribute(testMBeanName,"ShardName");
38     Assert.assertEquals((String) attribute, "shard-1");
39
40   }
41
42   @Test
43   public void testGetCommittedTransactionsCount() throws Exception {
44     //let us increment some transactions count and then check
45     shardStats.incrementCommittedTransactionCount();
46     shardStats.incrementCommittedTransactionCount();
47     shardStats.incrementCommittedTransactionCount();
48
49     //now let us get from MBeanServer what is the transaction count.
50     Object attribute = mbeanServer.getAttribute(testMBeanName,"CommittedTransactionsCount");
51     Assert.assertEquals((Long) attribute, (Long)3L);
52
53
54   }
55 }