Package org.jboss.cache

Examples of org.jboss.cache.Cache


    private void evictOrRemoveTest(String configName) throws Exception {
   
        Configuration cfg = createConfiguration(configName);
        JBossCacheRegionFactory regionFactory = CacheTestUtil.startRegionFactory(cfg, getCacheTestSupport());
        Cache localCache = getJBossCache(regionFactory);
        boolean invalidation = CacheHelper.isClusteredInvalidation(localCache);
       
        // Sleep a bit to avoid concurrent FLUSH problem
        avoidConcurrentFlush();
       
View Full Code Here


    private void evictOrRemoveAllTest(String configName) throws Exception {
   
        Configuration cfg = createConfiguration(configName);
        JBossCacheRegionFactory regionFactory = CacheTestUtil.startRegionFactory(cfg, getCacheTestSupport());
        Cache localCache = getJBossCache(regionFactory);
        boolean optimistic = "OPTIMISTIC".equals(localCache.getConfiguration().getNodeLockingSchemeString());
        boolean invalidation = CacheHelper.isClusteredInvalidation(localCache);
       
        // Sleep a bit to avoid concurrent FLUSH problem
        avoidConcurrentFlush();
   
        GeneralDataRegion localRegion = (GeneralDataRegion) createRegion(regionFactory, getStandardRegionName(REGION_PREFIX), cfg.getProperties(), null);
       
        cfg = createConfiguration(configName);
        regionFactory = CacheTestUtil.startRegionFactory(cfg, getCacheTestSupport());
        Cache remoteCache = getJBossCache(regionFactory);
       
        // Sleep a bit to avoid concurrent FLUSH problem
        avoidConcurrentFlush();
   
        GeneralDataRegion remoteRegion = (GeneralDataRegion) createRegion(regionFactory, getStandardRegionName(REGION_PREFIX), cfg.getProperties(), null);
        Fqn regionFqn = getRegionFqn(getStandardRegionName(REGION_PREFIX), REGION_PREFIX);
       
        Node regionRoot = localCache.getRoot().getChild(regionFqn);
        assertFalse(regionRoot == null);
        assertEquals("No children in " + regionRoot, 0, getValidChildrenCount(regionRoot));
        assertTrue(regionRoot.isResident());
       
        if (optimistic) {
            assertEquals(NonLockingDataVersion.class, ((NodeSPI) regionRoot).getVersion().getClass());
        }
   
        regionRoot = remoteCache.getRoot().getChild(regionFqn);
        assertFalse(regionRoot == null);
        assertEquals(0, getValidChildrenCount(regionRoot));
        assertTrue(regionRoot.isResident());
       
        if (optimistic) {
            assertEquals(NonLockingDataVersion.class, ((NodeSPI) regionRoot).getVersion().getClass());
        }
       
        assertNull("local is clean", localRegion.get(KEY));
        assertNull("remote is clean", remoteRegion.get(KEY));
       
        localRegion.put(KEY, VALUE1);
        assertEquals(VALUE1, localRegion.get(KEY));    
       
        // Allow async propagation
        sleep(250);
       
        remoteRegion.put(KEY, VALUE1);
        assertEquals(VALUE1, remoteRegion.get(KEY));    
       
        // Allow async propagation
        sleep(250);
       
        if (optimistic) {
            regionRoot = localCache.getRoot().getChild(regionFqn);
            assertEquals(NonLockingDataVersion.class, ((NodeSPI) regionRoot).getVersion().getClass());
            regionRoot = remoteCache.getRoot().getChild(regionFqn);
            assertEquals(NonLockingDataVersion.class, ((NodeSPI) regionRoot).getVersion().getClass());
        }
       
        localRegion.evictAll();
       
        // This should re-establish the region root node
        assertNull(localRegion.get(KEY));
       
        regionRoot = localCache.getRoot().getChild(regionFqn);
        assertFalse(regionRoot == null);
        assertEquals(0, getValidChildrenCount(regionRoot));
        assertTrue(regionRoot.isValid());
        assertTrue(regionRoot.isResident());

        // Re-establishing the region root on the local node doesn't
        // propagate it to other nodes. Do a get on the remote node to re-establish
        assertEquals(null, remoteRegion.get(KEY));
       
        regionRoot = remoteCache.getRoot().getChild(regionFqn);
        assertFalse(regionRoot == null);
        assertEquals(0, getValidChildrenCount(regionRoot));
        assertTrue(regionRoot.isValid());
        assertTrue(regionRoot.isResident());
       
View Full Code Here

        JBossCacheRegionFactory regionFactory = CacheTestUtil.startRegionFactory(cfg, getCacheTestSupport());
       
        CacheInstanceManager mgr = regionFactory.getCacheInstanceManager();
        assertTrue("Correct default CacheInstanceManager type", mgr instanceof SharedCacheInstanceManager);
       
        Cache cache = mgr.getEntityCacheInstance();
        assertTrue("entity cache exists", cache != null);
        assertEquals("Used correct config", "TestSharedCache", cache.getConfiguration().getClusterName());
        assertEquals("Cache started", CacheStatus.STARTED, cache.getCacheStatus());       
       
        CacheTestUtil.stopRegionFactory(regionFactory, getCacheTestSupport());
       
        assertEquals("Cache destroyed", CacheStatus.DESTROYED, cache.getCacheStatus());
    }
View Full Code Here

     * @throws Exception
     */
    public void testActivationDeactivation() throws Exception {
       
        // Set up a cache to monitor affects of starting the region
        Cache remoteCache = DefaultCacheFactory.getInstance().createCache(SharedCacheInstanceManager.DEFAULT_CACHE_RESOURCE, false);
       
        // This test assumes replication; verify that's correct
        assertEquals("Cache is REPL_SYNC", "REPL_SYNC", remoteCache.getConfiguration().getCacheModeString());
       
        JChannelFactory channelFactory = new JChannelFactory();
        channelFactory.setMultiplexerConfig(SharedCacheInstanceManager.DEF_JGROUPS_RESOURCE);
        remoteCache.getConfiguration().getRuntimeConfig().setMuxChannelFactory(channelFactory);
        remoteCache.start();
       
        // Make sure we stop the remoteCache
        registerCache(remoteCache);
       
        Fqn regionFqn = getRegionFqn("test/test", "test");
       
        assertNull("No region node", remoteCache.getRoot().getChild( regionFqn ));
       
        Configuration cfg = CacheTestUtil.buildConfiguration("test", SharedJBossCacheRegionFactory.class, true, true);
        JBossCacheRegionFactory regionFactory = CacheTestUtil.startRegionFactory(cfg, getCacheTestSupport());
       
        Region region = createRegion(regionFactory, "test/test", cfg.getProperties(), getCacheDataDescription());
       
        Cache localCache = getJBossCache( regionFactory );
       
        // This test assumes replication; verify that's correct
        assertEquals("Cache is REPL_SYNC", "REPL_SYNC", localCache.getConfiguration().getCacheModeString());
       
        // Region creation should not have affected remoteCache

        assertNull("No region node", remoteCache.getRoot().getChild( regionFqn ));
        Node regionRoot = localCache.getRoot().getChild( regionFqn );
        assertTrue("Has a node at " + regionFqn, regionRoot != null );
        assertTrue(regionFqn + " is resident", regionRoot.isResident() );
       
        // Confirm region destroy does not affect remote cache
       
        Option option = new Option();
        option.setCacheModeLocal(true);
        remoteCache.getInvocationContext().setOptionOverrides(option);
        remoteCache.put(regionFqn, "test", "test");
       
        assertEquals("Put succeeded", "test", remoteCache.get(regionFqn, "test"));
        assertNull("Put was local", localCache.get(regionFqn, "test"));
       
        region.destroy();
       
        assertEquals("Remote cache unchanged", "test", remoteCache.get(regionFqn, "test"));
        assertNull("No region node", localCache.getRoot().getChild( regionFqn ));
    }
View Full Code Here

        super.setUp();
       
        if (getEntityAccessStrategy() == null) {
            Configuration cfg = createConfiguration();
            JBossCacheRegionFactory rf  = CacheTestUtil.startRegionFactory(cfg, getCacheTestSupport());
            Cache localCache = rf.getCacheInstanceManager().getEntityCacheInstance();
            optimistic = localCache.getConfiguration().getNodeLockingScheme() == org.jboss.cache.config.Configuration.NodeLockingScheme.OPTIMISTIC;
           
            // Sleep a bit to avoid concurrent FLUSH problem
            avoidConcurrentFlush();
           
            EntityRegion localEntityRegion = rf.buildEntityRegion(REGION_NAME, cfg.getProperties(), null);
View Full Code Here

        super.setUp();
       
        if (getCollectionAccessStrategy() == null) {
            Configuration cfg = createConfiguration();
            JBossCacheRegionFactory rf  = CacheTestUtil.startRegionFactory(cfg, getCacheTestSupport());
            Cache localCache = rf.getCacheInstanceManager().getEntityCacheInstance();
            optimistic = localCache.getConfiguration().getNodeLockingScheme() == org.jboss.cache.config.Configuration.NodeLockingScheme.OPTIMISTIC;
           
            // Sleep a bit to avoid concurrent FLUSH problem
            avoidConcurrentFlush();
           
            CollectionRegion localCollectionRegion = rf.buildCollectionRegion(REGION_NAME, cfg.getProperties(), null);
View Full Code Here

        region = getTimestampRegion(cache);
        region.preInvalidate(KEY1, TEN);
        region.preInvalidate(KEY2, ELEVEN);
        region.invalidate(KEY1, ONE, TEN);
       
        Cache cache2 = createCache();
        registerCache(cache2);
       
        // Sleep a bit to avoid concurrent FLUSH problem
        avoidConcurrentFlush();
       
View Full Code Here

       
        region = getTimestampRegion(cache);
        ClusteredConcurrentTimestampsRegionImpl region2 = region;
       
        if (clustered) {
            Cache cache2 = createCache();
            registerCache(cache2);
           
            // Sleep a bit to avoid concurrent FLUSH problem
            avoidConcurrentFlush();
           
View Full Code Here

       
        region.put(KEY, VALUE1);
        assertEquals(VALUE1, region.get(KEY));
       
        final Fqn rootFqn = getRegionFqn(getStandardRegionName(REGION_PREFIX), REGION_PREFIX);
        final Cache jbc = getJBossCache(regionFactory);

        final CountDownLatch blockerLatch = new CountDownLatch(1);
        final CountDownLatch writerLatch = new CountDownLatch(1);
        final CountDownLatch completionLatch = new CountDownLatch(1);
        final ExceptionHolder holder = new ExceptionHolder();
       
        Thread blocker = new Thread() {
         
            public void run() {
                Fqn toBlock = new Fqn(rootFqn, KEY);
                GetBlocker blocker = new GetBlocker(blockerLatch,toBlock);
                try {
                    jbc.addCacheListener(blocker);
                   
                    BatchModeTransactionManager.getInstance().begin();
                    region.get(KEY);
                    BatchModeTransactionManager.getInstance().commit();
                }
                catch (Exception e) {
                    holder.e1 = e;
                    rollback();
                }
                finally {
                    jbc.removeCacheListener(blocker);
                }
            }
        };
       
        Thread writer = new Thread() {
         
            public void run() {
                try {
                    writerLatch.await();
                   
                    BatchModeTransactionManager.getInstance().begin();
                    region.put(KEY, VALUE2);
                    BatchModeTransactionManager.getInstance().commit();
                }
                catch (Exception e) {
                    holder.e2 = e;
                    rollback();
                }
                finally {
                    completionLatch.countDown();
                }
            }
        };
       
        blocker.setDaemon(true);
        writer.setDaemon(true);
       
        boolean unblocked = false;
        try {
            blocker.start();
            writer.start();
           
            assertFalse("Blocker is blocking", completionLatch.await(100, TimeUnit.MILLISECONDS));
            // Start the writer
            writerLatch.countDown();
            assertTrue("Writer finished promptly", completionLatch.await(100, TimeUnit.MILLISECONDS));
           
            blockerLatch.countDown();
            unblocked = true;
           
            if ("PESSIMISTIC".equals(jbc.getConfiguration().getNodeLockingSchemeString())
                  && "REPEATABLE_READ".equals(jbc.getConfiguration().getIsolationLevelString())) {
                assertEquals(VALUE1, region.get(KEY));
            }
            else {
                assertEquals(VALUE2, region.get(KEY));
            }           
View Full Code Here

     
      configNames = registry.getConfigurationNames();
      assertEquals(8, configNames.size());
      assertTrue(configNames.contains("alias"));
     
      Cache cache = registry.getCache("alias", true);
      assertNotNull(cache);
      Cache other = registry.getCache(DEFAULT_STACK, false);
      assertEquals(cache, other);
     
      assertEquals(1, registry.getCacheNames().size());
     
      registry.releaseCache(DEFAULT_STACK);
View Full Code Here

TOP

Related Classes of org.jboss.cache.Cache

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.