⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abstractentityregionaccessstrategytestcase.java

📁 hibernate-distribution-3.3.1.GA-dist.zip源码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                }                finally {                    commitLatch.countDown();                    completionLatch.countDown();                }                            }        };                updater.setDaemon(true);        reader.setDaemon(true);        updater.start();        reader.start();                if (isUsingOptimisticLocking())            // Should complete promptly            assertTrue(completionLatch.await(1, TimeUnit.SECONDS));        else {                    // Reader thread should be blocking            assertFalse(completionLatch.await(250, TimeUnit.MILLISECONDS));            // Let the writer commit down            commitLatch.countDown();            assertTrue(completionLatch.await(1, TimeUnit.SECONDS));        }                assertThreadsRanCleanly();                long txTimestamp = System.currentTimeMillis();        assertEquals("Correct node1 value", VALUE2, localAccessStrategy.get(KEY, txTimestamp));        Object expected = isUsingInvalidation() ? null : VALUE2;        assertEquals("Correct node2 value", expected, remoteAccessStrategy.get(KEY, txTimestamp));    }    /**     * Test method for {@link TransactionalAccess#remove(java.lang.Object)}.     */    public void testRemove() {        evictOrRemoveTest(false);    }    /**     * Test method for {@link TransactionalAccess#removeAll()}.     */    public void testRemoveAll() {        evictOrRemoveAllTest(false);    }    /**     * Test method for {@link TransactionalAccess#evict(java.lang.Object)}.     *      * FIXME add testing of the "immediately without regard for transaction     * isolation" bit in the EntityRegionAccessStrategy API.     */    public void testEvict() {        evictOrRemoveTest(true);    }    /**     * Test method for {@link TransactionalAccess#evictAll()}.     *      * FIXME add testing of the "immediately without regard for transaction     * isolation" bit in the EntityRegionAccessStrategy API.     */    public void testEvictAll() {        evictOrRemoveAllTest(true);    }    private void evictOrRemoveTest(boolean evict) {               final String KEY = KEY_BASE + testCount++;                assertNull("local is clean", localAccessStrategy.get(KEY, System.currentTimeMillis()));        assertNull("remote is clean", remoteAccessStrategy.get(KEY, System.currentTimeMillis()));                localAccessStrategy.putFromLoad(KEY, VALUE1, System.currentTimeMillis(), new Integer(1));        assertEquals(VALUE1, localAccessStrategy.get(KEY, System.currentTimeMillis()));        remoteAccessStrategy.putFromLoad(KEY, VALUE1, System.currentTimeMillis(), new Integer(1));        assertEquals(VALUE1, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));                // Wait for async propagation        sleep(250);                if (evict)            localAccessStrategy.evict(KEY);        else            localAccessStrategy.remove(KEY);                assertEquals(null, localAccessStrategy.get(KEY, System.currentTimeMillis()));        //        sleep(1000);                assertEquals(null, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));    }    private void evictOrRemoveAllTest(boolean evict) {               final String KEY = KEY_BASE + testCount++;                Fqn regionFqn = getRegionFqn(REGION_NAME, REGION_PREFIX);                Node regionRoot = localCache.getRoot().getChild(regionFqn);        assertFalse(regionRoot == null);        assertEquals(0, getValidChildrenCount(regionRoot));        assertTrue(regionRoot.isResident());                if (isUsingOptimisticLocking()) {            assertEquals(NonLockingDataVersion.class, ((NodeSPI) regionRoot).getVersion().getClass());        }        regionRoot = remoteCache.getRoot().getChild(regionFqn);        assertFalse(regionRoot == null);        assertEquals(0, getValidChildrenCount(regionRoot));        assertTrue(regionRoot.isResident());                if (isUsingOptimisticLocking()) {            assertEquals(NonLockingDataVersion.class, ((NodeSPI) regionRoot).getVersion().getClass());        }                assertNull("local is clean", localAccessStrategy.get(KEY, System.currentTimeMillis()));        assertNull("remote is clean", remoteAccessStrategy.get(KEY, System.currentTimeMillis()));                localAccessStrategy.putFromLoad(KEY, VALUE1, System.currentTimeMillis(), new Integer(1));        assertEquals(VALUE1, localAccessStrategy.get(KEY, System.currentTimeMillis()));                // Wait for async propagation        sleep(250);                remoteAccessStrategy.putFromLoad(KEY, VALUE1, System.currentTimeMillis(), new Integer(1));        assertEquals(VALUE1, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));                // Wait for async propagation        sleep(250);                if (isUsingOptimisticLocking()) {            regionRoot = localCache.getRoot().getChild(regionFqn);            assertEquals(NonLockingDataVersion.class, ((NodeSPI) regionRoot).getVersion().getClass());            regionRoot = remoteCache.getRoot().getChild(regionFqn);            assertEquals(NonLockingDataVersion.class, ((NodeSPI) regionRoot).getVersion().getClass());        }                if (evict)            localAccessStrategy.evictAll();        else            localAccessStrategy.removeAll();                // This should re-establish the region root node in the optimistic case        assertNull(localAccessStrategy.get(KEY, System.currentTimeMillis()));                regionRoot = localCache.getRoot().getChild(regionFqn);        if (isUsingOptimisticLocking()) {            assertFalse(regionRoot == null);            assertEquals(0, getValidChildrenCount(regionRoot));            assertTrue(regionRoot.isValid());            assertTrue(regionRoot.isResident());        }        else {            assertTrue("region root is removed", regionRoot == null || !regionRoot.isValid());        }        // 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, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));        regionRoot = remoteCache.getRoot().getChild(regionFqn);        if (isUsingOptimisticLocking()) {           assertFalse(regionRoot == null);           assertTrue(regionRoot.isValid());           assertTrue(regionRoot.isResident());           // Not invalidation, so we didn't insert a child above           assertEquals(0, getValidChildrenCount(regionRoot));       }               else {          assertTrue("region root is removed", regionRoot == null || !regionRoot.isValid());       }                // Test whether the get above messes up the optimistic version        remoteAccessStrategy.putFromLoad(KEY, VALUE1, System.currentTimeMillis(), new Integer(1));        assertEquals(VALUE1, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));                // Revalidate the region root        regionRoot = remoteCache.getRoot().getChild(regionFqn);        assertFalse(regionRoot == null);        assertTrue(regionRoot.isValid());        assertTrue(regionRoot.isResident());        // Region root should have 1 child -- the one we added above        assertEquals(1, getValidChildrenCount(regionRoot));                // Wait for async propagation        sleep(250);                assertEquals("local is correct", (isUsingInvalidation() ? null : VALUE1), localAccessStrategy.get(KEY, System.currentTimeMillis()));        assertEquals("remote is correct", VALUE1, remoteAccessStrategy.get(KEY, System.currentTimeMillis()));    }        private int getValidChildrenCount(Node node) {        int result = 0;        for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) {           if (((Node) it.next()).isValid()) {              result++;           }        }        return result;            }        protected void rollback() {        try {            BatchModeTransactionManager.getInstance().rollback();        }        catch (Exception e) {            log.error(e.getMessage(), e);        }            }        private static class AccessStrategyTestSetup extends TestSetup {                private static final String PREFER_IPV4STACK = "java.net.preferIPv4Stack";                private String configName;        private String preferIPv4Stack;                public AccessStrategyTestSetup(Test test, String configName) {            super(test);            this.configName = configName;        }        @Override        protected void setUp() throws Exception {            try {                super.tearDown();            }            finally {                if (preferIPv4Stack == null)                    System.clearProperty(PREFER_IPV4STACK);                else                     System.setProperty(PREFER_IPV4STACK, preferIPv4Stack);                            }                        // Try to ensure we use IPv4; otherwise cluster formation is very slow             preferIPv4Stack = System.getProperty(PREFER_IPV4STACK);            System.setProperty(PREFER_IPV4STACK, "true");                        localCfg = createConfiguration(configName);            localRegionFactory = CacheTestUtil.startRegionFactory(localCfg);            localCache = localRegionFactory.getCacheInstanceManager().getEntityCacheInstance();                        remoteCfg = createConfiguration(configName);            remoteRegionFactory  = CacheTestUtil.startRegionFactory(remoteCfg);            remoteCache = remoteRegionFactory.getCacheInstanceManager().getEntityCacheInstance();                        invalidation = CacheHelper.isClusteredInvalidation(localCache);            synchronous = CacheHelper.isSynchronous(localCache);            optimistic = localCache.getConfiguration().getNodeLockingScheme() == org.jboss.cache.config.Configuration.NodeLockingScheme.OPTIMISTIC;        }        @Override        protected void tearDown() throws Exception {                        super.tearDown();                        if (localRegionFactory != null)                localRegionFactory.stop();                        if (remoteRegionFactory != null)                remoteRegionFactory.stop();        }                    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -