1 package org.opendaylight.controller.cluster.datastore.jmx.mbeans.shard;
3 import org.junit.After;
4 import org.junit.Assert;
5 import org.junit.Before;
7 import org.opendaylight.controller.cluster.datastore.jmx.mbeans.AbstractBaseMBean;
9 import javax.management.MBeanServer;
10 import javax.management.ObjectName;
12 public class ShardStatsTest {
13 private MBeanServer mbeanServer;
14 private ShardStats shardStats;
15 private ObjectName testMBeanName;
18 public void setUp() throws Exception {
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);
30 public void tearDown() throws Exception {
31 shardStats.unregisterMBean();
35 public void testGetShardName() throws Exception {
37 Object attribute = mbeanServer.getAttribute(testMBeanName,"ShardName");
38 Assert.assertEquals((String) attribute, "shard-1");
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();
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);