[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/multiplexer ...
Brian Stansberry
brian.stansberry at jboss.com
Wed May 9 14:32:32 EDT 2007
User: bstansberry
Date: 07/05/09 14:32:32
Added: tests/functional/org/jboss/cache/multiplexer
ChannelInjectionPreferenceTest.java
Log:
[JBCACHE--1023] Inject preconfigured Channel
Revision Changes Path
1.1 date: 2007/05/09 18:32:32; author: bstansberry; state: Exp;JBossCache/tests/functional/org/jboss/cache/multiplexer/ChannelInjectionPreferenceTest.java
Index: ChannelInjectionPreferenceTest.java
===================================================================
package org.jboss.cache.multiplexer;
import junit.framework.TestCase;
import org.jboss.cache.Cache;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.RuntimeConfig;
import org.jgroups.Channel;
import org.jgroups.JChannel;
/**
* Tests that JBC prefers an injected Channel to creating one via
* a configured JChannelFactory and stack name.
*
* @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
* @version $Revision: 1.1 $
*/
public class ChannelInjectionPreferenceTest extends TestCase
{
private MultiplexerTestHelper muxHelper;
private Cache cache;
private boolean cacheStarted;
protected void setUp() throws Exception
{
muxHelper = new MultiplexerTestHelper();
Configuration config = new Configuration();
config.setCacheMode(Configuration.CacheMode.REPL_SYNC);
config.setClusterConfig(JChannel.DEFAULT_PROTOCOL_STACK);
cache = DefaultCacheFactory.getInstance().createCache(config, false);
cacheStarted = false;
super.setUp();
}
public void tearDown() throws Exception
{
try
{
super.tearDown();
if (cacheStarted && cache != null)
{
cache.stop();
cache.destroy();
}
}
finally
{
if (muxHelper != null)
{
muxHelper.tearDown();
muxHelper = null;
}
}
}
public void testChannelInjectionPreference() throws Exception
{
muxHelper.configureCacheForMux(cache);
Channel channel = new JChannel(JChannel.DEFAULT_PROTOCOL_STACK);
RuntimeConfig rtcfg = cache.getConfiguration().getRuntimeConfig();
rtcfg.setChannel(channel);
// Start shouldn't fail and we shouldn't be using mulitplexer
checkStart(false, false);
assertEquals("Injected channel used", channel, rtcfg.getChannel());
}
private void checkStart(boolean expectFail, boolean expectMux)
{
try
{
cache.start();
cacheStarted = true;
if (expectFail)
{
fail("Start did not fail as expected");
}
if (expectMux)
{
assertTrue("Cache is using mux", cache.getConfiguration().isUsingMultiplexer());
}
else
{
assertFalse("Cache is not using mux ", cache.getConfiguration().isUsingMultiplexer());
}
}
catch (Exception e)
{
if (!expectFail)
{
fail("Caught exception starting cache " + e.getLocalizedMessage());
}
}
}
}
More information about the jboss-cvs-commits
mailing list