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

Brian Stansberry brian.stansberry at jboss.com
Fri Jan 12 17:59:38 EST 2007


  User: bstansberry
  Date: 07/01/12 17:59:38

  Added:       tests/functional/org/jboss/cache/api 
                        PutForExternalReadTest.java
  Log:
  Add trivial testing of putForExternalRead
  
  Revision  Changes    Path
  1.1      date: 2007/01/12 22:59:38;  author: bstansberry;  state: Exp;JBossCache/tests/functional/org/jboss/cache/api/PutForExternalReadTest.java
  
  Index: PutForExternalReadTest.java
  ===================================================================
  package org.jboss.cache.api;
  
  import junit.framework.TestCase;
  
  import org.jboss.cache.CacheImpl;
  import org.jboss.cache.CacheSPI;
  import org.jboss.cache.Fqn;
  import org.jboss.cache.DefaultCacheFactory;
  import org.jboss.cache.config.Configuration.CacheMode;
  import org.jboss.cache.factories.UnitTestCacheFactory;
  import org.jboss.cache.misc.TestingUtil;
  
  public class PutForExternalReadTest extends TestCase
  {
     private static final Fqn FQN = Fqn.fromString("/a/b");
     private static final String KEY = "key";
     private static final String VALUE = "value";
     
     private CacheSPI[] caches;
     
     protected void tearDown() throws Exception
     {
        if (caches != null)
        {
           try
           {
              for (int i = 0; i < caches.length; i++)
              {
                 if (caches[i] != null)
                 {
                    caches[i].stop();
                    caches[i].destroy();
                 }
              }
           }
           finally
           {
              caches = null;
           }
        }
     }
     
     private void createCaches(boolean sync) throws Exception
     {
        CacheImpl cache0 = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
        cache0.setConfiguration(UnitTestCacheFactory.createConfiguration(sync ? CacheMode.REPL_SYNC : CacheMode.REPL_ASYNC));
        CacheImpl cache1 = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
        cache1.setConfiguration(UnitTestCacheFactory.createConfiguration(sync ? CacheMode.REPL_SYNC : CacheMode.REPL_ASYNC));
        
        caches = new CacheSPI[2];
        caches[0] = cache0;
        caches[1] = cache1;
        
        cache0.start();
        cache1.start();
        
        TestingUtil.blockUntilViewsReceived(caches, 5000);
     }
     
     public void testAsync() throws Exception
     {
        createCaches(false);
        simpleTest(false);
     }
     
     public void testAsyncTx() throws Exception
     {
        createCaches(false);
        simpleTest(true);
     }
     
     public void testSync() throws Exception
     {
        createCaches(true);
        simpleTest(false);
     }
  
     public void testSyncTx() throws Exception
     {
        createCaches(true);
        simpleTest(true);
     }
     
     private void simpleTest(boolean useTx) throws Exception
     {
        assertNull("Cache 1 empty", caches[1].get(FQN, KEY));
        
        if (useTx)
        {
           caches[0].getTransactionManager().begin();
        }
        
        caches[0].putForExternalRead(FQN, KEY, VALUE);
        if (useTx)
        {
           caches[0].getTransactionManager().commit();
        }
        
        TestingUtil.sleepThread(25);
        
        assertEquals("Cache 1 got value", VALUE, caches[1].get(FQN, KEY));
     }
  }
  
  
  



More information about the jboss-cvs-commits mailing list