jbosscache-core-2.2.2.GA/ 0000755 0001750 0001750 00000000000 11376174036 015003 5 ustar twerner twerner jbosscache-core-2.2.2.GA/README-i18n.txt 0000644 0001750 0001750 00000002234 10676513755 017266 0 ustar twerner twerner Internationalising documentation
--------------------------------
Documentation for JBoss Cache is written using docbook XML. There is a lot of reference material on docbook XML if
you are unfamiliar with it, but JBoss Cache's usage of docbook is pretty basic and most of it can be picked up by looking
through the existing documentation sources, which are in src/main/docbook.
For each document, the 'en' version is treated as the reference source for all translations.
Starting a new translation
--------------------------
** NB: This section needs updating since moving to subversion.
Each time a new translation is started, the docs directory should be updated and tagged as I18N_<2-letter iso lang code>_<2-letter iso country code> (optional)
such as I18N_IT or I18N_PT_BR (note all in upper case)
Updating translations
---------------------
Each time a new release is made, translations should be updated by:
1) Doing a diff of the 'en' docs, comparing the latest against the translation tag (e.g., I18N_IT)
2) Updating the translation (e.g., the 'it' docs)
3) Moving the translation tag on the 'en' files (e.g., I18N_IT) to the current snapshot.
- Manik Surtani
jbosscache-core-2.2.2.GA/pom.xml 0000644 0001750 0001750 00000043104 11147506161 016314 0 ustar twerner twerner
4.0.0
2.2.2.GA
unit
install
org.jboss.cache
jbosscache-common-parent
1.4
org.jboss.cache
jbosscache-core
${jbosscache-core-version}
JBoss Cache - Core Edition
JBoss Cache - Core Edition
http://www.jbosscache.org
jar
jgroups
jgroups
2.6.5.GA
javax.transaction
jta
1.1
commons-logging
commons-logging
1.0.4
org.jboss
jboss-common-core
2.2.8.GA
apache-slide
webdavlib
apache-xerces
xml-apis
apache-httpclient
commons-httpclient
jdbm
jdbm
1.0
true
c3p0
c3p0
0.9.1.1
true
sleepycat
je
1.7.0
true
net.jcip
jcip-annotations
1.0
true
net.noderunner
amazon-s3
1.0.0.0
true
org.easymock
easymock
2.3
test
jboss.jbossts
jbossjta
4.3.0.GA
test
beanshell
bsh
2.0b4
test
net.noderunner
http
1.0
test
javax.servlet
servlet-api
2.3
test
maven-assembly-plugin
2.2-beta-1
assemble
install
attached
assembly/bin.xml
assembly/doc.xml
assembly/all.xml
${artifactId}-${jbosscache-core-version}
target/distribution
target/assembly/work
org.apache.maven.plugins
maven-jar-plugin
true
true
org.jboss.cache.Version
build-test-jar
test-jar
true
true
repository.jboss.org
http://repository.jboss.org/maven2
snapshots.jboss.org
http://snapshots.jboss.org/maven2
e-xml.sourceforge.net
http://e-xml.sourceforge.net/maven2/repository
Docs
false
package
org.jboss.maven.plugins
maven-jdocbook-plugin
2.0.0
true
org.jboss
jbossorg-docbook-xslt
1.1.0
org.jboss
jbossorg-jdocbook-style
1.1.0
jdocbook-style
userguide_en
package
resources
generate
master.xml
${basedir}/src/main/docbook/userguide/en
${basedir}/src/main/docbook/images
${basedir}/src/main/docbook/css
${basedir}/target/docbook/userguide_en
pdf
classpath:/xslt/org/jboss/pdf.xsl
userguide_en.pdf
html
classpath:/xslt/org/jboss/xhtml.xsl
index.html
html_single
classpath:/xslt/org/jboss/xhtml-single.xsl
index.html
false
tutorial_en
package
resources
generate
master.xml
${basedir}/src/main/docbook/tutorial/en
${basedir}/src/main/docbook/images
${basedir}/src/main/docbook/css
${basedir}/target/docbook/tutorial_en
pdf
classpath:/xslt/org/jboss/pdf.xsl
tutorial_en.pdf
html
classpath:/xslt/org/jboss/xhtml.xsl
index.html
html_single
classpath:/xslt/org/jboss/xhtml-single.xsl
index.html
false
faq_en
package
resources
generate
master.xml
${basedir}/src/main/docbook/faq/en
${basedir}/src/main/docbook/images
${basedir}/src/main/docbook/css
${basedir}/target/docbook/faq_en
pdf
classpath:/xslt/org/jboss/pdf.xsl
faq_en.pdf
html
classpath:/xslt/org/jboss/xhtml.xsl
index.html
html_single
classpath:/xslt/org/jboss/xhtml-single.xsl
index.html
false
test-hudson
functional,unit
test-functional
functional
test-unit
unit
test-jgroups
jgroups
test-transaction
transaction
test-integration
integration
JBossAS
false
2.2.1-SNAPSHOT-JBossAS
functional,unit
jgroups
jgroups
2.6.5.GA
org.jboss.javaee
jboss-javaee
5.0.0.CR2
org.jboss
jboss-common-core
2.2.8.GA
commons-logging
commons-logging
1.1.0.jboss
jboss.jbossts
jbossjta
4.4.0.GA
test
jbosscache-core-2.2.2.GA/README-Maven.txt 0000644 0001750 0001750 00000021711 11021255727 017541 0 ustar twerner twerner
1. WORKING WITH MAVEN
=====================
Requirements:
* Java 5.0 and above
* Maven 2.0.8 and above
1.1. Quickstart: Typical lifecycle phases
-----------------------------------------
Maven will create a target/ directory under the root for the creation of
output at every stage.
* mvn clean: Cleans out any old builds and binaries
* mvn compile: Compiles java source code.
* mvn test: Runs the TestNG unit test suite on the compiled code. Will also compile the tests. See the testing section
below for more information on running different test groups. The default test group run is the "unit" group.
* mvn package: Packages the module as a JAR file, the resulting JAR file will be in target/
* mvn package -Dmaven.test.skip=true: Creates a JAR file without running tests.
* mvn package -P Docs: Packages the module as a JAR file, and builds the javadocs and user documentation from docbook sources.
* mvn install: will install the artifacts in your local repo for use by other projects (such as JBoss Cache POJO edition
which depends on JBoss Cache Core). Will also use Maven's assembly plugin to build ZIP files for download
(in target/distribution)
* mvn deploy: will build and deploy the project to the JBoss snapshots repository. Note that you should have your WebDAV
username and password set up. (Deploys snapshots to http://snapshots.jboss.org/maven2/org/jboss/cache/). If you have
a non-SNAPSHOT version number in your pom.xml, it will be deployed to the live releases repository (see below)
* mvn clean site -Ptest-functional,codeCoverage: will run all tests in the test-functional profile and generate code
coverage reports using EMMA.
1.2. Setting up your WebDAV username and password to deploy project snapshots
-----------------------------------------------------------------------------
You will also have to configure maven to use your username and password to access this repository. For this, you will
have to modify the servers section of maven settings file ($MAVEN_HOME/conf/settings.xml, or ~/.m2/settings.xml).
Something similar to the following should be added:
...
...
snapshots.jboss.org
webdav-user
webdav-pass
...
...
1.3. Deploying a release to a live repository
---------------------------------------------
Very simple. Make sure you have the version number in your pom.xml set to a non-SNAPSHOT version. Maven will pick up
on this and deploy to your release repository rather than the snapshot repository.
JBoss release repository cannot be accessed via WebDAV, as the snapshot repository can. So what you need to do is:
1) Check out the release repository from Subversion (svn co https://svn.jboss.org/repos/repository.jboss.org/maven2)
2) Add a property in ~/.m2/settings.xml to point to this 'local' copy of the repo. (See maven settings below)
3) Update your project's pom.xml to reflect a non-SNAPSHOT version number
4) Deploy your project (mvn clean deploy)
5) Check in your 'local' copy of the repo checked out in (1), adding any new directories/files created by (4).
1.4. Maven settings.xml
-----------------------
Working with the JBoss Cache source tree, I have configured my ~/.m2/settings.xml to look like:
snapshots.jboss.org
MY_JBOSS_ORG_USERNAME
WONT_TELL_YOU
jboss
/Users/manik/Code/maven2
jboss
2. TESTING
==========
Tests are written against the TestNG testing framework. Each test should belong to one or more group. The group acts as
a filter, and is used to select which tests are ran as part of the maven test lifecycle. There are 3 groups that are
currently in use, but there is not formal, you can make up any group name if you like.
2.1. Current Groups
-------------------
* unit - Unit tests using stubs to isolate and test each major class in JBoss Cache. This is the default group run if no test group is specified.
* functional - Tests which test the general functionality of JBoss Cache
* jgroups - Tests which need to send data on a JGroups Channel
* transaction - Tests which use a transaction manager
* profiling - Tests used for manual profiling, not meant for automated test runs
* manual - Other tests that are run manually
* integration - Integration tests emulating usage patterns for specific products such as JBoss AS Clustering and Hibernate clustering
It should be noted that every test (except those not intended to be run by Hudson) should at least be in the functional
group, since this is the default test group that is executed by maven, and the one that is required to prepare a release.
2.2. Executing the default test run
-----------------------------------
The default run executes all tests in the functional group. To just run the tests with txt and xml output the command is:
$ mvn test
Alternatively, you can execute the tests AND generate a report with:
$ mvn surefire-report:report
If you already have ran a test cycle, and you want to generate a report off the current reports, then you use the
report-only goal, ike so:
$ mvn surefire-report:report-only
2.3. Executing different groups
-------------------------------
A group can be executed (using the default configuration) by simply using the appropriate profile, like so:
$ mvn -P test-jgroups test
2.4. Executing a single test
----------------------------
A single test can be executed using the test property. The value is the short name (not the fully qualified package name)
of the test.
$ mvn -P test-XXX -Dtest=FqnTest test
Alternatively, if there is more than one test with a given classname in your test suite, you could provide the path to
the test.
$ mvn -P test-XXX -Dtest=org/jboss/cache/multiplexer/SyncReplTxTest test
2.5. Executing all tests in a given package
--------------------------------------------
This can be achieved by passing in the package name with a wildcard to the test parameter.
$ mvn -P test-XXX -Dtest=org/jboss/cache/multiplexer/* test
2.6. Skipping the test run
--------------------------
It is sometimes desirable to install the jboss cache package in your local repository without performing a full test run.
To do this, simply use the maven.test.skip.exec property:
$ mvn -Dmaven.test.skip.exec=true install
Again, this is just a shortcut for local use. It SHOULD NEVER BE USED when releasing. Also, make sure "exec" is included
in the property, if not the tests will not be built, which will prevent a test jar being produced (POJO Cache needs the
Core Cache test jar).
2.7. Permutations
-----------------
We use the term permutation to describe a group execution against a particular config. This allows us to test a variety
of environments and configurations without rewriting the same basic test over and over again. For example, the jgroups-tcp
permutation executes the jgroups group using the TCP config. Each permutation requires a maven profile which defines the
various options, environmental variables, etc. The command to run the jgroups-tcp permutatin is:
$ mvn -Pjgroups-tcp surefire-report:report
Each permutation uses its own report directory, and its own html output file name. This allows you to execute multiple
permutations without wiping the results from the previous run. Note that due to the way maven operates, only one
permutation can be executed per mvn command. So automating multiple runs requires shell scripting, or some other execution
framework to make multiple called to maven.
2.8. Running permutations manually or in an IDE
-----------------------------------------------
Sometimes you want to run a test using settings other than the defaults (such as UDP for "jgroups" group tests or the
DummyTransactionManager for "transaction" group tests). This can be achieved by referring to the Maven POM file
to figure out which system properties are passed in to the test when doing something different.
E.g., to run a "jgroups" group test in your IDE using TCP instead of the default UDP, set the following:
-Djgroups.stack=tcp
Or, to use JBoss JTA (Arjuna TM) instead of the DummyTransactionManager in a "transaction" group test, set:
-Dorg.jboss.cache.test.tm=jboss-jta
Please refer to the POM file for more properties and permutations.
2.9. Integration with CruiseControl / Hudson
--------------------------------------------
CruiseControl should do the following:
* Run "mvn clean site" - will clean and run tests, and then prepare reports. In addition to unit tests, this project is
set up to run FindBugs, PMD, jxr, and a bunch of other code analysis tools and provide a report in
target/site/project-reports.html - which should be linked from the CruiseControl summary page.
jbosscache-core-2.2.2.GA/assembly/ 0000755 0001750 0001750 00000000000 11376173731 016623 5 ustar twerner twerner jbosscache-core-2.2.2.GA/assembly/bin.xml 0000644 0001750 0001750 00000002614 10757176162 020123 0 ustar twerner twerner
bin
zip
true
target
*.jar
*test*.jar
src/main/etc
etc
src/main/release
**/*.txt
lib
${artifactId}.${extension}
false
runtime
apache-xerces:xml-apis
apache-httpclient:commons-httpclient
apache-slide:webdavlib
jbosscache-core-2.2.2.GA/assembly/doc.xml 0000644 0001750 0001750 00000001345 10660525510 020104 0 ustar twerner twerner
doc
zip
true
src/main/release
*.txt
**lib**
license/*
target/site/apidocs
doc/apidocs
target/docbook
doc/
jbosscache-core-2.2.2.GA/assembly/all.xml 0000644 0001750 0001750 00000004253 10757176162 020124 0 ustar twerner twerner
all
zip
true
target
*.jar
*test*.jar
src/main/etc
etc
src/main/java
src
src/test/java
test
src/test/resources
test
src/main/release
**/*.txt
**/*.xml
target/site/apidocs
doc/apidocs
target/docbook
doc/
lib
${scope}/${artifactId}.${extension}
false
test
apache-xerces:xml-apis
apache-httpclient:commons-httpclient
apache-slide:webdavlib
jbosscache-core-2.2.2.GA/src/ 0000755 0001750 0001750 00000000000 11376173772 015600 5 ustar twerner twerner jbosscache-core-2.2.2.GA/src/test/ 0000755 0001750 0001750 00000000000 11376173770 016555 5 ustar twerner twerner jbosscache-core-2.2.2.GA/src/test/java/ 0000755 0001750 0001750 00000000000 11376173731 017473 5 ustar twerner twerner jbosscache-core-2.2.2.GA/src/test/java/org/ 0000755 0001750 0001750 00000000000 11376173731 020262 5 ustar twerner twerner jbosscache-core-2.2.2.GA/src/test/java/org/jboss/ 0000755 0001750 0001750 00000000000 11376173731 021402 5 ustar twerner twerner jbosscache-core-2.2.2.GA/src/test/java/org/jboss/cache/ 0000755 0001750 0001750 00000000000 11376173770 022450 5 ustar twerner twerner jbosscache-core-2.2.2.GA/src/test/java/org/jboss/cache/jmx/ 0000755 0001750 0001750 00000000000 11376173752 023246 5 ustar twerner twerner jbosscache-core-2.2.2.GA/src/test/java/org/jboss/cache/jmx/CacheJmxWrapperTestBase.java 0000644 0001750 0001750 00000012335 10736672510 030566 0 ustar twerner twerner package org.jboss.cache.jmx;
import org.jboss.cache.Cache;
import org.jboss.cache.CacheFactory;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.config.Configuration;
import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertTrue;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.MBeanServerInvocationHandler;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
/**
* Tests the JMX wrapper class around the cache.
*
* @author Manik Surtani
* @author Brian Stansberry
*/
@Test(groups = "functional")
public abstract class CacheJmxWrapperTestBase
{
public static final String CLUSTER_NAME = "CacheMBeanTest";
protected Cache cache;
protected CacheJmxWrapperMBean jmxWrapper;
protected MBeanServer mBeanServer;
protected ObjectName mBeanName;
protected String mBeanNameStr;
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
mBeanServer = MBeanServerFactory.createMBeanServer("CacheMBeanTest");
mBeanNameStr = JmxUtil.PREFIX + CLUSTER_NAME;
mBeanName = new ObjectName(mBeanNameStr);
}
@AfterMethod(alwaysRun = true)
public void tearDown() throws Exception
{
try
{
cleanup();
}
finally
{
if (mBeanServer != null)
{
MBeanServerFactory.releaseMBeanServer(mBeanServer);
mBeanServer = null;
}
}
}
protected CacheJmxWrapperMBean registerWrapper() throws Exception
{
if (cache == null)
cache = createCache(createConfiguration());
return registerWrapper(cache);
}
protected CacheJmxWrapperMBean registerWrapper(Cache toWrap) throws Exception
{
CacheJmxWrapper wrapper = new CacheJmxWrapper(toWrap);
return registerWrapper(wrapper);
}
protected CacheJmxWrapperMBean registerWrapper(Configuration config) throws Exception
{
CacheJmxWrapper wrapper = new CacheJmxWrapper();
wrapper.setConfiguration(config);
return registerWrapper(wrapper);
}
@SuppressWarnings("unchecked")
protected CacheJmxWrapperMBean registerWrapper(CacheJmxWrapperMBean wrapper) throws Exception
{
JmxUtil.registerCacheMBean(mBeanServer, wrapper, mBeanNameStr);
jmxWrapper = (CacheJmxWrapperMBean) MBeanServerInvocationHandler.newProxyInstance(mBeanServer, mBeanName, CacheJmxWrapperMBean.class, false);
return jmxWrapper;
}
protected void unregisterWrapper() throws Exception
{
mBeanServer.unregisterMBean(mBeanName);
}
protected CacheJmxWrapper createWrapper(Configuration config)
{
CacheJmxWrapper wrapper = new CacheJmxWrapper();
wrapper.setConfiguration(config);
return wrapper;
}
protected Cache createCache(Configuration config)
{
CacheFactory factory = new DefaultCacheFactory();
cache = factory.createCache(config, false);
return cache;
}
protected Configuration createConfiguration()
{
Configuration c = new Configuration();
c.setClusterName(CLUSTER_NAME);
c.setExposeManagementStatistics(true);
c.setCacheMode(Configuration.CacheMode.LOCAL);
return c;
}
private void cleanup() throws Exception
{
if (cache != null)
{
try
{
cache.stop();
}
catch (Exception ignored)
{
}
cache = null;
}
if (jmxWrapper != null)
{
try
{
jmxWrapper.stop();
jmxWrapper.destroy();
}
catch (Exception ignored)
{
}
jmxWrapper = null;
}
if (mBeanServer != null && mBeanName != null && mBeanServer.isRegistered(mBeanName))
mBeanServer.unregisterMBean(mBeanName);
}
protected void interceptorRegistrationTest(boolean expectMbeans) throws MalformedObjectNameException, NullPointerException
{
interceptorRegistrationTest(mBeanNameStr, expectMbeans);
}
protected void interceptorRegistrationTest(String baseName, boolean expectMbeans) throws MalformedObjectNameException, NullPointerException
{
// should be 3 interceptor MBeans loaded:
ObjectName[] interceptorMBeanNames = {
new ObjectName(baseName + JmxUtil.INTERCEPTOR_KEY + "TxInterceptor"),
new ObjectName(baseName + JmxUtil.INTERCEPTOR_KEY + "CacheMgmtInterceptor"),
new ObjectName(baseName + JmxUtil.INTERCEPTOR_KEY + "InvocationContextInterceptor")
};
for (ObjectName n : interceptorMBeanNames)
{
if (expectMbeans)
assertTrue(n + " should be registered", mBeanServer.isRegistered(n));
else
assertFalse(n + " should not be registered", mBeanServer.isRegistered(n));
}
}
}
jbosscache-core-2.2.2.GA/src/test/java/org/jboss/cache/jmx/LegacyConfigurationTest.java 0000644 0001750 0001750 00000054620 10712333755 030706 0 ustar twerner twerner /*
* JBoss, Home of Professional Open Source.
* Copyright 2006, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file 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 org.jboss.cache.Version;
import org.jboss.cache.config.*;
import org.jboss.cache.config.BuddyReplicationConfig.BuddyLocatorConfig;
import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.config.Configuration.NodeLockingScheme;
import org.jboss.cache.eviction.*;
import org.jboss.cache.loader.FileCacheLoader;
import org.jboss.cache.loader.SingletonStoreCacheLoader;
import org.jboss.cache.loader.jdbm.JdbmCacheLoader;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.multiplexer.MultiplexerTestHelper;
import org.jboss.cache.transaction.BatchModeTransactionManagerLookup;
import org.jboss.cache.xml.XmlHelper;
import org.jgroups.ChannelFactory;
import org.jgroups.JChannelFactory;
import org.jgroups.jmx.JChannelFactoryMBean;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
import javax.management.MBeanServerInvocationHandler;
import javax.management.ObjectName;
import javax.transaction.TransactionManager;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.List;
import java.util.Properties;
/**
* Test of the CacheLegacyJmxWrapper.
*
* @author Brian Stansberry
* @version $Revision: 4719 $
*/
public class LegacyConfigurationTest extends CacheJmxWrapperTestBase
{
@SuppressWarnings({"deprecation", "unchecked"})
public void testLocalCache() throws Exception
{
CacheJmxWrapperMBean wrapper = new CacheJmxWrapper();
registerWrapper(wrapper);
wrapper = (CacheJmxWrapperMBean) MBeanServerInvocationHandler.newProxyInstance(mBeanServer, mBeanName, CacheJmxWrapperMBean.class, false);
wrapper.setBuddyReplicationConfig(getBuddyReplicationConfig());
wrapper.setCacheLoaderConfig(getCacheLoaderConfig());
wrapper.setCacheMode("REPL_SYNC");
wrapper.setClusterName("LocalTest");
wrapper.setClusterConfig(getClusterConfig());
wrapper.setEvictionPolicyConfig(getEvictionPolicyConfig());
wrapper.setFetchInMemoryState(false);
wrapper.setInitialStateRetrievalTimeout(100);
wrapper.setInactiveOnStartup(true);
wrapper.setNodeLockingScheme("OPTIMISTIC");
wrapper.setIsolationLevel("READ_UNCOMMITTED");
wrapper.setLockAcquisitionTimeout(200);
wrapper.setReplicationVersion("1.0.1");
wrapper.setReplQueueInterval(15);
wrapper.setReplQueueMaxElements(50);
wrapper.setSyncReplTimeout(300);
wrapper.setSyncCommitPhase(true);
wrapper.setSyncRollbackPhase(true);
wrapper.setTransactionManagerLookupClass(BatchModeTransactionManagerLookup.class.getName());
wrapper.setExposeManagementStatistics(false);
wrapper.setUseRegionBasedMarshalling(true);
wrapper.setUseReplQueue(true);
Configuration c = wrapper.getConfiguration();
assertEquals("CacheMode", "REPL_SYNC", wrapper.getCacheMode());
assertEquals("CacheMode", CacheMode.REPL_SYNC, c.getCacheMode());
assertEquals("ClusterName", "LocalTest", wrapper.getClusterName());
assertEquals("ClusterName", "LocalTest", c.getClusterName());
assertEquals("FetchInMemoryState", false, wrapper.getFetchInMemoryState());
assertEquals("FetchInMemoryState", false, c.isFetchInMemoryState());
assertEquals("InitialStateRetrievalTimeout", 100, wrapper.getInitialStateRetrievalTimeout());
assertEquals("InitialStateRetrievalTimeout", 100, c.getStateRetrievalTimeout());
assertEquals("InactiveOnStartup", true, wrapper.isInactiveOnStartup());
assertEquals("InactiveOnStartup", true, c.isInactiveOnStartup());
assertEquals("NodeLockingScheme", "OPTIMISTIC", wrapper.getNodeLockingScheme());
assertEquals("NodeLockingScheme", NodeLockingScheme.OPTIMISTIC, c.getNodeLockingScheme());
assertEquals("IsolationLevel", "READ_UNCOMMITTED", wrapper.getIsolationLevel());
assertEquals("IsolationLevel", IsolationLevel.READ_UNCOMMITTED, c.getIsolationLevel());
assertEquals("LockAcquisitionTimeout", 200, wrapper.getLockAcquisitionTimeout());
assertEquals("LockAcquisitionTimeout", 200, c.getLockAcquisitionTimeout());
assertEquals("ReplicationVersion", "1.0.1", wrapper.getReplicationVersion());
assertEquals("ReplicationVersion", Version.getVersionShort("1.0.1"), c.getReplicationVersion());
assertEquals("ReplQueueInterval", 15, wrapper.getReplQueueInterval());
assertEquals("ReplQueueInterval", 15, c.getReplQueueInterval());
assertEquals("ReplQueueMaxElements", 50, wrapper.getReplQueueMaxElements());
assertEquals("ReplQueueMaxElements", 50, c.getReplQueueMaxElements());
assertEquals("SyncReplTimeout", 300, wrapper.getSyncReplTimeout());
assertEquals("SyncReplTimeout", 300, c.getSyncReplTimeout());
assertEquals("SyncCommitPhase", true, wrapper.getSyncCommitPhase());
assertEquals("SyncCommitPhase", true, c.isSyncCommitPhase());
assertEquals("SyncRollbackPhase", true, wrapper.getSyncRollbackPhase());
assertEquals("SyncRollbackPhase", true, c.isSyncRollbackPhase());
assertEquals("TransactionManagerLookupClass", BatchModeTransactionManagerLookup.class.getName(), wrapper.getTransactionManagerLookupClass());
assertEquals("TransactionManagerLookupClass", BatchModeTransactionManagerLookup.class.getName(), c.getTransactionManagerLookupClass());
assertEquals("ExposeManagementStatistics", false, wrapper.getExposeManagementStatistics());
assertEquals("ExposeManagementStatistics", false, c.getExposeManagementStatistics());
assertEquals("UseRegionBasedMarshalling", true, wrapper.getUseRegionBasedMarshalling());
assertEquals("UseRegionBasedMarshalling", true, c.isUseRegionBasedMarshalling());
assertEquals("UseReplQueue", true, wrapper.getUseReplQueue());
assertEquals("UseReplQueue", true, c.isUseReplQueue());
assertEquals("ClusterConfig", getClusterConfig().toString(), wrapper.getClusterConfig().toString());
assertEquals("BuddyReplicationConfig", getBuddyReplicationConfig().toString(), wrapper.getBuddyReplicationConfig().toString());
BuddyReplicationConfig brc = c.getBuddyReplicationConfig();
assertEquals("BR enabled", true, brc.isEnabled());
assertEquals("BR auto grav", false, brc.isAutoDataGravitation());
assertEquals("BR remove find", false, brc.isDataGravitationRemoveOnFind());
assertEquals("BR search backup", false, brc.isDataGravitationSearchBackupTrees());
assertEquals("BR comm timeout", 600000, brc.getBuddyCommunicationTimeout());
assertEquals("BR poolname", "testpool", brc.getBuddyPoolName());
BuddyLocatorConfig blc = brc.getBuddyLocatorConfig();
assertEquals("BR locator", "org.jboss.cache.buddyreplication.TestBuddyLocator", blc.getBuddyLocatorClass());
Properties props = blc.getBuddyLocatorProperties();
assertEquals("BR props", "2", props.get("numBuddies"));
assertEquals("CacheLoaderConfig", getCacheLoaderConfig().toString(), wrapper.getCacheLoaderConfig().toString());
CacheLoaderConfig clc = c.getCacheLoaderConfig();
assertEquals("CL passivation", false, clc.isPassivation());
assertEquals("CL passivation", true, clc.isShared());
assertEquals("CL preload", "/foo", clc.getPreload());
List iclcs = clc.getIndividualCacheLoaderConfigs();
IndividualCacheLoaderConfig iclc = iclcs.get(0);
assertEquals("CL0 class", FileCacheLoader.class.getName(), iclc.getClassName());
assertEquals("CL0 async", false, iclc.isAsync());
assertEquals("CL0 fetch", true, iclc.isFetchPersistentState());
assertEquals("CL0 ignore", true, iclc.isIgnoreModifications());
assertEquals("CL0 purge", true, iclc.isPurgeOnStartup());
assertEquals("CL0 singleton", true, iclc.getSingletonStoreConfig().isSingletonStoreEnabled());
assertEquals("CL0 singleton class", SingletonStoreCacheLoader.class.getName(), iclc.getSingletonStoreConfig().getSingletonStoreClass());
iclc = iclcs.get(1);
assertEquals("CL1 class", JdbmCacheLoader.class.getName(), iclc.getClassName());
assertEquals("CL1 async", true, iclc.isAsync());
assertEquals("CL1 fetch", false, iclc.isFetchPersistentState());
assertEquals("CL1 ignore", false, iclc.isIgnoreModifications());
assertEquals("CL1 purge", false, iclc.isPurgeOnStartup());
assertEquals("CL1 singleton", false, iclc.getSingletonStoreConfig().isSingletonStoreEnabled());
assertEquals("CL1 singleton class", SingletonStoreCacheLoader.class.getName(), iclc.getSingletonStoreConfig().getSingletonStoreClass());
assertEquals("EvictionPolicyConfig", getEvictionPolicyConfig().toString(), wrapper.getEvictionPolicyConfig().toString());
EvictionConfig ec = c.getEvictionConfig();
assertEquals("EC queue size", 20000, ec.getDefaultEventQueueSize());
assertEquals("EC wakeup", 5, ec.getWakeupIntervalSeconds());
assertEquals("EC default pol", LRUPolicy.class.getName(), ec.getDefaultEvictionPolicyClass());
List ercs = ec.getEvictionRegionConfigs();
EvictionRegionConfig erc = ercs.get(0);
assertEquals("ERC0 name", "/_default_", erc.getRegionName());
assertEquals("ERC0 queue size", 1000, erc.getEventQueueSize());
LRUConfiguration lru = (LRUConfiguration) erc.getEvictionPolicyConfig();
assertEquals("EPC0 pol", LRUPolicy.class.getName(), lru.getEvictionPolicyClass());
assertEquals("EPC0 maxnodes", 5000, lru.getMaxNodes());
assertEquals("EPC0 ttl", 1000, lru.getTimeToLiveSeconds());
erc = ercs.get(1);
assertEquals("ERC1 name", "/org/jboss/data", erc.getRegionName());
assertEquals("ERC1 queue size", 20000, erc.getEventQueueSize());
FIFOConfiguration fifo = (FIFOConfiguration) erc.getEvictionPolicyConfig();
assertEquals("EPC1 pol", FIFOPolicy.class.getName(), fifo.getEvictionPolicyClass());
assertEquals("EPC1 maxnodes", 5000, fifo.getMaxNodes());
erc = ercs.get(2);
assertEquals("ERC2 name", "/test", erc.getRegionName());
assertEquals("ERC2 queue size", 20000, erc.getEventQueueSize());
MRUConfiguration mru = (MRUConfiguration) erc.getEvictionPolicyConfig();
assertEquals("EPC2 pol", MRUPolicy.class.getName(), mru.getEvictionPolicyClass());
assertEquals("EPC2 maxnodes", 10000, mru.getMaxNodes());
erc = ercs.get(3);
assertEquals("ERC3 name", "/maxAgeTest", erc.getRegionName());
assertEquals("ERC3 queue size", 20000, erc.getEventQueueSize());
lru = (LRUConfiguration) erc.getEvictionPolicyConfig();
assertEquals("EPC3 pol", LRUPolicy.class.getName(), lru.getEvictionPolicyClass());
assertEquals("EPC3 maxnodes", 10000, lru.getMaxNodes());
assertEquals("EPC3 maxage", 10, lru.getMaxAgeSeconds());
assertEquals("EPC3 ttl", 8, lru.getTimeToLiveSeconds());
}
@SuppressWarnings("unchecked")
public void testRuntimeConfig() throws Exception
{
CacheJmxWrapperMBean wrapper = new CacheJmxWrapper();
registerWrapper(wrapper);
wrapper = (CacheJmxWrapperMBean) MBeanServerInvocationHandler.newProxyInstance(mBeanServer, mBeanName, CacheJmxWrapperMBean.class, false);
// Fake a TM by making a bogus proxy
TransactionManager tm = (TransactionManager) Proxy.newProxyInstance(getClass().getClassLoader(),
new Class[]{TransactionManager.class}, new MockInvocationHandler());
wrapper.setTransactionManager(tm);
ChannelFactory cf = new JChannelFactory();
wrapper.setMuxChannelFactory(cf);
RuntimeConfig rc = wrapper.getConfiguration().getRuntimeConfig();
assertSame("Same TM", tm, wrapper.getTransactionManager());
assertSame("Same TM", tm, rc.getTransactionManager());
assertSame("Same ChannelFactory", cf, wrapper.getMuxChannelFactory());
assertSame("Same ChannelFactory", cf, rc.getMuxChannelFactory());
}
@SuppressWarnings("unchecked")
public void testLegacyMuxChannelCreation() throws Exception
{
CacheJmxWrapperMBean wrapper = new CacheJmxWrapper();
registerWrapper(wrapper);
wrapper = (CacheJmxWrapperMBean) MBeanServerInvocationHandler.newProxyInstance(mBeanServer, mBeanName, CacheJmxWrapperMBean.class, false);
wrapper.setMultiplexerStack(MultiplexerTestHelper.MUX_STACK);
JChannelFactory factory = new JChannelFactory();
factory.setDomain("jbc.mux.test");
factory.setExposeChannels(false);
factory.setMultiplexerConfig(MultiplexerTestHelper.getClusterConfigElement(getDefaultProperties()));
ObjectName on = new ObjectName("jgroups:service=Mux");
mBeanServer.registerMBean(new org.jgroups.jmx.JChannelFactory(factory), on);
wrapper.setMultiplexerService((JChannelFactoryMBean) MBeanServerInvocationHandler.newProxyInstance(mBeanServer, on, JChannelFactoryMBean.class, false));
wrapper.start();
RuntimeConfig rc = wrapper.getConfiguration().getRuntimeConfig();
assertNotNull("Channel created", rc.getChannel());
}
protected static Element getBuddyReplicationConfig() throws Exception
{
String xmlString = "true\n" +
" 600000\n" +
" org.jboss.cache.buddyreplication.TestBuddyLocator\n" +
" numBuddies = 2\n" +
" testpool" +
" false\n" +
" false\n" +
" false" +
"";
return XmlHelper.stringToElement(xmlString);
}
protected static Element getCacheLoaderConfig() throws Exception
{
String xml = "\n" +
"false\n" +
"/foo\n" +
"true\n" +
"\n" +
"org.jboss.cache.loader.FileCacheLoader\n" +
"" +
" location=/tmp\n" +
"\n" +
"false\n" +
"true\n" +
"true\n" +
"true\n" +
"" +
"true" +
"" +
"\n" +
"\n" +
"org.jboss.cache.loader.jdbm.JdbmCacheLoader\n" +
"" +
" location=/home/bstansberry\n" +
"\n" +
"true\n" +
"false\n" +
"false\n" +
"false\n" +
"" +
"false" +
"" +
"\n" +
"";
return XmlHelper.stringToElement(xml);
}
protected static Element getEvictionPolicyConfig() throws Exception
{
String xml = "\n" +
"5\n" +
"20000\n" +
"org.jboss.cache.eviction.LRUPolicy\n" +
"\n" +
" 5000\n" +
" 1000\n" +
"\n" +
"\n" +
" 5000\n" +
"\n" +
"\n" +
" 10000\n" +
"\n" +
"\n" +
" 10000\n" +
" 8\n" +
" 10\n" +
"\n" +
" \n";
return XmlHelper.stringToElement(xml);
}
protected static Element getClusterConfig() throws Exception
{
String xml =
"\n" +
" \n" +
" \n" +
" \n" +
" \n" +
" \n" +
" \n" +
" \n" +
" \n" +
" \n" +
" \n" +
" \n" +
" \n" +
" \n" +
"";
return XmlHelper.stringToElement(xml);
}
protected String getDefaultProperties()
{
return "UDP(mcast_addr=224.0.0.36;mcast_port=55566;ip_ttl=32;" +
"mcast_send_buf_size=150000;mcast_recv_buf_size=80000):" +
"PING(timeout=1000;num_initial_members=2):" +
"MERGE2(min_interval=5000;max_interval=10000):" +
"FD_SOCK:" +
"VERIFY_SUSPECT(timeout=1500):" +
"pbcast.NAKACK(gc_lag=50;max_xmit_size=8192;retransmit_timeout=600,1200,2400,4800):" +
"UNICAST(timeout=600,1200,2400,4800):" +
"pbcast.STABLE(desired_avg_gossip=20000):" +
"FRAG(frag_size=8192;down_thread=false;up_thread=false):" +
"pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;" +
"shun=false;print_local_addr=true):" +
"pbcast.STATE_TRANSFER";
}
class MockInvocationHandler implements InvocationHandler
{
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
{
return null;
}
}
}
jbosscache-core-2.2.2.GA/src/test/java/org/jboss/cache/jmx/LifecycleNotificationTest.java 0000644 0001750 0001750 00000010161 10665031725 031207 0 ustar twerner twerner /*
* JBoss, Home of Professional Open Source.
* Copyright 2006, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file 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 static org.testng.AssertJUnit.assertEquals;
import java.util.LinkedList;
import java.util.List;
import javax.management.AttributeChangeNotification;
import javax.management.Notification;
import javax.management.NotificationListener;
/**
* A LifecycleNotificationTest.
*
* @author Brian Stansberry
* @version $Revision: 4444 $
*/
public class LifecycleNotificationTest extends CacheJmxWrapperTestBase
{
@SuppressWarnings("unchecked")
public void testGetStateAndStateNotification() throws Exception
{
CacheJmxWrapper wrapper = createWrapper(createConfiguration());
StateNotificationListener listener = new StateNotificationListener();
wrapper.addNotificationListener(listener, null, null);
assertEquals("Correct state after instanitation",
CacheJmxWrapperMBean.UNREGISTERED, wrapper.getState());
registerWrapper(wrapper);
assertEquals("Correct state after registration",
CacheJmxWrapperMBean.REGISTERED, wrapper.getState());
wrapper.create();
assertEquals("Correct state after create",
CacheJmxWrapperMBean.CREATED, wrapper.getState());
wrapper.start();
assertEquals("Correct state after start",
CacheJmxWrapperMBean.STARTED, wrapper.getState());
wrapper.stop();
assertEquals("Correct state after stop",
CacheJmxWrapperMBean.STOPPED, wrapper.getState());
wrapper.destroy();
assertEquals("Correct state after destroy",
CacheJmxWrapperMBean.DESTROYED, wrapper.getState());
unregisterWrapper();
assertEquals("Correct state after unregistration",
CacheJmxWrapperMBean.UNREGISTERED, wrapper.getState());
System.out.println(listener.notifications);
assertEquals("Correct number of notifications received", 4, listener.notifications.size());
assertEquals("Correct first notification", new Integer(CacheJmxWrapperMBean.STARTING), listener.notifications.get(0));
assertEquals("Correct second notification", new Integer(CacheJmxWrapperMBean.STARTED), listener.notifications.get(1));
assertEquals("Correct third notification", new Integer(CacheJmxWrapperMBean.STOPPING), listener.notifications.get(2));
assertEquals("Correct fourth notification", new Integer(CacheJmxWrapperMBean.STOPPED), listener.notifications.get(3));
}
private static class StateNotificationListener
implements NotificationListener
{
private List notifications = new LinkedList();
public void handleNotification(Notification msg, Object handback)
{
if (msg instanceof AttributeChangeNotification)
{
AttributeChangeNotification change = (AttributeChangeNotification) msg;
String attrName = change.getAttributeName();
Object newValue = change.getNewValue();
if ("State".equals(attrName) && newValue != null && newValue instanceof Integer)
{
notifications.add((Integer) newValue);
return;
}
}
}
}
}
jbosscache-core-2.2.2.GA/src/test/java/org/jboss/cache/jmx/CacheJmxWrapperTest.java 0000644 0001750 0001750 00000034316 11017455042 027766 0 ustar twerner twerner package org.jboss.cache.jmx;
import org.jboss.cache.Cache;
import org.jboss.cache.CacheException;
import org.jboss.cache.CacheStatus;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.util.TestingUtil;
import org.jboss.cache.notifications.annotation.CacheListener;
import org.jboss.cache.notifications.annotation.CacheStarted;
import org.jboss.cache.notifications.annotation.CacheStopped;
import org.jboss.cache.notifications.event.Event;
import org.jboss.cache.transaction.DummyTransactionManagerLookup;
import org.jgroups.Address;
import org.jgroups.stack.IpAddress;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.Test;
import javax.management.ObjectName;
import javax.transaction.TransactionManager;
import java.util.List;
/**
* Tests the JMX wrapper class around the cache.
*
* @author Manik Surtani
* @author Brian Stansberry
*/
@Test(groups = "functional")
public class CacheJmxWrapperTest extends CacheJmxWrapperTestBase
{
public void testCacheMBeanBinding() throws Exception
{
registerWrapper();
assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
}
public void testSetCacheObjectName() throws Exception
{
ObjectName on = new ObjectName("jboss.cache:test=SetCacheObjectName");
boolean registered = false;
try
{
CacheJmxWrapper wrapper = createWrapper(createConfiguration());
wrapper.setCacheObjectName(on.getCanonicalName());
// Register under the standard name
registerWrapper(wrapper);
// Should be registered under 'on'
registered = mBeanServer.isRegistered(on);
assertTrue("Registered with configured name", registered);
assertEquals("Configured name retained", on.getCanonicalName(), wrapper.getCacheObjectName());
wrapper.create();
wrapper.start();
interceptorRegistrationTest(on.getCanonicalName(), true);
wrapper.stop();
wrapper.destroy();
interceptorRegistrationTest(false);
}
finally
{
if (registered)
mBeanServer.unregisterMBean(on);
}
}
public void testGetCacheObjectName() throws Exception
{
ObjectName on = new ObjectName("jboss.cache:test=SetCacheObjectName");
String str = on.getCanonicalName();
CacheJmxWrapper wrapper = createWrapper(createConfiguration());
wrapper.setCacheObjectName(str);
assertEquals("Setter and getter match", str, wrapper.getCacheObjectName());
// Go back to the default
wrapper.setCacheObjectName(null);
assertEquals("Got default ObjectName", JmxUtil.PREFIX + CLUSTER_NAME, wrapper.getCacheObjectName());
registerWrapper(wrapper);
assertEquals("Returns standard name", mBeanName, new ObjectName(wrapper.getCacheObjectName()));
}
public void testGetConfiguration1() throws Exception
{
CacheJmxWrapperMBean wrapper = registerWrapper();
Configuration cfgFromJmx = wrapper.getConfiguration();
assertNotNull("Got a configuration", cfgFromJmx);
assertSame(cache.getConfiguration(), cfgFromJmx);
}
public void testGetConfiguration2() throws Exception
{
Configuration cfg = createConfiguration();
CacheJmxWrapperMBean wrapper = registerWrapper(cfg);
Configuration cfgFromJmx = wrapper.getConfiguration();
assertNotNull("Got a configuration", cfgFromJmx);
assertSame(cfg, cfgFromJmx);
}
/**
* Note that this is a bit of a 'white box' test as it assumes that the
* returned String equals Configuration.toString(). That could change and
* break this test; if it does, and there's nothing wrong with the
* change, just modify the test.
*
* @throws Exception
*/
public void testPrintConfigurationAsString1() throws Exception
{
CacheJmxWrapperMBean wrapper = registerWrapper();
String cfgFromJmx = wrapper.printConfigurationAsString();
assertEquals(cache.getConfiguration().toString(), cfgFromJmx);
}
/**
* Note that this is a bit of a 'white box' test as it assumes that the
* returned String equals Configuration.toString(). That could change and
* break this test; if it does, and there's nothing wrong with the
* change, just modify the test.
*
* @throws Exception
*/
public void testPrintConfigurationAsString2() throws Exception
{
Configuration cfg = createConfiguration();
CacheJmxWrapperMBean wrapper = registerWrapper(cfg);
wrapper.create();
wrapper.start();
String cfgFromJmx = wrapper.printConfigurationAsString();
assertEquals(wrapper.getCache().getConfiguration().toString(), cfgFromJmx);
}
/**
* Note that this is a bit of a 'white box' test as it checks
* the currently coded HTML format and assumes that the HTML content is
* derived from Configuration.toString(). That could change and break
* this test; if it does, and there's nothing wrong with the
* change, just modify the test.
*
* @throws Exception
*/
public void testPrintConfigurationAsHtml1() throws Exception
{
CacheJmxWrapperMBean wrapper = registerWrapper();
String cfgFromJmx = wrapper.printConfigurationAsHtmlString();
assertEquals(CacheJmxWrapper.formatHtml(cache.getConfiguration().toString()), cfgFromJmx);
checkHtml(cfgFromJmx, false);
}
/**
* Note that this is a bit of a 'white box' test as it checks
* the currently coded HTML format and assumes that the HTML content is
* derived from Configuration.toString(). That could change and break
* this test; if it does, and there's nothing wrong with the
* change, just modify the test.
*
* @throws Exception
*/
public void testPrintConfigurationAsHtml2() throws Exception
{
Configuration cfg = createConfiguration();
CacheJmxWrapperMBean wrapper = registerWrapper(cfg);
wrapper.create();
wrapper.start();
String cfgFromJmx = wrapper.printConfigurationAsHtmlString();
assertEquals(CacheJmxWrapper.formatHtml(wrapper.getCache().getConfiguration().toString()), cfgFromJmx);
checkHtml(cfgFromJmx, false);
}
@SuppressWarnings("unchecked")
public void testGetCache() throws Exception
{
registerWrapper();
// have to start the cache before we'll have a root
cache.start();
Cache cacheJmx = (Cache) mBeanServer.getAttribute(mBeanName, "Cache");
cacheJmx.getRoot().put("key", "value");
assertEquals("value", cache.getRoot().get("key"));
Fqn fqn = Fqn.fromString("/testing/jmx");
cache.put(fqn, "key", "value");
assertEquals("value", cacheJmx.get(fqn, "key"));
}
public void testPrintCacheDetails() throws Exception
{
printCacheDetailsTest(false);
}
/**
* Note that this is a bit of a 'white box' test as it checks
* the currently coded HTML format. That could change and break
* this test; if it does, and there's nothing wrong with the
* change, just modify the test.
*
* @throws Exception
*/
public void testPrintCacheDetailsAsHtml() throws Exception
{
String html = printCacheDetailsTest(true);
checkHtml(html, true);
}
public void testPrintLockInfo() throws Exception
{
printLockInfoTest(false);
}
/**
* Note that this is a bit of a 'white box' test as it checks
* the currently coded HTML format. That could change and break
* this test; if it does, and there's nothing wrong with the
* change, just modify the test.
*
* @throws Exception
*/
public void testPrintLockInfoAsHtml() throws Exception
{
printLockInfoTest(true);
}
public void testGetLocalAddress() throws Exception
{
Configuration c = createConfiguration();
c.setCacheMode(CacheMode.REPL_ASYNC);
CacheJmxWrapperMBean wrapper = registerWrapper(c);
wrapper.start();
assertTrue("Got an IpAddress", wrapper.getLocalAddress() instanceof IpAddress);
}
public void testGetMembers() throws Exception
{
Configuration c = createConfiguration();
c.setCacheMode(CacheMode.REPL_ASYNC);
CacheJmxWrapperMBean wrapper = registerWrapper(c);
wrapper.start();
c = createConfiguration();
c.setCacheMode(CacheMode.REPL_ASYNC);
Cache cache2 = null;
try
{
cache2 = createCache(c);
cache2.start();
Cache[] caches = new Cache[]{wrapper.getCache(), cache2};
TestingUtil.blockUntilViewsReceived(caches, 5000);
Address addr = wrapper.getLocalAddress();
assertNotNull("Got an Address", addr);
List members = wrapper.getMembers();
assertNotNull("Got members", addr);
assertEquals("Got correct number of members", 2, members.size());
assertTrue("I am a member", members.contains(addr));
}
finally
{
if (cache2 != null)
{
cache2.destroy();
}
}
}
public void testDuplicateInvocation() throws Exception
{
CacheJmxWrapperMBean cache = registerWrapper();
cache.create();
cache.start();
cache.create();
cache.start();
cache.getCache().put(Fqn.fromString("/a/b/c"), null);
assertTrue(cache.getNumberOfNodes() > 0);
assertEquals(0, cache.getNumberOfAttributes());
System.out.println("cache locks before restart:\n" + cache.printLockInfo());
cache.destroy();
cache.start();
System.out.println("cache locks after restart:\n" + cache.printLockInfo());
assertEquals(0, cache.getNumberOfNodes());
assertEquals(0, cache.getNumberOfAttributes());
cache.stop();
cache.destroy();
cache.stop();
cache.destroy();
}
public void testFailedStart() throws Exception
{
CacheJmxWrapper wrapper = new CacheJmxWrapper(createCache(createConfiguration()));
registerWrapper(wrapper);
assertEquals("Correct state", CacheStatus.INSTANTIATED, wrapper.getCacheStatus());
wrapper.create();
DisruptLifecycleListener listener = new DisruptLifecycleListener();
listener.setDisrupt(true);
wrapper.getCache().addCacheListener(listener);
assertEquals("Correct state", CacheStatus.CREATED, wrapper.getCacheStatus());
try
{
wrapper.start();
fail("Listener did not prevent start");
}
catch (CacheException good)
{
}
assertEquals("Correct state", CacheStatus.FAILED, wrapper.getCacheStatus());
listener.setDisrupt(false);
wrapper.start();
assertEquals("Correct state", CacheStatus.STARTED, wrapper.getCacheStatus());
wrapper.getCache().put(Fqn.fromString("/a/b/c"), null);
assertTrue(wrapper.getNumberOfNodes() > 0);
assertEquals(0, wrapper.getNumberOfAttributes());
listener.setDisrupt(true);
// need to re-add the listener since the failed start would have nullified the notifier.
cache.addCacheListener(listener);
try
{
wrapper.stop();
fail("Listener did not prevent stop");
}
catch (CacheException good)
{
}
assertEquals("Correct state", CacheStatus.FAILED, wrapper.getCacheStatus());
listener.setDisrupt(false);
wrapper.stop();
assertEquals("Correct state", CacheStatus.STOPPED, wrapper.getCacheStatus());
wrapper.destroy();
assertEquals("Correct state", CacheStatus.DESTROYED, wrapper.getCacheStatus());
}
private String printCacheDetailsTest(boolean html) throws Exception
{
CacheJmxWrapperMBean wrapper = registerWrapper();
// have to start the cache before we'll have a root
cache.start();
Fqn fqn = Fqn.fromString("/testing/jmx");
cache.put(fqn, "foobar", "barfoo");
assertEquals("barfoo", cache.get(fqn, "foobar"));
String details = html ? wrapper.printCacheDetailsAsHtml() : wrapper.printCacheDetails();
assertTrue("Details include testing", details.contains("testing"));
assertTrue("Details include jmx", details.contains("jmx"));
assertTrue("Details include foobar", details.contains("foobar"));
assertTrue("Details include barfoo", details.contains("barfoo"));
return details;
}
private String printLockInfoTest(boolean html) throws Exception
{
Configuration config = createConfiguration();
config.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
Cache c = createCache(config);
CacheJmxWrapperMBean wrapper = registerWrapper(c);
// wrapper.setManageCacheLifecycle(true);
wrapper.create();
wrapper.start();
TransactionManager tm = config.getRuntimeConfig().getTransactionManager();
tm.begin();
try
{
Fqn fqn = Fqn.fromString("/testing/jmx");
cache.put(fqn, "foobar", "barfoo");
String locks = html ? wrapper.printLockInfoAsHtml() : wrapper.printLockInfo();
assertTrue("Details include testing", locks.contains("testing"));
assertTrue("Details include jmx", locks.contains("jmx"));
return locks;
}
catch (Exception e)
{
tm.setRollbackOnly();
throw e;
}
finally
{
tm.commit();
}
}
private void checkHtml(String html, boolean checkBR)
{
if (checkBR)
assertTrue("Has