[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/multiplexer ...

Brian Stansberry brian.stansberry at jboss.com
Tue Jan 2 23:03:47 EST 2007


  User: bstansberry
  Date: 07/01/02 23:03:47

  Added:       tests/functional/org/jboss/cache/multiplexer         
                        BuddyAssignmentStateTransferTest.java
                        SyncReplTxTest.java
                        BuddyReplicationFailoverTest.java
                        BuddyBackupActivationInactivationTest.java
                        AsyncReplTest.java StateTransferTest.java
                        BadMuxConfigTest.java BuddyGroupAssignmentTest.java
                        MultiplexerTestHelper.java
  Log:
  [JBCACHE-920] Port multiplexer integration tests to HEAD
  
  Revision  Changes    Path
  1.2       +70 -0     JBossCache/tests/functional/org/jboss/cache/multiplexer/BuddyAssignmentStateTransferTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: BuddyAssignmentStateTransferTest.java
  ===================================================================
  RCS file: BuddyAssignmentStateTransferTest.java
  diff -N BuddyAssignmentStateTransferTest.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ BuddyAssignmentStateTransferTest.java	3 Jan 2007 04:03:47 -0000	1.2
  @@ -0,0 +1,70 @@
  +/*
  + * 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.multiplexer;
  +
  +import org.jboss.cache.Cache;
  +
  +/**
  + * Repeats the superclass tests, but with the multiplexer enabled.
  + * 
  + * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
  + * @version $Revision: 1.2 $
  + */
  +public class BuddyAssignmentStateTransferTest 
  +   extends org.jboss.cache.buddyreplication.BuddyAssignmentStateTransferTest
  +{
  +   private MultiplexerTestHelper muxHelper;
  +   
  +   protected void setUp() throws Exception
  +   {
  +      muxHelper = new MultiplexerTestHelper();
  +      
  +      super.setUp();
  +   }
  +
  +   protected void tearDown() throws Exception
  +   {
  +      try
  +      {
  +         super.tearDown();
  +      }
  +      finally
  +      {
  +         if (muxHelper != null)
  +            muxHelper.tearDown();
  +         muxHelper = null;
  +      }
  +   }
  +
  +   @Override
  +   protected void configureMultiplexer(Cache cache) throws Exception
  +   {
  +      muxHelper.configureCacheForMux(cache);
  +   }
  +   
  +   @Override
  +   protected void validateMultiplexer(Cache cache)
  +   {
  +      assertTrue("Cache is using multiplexer", cache.getConfiguration().isUsingMultiplexer());
  +   }
  +   
  +}
  
  
  
  1.2       +76 -0     JBossCache/tests/functional/org/jboss/cache/multiplexer/SyncReplTxTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SyncReplTxTest.java
  ===================================================================
  RCS file: SyncReplTxTest.java
  diff -N SyncReplTxTest.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ SyncReplTxTest.java	3 Jan 2007 04:03:47 -0000	1.2
  @@ -0,0 +1,76 @@
  +/*
  + * 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.multiplexer;
  +
  +import org.jboss.cache.Cache;
  +
  +
  +/**
  + * Repeats the superclass tests, but with the multiplexer enabled.
  + * 
  + * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
  + * @version $Revision: 1.2 $
  + */
  +public class SyncReplTxTest extends org.jboss.cache.replicated.SyncReplTxTest
  +{
  +   private MultiplexerTestHelper muxHelper;
  +
  +   public SyncReplTxTest(String name) {
  +      super(name);
  +   }
  +   
  +   public void setUp() throws Exception
  +   {
  +      muxHelper = new MultiplexerTestHelper();
  +      
  +      super.setUp();
  +   }
  +
  +   public void tearDown() throws Exception
  +   {
  +      try
  +      {
  +         super.tearDown();
  +      }
  +      finally
  +      {
  +         if (muxHelper != null)
  +         {
  +            muxHelper.tearDown();
  +            muxHelper = null;
  +         }
  +      }
  +   }
  +
  +   @Override   
  +   protected void configureMultiplexer(Cache cache) throws Exception
  +   {
  +      muxHelper.configureCacheForMux(cache);
  +   }
  +   
  +   @Override   
  +   protected void validateMultiplexer(Cache cache)
  +   {
  +      assertTrue("Cache is using multiplexer", cache.getConfiguration().isUsingMultiplexer());
  +   }
  +   
  +}
  
  
  
  1.2       +71 -0     JBossCache/tests/functional/org/jboss/cache/multiplexer/BuddyReplicationFailoverTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: BuddyReplicationFailoverTest.java
  ===================================================================
  RCS file: BuddyReplicationFailoverTest.java
  diff -N BuddyReplicationFailoverTest.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ BuddyReplicationFailoverTest.java	3 Jan 2007 04:03:47 -0000	1.2
  @@ -0,0 +1,71 @@
  +/*
  + * 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.multiplexer;
  +
  +import org.jboss.cache.Cache;
  +
  +
  +/**
  + * Repeats the superclass tests, but with the multiplexer enabled.
  + * 
  + * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
  + * @version $Revision: 1.2 $
  + */
  +public class BuddyReplicationFailoverTest 
  +   extends org.jboss.cache.buddyreplication.BuddyReplicationFailoverTest
  +{
  +   private MultiplexerTestHelper muxHelper;
  +   
  +   protected void setUp() throws Exception
  +   {
  +      muxHelper = new MultiplexerTestHelper();
  +      
  +      super.setUp();
  +   }
  +
  +   protected void tearDown() throws Exception
  +   {
  +      try
  +      {
  +         super.tearDown();
  +      }
  +      finally
  +      {
  +         if (muxHelper != null)
  +            muxHelper.tearDown();
  +         muxHelper = null;
  +      }
  +   }
  +
  +   @Override
  +   protected void configureMultiplexer(Cache cache) throws Exception
  +   {
  +      muxHelper.configureCacheForMux(cache);
  +   }
  +   
  +   @Override
  +   protected void validateMultiplexer(Cache cache)
  +   {
  +      assertTrue("Cache is using multiplexer", cache.getConfiguration().isUsingMultiplexer());
  +   }
  +   
  +}
  
  
  
  1.2       +70 -0     JBossCache/tests/functional/org/jboss/cache/multiplexer/BuddyBackupActivationInactivationTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: BuddyBackupActivationInactivationTest.java
  ===================================================================
  RCS file: BuddyBackupActivationInactivationTest.java
  diff -N BuddyBackupActivationInactivationTest.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ BuddyBackupActivationInactivationTest.java	3 Jan 2007 04:03:47 -0000	1.2
  @@ -0,0 +1,70 @@
  +/*
  + * 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.multiplexer;
  +
  +import org.jboss.cache.Cache;
  +
  +/**
  + * Repeats the superclass tests, but with the multiplexer enabled.
  + * 
  + * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
  + * @version $Revision: 1.2 $
  + */
  +public class BuddyBackupActivationInactivationTest 
  +   extends org.jboss.cache.buddyreplication.BuddyBackupActivationInactivationTest
  +{
  +   private MultiplexerTestHelper muxHelper;
  +   
  +   protected void setUp() throws Exception
  +   {
  +      muxHelper = new MultiplexerTestHelper();
  +      
  +      super.setUp();
  +   }
  +
  +   protected void tearDown() throws Exception
  +   {
  +      try
  +      {
  +         super.tearDown();
  +      }
  +      finally
  +      {
  +         if (muxHelper != null)
  +            muxHelper.tearDown();
  +         muxHelper = null;
  +      }
  +   }
  +
  +   @Override
  +   protected void configureMultiplexer(Cache cache) throws Exception
  +   {
  +      muxHelper.configureCacheForMux(cache);
  +   }
  +   
  +   @Override
  +   protected void validateMultiplexer(Cache cache)
  +   {
  +      assertTrue("Cache is using multiplexer", cache.getConfiguration().isUsingMultiplexer());
  +   }
  +   
  +}
  
  
  
  1.2       +82 -0     JBossCache/tests/functional/org/jboss/cache/multiplexer/AsyncReplTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: AsyncReplTest.java
  ===================================================================
  RCS file: AsyncReplTest.java
  diff -N AsyncReplTest.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ AsyncReplTest.java	3 Jan 2007 04:03:47 -0000	1.2
  @@ -0,0 +1,82 @@
  +/*
  + * 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.multiplexer;
  +
  +import org.jboss.cache.Cache;
  +
  +/**
  + * Repeats the superclass tests, but with the multiplexer enabled.
  + * 
  + * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
  + * @version $Revision: 1.2 $
  + */
  +public class AsyncReplTest extends org.jboss.cache.replicated.AsyncReplTest
  +{
  +   private MultiplexerTestHelper muxHelper;
  +
  +   public AsyncReplTest(String name) {
  +      super(name);
  +   }
  +   
  +   
  +   @Override
  +   public void testAsyncReplDelay()
  +   {
  +      // TODO Auto-generated method stub
  +      super.testAsyncReplDelay();
  +   }
  +
  +
  +   public void setUp() throws Exception
  +   {
  +      muxHelper = new MultiplexerTestHelper();
  +      
  +      super.setUp();
  +   }
  +
  +   public void tearDown() throws Exception
  +   {
  +      try
  +      {
  +         super.tearDown();
  +      }
  +      finally
  +      {
  +         if (muxHelper != null)
  +         {
  +            muxHelper.tearDown();
  +            muxHelper = null;
  +         }
  +      }
  +   }
  +
  +   protected void configureMultiplexer(Cache cache) throws Exception
  +   {
  +      muxHelper.configureCacheForMux(cache);
  +   }
  +   
  +   protected void validateMultiplexer(Cache cache)
  +   {
  +      assertTrue("Cache is using multiplexer", cache.getConfiguration().isUsingMultiplexer());
  +   }
  +   
  +}
  
  
  
  1.2       +72 -0     JBossCache/tests/functional/org/jboss/cache/multiplexer/StateTransferTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: StateTransferTest.java
  ===================================================================
  RCS file: StateTransferTest.java
  diff -N StateTransferTest.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ StateTransferTest.java	3 Jan 2007 04:03:47 -0000	1.2
  @@ -0,0 +1,72 @@
  +/*
  + * 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.multiplexer;
  +
  +import org.jboss.cache.Cache;
  +import org.jboss.cache.statetransfer.StateTransfer200Test;
  +
  +/**
  + * Repeats the superclass tests, but with the multiplexer enabled.
  + * 
  + * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
  + * @version $Revision: 1.2 $
  + */
  +public class StateTransferTest extends StateTransfer200Test
  +{
  +   private MultiplexerTestHelper muxHelper;
  +   
  +   protected void setUp() throws Exception
  +   {
  +      muxHelper = new MultiplexerTestHelper();
  +      
  +      super.setUp();
  +   }
  +
  +   protected void tearDown() throws Exception
  +   {
  +      try
  +      {
  +         super.tearDown();
  +      }
  +      finally
  +      {
  +         if (muxHelper != null)
  +         {
  +            muxHelper.tearDown();
  +            muxHelper = null;
  +         }
  +      }
  +   }
  +
  +   @Override
  +   protected void configureMultiplexer(Cache cache) throws Exception
  +   {
  +      muxHelper.configureCacheForMux(cache);
  +   }
  +   
  +   @Override
  +   protected void validateMultiplexer(Cache cache)
  +   {
  +      assertTrue("Cache is using multiplexer", cache.getConfiguration().isUsingMultiplexer());
  +   }
  +   
  +}
  
  
  
  1.2       +158 -0    JBossCache/tests/functional/org/jboss/cache/multiplexer/BadMuxConfigTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: BadMuxConfigTest.java
  ===================================================================
  RCS file: BadMuxConfigTest.java
  diff -N BadMuxConfigTest.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ BadMuxConfigTest.java	3 Jan 2007 04:03:47 -0000	1.2
  @@ -0,0 +1,158 @@
  +package org.jboss.cache.multiplexer;
  +
  +import javax.management.MBeanServer;
  +import javax.management.MBeanServerFactory;
  +import javax.management.ObjectName;
  +
  +import org.jboss.cache.Cache;
  +import org.jboss.cache.CacheImpl;
  +import org.jboss.cache.config.Configuration;
  +import org.jgroups.JChannel;
  +
  +import junit.framework.TestCase;
  +
  +/**
  + * Tests that JBC starts correctly even if the multiplexer
  + * configuration is incorrect.
  + * 
  + * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
  + * @version $Revision: 1.2 $
  + */
  +public class BadMuxConfigTest 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 = new CacheImpl(config);
  +      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 testValidMuxConfig() throws Exception
  +   {
  +      muxHelper.configureCacheForMux(cache);
  +      
  +      checkStart(false, true);      
  +   }
  +   
  +   public void testMuxConfigViaInjection() throws Exception
  +   {
  +      muxHelper.configureCacheForMuxViaDirectInjection(cache);
  +      
  +      checkStart(false, true);      
  +   }
  +   
  +   public void testWrongMBeanServer() throws Exception
  +   {
  +      ObjectName on = muxHelper.createMuxChannelFactory(cache.getConfiguration().getClusterConfig());
  +      cache.getConfiguration().setMultiplexerService(on.getCanonicalName());
  +      cache.getConfiguration().setMultiplexerStack(MultiplexerTestHelper.MUX_STACK);
  +      
  +      MBeanServer wrong = 
  +         MBeanServerFactory.createMBeanServer("wrong");
  +      try
  +      {
  +         cache.getConfiguration().getRuntimeConfig().setMbeanServer(wrong);
  +         checkStart(false, false);
  +      }
  +      finally
  +      {
  +         MBeanServerFactory.releaseMBeanServer(wrong);
  +      }
  +   }
  +   
  +   public void testBadMuxServiceName() throws Exception
  +   {
  +      muxHelper.configureCacheForMux(cache);
  +      // This creates a non-conformant ObjectName
  +      String badName = cache.getConfiguration().getMultiplexerService() + ",bad";
  +      cache.getConfiguration().setMultiplexerService(badName);
  +      
  +      checkStart(false, false);
  +   }
  +   
  +   public void testInvalidMuxServiceName() throws Exception
  +   {
  +      muxHelper.configureCacheForMux(cache);
  +      // This is a valid but non-existent ObjectName
  +      String badName = cache.getConfiguration().getMultiplexerService() + ",type=invalid";
  +      cache.getConfiguration().setMultiplexerService(badName);
  +      
  +      checkStart(false, false);      
  +   }
  +   
  +   public void testMissingMuxServiceName() throws Exception
  +   {
  +      muxHelper.configureCacheForMux(cache);
  +      cache.getConfiguration().setMultiplexerService(null);
  +      
  +      checkStart(false, false);       
  +   }
  +   
  +   public void testInvalidStackName() throws Exception
  +   {
  +      muxHelper.configureCacheForMux(cache);
  +      cache.getConfiguration().setMultiplexerStack("bogus");
  +      
  +      checkStart(false, false);      
  +   }
  +   
  +   public void testMissingStackName() throws Exception
  +   {
  +      muxHelper.configureCacheForMux(cache);
  +      cache.getConfiguration().setMultiplexerStack(null);
  +      
  +      checkStart(false, false);      
  +   }
  +
  +   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());
  +      }
  +      
  +   }
  +}
  
  
  
  1.2       +70 -0     JBossCache/tests/functional/org/jboss/cache/multiplexer/BuddyGroupAssignmentTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: BuddyGroupAssignmentTest.java
  ===================================================================
  RCS file: BuddyGroupAssignmentTest.java
  diff -N BuddyGroupAssignmentTest.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ BuddyGroupAssignmentTest.java	3 Jan 2007 04:03:47 -0000	1.2
  @@ -0,0 +1,70 @@
  +/*
  + * 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.multiplexer;
  +
  +import org.jboss.cache.Cache;
  +
  +/**
  + * Repeats the superclass tests, but with the multiplexer enabled.
  + * 
  + * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
  + * @version $Revision: 1.2 $
  + */
  +public class BuddyGroupAssignmentTest 
  +   extends org.jboss.cache.buddyreplication.BuddyGroupAssignmentTest
  +{
  +   private MultiplexerTestHelper muxHelper;
  +   
  +   protected void setUp() throws Exception
  +   {
  +      muxHelper = new MultiplexerTestHelper();
  +      
  +      super.setUp();
  +   }
  +
  +   protected void tearDown() throws Exception
  +   {
  +      try
  +      {
  +         super.tearDown();
  +      }
  +      finally
  +      {
  +         if (muxHelper != null)
  +            muxHelper.tearDown();
  +         muxHelper = null;
  +      }
  +   }
  +
  +   @Override
  +   protected void configureMultiplexer(Cache cache) throws Exception
  +   {
  +      muxHelper.configureCacheForMux(cache);
  +   }
  +   
  +   @Override
  +   protected void validateMultiplexer(Cache cache)
  +   {
  +      assertTrue("Cache is using multiplexer", cache.getConfiguration().isUsingMultiplexer());
  +   }
  +   
  +}
  
  
  
  1.2       +315 -0    JBossCache/tests/functional/org/jboss/cache/multiplexer/MultiplexerTestHelper.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: MultiplexerTestHelper.java
  ===================================================================
  RCS file: MultiplexerTestHelper.java
  diff -N MultiplexerTestHelper.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ MultiplexerTestHelper.java	3 Jan 2007 04:03:47 -0000	1.2
  @@ -0,0 +1,315 @@
  +/*
  + * 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.multiplexer;
  +
  +import java.util.Collections;
  +import java.util.HashSet;
  +import java.util.Iterator;
  +import java.util.Set;
  +import java.util.StringTokenizer;
  +
  +import javax.management.MBeanServer;
  +import javax.management.MBeanServerFactory;
  +import javax.management.ObjectName;
  +import javax.xml.parsers.DocumentBuilder;
  +import javax.xml.parsers.DocumentBuilderFactory;
  +
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
  +import org.jboss.cache.Cache;
  +import org.jgroups.JChannel;
  +import org.jgroups.JChannelFactory;
  +import org.jgroups.jmx.JChannelFactoryMBean;
  +import org.w3c.dom.Document;
  +import org.w3c.dom.Element;
  +
  +/**
  + * Utility class that can associate a cache with a JMX server and a
  + * a JGroups JChannelFactory.
  + * 
  + * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
  + * @version $Revision: 1.2 $
  + */
  +public class MultiplexerTestHelper
  +{
  +   private static final Log log = LogFactory.getLog(MultiplexerTestHelper.class);
  +   
  +   public static final String MUX_STACK = "jbc-test";
  +   private static final String FACTORY_OBJECT_NAME_BASE = "jboss.cache:service=MuxChannelFactory,count=";
  +   
  +   private MBeanServer mbeanServer;
  +   private final Set factories = Collections.synchronizedSet(new HashSet());
  +   private final Set caches = Collections.synchronizedSet(new HashSet());
  +
  +   
  +   public MultiplexerTestHelper() 
  +   {
  +      mbeanServer = 
  +         MBeanServerFactory.createMBeanServer();
  +   }
  +   
  +   /**
  +    * Configures the given cache to get its JChannel from a
  +    * multiplexer-enabled JChannelFactory.  The JChannelFactory will
  +    * produce MuxChannels configured with the same protocol stack as
  +    * whatever the provided cache is configured with.
  +    * 
  +    * @param cache
  +    * @throws Exception
  +    */
  +   public void configureCacheForMux(Cache cache) throws Exception
  +   {
  +      synchronized (caches)
  +      {
  +         ObjectName on = createMuxChannelFactory(cache);
  +         cache.getConfiguration().setMultiplexerService(on.getCanonicalName());
  +         cache.getConfiguration().setMultiplexerStack(MUX_STACK);
  +         cache.getConfiguration().getRuntimeConfig().setMbeanServer(mbeanServer);
  +//         ObjectName cacheON = new ObjectName("jboss.cache:service=TestCache,count=" + caches.size());
  +//         mbeanServer.registerMBean(cache, cacheON);
  +//         caches.add(cacheON);
  +      }
  +   }
  +   
  +   /**
  +    * Configures the given cache to get its JChannel from a
  +    * multiplexer-enabled JChannelFactory.  The JChannelFactory will
  +    * produce MuxChannels configured with the same protocol stack as
  +    * whatever the provided cache is configured with.
  +    * 
  +    * @param cache
  +    * @throws Exception
  +    */
  +   public void configureCacheForMuxViaDirectInjection(Cache cache) throws Exception
  +   {
  +      synchronized (caches)
  +      {
  +         String props = getChannelProperties(cache);
  +         
  +         JChannelFactoryMBean mbean = (JChannelFactoryMBean) createMuxChannelFactory(props, false);
  +         cache.getConfiguration().getRuntimeConfig().setMuxChannelFactory(mbean);
  +         cache.getConfiguration().setMultiplexerStack(MUX_STACK);
  +      }
  +   }
  +   
  +   /**
  +    * Creates a JChannelFactory and binds it to this object's
  +    * internal MBeanServer.  The JChannelFactory will
  +    * produce MuxChannels configured with the same protocol stack as
  +    * whatever the provided cache is configured with.
  +    * 
  +    * @param cache  the cache from which the protocol stack config should
  +    *               be obtained
  +    *               
  +    * @return the ObjectName of the channel factory.
  +    * @throws Exception
  +    */
  +   public ObjectName createMuxChannelFactory(Cache cache) throws Exception
  +   {
  +      return createMuxChannelFactory(getChannelProperties(cache));
  +   }
  +   
  +   private String getChannelProperties(Cache cache)
  +   {
  +      String props = cache.getConfiguration().getClusterConfig();
  +      return (props == null ? JChannel.DEFAULT_PROTOCOL_STACK : props);
  +   }
  +   
  +   /**
  +    * Creates a JChannelFactory and binds it to this object's
  +    * internal MBeanServer.  The JChannelFactory will
  +    * produce MuxChannels configured with according to the given 
  +    * protocol stack(s).
  +    * 
  +    * @param muxConfig  Element that looks like the root element 
  +    *                   of a multiplexer stacks.xml file.
  +    *               
  +    * @return the ObjectName of the channel factory.
  +    * @throws Exception
  +    */
  +   public ObjectName createMuxChannelFactory(String muxConfig) throws Exception
  +   { 
  +      return (ObjectName) createMuxChannelFactory(muxConfig, true);
  +   }
  +   
  +   private Object createMuxChannelFactory(String muxConfig, boolean returnObjectName) 
  +         throws Exception
  +   { 
  +      synchronized (factories)
  +      {
  +         JChannelFactory factory = new JChannelFactory();
  +         factory.setDomain("jbc.mux.test");
  +         factory.setExposeChannels(false);
  +         factory.setMultiplexerConfig(getClusterConfigElement(muxConfig));
  +            
  +         JChannelFactoryMBean muxFactory = new org.jgroups.jmx.JChannelFactory(factory);
  +         // Give the factory a unique ObjectName
  +         ObjectName on = new ObjectName(FACTORY_OBJECT_NAME_BASE + factories.size());
  +         mbeanServer.registerMBean(muxFactory, on);
  +         
  +         factories.add(on);
  +         
  +         muxFactory.create();
  +         muxFactory.start();
  +         
  +         return returnObjectName ? on : muxFactory;   
  +      }
  +   }
  +   
  +   /**
  +    * Converts an old-style JGroups protocol stack config string to an Element
  +    * that looks like the root element of a multiplexer stacks.xml file.
  +    * 
  +    * @param clusterConfig
  +    * @return
  +    * @throws Exception
  +    */
  +   public static Element getClusterConfigElement(String clusterConfig) throws Exception
  +   {
  +      clusterConfig = clusterConfig.trim();
  +      DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
  +      Document doc = db.newDocument();
  +      Element top = doc.createElement("protocol_stacks");
  +      doc.appendChild(top);
  +      Element stack = doc.createElement("stack");
  +      stack.setAttribute("name", MUX_STACK);
  +      top.appendChild(stack);
  +      Element config = doc.createElement("config");
  +      
  +      StringTokenizer outer = new StringTokenizer(clusterConfig, ":");
  +      while (outer.hasMoreTokens())
  +      {
  +         String protocol = outer.nextToken();
  +         String protName = protocol;
  +         String attribs = null;
  +         int nameEnd = protocol.indexOf('(');         
  +         if (nameEnd > 0)
  +         {
  +            protName = protocol.substring(0, nameEnd);
  +            attribs = protocol.substring(nameEnd + 1, protocol.length() -1);
  +         }
  +         Element element = doc.createElement(protName);
  +         if (attribs != null && attribs.length() > 0)
  +         {
  +            StringTokenizer inner = new StringTokenizer(attribs, ";");
  +            while (inner.hasMoreTokens())
  +            {
  +               String attrib = inner.nextToken();
  +               int eq = attrib.indexOf('=');
  +               String name = attrib.substring(0, eq);
  +               String value = attrib.substring(eq +1);
  +               element.setAttribute(name, value);
  +            }
  +         }
  +         config.appendChild(element);
  +      }
  +
  +      stack.appendChild(config);
  +      return top;
  +   }
  +
  +   /**
  +    * Performs cleanup work, most importantly unregistering the
  +    * internal MBeanServer.  Once this method is invoked, this
  +    * object should no longer be used.
  +    */
  +   public void tearDown()
  +   {
  +      try
  +      {
  +         for (Iterator it = caches.iterator(); it.hasNext(); )
  +         {
  +            try
  +            {
  +               mbeanServer.unregisterMBean((ObjectName) it.next());
  +            }
  +            catch (Exception e)
  +            {
  +               log.error(e);
  +            }
  +         }
  +         
  +         for (Iterator it = factories.iterator(); it.hasNext(); )
  +         {
  +            try
  +            {
  +               mbeanServer.unregisterMBean((ObjectName) it.next());
  +            }
  +            catch (Exception e)
  +            {
  +               log.error(e);
  +            }
  +         }
  +      }
  +      catch (Exception e)
  +      {
  +         log.error(e);
  +      }
  +      finally
  +      {         
  +         factories.clear();
  +         caches.clear();
  +         
  +         if (mbeanServer != null)
  +         {
  +            MBeanServerFactory.releaseMBeanServer(mbeanServer);
  +            mbeanServer = null;
  +         }
  +         
  +         
  +      }
  +   }
  +   
  +   /**
  +    * Makes sure the internal MBeanServer is unregistered.
  +    */
  +   protected void finalize() throws Throwable
  +   {
  +      if (mbeanServer != null)
  +      {
  +         MBeanServerFactory.releaseMBeanServer(mbeanServer);
  +      }
  +      super.finalize();
  +   }
  +
  +   /**
  +    * Tests creation of a channel factory.
  +    * 
  +    * @param args
  +    */
  +   public static void main(String[] args)
  +   {
  +      MultiplexerTestHelper helper = new MultiplexerTestHelper();
  +      try
  +      {         
  +         helper.createMuxChannelFactory(JChannel.DEFAULT_PROTOCOL_STACK);
  +      }
  +      catch (Exception e)
  +      {
  +         e.printStackTrace();
  +      }
  +      finally
  +      {
  +         helper.tearDown();
  +      }
  +   }
  +}
  
  
  



More information about the jboss-cvs-commits mailing list