Package org.jboss.cache.jmx

Source Code of org.jboss.cache.jmx.JmxRegistrationManagerTest

/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.cache.jmx;

import com.mchange.v2.c3p0.util.TestUtils;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Cache;
import org.jboss.cache.CacheFactory;
import org.jboss.cache.interceptors.CacheMgmtInterceptor;

import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.UnitTestCacheFactory;
import org.jboss.cache.util.TestingUtil;

/**
* Tester class for {@link JmxRegistrationManager}.
*
* @author Mircea.Markus@jboss.com
* @since 3.0
*/
@Test (groups = "functional", sequential = true)
public class JmxRegistrationManagerTest
{
   private UnitTestCacheFactory cacheFactory = new UnitTestCacheFactory();
   private MBeanServer mBeanServer;

   @BeforeMethod
   public void setUp()
   {
      mBeanServer = MBeanServerFactory.createMBeanServer();
   }

   @AfterMethod
   public void tearDown()
   {
      MBeanServerFactory.releaseMBeanServer(mBeanServer);
   }

   public void testRegisterLocalCache() throws Exception
   {
      Configuration localConfig = UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL);
      localConfig.setExposeManagementStatistics(true);
      Cache cache = cacheFactory.createCache(localConfig);
      JmxRegistrationManager regManager = new JmxRegistrationManager(mBeanServer, cache, (ObjectName)null);
      assert regManager.getObjectNameBase().indexOf(JmxRegistrationManager.LOCAL_CACHE_PREFIX) == 0;
      regManager.registerAllMBeans();
      String name = regManager.getObjectName(CacheMgmtInterceptor.class.getSimpleName());
      assert mBeanServer.isRegistered(new ObjectName(name));
      regManager.unregisterAllMBeans();
      assert !mBeanServer.isRegistered(new ObjectName(name));
      cache.stop();
   }

   public void testRegisterReplicatedCache() throws Exception
   {
      Configuration localConfig = UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.REPL_SYNC);
      localConfig.setExposeManagementStatistics(true);
      Cache cache = cacheFactory.createCache(localConfig);
      JmxRegistrationManager regManager = new JmxRegistrationManager(mBeanServer, cache, (ObjectName)null);
      assert regManager.getObjectNameBase().indexOf(JmxRegistrationManager.REPLICATED_CACHE_PREFIX) == 0;
      regManager.registerAllMBeans();
      String name = regManager.getObjectName(CacheMgmtInterceptor.class.getSimpleName());
      assert mBeanServer.isRegistered(new ObjectName(name));
      regManager.unregisterAllMBeans();
      assert !mBeanServer.isRegistered(new ObjectName(name));
      cache.stop();
   }

   /**
    * This is useful when wanting to startup jconsole...
    */
   @Test(enabled = false)
   public static void main(String[] args)
   {
      Configuration localConfig = UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.REPL_SYNC);
      localConfig.setExposeManagementStatistics(true);
      CacheFactory cacheFactory = new DefaultCacheFactory();
      Cache cache = cacheFactory.createCache(localConfig);
      JmxRegistrationManager regManager = new JmxRegistrationManager(cache);
      while (true){}
   }
}
TOP

Related Classes of org.jboss.cache.jmx.JmxRegistrationManagerTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.