[jboss-cvs] JBossAS SVN: r72377 - in trunk/testsuite/src: resources/cluster and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Apr 17 14:00:07 EDT 2008
Author: bstansberry at jboss.com
Date: 2008-04-17 14:00:07 -0400 (Thu, 17 Apr 2008)
New Revision: 72377
Added:
trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/CacheManagerTest.java
trunk/testsuite/src/resources/cluster/cachemanager/
trunk/testsuite/src/resources/cluster/cachemanager/jbc-configs.xml
trunk/testsuite/src/resources/cluster/cachemanager/stacks.xml
Log:
[JBAS-5378] Add tests of cache manager
Added: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/CacheManagerTest.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/CacheManagerTest.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/CacheManagerTest.java 2008-04-17 18:00:07 UTC (rev 72377)
@@ -0,0 +1,285 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.test.cluster.defaultcfg.test;
+
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.CacheStatus;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.ConfigurationRegistry;
+import org.jboss.cache.pojo.PojoCache;
+import org.jboss.ha.cachemanager.CacheManager;
+import org.jboss.ha.framework.server.JChannelFactory;
+import org.jboss.test.JBossTestCase;
+
+/**
+ * Tests CacheRegistry.
+ *
+ * @author Brian Stansberry
+ */
+public class CacheManagerTest extends JBossTestCase
+{
+ /** A file that includes every configuration element I could think of */
+ public static final String DEFAULT_CONFIGURATION_FILE = "cluster/cachemanager/jbc-configs.xml";
+ public static final String DEFAULT_STACKS_FILE = "cluster/cachemanager/stacks.xml";
+
+ private Set<Cache<Object, Object>> caches = new HashSet<Cache<Object, Object>>();
+ private Set<PojoCache> pojoCaches = new HashSet<PojoCache>();
+ private String jgroups_bind_addr;
+
+ public CacheManagerTest(String name)
+ {
+ super(name);
+ }
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ String jgroups_bind_addr = System.getProperty("jgroups.bind_addr");
+ if (jgroups_bind_addr == null)
+ {
+ System.setProperty("jbosstest.cluster.node0", System.getProperty("jbosstest.cluster.node0", "localhost"));
+ }
+ }
+
+ public void tearDown() throws Exception
+ {
+ if (jgroups_bind_addr == null)
+ System.clearProperty("jgroups.bind_addr");
+
+ for (Cache<Object, Object> cache : caches)
+ {
+ try
+ {
+ cache.stop();
+ cache.destroy();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(System.out);
+ }
+ }
+
+ for (PojoCache pojoCache : pojoCaches)
+ {
+ try
+ {
+ pojoCache.stop();
+ pojoCache.destroy();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(System.out);
+ }
+ }
+
+ super.tearDown();
+ }
+
+ /**
+ * A test that instantiates a CacheRegistry and cycles through all its
+ * core configs, creating and releasing a plain JBoss Cache for each.
+ *
+ * @throws Exception
+ */
+ public void testBasic() throws Exception
+ {
+ JChannelFactory cf = new JChannelFactory();
+ cf.setMultiplexerConfig(DEFAULT_STACKS_FILE);
+ cf.setExposeChannels(false);
+ cf.start();
+ CacheManager registry = new CacheManager(DEFAULT_CONFIGURATION_FILE, cf);
+ registry.start();
+
+ ConfigurationRegistry configRegistry = registry.getConfigurationRegistry();
+
+ Set<String> configNames = registry.getConfigurationNames();
+ assertEquals(7, configNames.size());
+ Set<String> cacheNames = registry.getCacheNames();
+ assertEquals(0, cacheNames.size());
+
+ for (String configName : configNames)
+ {
+ assertNull(configName + " not created", registry.getCache(configName, false));
+ Cache<Object, Object> cache = registry.getCache(configName, true);
+ caches.add(cache);
+
+ // Cache shouldn't be started
+ assertEquals(CacheStatus.INSTANTIATED, cache.getCacheStatus());
+ cache.create();
+ cache.start();
+
+ // Config should be a clone
+ Configuration rawConfig = configRegistry.getConfiguration(configName);
+ Configuration realConfig = cache.getConfiguration();
+ assertFalse(rawConfig == realConfig);
+ assertEquals(rawConfig.getClusterName(), realConfig.getClusterName());
+ }
+
+ cacheNames = registry.getCacheNames();
+ assertEquals(configNames, cacheNames);
+
+ // Test basic releasing of caches
+ for (String configName : configNames)
+ {
+ registry.releaseCache(configName);
+ }
+
+ cacheNames = registry.getCacheNames();
+ assertEquals(0, cacheNames.size());
+
+ // We shouldn't have affected configuration set
+ Set<String> configNames2 = registry.getConfigurationNames();
+ assertEquals(configNames, configNames2);
+
+ // Releasing only checkout of cache should have destroyed it
+ for (Iterator<Cache<Object, Object>> it = caches.iterator(); it.hasNext();)
+ {
+ assertEquals(CacheStatus.DESTROYED, it.next().getCacheStatus());
+ it.remove();
+ }
+
+ // Get cache w/o asking to create returns null
+ String configName = configNames.iterator().next();
+ assertNull(configName + " not created", registry.getCache(configName, false));
+ // Get cache w/ asking to create returns cache
+ Cache<Object, Object> cache = registry.getCache(configName, true);
+ assertFalse(null == cache);
+ caches.add(cache);
+
+ cache.create();
+ cache.start();
+
+ // Test 2 checkouts of the same cache
+ Cache<Object, Object> cache2 = registry.getCache(configName, true);
+ assertTrue(cache == cache2);
+
+ registry.releaseCache(configName);
+
+ // One release does not cause registry to stop cache
+ assertEquals(CacheStatus.STARTED, cache.getCacheStatus());
+
+ registry.stop();
+
+ // Now it's stopped
+ assertEquals(CacheStatus.DESTROYED, cache.getCacheStatus());
+ caches.remove(cache);
+
+ cacheNames = registry.getCacheNames();
+ assertEquals(0, cacheNames.size());
+ assertEquals(cacheNames, registry.getConfigurationNames());
+ }
+
+ /**
+ * Same as testBasic() but here we ask for instances of PojoCache.
+ *
+ * @throws Exception
+ */
+ public void testBasicPojo() throws Exception
+ {
+ JChannelFactory cf = new JChannelFactory();
+ cf.setMultiplexerConfig(DEFAULT_STACKS_FILE);
+ cf.setExposeChannels(false);
+ cf.start();
+ CacheManager registry = new CacheManager(DEFAULT_CONFIGURATION_FILE, cf);
+ registry.start();
+
+ ConfigurationRegistry configRegistry = registry.getConfigurationRegistry();
+
+ Set<String> configNames = registry.getConfigurationNames();
+ assertEquals(7, configNames.size());
+ Set<String> cacheNames = registry.getPojoCacheNames();
+ assertEquals(0, cacheNames.size());
+
+ for (String configName : configNames)
+ {
+ assertNull(configName + " not created", registry.getPojoCache(configName, false));
+ PojoCache cache = registry.getPojoCache(configName, true);
+ pojoCaches.add(cache);
+
+ // Cache shouldn't be started
+ assertEquals(CacheStatus.INSTANTIATED, cache.getCache().getCacheStatus());
+ cache.create();
+ cache.start();
+
+ // Config should be a clone
+ Configuration rawConfig = configRegistry.getConfiguration(configName);
+ Configuration realConfig = cache.getCache().getConfiguration();
+ assertFalse(rawConfig == realConfig);
+ assertEquals(rawConfig.getClusterName(), realConfig.getClusterName());
+ }
+
+ cacheNames = registry.getPojoCacheNames();
+ assertEquals(configNames, cacheNames);
+
+ // Test basic releasing of caches
+ for (String configName : configNames)
+ {
+ registry.releaseCache(configName);
+ }
+
+ cacheNames = registry.getPojoCacheNames();
+ assertEquals(0, cacheNames.size());
+
+ // We shouldn't have affected configuration set
+ Set<String> configNames2 = registry.getConfigurationNames();
+ assertEquals(configNames, configNames2);
+
+ // Releasing only checkout of cache should have destroyed it
+ for (Iterator<PojoCache> it = pojoCaches.iterator(); it.hasNext();)
+ {
+ assertEquals(CacheStatus.DESTROYED, it.next().getCache().getCacheStatus());
+ it.remove();
+ }
+
+ // Get cache w/o asking to create returns null
+ String configName = configNames.iterator().next();
+ assertNull(configName + " not created", registry.getPojoCache(configName, false));
+ // Get cache w/ asking to create returns cache
+ PojoCache cache = registry.getPojoCache(configName, true);
+ assertFalse(null == cache);
+ pojoCaches.add(cache);
+
+ cache.create();
+ cache.start();
+
+ // Test 2 checkouts of the same cache
+ PojoCache cache2 = registry.getPojoCache(configName, true);
+ assertTrue(cache == cache2);
+
+ registry.releaseCache(configName);
+
+ // One release does not cause registry to stop cache
+ assertEquals(CacheStatus.STARTED, cache.getCache().getCacheStatus());
+
+ registry.stop();
+
+ // Now it's stopped
+ assertEquals(CacheStatus.DESTROYED, cache.getCache().getCacheStatus());
+ caches.remove(cache);
+
+ cacheNames = registry.getPojoCacheNames();
+ assertEquals(0, cacheNames.size());
+ assertEquals(cacheNames, registry.getConfigurationNames());
+ }
+
+ public void testNullConfigResource() throws Exception
+ {
+ JChannelFactory cf = new JChannelFactory();
+ cf.setMultiplexerConfig(DEFAULT_STACKS_FILE);
+ String configResource = null;
+ CacheManager registry = new CacheManager(configResource, cf);
+ registry.start();
+
+ assertEquals("No configs", 0, registry.getConfigurationNames().size());
+ }
+}
Added: trunk/testsuite/src/resources/cluster/cachemanager/jbc-configs.xml
===================================================================
(Binary files differ)
Property changes on: trunk/testsuite/src/resources/cluster/cachemanager/jbc-configs.xml
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/testsuite/src/resources/cluster/cachemanager/stacks.xml
===================================================================
--- trunk/testsuite/src/resources/cluster/cachemanager/stacks.xml (rev 0)
+++ trunk/testsuite/src/resources/cluster/cachemanager/stacks.xml 2008-04-17 18:00:07 UTC (rev 72377)
@@ -0,0 +1,65 @@
+
+<protocol_stacks>
+ <stack name="test"
+ description="Test stack">
+ <config>
+ <UDP
+ singleton_name="test"
+ mcast_port="${jgroups.udp.mcast_port:24688}"
+ mcast_addr="${jgroups.udp.mcast_addr:228.211.11.11}"
+ tos="8"
+ ucast_recv_buf_size="20000000"
+ ucast_send_buf_size="640000"
+ mcast_recv_buf_size="25000000"
+ mcast_send_buf_size="640000"
+ loopback="false"
+ discard_incompatible_packets="true"
+ max_bundle_size="64000"
+ max_bundle_timeout="30"
+ use_incoming_packet_handler="true"
+ ip_ttl="${jgroups.udp.ip_ttl:2}"
+ enable_bundling="false"
+
+ use_concurrent_stack="true"
+
+ thread_pool.enabled="true"
+ thread_pool.min_threads="1"
+ thread_pool.max_threads="25"
+ thread_pool.keep_alive_time="5000"
+ thread_pool.queue_enabled="false"
+ thread_pool.queue_max_size="100"
+ thread_pool.rejection_policy="Run"
+
+ oob_thread_pool.enabled="true"
+ oob_thread_pool.min_threads="1"
+ oob_thread_pool.max_threads="8"
+ oob_thread_pool.keep_alive_time="5000"
+ oob_thread_pool.queue_enabled="false"
+ oob_thread_pool.queue_max_size="100"
+ oob_thread_pool.rejection_policy="Run"/>
+ <PING timeout="2000" num_initial_members="3"/>
+ <MERGE2 max_interval="100000" min_interval="20000"/>
+ <FD_SOCK/>
+ <FD timeout="10000" max_tries="5" shun="true"/>
+ <VERIFY_SUSPECT timeout="1500"/>
+ <pbcast.NAKACK use_mcast_xmit="false" gc_lag="0"
+ retransmit_timeout="300,600,1200,2400,4800"
+ discard_delivered_msgs="true"/>
+ <UNICAST timeout="300,600,1200,2400,3600"/>
+ <pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000"
+ max_bytes="400000"/>
+ <pbcast.GMS print_local_addr="true" join_timeout="3000"
+ shun="true"
+ view_bundling="true"
+ view_ack_collection_timeout="5000"/>
+ <FC max_credits="2000000" min_threshold="0.10"/>
+ <FRAG2 frag_size="60000"/>
+ <!-- pbcast.STREAMING_STATE_TRANSFER use_reading_thread="true"/ -->
+ <pbcast.STATE_TRANSFER/>
+ <pbcast.FLUSH timeout="0"/>
+ </config>
+ </stack>
+
+</protocol_stacks>
+
+
More information about the jboss-cvs-commits
mailing list