http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/952ab6fa/geode-core/src/test/java/org/apache/geode/cache30/CacheXml57DUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/cache30/CacheXml57DUnitTest.java b/geode-core/src/test/java/org/apache/geode/cache30/CacheXml57DUnitTest.java deleted file mode 100644 index 833093d..0000000 --- a/geode-core/src/test/java/org/apache/geode/cache30/CacheXml57DUnitTest.java +++ /dev/null @@ -1,662 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.geode.cache30; - -import static org.junit.Assert.*; - -import java.io.IOException; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.UnknownHostException; -import java.util.Arrays; -import java.util.Properties; - -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import org.apache.geode.cache.Cache; -import org.apache.geode.cache.CacheException; -import org.apache.geode.cache.CustomExpiry; -import org.apache.geode.cache.DataPolicy; -import org.apache.geode.cache.Declarable; -import org.apache.geode.cache.DynamicRegionFactory; -import org.apache.geode.cache.ExpirationAttributes; -import org.apache.geode.cache.InterestPolicy; -import org.apache.geode.cache.MirrorType; -import org.apache.geode.cache.Region; -import org.apache.geode.cache.Region.Entry; -import org.apache.geode.cache.Scope; -import org.apache.geode.cache.SubscriptionAttributes; -import org.apache.geode.cache.client.Pool; -import org.apache.geode.cache.client.PoolFactory; -import org.apache.geode.cache.client.PoolManager; -import org.apache.geode.cache.server.CacheServer; -import org.apache.geode.cache.server.ClientSubscriptionConfig; -import org.apache.geode.cache.server.ServerLoad; -import org.apache.geode.cache.server.ServerLoadProbeAdapter; -import org.apache.geode.cache.server.ServerMetrics; -import org.apache.geode.internal.AvailablePort; -import org.apache.geode.internal.AvailablePortHelper; -import org.apache.geode.internal.cache.PoolFactoryImpl; -import org.apache.geode.internal.cache.xmlcache.CacheCreation; -import org.apache.geode.internal.cache.xmlcache.CacheXml; -import org.apache.geode.internal.cache.xmlcache.Declarable2; -import org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation; -import org.apache.geode.internal.cache.xmlcache.RegionCreation; -import org.apache.geode.internal.i18n.LocalizedStrings; -import org.apache.geode.test.dunit.Host; -import org.apache.geode.test.dunit.IgnoredException; -import org.apache.geode.test.dunit.NetworkUtils; -import org.apache.geode.test.dunit.SerializableCallable; -import org.apache.geode.test.dunit.VM; -import org.apache.geode.test.junit.categories.DistributedTest; - -/** - * Tests 5.7 cache.xml features. - * - * @since GemFire 5.7 - */ -@Category(DistributedTest.class) -public class CacheXml57DUnitTest extends CacheXml55DUnitTest { - - private final static String ALIAS1; - private final static String ALIAS2; - - static { - String tmp_alias1 = "localhost"; - String tmp_alias2 = "localhost"; - ALIAS1 = tmp_alias1; - ALIAS2 = tmp_alias2; - } - - @Override - protected String getGemFireVersion() { - return CacheXml.VERSION_5_7; - } - - /** - * Tests the groups subelement on bridge-server. - */ - @Test - public void testDefaultCacheServerGroups() throws CacheException { - CacheCreation cache = new CacheCreation(); - CacheServer bs = cache.addCacheServer(); - bs.setPort(AvailablePortHelper.getRandomAvailableTCPPort()); - bs.setGroups(CacheServer.DEFAULT_GROUPS); - testXml(cache); - Cache c = getCache(); - assertNotNull(c); - CacheServer server = (CacheServer)cache.getCacheServers().iterator().next(); - assertNotNull(server); - assertEquals(CacheServer.DEFAULT_GROUPS, server.getGroups()); - } - - @Test - public void testOneCacheServerGroups() throws CacheException { - CacheCreation cache = new CacheCreation(); - CacheServer bs = cache.addCacheServer(); - bs.setPort(AvailablePortHelper.getRandomAvailableTCPPort()); - String[] groups = new String[]{"group1"}; - bs.setGroups(groups); - testXml(cache); - Cache c = getCache(); - assertNotNull(c); - CacheServer server = (CacheServer)cache.getCacheServers().iterator().next(); - assertNotNull(server); - assertEquals(Arrays.asList(groups), Arrays.asList(server.getGroups())); - } - @Test - public void testTwoCacheServerGroups() throws CacheException { - CacheCreation cache = new CacheCreation(); - CacheServer bs = cache.addCacheServer(); - bs.setPort(AvailablePortHelper.getRandomAvailableTCPPort()); - String[] groups = new String[]{"group1", "group2"}; - bs.setGroups(groups); - testXml(cache); - Cache c = getCache(); - assertNotNull(c); - CacheServer server = (CacheServer)cache.getCacheServers().iterator().next(); - assertNotNull(server); - assertEquals(Arrays.asList(groups), Arrays.asList(server.getGroups())); - } - @Test - public void testDefaultCacheServerBindAddress() throws CacheException { - CacheCreation cache = new CacheCreation(); - CacheServer bs = cache.addCacheServer(); - bs.setPort(AvailablePortHelper.getRandomAvailableTCPPort()); - testXml(cache); - Cache c = getCache(); - assertNotNull(c); - CacheServer server = (CacheServer)cache.getCacheServers().iterator().next(); - assertNotNull(server); - assertEquals(CacheServer.DEFAULT_BIND_ADDRESS, server.getBindAddress()); - } - @Test - public void testCacheServerBindAddress() throws CacheException { - CacheCreation cache = new CacheCreation(); - CacheServer bs = cache.addCacheServer(); - bs.setPort(AvailablePortHelper.getRandomAvailableTCPPort()); - final String BA = ALIAS1; - bs.setBindAddress(BA); - testXml(cache); - Cache c = getCache(); - assertNotNull(c); - CacheServer server = (CacheServer)cache.getCacheServers().iterator().next(); - assertNotNull(server); - assertEquals(BA, server.getBindAddress()); - } - @Test - public void testCacheServerHostnameForClients() throws CacheException { - CacheCreation cache = new CacheCreation(); - CacheServer bs = cache.addCacheServer(); - bs.setPort(AvailablePortHelper.getRandomAvailableTCPPort()); - final String BA = ALIAS1; - bs.setBindAddress(BA); - bs.setHostnameForClients("clientHostName"); - testXml(cache); - Cache c = getCache(); - assertNotNull(c); - CacheServer server = (CacheServer)cache.getCacheServers().iterator().next(); - assertNotNull(server); - assertEquals(BA, server.getBindAddress()); - assertEquals("clientHostName", server.getHostnameForClients()); - } - @Test - public void testExplicitConnectionPool() throws CacheException { - getSystem(); - CacheCreation cache = new CacheCreation(); - PoolFactory f = cache.createPoolFactory(); - f.addServer(ALIAS2, 3777).addServer(ALIAS1, 3888); - f.setFreeConnectionTimeout(12345) - .setLoadConditioningInterval(12345) - .setSocketBufferSize(12345) - .setThreadLocalConnections(true) - .setReadTimeout(12345) - .setMinConnections(12346) - .setMaxConnections(12347) - .setRetryAttempts(12348) - .setIdleTimeout(12349) - .setPingInterval(12350) - .setStatisticInterval(12351) - .setServerGroup("mygroup") - // commented this out until queues are implemented -// .setQueueEnabled(true) - .setSubscriptionRedundancy(12345) - .setSubscriptionMessageTrackingTimeout(12345) - .setSubscriptionAckInterval(333); - f.create("mypool"); - RegionAttributesCreation attrs = new RegionAttributesCreation(cache); - attrs.setPoolName("mypool"); - cache.createVMRegion("rootNORMAL", attrs); - IgnoredException.addIgnoredException("Connection refused: connect"); - testXml(cache); - Cache c = getCache(); - assertNotNull(c); - Region r = c.getRegion("rootNORMAL"); - assertNotNull(r); - assertEquals("mypool", r.getAttributes().getPoolName()); - Pool cp = PoolManager.find("mypool"); - assertNotNull(cp); - assertEquals(0, cp.getLocators().size()); - assertEquals(2, cp.getServers().size()); - assertEquals(createINSA(ALIAS2, 3777), cp.getServers().get(0)); - assertEquals(createINSA(ALIAS1, 3888), cp.getServers().get(1)); - assertEquals(12345, cp.getFreeConnectionTimeout()); - assertEquals(12345, cp.getLoadConditioningInterval()); - assertEquals(12345, cp.getSocketBufferSize()); - assertEquals(true, cp.getThreadLocalConnections()); - assertEquals(12345, cp.getReadTimeout()); - assertEquals(12346, cp.getMinConnections()); - assertEquals(12347, cp.getMaxConnections()); - assertEquals(12348, cp.getRetryAttempts()); - assertEquals(12349, cp.getIdleTimeout()); - assertEquals(12350, cp.getPingInterval()); - assertEquals(12351, cp.getStatisticInterval()); - assertEquals("mygroup", cp.getServerGroup()); - // commented this out until queues are implemented - // assertIndexDetailsEquals(true, cp.getQueueEnabled()); - assertEquals(12345, cp.getSubscriptionRedundancy()); - assertEquals(12345, cp.getSubscriptionMessageTrackingTimeout()); - assertEquals(333, cp.getSubscriptionAckInterval()); - } - @Test - public void testDefaultConnectionPool() throws CacheException { - getSystem(); - CacheCreation cache = new CacheCreation(); - PoolFactory f = cache.createPoolFactory(); - f.addLocator(ALIAS2, 3777); - f.create("mypool"); - RegionAttributesCreation attrs = new RegionAttributesCreation(cache); - attrs.setPoolName("mypool"); - cache.createVMRegion("rootNORMAL", attrs); - testXml(cache); - Cache c = getCache(); - assertNotNull(c); - Region r = c.getRegion("rootNORMAL"); - assertNotNull(r); - assertEquals("mypool", r.getAttributes().getPoolName()); - Pool cp = PoolManager.find("mypool"); - assertNotNull(cp); - assertEquals(1, cp.getLocators().size()); - assertEquals(0, cp.getServers().size()); - assertEquals(createINSA(ALIAS2, 3777), cp.getLocators().get(0)); - assertEquals(PoolFactory.DEFAULT_FREE_CONNECTION_TIMEOUT, cp.getFreeConnectionTimeout()); - assertEquals(PoolFactory.DEFAULT_LOAD_CONDITIONING_INTERVAL, cp.getLoadConditioningInterval()); - assertEquals(PoolFactory.DEFAULT_SOCKET_BUFFER_SIZE, cp.getSocketBufferSize()); - assertEquals(PoolFactory.DEFAULT_THREAD_LOCAL_CONNECTIONS, cp.getThreadLocalConnections()); - assertEquals(PoolFactory.DEFAULT_READ_TIMEOUT, cp.getReadTimeout()); - assertEquals(PoolFactory.DEFAULT_MIN_CONNECTIONS, cp.getMinConnections()); - assertEquals(PoolFactory.DEFAULT_MAX_CONNECTIONS, cp.getMaxConnections()); - assertEquals(PoolFactory.DEFAULT_RETRY_ATTEMPTS, cp.getRetryAttempts()); - assertEquals(PoolFactory.DEFAULT_IDLE_TIMEOUT, cp.getIdleTimeout()); - assertEquals(PoolFactory.DEFAULT_PING_INTERVAL, cp.getPingInterval()); - assertEquals(PoolFactory.DEFAULT_STATISTIC_INTERVAL, cp.getStatisticInterval()); - assertEquals(PoolFactory.DEFAULT_SERVER_GROUP, cp.getServerGroup()); - assertEquals(PoolFactory.DEFAULT_SUBSCRIPTION_ENABLED, cp.getSubscriptionEnabled()); - assertEquals(PoolFactory.DEFAULT_SUBSCRIPTION_REDUNDANCY, cp.getSubscriptionRedundancy()); - assertEquals(PoolFactory.DEFAULT_SUBSCRIPTION_MESSAGE_TRACKING_TIMEOUT, cp.getSubscriptionMessageTrackingTimeout()); - assertEquals(PoolFactory.DEFAULT_SUBSCRIPTION_ACK_INTERVAL, cp.getSubscriptionAckInterval()); - } - @Test - public void testTwoConnectionPools() throws CacheException { - getSystem(); - CacheCreation cache = new CacheCreation(); - PoolFactory f = cache.createPoolFactory(); - f.addLocator(ALIAS2, 3777).create("mypool"); - f.reset().addLocator(ALIAS1, 3888).create("mypool2"); - try { - f.create("mypool"); - fail("expected IllegalStateException"); - } catch (IllegalStateException expected) { - } - try { - f.create("mypool2"); - fail("expected IllegalStateException"); - } catch (IllegalStateException expected) { - } - RegionAttributesCreation attrs = new RegionAttributesCreation(cache); - attrs.setPoolName("mypool"); - cache.createVMRegion("rootNORMAL", attrs); - testXml(cache); - Cache c = getCache(); - assertNotNull(c); - Region r = c.getRegion("rootNORMAL"); - assertNotNull(r); - assertEquals("mypool", r.getAttributes().getPoolName()); - Pool cp = PoolManager.find("mypool"); - assertNotNull(cp); - assertEquals(0, cp.getServers().size()); - assertEquals(1, cp.getLocators().size()); - assertEquals(createINSA(ALIAS2, 3777), cp.getLocators().get(0)); - cp = PoolManager.find("mypool2"); - assertNotNull(cp); - assertEquals(0, cp.getServers().size()); - assertEquals(1, cp.getLocators().size()); - assertEquals(createINSA(ALIAS1, 3888), cp.getLocators().get(0)); - } - private static InetSocketAddress createINSA(String host, int port) { - try { - InetAddress hostAddr = InetAddress.getByName(host); - return new InetSocketAddress(hostAddr, port); - } catch (UnknownHostException cause) { - IllegalArgumentException ex = new IllegalArgumentException("Unknown host " + host); - ex.initCause(cause); - throw ex; - } - } - @Test - public void testNoConnectionPools() throws CacheException { - CacheCreation cache = new CacheCreation(); - RegionAttributesCreation attrs = new RegionAttributesCreation(cache); - attrs.setPoolName("mypool"); - cache.createVMRegion("rootNORMAL", attrs); - IgnoredException expectedException = IgnoredException.addIgnoredException(LocalizedStrings.AbstractRegion_THE_CONNECTION_POOL_0_HAS_NOT_BEEN_CREATED.toLocalizedString("mypool")); - try { - testXml(cache); - fail("expected IllegalStateException"); - } catch (IllegalStateException expected) { - } finally { - expectedException.remove(); - } - } - @Test - public void testAlreadyExistingPool() throws CacheException { - getSystem(); - PoolFactoryImpl f = (PoolFactoryImpl) - PoolManager.createFactory(); - f.setStartDisabled(true).addLocator(ALIAS2, 12345).create("mypool"); - try { - // now make sure declarative cache can't create the same pool - CacheCreation cache = new CacheCreation(); - cache.createPoolFactory().addLocator(ALIAS2, 12345).create("mypool"); - IgnoredException expectedException = IgnoredException.addIgnoredException(LocalizedStrings.PoolManagerImpl_POOL_NAMED_0_ALREADY_EXISTS.toLocalizedString("mypool")); - try { - testXml(cache); - fail("expected IllegalStateException"); - } catch (IllegalStateException expected) { - } finally { - expectedException.remove(); - } - } finally { - PoolManager.close(); - } - } - - @Test - public void testDynamicRegionFactoryConnectionPool() throws CacheException, IOException { - IgnoredException.addIgnoredException("Connection reset"); - IgnoredException.addIgnoredException("SocketTimeoutException"); - IgnoredException.addIgnoredException("ServerConnectivityException"); - IgnoredException.addIgnoredException("Socket Closed"); - getSystem(); - VM vm0 = Host.getHost(0).getVM(0); - final int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET); - vm0.invoke(new SerializableCallable("Create cache server") { - public Object call() throws IOException { - DynamicRegionFactory.get().open(); - Cache cache = getCache(); - CacheServer bridge = cache.addCacheServer(); - bridge.setPort(port); - bridge.setNotifyBySubscription(true); - bridge.start(); - return null; - } - }); - CacheCreation cache = new CacheCreation(); - cache.createPoolFactory() - .addServer(NetworkUtils.getServerHostName(vm0.getHost()), port) - .setSubscriptionEnabled(true) - .create("connectionPool"); - cache.setDynamicRegionFactoryConfig(new DynamicRegionFactory.Config(null, "connectionPool", false, false)); - RegionAttributesCreation attrs = new RegionAttributesCreation(cache); - cache.createRegion("root", attrs); - // note that testXml can't check if they are same because enabling - // dynamic regions causes a meta region to be produced. - testXml(cache, false); - assertEquals(false, DynamicRegionFactory.get().getConfig().getRegisterInterest()); - assertEquals(false, DynamicRegionFactory.get().getConfig().getPersistBackup()); - assertEquals(true, DynamicRegionFactory.get().isOpen()); - assertEquals(null, DynamicRegionFactory.get().getConfig().getDiskDir()); - assertEquals("connectionPool", DynamicRegionFactory.get().getConfig().getPoolName()); - Region dr = getCache().getRegion("__DynamicRegions"); - if(dr != null) { - dr.localDestroyRegion(); - } - } - - /** - * Tests the client subscription attributes (<code>eviction-policy</code>, - * <code>capacity</code> and <code>overflow-directory</code>) related to - * client subscription config in gemfire cache-server framework - * - * @throws CacheException - * @since GemFire 5.7 - */ - @Test - public void testBridgeAttributesRelatedToHAOverFlow() throws CacheException { - CacheCreation cache = new CacheCreation(); - cache.setMessageSyncInterval(3445); - CacheServer bs = cache.addCacheServer(); - ClientSubscriptionConfig csc = bs.getClientSubscriptionConfig(); - csc.setEvictionPolicy("entry"); - cache.getLogger().config( - "EvictionPolicy : " + csc.getEvictionPolicy()); - csc.setCapacity(501); - cache.getLogger().config( - "EvictionCapacity : " + csc.getCapacity()); - csc.setOverflowDirectory("overFlow"); - cache.getLogger().config( - "EvictionOverflowDirectory : " - + csc.getOverflowDirectory()); - bs.setPort(AvailablePortHelper.getRandomAvailableTCPPort()); - RegionAttributesCreation attrs = new RegionAttributesCreation(cache); - attrs.setDataPolicy(DataPolicy.NORMAL); - cache.createVMRegion("rootNORMAL", attrs); - testXml(cache); - Cache c = getCache(); - assertNotNull(c); - CacheServer server = (CacheServer)cache.getCacheServers().iterator() - .next(); - assertNotNull(server); - ClientSubscriptionConfig chaqf = server.getClientSubscriptionConfig(); - assertEquals("entry", chaqf.getEvictionPolicy()); - assertEquals(501, chaqf.getCapacity()); - assertEquals("overFlow", chaqf.getOverflowDirectory()); - } - - @Test - public void testBridgeLoadProbe() { - CacheCreation cache = new CacheCreation(); - CacheServer server = cache.addCacheServer(); - server.setPort(AvailablePortHelper.getRandomAvailableTCPPort()); - server.setLoadProbe(new MyLoadProbe()); - - testXml(cache); - - Cache c= getCache(); - server = c.getCacheServers().get(0); - assertEquals(MyLoadProbe.class,server.getLoadProbe().getClass()); - } - - @Test - public void testLoadPollInterval() { - CacheCreation cache = new CacheCreation(); - CacheServer server = cache.addCacheServer(); - server.setPort(AvailablePortHelper.getRandomAvailableTCPPort()); - server.setLoadPollInterval(12345); - - testXml(cache); - - Cache c = getCache(); - server = c.getCacheServers().get(0); - assertEquals(12345, server.getLoadPollInterval()); - } - - public static class MyLoadProbe extends ServerLoadProbeAdapter implements Declarable { - public ServerLoad getLoad(ServerMetrics metrics) { - return null; - } - - public void init(Properties props) { - } - - public boolean equals(Object o) { - return o instanceof MyLoadProbe; - } - } - - static public class Expiry1 implements CustomExpiry, Declarable{ - public ExpirationAttributes getExpiry(Entry entry) { - return null; - } - - public void init(Properties props) { - } - - public void close() { - } - } - - static public class Expiry2 implements CustomExpiry, Declarable { - public ExpirationAttributes getExpiry(Entry entry) { - return null; - } - - public void init(Properties props) { - } - - public void close() { - } - } - - static public class Expiry3 implements CustomExpiry, Declarable { - public ExpirationAttributes getExpiry(Entry entry) { - return null; - } - - public void init(Properties props) { - } - - public void close() { - } - } - - static public class Expiry4 implements CustomExpiry, Declarable { - public ExpirationAttributes getExpiry(Entry entry) { - return null; - } - - public void init(Properties props) { - } - - public void close() { - } - } - - static public class Expiry5 implements CustomExpiry, Declarable2 { - public ExpirationAttributes getExpiry(Entry entry) { - return null; - } - - public void init(Properties props) { - } - - public void close() { - } - - /* (non-Javadoc) - * @see org.apache.geode.internal.cache.xmlcache.Declarable2#getConfig() - */ - public Properties getConfig() { - Properties p = new Properties(); - p.put("prop1", "val1"); - p.put("prop2", "val2"); - return p; - } - } - - /** - * Test both customEntryIdleTime and customEntryTimeToLife - */ - @Test - public void testCustomEntryXml() { - CacheCreation cache = new CacheCreation(); - - RegionAttributesCreation attrs = new RegionAttributesCreation(cache); - attrs.setScope(Scope.DISTRIBUTED_NO_ACK); - - RegionCreation root = - (RegionCreation) cache.createRegion("root", attrs); - - { - attrs = new RegionAttributesCreation(cache); - attrs.setScope(Scope.DISTRIBUTED_NO_ACK); - attrs.setInitialCapacity(142); - attrs.setLoadFactor(42.42f); - attrs.setStatisticsEnabled(true); - attrs.setCustomEntryIdleTimeout(new Expiry1()); - attrs.setCustomEntryTimeToLive(new Expiry5()); - - root.createSubregion("one", attrs); - } - - { - attrs = new RegionAttributesCreation(cache); - attrs.setScope(Scope.DISTRIBUTED_ACK); - attrs.setInitialCapacity(242); - attrs.setStatisticsEnabled(true); - attrs.setCustomEntryIdleTimeout(new Expiry2()); - - Region region = root.createSubregion("two", attrs); - - { - attrs = new RegionAttributesCreation(cache); - attrs.setScope(Scope.DISTRIBUTED_ACK); - attrs.setLoadFactor(43.43f); - attrs.setStatisticsEnabled(true); - attrs.setCustomEntryIdleTimeout(new Expiry3()); - attrs.setCustomEntryTimeToLive(new Expiry4()); - - region.createSubregion("three", attrs); - } - } - - testXml(cache); - } - - @Test - public void testPreloadDataPolicy() throws CacheException { - CacheCreation cache = new CacheCreation(); - - { - RegionAttributesCreation attrs = new RegionAttributesCreation(cache); - attrs.setDataPolicy(DataPolicy.NORMAL); - cache.createRegion("rootNORMAL", attrs); - } - { - RegionAttributesCreation attrs = new RegionAttributesCreation(cache); - attrs.setDataPolicy(DataPolicy.NORMAL); - attrs.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL)); - cache.createRegion("rootNORMAL_ALL", attrs); - } - { - RegionAttributesCreation attrs = new RegionAttributesCreation(cache); - attrs.setMirrorType(MirrorType.KEYS_VALUES); - cache.createRegion("rootREPLICATE", attrs); - } - { - RegionAttributesCreation attrs = new RegionAttributesCreation(cache); - attrs.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE); - cache.createRegion("rootPERSISTENT_REPLICATE", attrs); - } - { - RegionAttributesCreation attrs = new RegionAttributesCreation(cache); - attrs.setDataPolicy(DataPolicy.EMPTY); - cache.createRegion("rootEMPTY", attrs); - } - { - RegionAttributesCreation attrs = new RegionAttributesCreation(cache); - attrs.setDataPolicy(DataPolicy.EMPTY); - attrs.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL)); - cache.createRegion("rootEMPTY_ALL", attrs); - } - { - RegionAttributesCreation attrs = new RegionAttributesCreation(cache); - attrs.setDataPolicy(DataPolicy.PRELOADED); - attrs.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL)); - cache.createRegion("rootPRELOADED_ALL", attrs); - } - - testXml(cache); - - } - - /** - * Test EnableSubscriptionConflation region attribute - * @since GemFire 5.7 - */ - @Test - public void testEnableSubscriptionConflationAttribute() throws CacheException { - - CacheCreation cache = new CacheCreation(); - RegionAttributesCreation attrs = new RegionAttributesCreation(cache); - attrs.setEnableSubscriptionConflation(true); - cache.createRegion("root", attrs); - testXml(cache); - assertEquals(true, cache.getRegion("root").getAttributes().getEnableSubscriptionConflation()); - } -}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/952ab6fa/geode-core/src/test/java/org/apache/geode/cache30/CacheXml58DUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/cache30/CacheXml58DUnitTest.java b/geode-core/src/test/java/org/apache/geode/cache30/CacheXml58DUnitTest.java deleted file mode 100644 index 4040b15..0000000 --- a/geode-core/src/test/java/org/apache/geode/cache30/CacheXml58DUnitTest.java +++ /dev/null @@ -1,518 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.geode.cache30; - -import static org.junit.Assert.*; - -import java.util.Map; -import java.util.Properties; - -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import org.apache.geode.cache.AttributesFactory; -import org.apache.geode.cache.Cache; -import org.apache.geode.cache.CacheException; -import org.apache.geode.cache.DataPolicy; -import org.apache.geode.cache.DiskWriteAttributesFactory; -import org.apache.geode.cache.EvictionAction; -import org.apache.geode.cache.EvictionAlgorithm; -import org.apache.geode.cache.EvictionAttributes; -import org.apache.geode.cache.ExpirationAction; -import org.apache.geode.cache.ExpirationAttributes; -import org.apache.geode.cache.PartitionAttributes; -import org.apache.geode.cache.PartitionAttributesFactory; -import org.apache.geode.cache.Region; -import org.apache.geode.cache.RegionAttributes; -import org.apache.geode.cache.execute.Function; -import org.apache.geode.cache.execute.FunctionService; -import org.apache.geode.internal.cache.functions.TestFunction; -import org.apache.geode.internal.cache.lru.MemLRUCapacityController; -import org.apache.geode.internal.cache.xmlcache.CacheCreation; -import org.apache.geode.internal.cache.xmlcache.CacheXml; -import org.apache.geode.internal.cache.xmlcache.FunctionServiceCreation; -import org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation; -import org.apache.geode.internal.cache.xmlcache.ResourceManagerCreation; -import org.apache.geode.test.junit.categories.DistributedTest; - -/** - * Tests 5.8 cache.xml features. - * - * @since GemFire 5.8 - */ - -@Category(DistributedTest.class) -public class CacheXml58DUnitTest extends CacheXml57DUnitTest -{ - - // ////// Constructors - - public CacheXml58DUnitTest() { - super(); - } - - // ////// Helper methods - - protected String getGemFireVersion() - { - return CacheXml.VERSION_5_8; - } - - - /** - * Tests that a region created with a named attributes set programmatically - * for partition-resolver has the correct attributes. - * - */ - @Test - public void testPartitionedRegionAttributesForCustomPartitioning() throws CacheException - { - CacheCreation cache = new CacheCreation(); - RegionAttributesCreation attrs = new RegionAttributesCreation(cache); - - CacheXMLPartitionResolver partitionResolver = new CacheXMLPartitionResolver(); - Properties params = new Properties(); - params.setProperty("initial-index-value", "1000"); - params.setProperty("secondary-index-value", "5000"); - partitionResolver.init(params); - - PartitionAttributesFactory paf = new PartitionAttributesFactory(); - paf.setRedundantCopies(1); - paf.setTotalMaxMemory(500); - paf.setLocalMaxMemory(100); - paf.setPartitionResolver(partitionResolver); - - attrs.setPartitionAttributes(paf.create()); - - cache.createRegion("parRoot", attrs); - - Region r = cache.getRegion("parRoot"); - assertEquals(r.getAttributes().getPartitionAttributes().getRedundantCopies(),1); - assertEquals(r.getAttributes().getPartitionAttributes().getLocalMaxMemory(),100); - assertEquals(r.getAttributes().getPartitionAttributes().getTotalMaxMemory(),500); - assertEquals(r.getAttributes().getPartitionAttributes().getPartitionResolver(),partitionResolver); - - testXml(cache); - - Cache c = getCache(); - assertNotNull(c); - - Region region = c.getRegion("parRoot"); - assertNotNull(region); - - RegionAttributes regionAttrs = region.getAttributes(); - PartitionAttributes pa = regionAttrs.getPartitionAttributes(); - - assertEquals(pa.getRedundantCopies(), 1); - assertEquals(pa.getLocalMaxMemory(), 100); - assertEquals(pa.getTotalMaxMemory(), 500); - assertNotNull(pa.getPartitionResolver().getClass()); - assertEquals(pa.getPartitionResolver(), partitionResolver); - } - - /** - * Tests that a cache created with FunctionService and registered FabricFunction - * has correct registered Function - * - */ - @Test - public void testCacheCreationWithFuntionService() throws CacheException - { - CacheCreation cache = new CacheCreation(); - FunctionServiceCreation fsc = new FunctionServiceCreation(); - TestFunction function1 = new TestFunction(true,TestFunction.TEST_FUNCTION2); - TestFunction function2 = new TestFunction(true, TestFunction.TEST_FUNCTION3); - TestFunction function3 = new TestFunction(true, TestFunction.TEST_FUNCTION4); - fsc.registerFunction(function1); - fsc.registerFunction(function2); - fsc.registerFunction(function3); - fsc.create(); - cache.setFunctionServiceCreation(fsc); - - testXml(cache); - getCache(); - Map<String, Function> functionIdMap = FunctionService.getRegisteredFunctions(); - assertEquals(3, functionIdMap.size()); - - assertTrue(function1.equals(functionIdMap.get(function1.getId()))); - assertTrue(function2.equals(functionIdMap.get(function2.getId()))); - assertTrue(function3.equals(functionIdMap.get(function3.getId()))); - } - - /** - * Tests that a Partitioned Region can be created with a named attributes set programmatically - * for ExpirationAttributes - * - */ - @Test - public void testPartitionedRegionAttributesForExpiration() throws CacheException - { - CacheCreation cache = new CacheCreation(); - RegionAttributesCreation attrs = new RegionAttributesCreation(cache); - attrs.setStatisticsEnabled(true); - RegionAttributes rootAttrs = null; - ExpirationAttributes expiration = new ExpirationAttributes(60,ExpirationAction.DESTROY); - - CacheXMLPartitionResolver partitionResolver = new CacheXMLPartitionResolver(); - Properties params = new Properties(); - params.setProperty("initial-index-value", "1000"); - params.setProperty("secondary-index-value", "5000"); - partitionResolver.init(params); - - PartitionAttributesFactory paf = new PartitionAttributesFactory(); - paf.setRedundantCopies(1); - paf.setTotalMaxMemory(500); - paf.setLocalMaxMemory(100); - paf.setPartitionResolver(partitionResolver); - - AttributesFactory fac = new AttributesFactory(attrs); - fac.setEntryTimeToLive(expiration); - fac.setEntryIdleTimeout(expiration); - - fac.setPartitionAttributes(paf.create()); - rootAttrs = fac.create(); - cache.createRegion("parRoot", rootAttrs); - - Region r = cache.getRegion("parRoot"); - assertNotNull(r); - assertEquals(r.getAttributes().getPartitionAttributes().getRedundantCopies(),1); - assertEquals(r.getAttributes().getPartitionAttributes().getLocalMaxMemory(),100); - assertEquals(r.getAttributes().getPartitionAttributes().getTotalMaxMemory(),500); - assertEquals(r.getAttributes().getPartitionAttributes().getPartitionResolver(),partitionResolver); - - assertEquals(r.getAttributes().getEntryIdleTimeout().getTimeout(),expiration.getTimeout()); - assertEquals(r.getAttributes().getEntryTimeToLive().getTimeout(), expiration.getTimeout()); - - testXml(cache); - - Cache c = getCache(); - assertNotNull(c); - - Region region = c.getRegion("parRoot"); - assertNotNull(region); - - RegionAttributes regionAttrs = region.getAttributes(); - PartitionAttributes pa = regionAttrs.getPartitionAttributes(); - - assertEquals(pa.getRedundantCopies(), 1); - assertEquals(pa.getLocalMaxMemory(), 100); - assertEquals(pa.getTotalMaxMemory(), 500); - assertNotNull(pa.getPartitionResolver().getClass()); - assertEquals(pa.getPartitionResolver(), partitionResolver); - - assertEquals(regionAttrs.getEntryIdleTimeout().getTimeout(), expiration.getTimeout()); - assertEquals(regionAttrs.getEntryTimeToLive().getTimeout(), expiration.getTimeout()); - - } - - - /** - * Tests that a Partitioned Region can be created with a named attributes set programmatically - * for ExpirationAttributes - * - */ - @Test - public void testPartitionedRegionAttributesForEviction() throws CacheException - { - final int redundantCopies = 1; - CacheCreation cache = new CacheCreation(); - if (getGemFireVersion().equals(CacheXml.VERSION_6_0)) { - ResourceManagerCreation rm = new ResourceManagerCreation(); - rm.setCriticalHeapPercentage(95); - cache.setResourceManagerCreation(rm); - } - RegionAttributesCreation attrs = new RegionAttributesCreation(cache); - attrs.setStatisticsEnabled(true); - RegionAttributes rootAttrs = null; - - ExpirationAttributes expiration = new ExpirationAttributes(60,ExpirationAction.DESTROY); - - CacheXMLPartitionResolver partitionResolver = new CacheXMLPartitionResolver(); - Properties params = new Properties(); - params.setProperty("initial-index-value", "1000"); - params.setProperty("secondary-index-value", "5000"); - partitionResolver.init(params); - - PartitionAttributesFactory paf = new PartitionAttributesFactory(); - paf.setRedundantCopies(redundantCopies); - paf.setTotalMaxMemory(500); - paf.setLocalMaxMemory(100); - paf.setPartitionResolver(partitionResolver); - - AttributesFactory fac = new AttributesFactory(attrs); - -// TODO mthomas 01/20/09 Move test back to using LRUHeap when config issues have settled -// if (getGemFireVersion().equals(CacheXml.GEMFIRE_6_0)) { -// fac.setEvictionAttributes(EvictionAttributes.createLRUHeapAttributes(null, -// EvictionAction.OVERFLOW_TO_DISK)); -// } else { - fac.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes(100, null, - EvictionAction.OVERFLOW_TO_DISK)); -// } - - fac.setEntryTimeToLive(expiration); - fac.setEntryIdleTimeout(expiration); - - DiskWriteAttributesFactory dwaf = new DiskWriteAttributesFactory(); - dwaf.setSynchronous(true); - /*fac.setDiskWriteAttributes(dwaf.create()); - File[] diskDirs = new File[1]; - diskDirs[0] = new File("overflowDir/" + "_" - + OSProcess.getId()); - diskDirs[0].mkdirs(); - fac.setDiskDirs(diskDirs);*/ - - fac.setPartitionAttributes(paf.create()); - rootAttrs = fac.create(); - cache.createRegion("parRoot", rootAttrs); - - Region r = cache.getRegion("parRoot"); - assertNotNull(r); - assertEquals(r.getAttributes().getPartitionAttributes().getRedundantCopies(),redundantCopies); - assertEquals(r.getAttributes().getPartitionAttributes().getLocalMaxMemory(),100); - assertEquals(r.getAttributes().getPartitionAttributes().getTotalMaxMemory(),500); - assertEquals(r.getAttributes().getPartitionAttributes().getPartitionResolver(),partitionResolver); - - assertEquals(r.getAttributes().getEntryIdleTimeout().getTimeout(),expiration.getTimeout()); - assertEquals(r.getAttributes().getEntryTimeToLive().getTimeout(), expiration.getTimeout()); - - testXml(cache); - - Cache c = getCache(); - assertNotNull(c); - - Region region = c.getRegion("parRoot"); - assertNotNull(region); - - RegionAttributes regionAttrs = region.getAttributes(); - PartitionAttributes pa = regionAttrs.getPartitionAttributes(); - EvictionAttributes ea = regionAttrs.getEvictionAttributes(); - - assertEquals(pa.getRedundantCopies(), 1); - assertEquals(pa.getLocalMaxMemory(), 100); - assertEquals(pa.getTotalMaxMemory(), 500); - assertNotNull(pa.getPartitionResolver().getClass()); - assertEquals(pa.getPartitionResolver(), partitionResolver); - - assertEquals(regionAttrs.getEntryIdleTimeout().getTimeout(), expiration.getTimeout()); - assertEquals(regionAttrs.getEntryTimeToLive().getTimeout(), expiration.getTimeout()); -// TODO mthomas 01/20/09 Move test back to using LRUHeap when config issues have settled -// if (getGemFireVersion().equals(CacheXml.GEMFIRE_6_0)) { -// assertIndexDetailsEquals(ea.getAlgorithm(),EvictionAlgorithm.LRU_HEAP); -// } else { - assertEquals(ea.getAlgorithm(),EvictionAlgorithm.LRU_MEMORY); -// } - assertEquals(ea.getAction(), EvictionAction.OVERFLOW_TO_DISK); - } - - @Test - public void testPartitionedRegionAttributesForCoLocation(){ - closeCache(); - CacheCreation cache = new CacheCreation(); - RegionAttributesCreation custAttrs = new RegionAttributesCreation(cache); - RegionAttributesCreation orderAttrs = new RegionAttributesCreation(cache); - PartitionAttributesFactory custPaf = new PartitionAttributesFactory(); - PartitionAttributesFactory orderPaf = new PartitionAttributesFactory(); - custPaf.setRedundantCopies(1); - custPaf.setTotalMaxMemory(500); - custPaf.setLocalMaxMemory(100); - custAttrs.setPartitionAttributes(custPaf.create()); - cache.createRegion("Customer",custAttrs); - - orderPaf.setRedundantCopies(1); - orderPaf.setTotalMaxMemory(500); - orderPaf.setLocalMaxMemory(100); - orderPaf.setColocatedWith("Customer"); - orderAttrs.setPartitionAttributes(orderPaf.create()); - cache.createRegion("Order", orderAttrs); - - testXml(cache); - - Cache c = getCache(); - assertNotNull(c); - - Region cust = c.getRegion(Region.SEPARATOR+"Customer"); - assertNotNull(cust); - Region order = c.getRegion(Region.SEPARATOR+"Order"); - assertNotNull(order); - String coLocatedRegion = order.getAttributes().getPartitionAttributes().getColocatedWith(); - assertEquals("Customer", coLocatedRegion); - - } - - @Test - public void testPartitionedRegionAttributesForCoLocation2(){ - closeCache(); - setXmlFile(findFile("coLocation.xml")); - Cache c = getCache(); - assertNotNull(c); - Region cust = c.getRegion(Region.SEPARATOR+"Customer"); - assertNotNull(cust); - Region order = c.getRegion(Region.SEPARATOR+"Order"); - assertNotNull(order); - - assertTrue(cust.getAttributes().getPartitionAttributes().getColocatedWith()==null); - assertTrue(order.getAttributes().getPartitionAttributes().getColocatedWith().equals("Customer")); - - } - - @Test - public void testPartitionedRegionAttributesForMemLruWithoutMaxMem() throws CacheException - { - final int redundantCopies = 1; - CacheCreation cache = new CacheCreation(); - - RegionAttributesCreation attrs = new RegionAttributesCreation(cache); - attrs.setStatisticsEnabled(true); - PartitionAttributesFactory paf = new PartitionAttributesFactory(); - paf.setRedundantCopies(redundantCopies); - paf.setTotalMaxMemory(500); - paf.setLocalMaxMemory(100); - - AttributesFactory fac = new AttributesFactory(attrs); - fac.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes( null, - EvictionAction.LOCAL_DESTROY)); - fac.setPartitionAttributes(paf.create()); - cache.createRegion("parRoot", fac.create()); - - - testXml(cache); - - Cache c = getCache(); - assertNotNull(c); - - Region region = c.getRegion("parRoot"); - assertNotNull(region); - - RegionAttributes regionAttrs = region.getAttributes(); - PartitionAttributes pa = regionAttrs.getPartitionAttributes(); - EvictionAttributes ea = regionAttrs.getEvictionAttributes(); - - assertEquals(pa.getRedundantCopies(), 1); - assertEquals(pa.getLocalMaxMemory(), 100); - assertEquals(pa.getTotalMaxMemory(), 500); - - - assertEquals(ea.getAlgorithm(),EvictionAlgorithm.LRU_MEMORY); - assertEquals(ea.getAction(), EvictionAction.LOCAL_DESTROY); - assertEquals(ea.getMaximum(), pa.getLocalMaxMemory()); - } - - @Test - public void testPartitionedRegionAttributesForMemLruWithMaxMem() throws CacheException - { - final int redundantCopies = 1; - final int maxMem=25; - CacheCreation cache = new CacheCreation(); - - RegionAttributesCreation attrs = new RegionAttributesCreation(cache); - attrs.setStatisticsEnabled(true); - PartitionAttributesFactory paf = new PartitionAttributesFactory(); - paf.setRedundantCopies(redundantCopies); - paf.setTotalMaxMemory(500); - paf.setLocalMaxMemory(100); - - AttributesFactory fac = new AttributesFactory(attrs); - fac.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes(maxMem, null, - EvictionAction.LOCAL_DESTROY)); - fac.setPartitionAttributes(paf.create()); - cache.createRegion("parRoot", fac.create()); - - - testXml(cache); - - Cache c = getCache(); - assertNotNull(c); - - Region region = c.getRegion("parRoot"); - assertNotNull(region); - - RegionAttributes regionAttrs = region.getAttributes(); - PartitionAttributes pa = regionAttrs.getPartitionAttributes(); - EvictionAttributes ea = regionAttrs.getEvictionAttributes(); - - assertEquals(pa.getRedundantCopies(), 1); - assertEquals(pa.getLocalMaxMemory(), 100); - assertEquals(pa.getTotalMaxMemory(), 500); - - - assertEquals(ea.getAlgorithm(),EvictionAlgorithm.LRU_MEMORY); - assertEquals(ea.getAction(), EvictionAction.LOCAL_DESTROY); - assertNotSame(ea.getMaximum(), maxMem); - assertEquals(ea.getMaximum(), pa.getLocalMaxMemory()); - } - - @Test - public void testReplicatedRegionAttributesForMemLruWithoutMaxMem() throws CacheException - { - final int redundantCopies = 1; - CacheCreation cache = new CacheCreation(); - - AttributesFactory fac = new AttributesFactory(); - fac.setDataPolicy(DataPolicy.REPLICATE); - fac.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes( null, - EvictionAction.OVERFLOW_TO_DISK)); - cache.createRegion("parRoot", fac.create()); - - - testXml(cache); - - Cache c = getCache(); - assertNotNull(c); - - Region region = c.getRegion("parRoot"); - assertNotNull(region); - - RegionAttributes regionAttrs = region.getAttributes(); - EvictionAttributes ea = regionAttrs.getEvictionAttributes(); - - assertEquals(ea.getAlgorithm(),EvictionAlgorithm.LRU_MEMORY); - assertEquals(ea.getAction(), EvictionAction.OVERFLOW_TO_DISK); - assertEquals(ea.getMaximum(), MemLRUCapacityController.DEFAULT_MAXIMUM_MEGABYTES); - } - - @Test - public void testReplicatedRegionAttributesForMemLruWithMaxMem() throws CacheException - { - final int redundantCopies = 1; - final int maxMem=25; - CacheCreation cache = new CacheCreation(); - - AttributesFactory fac = new AttributesFactory(); - fac.setDataPolicy(DataPolicy.REPLICATE); - fac.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes( maxMem,null, - EvictionAction.OVERFLOW_TO_DISK)); - cache.createRegion("parRoot", fac.create()); - - - - testXml(cache); - - Cache c = getCache(); - assertNotNull(c); - - Region region = c.getRegion("parRoot"); - assertNotNull(region); - - RegionAttributes regionAttrs = region.getAttributes(); - EvictionAttributes ea = regionAttrs.getEvictionAttributes(); - assertEquals(ea.getAlgorithm(),EvictionAlgorithm.LRU_MEMORY); - assertEquals(ea.getAction(), EvictionAction.OVERFLOW_TO_DISK); - assertEquals(ea.getMaximum(), maxMem); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/952ab6fa/geode-core/src/test/java/org/apache/geode/cache30/CacheXml60DUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/cache30/CacheXml60DUnitTest.java b/geode-core/src/test/java/org/apache/geode/cache30/CacheXml60DUnitTest.java deleted file mode 100644 index 35026ba..0000000 --- a/geode-core/src/test/java/org/apache/geode/cache30/CacheXml60DUnitTest.java +++ /dev/null @@ -1,346 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.geode.cache30; - -import static org.junit.Assert.*; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; -import java.io.Serializable; - -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import org.apache.geode.DataSerializable; -import org.apache.geode.DataSerializer; -import org.apache.geode.cache.Cache; -import org.apache.geode.cache.CacheException; -import org.apache.geode.cache.PartitionAttributes; -import org.apache.geode.cache.PartitionAttributesFactory; -import org.apache.geode.cache.Region; -import org.apache.geode.cache.RegionAttributes; -import org.apache.geode.internal.InternalDataSerializer; -import org.apache.geode.internal.InternalInstantiator; -import org.apache.geode.internal.cache.xmlcache.CacheCreation; -import org.apache.geode.internal.cache.xmlcache.CacheXml; -import org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation; -import org.apache.geode.internal.cache.xmlcache.ResourceManagerCreation; -import org.apache.geode.internal.cache.xmlcache.SerializerCreation; -import org.apache.geode.internal.i18n.LocalizedStrings; -import org.apache.geode.test.dunit.IgnoredException; -import org.apache.geode.test.junit.categories.DistributedTest; - -/** - * Tests 6.0 cache.xml features. - * - * @since GemFire 6.0 - */ - -@Category(DistributedTest.class) -public class CacheXml60DUnitTest extends CacheXml58DUnitTest -{ - - // ////// Constructors - - public CacheXml60DUnitTest() { - super(); - } - - // ////// Helper methods - - protected String getGemFireVersion() - { - return CacheXml.VERSION_6_0; - } - - - /** - * Tests that a region created with a named attributes set programatically - * for recovery-delay has the correct attributes. - * - */ - @Test - public void testRecoveryDelayAttributes() throws CacheException - { - CacheCreation cache = new CacheCreation(); - RegionAttributesCreation attrs = new RegionAttributesCreation(cache); - - PartitionAttributesFactory paf = new PartitionAttributesFactory(); - paf.setRedundantCopies(1); - paf.setTotalMaxMemory(500); - paf.setLocalMaxMemory(100); - paf.setRecoveryDelay(33); - paf.setStartupRecoveryDelay(270); - - attrs.setPartitionAttributes(paf.create()); - - cache.createRegion("parRoot", attrs); - - Region r = cache.getRegion("parRoot"); - assertEquals(r.getAttributes().getPartitionAttributes().getRedundantCopies(),1); - assertEquals(r.getAttributes().getPartitionAttributes().getLocalMaxMemory(),100); - assertEquals(r.getAttributes().getPartitionAttributes().getTotalMaxMemory(),500); - assertEquals(33, r.getAttributes().getPartitionAttributes().getRecoveryDelay()); - assertEquals(270, r.getAttributes().getPartitionAttributes().getStartupRecoveryDelay()); - - testXml(cache); - - Cache c = getCache(); - assertNotNull(c); - - Region region = c.getRegion("parRoot"); - assertNotNull(region); - - RegionAttributes regionAttrs = region.getAttributes(); - PartitionAttributes pa = regionAttrs.getPartitionAttributes(); - - assertEquals(pa.getRedundantCopies(), 1); - assertEquals(pa.getLocalMaxMemory(), 100); - assertEquals(pa.getTotalMaxMemory(), 500); - assertEquals(33, r.getAttributes().getPartitionAttributes().getRecoveryDelay()); - assertEquals(270, r.getAttributes().getPartitionAttributes().getStartupRecoveryDelay()); - } - - /** - * Tests that a region created with a named attributes set programmatically - * for recovery-delay has the correct attributes. - * - */ - @Test - public void testDefaultRecoveryDelayAttributes() throws CacheException - { - CacheCreation cache = new CacheCreation(); - RegionAttributesCreation attrs = new RegionAttributesCreation(cache); - - PartitionAttributesFactory paf = new PartitionAttributesFactory(); - paf.setRedundantCopies(1); - paf.setTotalMaxMemory(500); - paf.setLocalMaxMemory(100); - attrs.setPartitionAttributes(paf.create()); - - cache.createRegion("parRoot", attrs); - - Region r = cache.getRegion("parRoot"); - assertEquals(r.getAttributes().getPartitionAttributes().getRedundantCopies(),1); - assertEquals(r.getAttributes().getPartitionAttributes().getLocalMaxMemory(),100); - assertEquals(r.getAttributes().getPartitionAttributes().getTotalMaxMemory(),500); - assertEquals(-1, r.getAttributes().getPartitionAttributes().getRecoveryDelay()); - assertEquals(0, r.getAttributes().getPartitionAttributes().getStartupRecoveryDelay()); - - testXml(cache); - - Cache c = getCache(); - assertNotNull(c); - - Region region = c.getRegion("parRoot"); - assertNotNull(region); - - RegionAttributes regionAttrs = region.getAttributes(); - PartitionAttributes pa = regionAttrs.getPartitionAttributes(); - - assertEquals(pa.getRedundantCopies(), 1); - assertEquals(pa.getLocalMaxMemory(), 100); - assertEquals(pa.getTotalMaxMemory(), 500); - assertEquals(-1, r.getAttributes().getPartitionAttributes().getRecoveryDelay()); - assertEquals(0, r.getAttributes().getPartitionAttributes().getStartupRecoveryDelay()); - } - - /** - * Test the ResourceManager element's critical-heap-percentage and - * eviction-heap-percentage attributes - * @throws Exception - */ - @Test - public void testResourceManagerThresholds() throws Exception { - CacheCreation cache = new CacheCreation(); - final float low = 90.0f; - final float high = 95.0f; - - Cache c; - ResourceManagerCreation rmc = new ResourceManagerCreation(); - rmc.setEvictionHeapPercentage(low); - rmc.setCriticalHeapPercentage(high); - cache.setResourceManagerCreation(rmc); - testXml(cache); - { - c = getCache(); - assertEquals(low, c.getResourceManager().getEvictionHeapPercentage(),0); - assertEquals(high, c.getResourceManager().getCriticalHeapPercentage(),0); - } - closeCache(); - - rmc = new ResourceManagerCreation(); - // Set them to similar values - rmc.setEvictionHeapPercentage(low); - rmc.setCriticalHeapPercentage(low + 1); - cache.setResourceManagerCreation(rmc); - testXml(cache); - { - c = getCache(); - assertEquals(low, c.getResourceManager().getEvictionHeapPercentage(),0); - assertEquals(low + 1, c.getResourceManager().getCriticalHeapPercentage(),0); - } - closeCache(); - - rmc = new ResourceManagerCreation(); - rmc.setEvictionHeapPercentage(high); - rmc.setCriticalHeapPercentage(low); - cache.setResourceManagerCreation(rmc); - IgnoredException expectedException = IgnoredException.addIgnoredException(LocalizedStrings.MemoryMonitor_EVICTION_PERCENTAGE_LTE_CRITICAL_PERCENTAGE.toLocalizedString()); - try { - testXml(cache); - assertTrue(false); - } catch (IllegalArgumentException expected) { - } finally { - expectedException.remove(); - closeCache(); - } - - // Disable eviction - rmc = new ResourceManagerCreation(); - rmc.setEvictionHeapPercentage(0); - rmc.setCriticalHeapPercentage(low); - cache.setResourceManagerCreation(rmc); - testXml(cache); - { - c = getCache(); - assertEquals(0f, c.getResourceManager().getEvictionHeapPercentage(),0); - assertEquals(low, c.getResourceManager().getCriticalHeapPercentage(),0); - } - closeCache(); - - // Disable refusing ops in "red zone" - rmc = new ResourceManagerCreation(); - rmc.setEvictionHeapPercentage(low); - rmc.setCriticalHeapPercentage(0); - cache.setResourceManagerCreation(rmc); - testXml(cache); - { - c = getCache(); - assertEquals(low, c.getResourceManager().getEvictionHeapPercentage(),0); - assertEquals(0f, c.getResourceManager().getCriticalHeapPercentage(),0); - } - closeCache(); - - // Disable both - rmc = new ResourceManagerCreation(); - rmc.setEvictionHeapPercentage(0); - rmc.setCriticalHeapPercentage(0); - cache.setResourceManagerCreation(rmc); - testXml(cache); - c = getCache(); - assertEquals(0f, c.getResourceManager().getEvictionHeapPercentage(),0); - assertEquals(0f, c.getResourceManager().getCriticalHeapPercentage(),0); - } - - // A bunch of classes for use in testing the serialization schtuff - public static class DS1 implements DataSerializable { - public void fromData(DataInput in) throws IOException, - ClassNotFoundException {} - public void toData(DataOutput out) throws IOException - {} - }; - - public static class DS2 implements DataSerializable { - public void fromData(DataInput in) throws IOException, - ClassNotFoundException {} - public void toData(DataOutput out) throws IOException - {} - }; - - public static class NotDataSerializable implements Serializable{} - - public static class GoodSerializer extends DataSerializer { - public GoodSerializer(){} - @Override - public Object fromData(DataInput in) throws IOException, - ClassNotFoundException {return null;} - @Override - public int getId() {return 101;} - @Override - public Class[] getSupportedClasses() { - return new Class[] {DS1.class}; - } - @Override - public boolean toData(Object o, DataOutput out) throws IOException - {return false;} - } - - public static class BadSerializer extends DataSerializer { - @Override - public Object fromData(DataInput in) throws IOException, - ClassNotFoundException {return null;} - @Override - public int getId() {return 101;} - @Override - public Class[] getSupportedClasses() { - return null; - } - @Override - public boolean toData(Object o, DataOutput out) throws IOException - {return false;} - } - - @Test - public void testSerializationRegistration() - { - CacheCreation cc = new CacheCreation(); - SerializerCreation sc = new SerializerCreation(); - - cc.setSerializerCreation(sc); - - sc.registerInstantiator(DS1.class, 15); - sc.registerInstantiator(DS2.class, 16); - sc.registerSerializer(GoodSerializer.class); - - testXml(cc); - - //Now make sure all of the classes were registered.... - assertEquals(15, InternalInstantiator.getClassId(DS1.class)); - assertEquals(16, InternalInstantiator.getClassId(DS2.class)); - assertEquals(GoodSerializer.class, InternalDataSerializer.getSerializer(101).getClass()); - - sc = new SerializerCreation(); - sc.registerInstantiator(NotDataSerializable.class, 15); - closeCache(); - cc.setSerializerCreation(sc); - - IgnoredException expectedException = IgnoredException.addIgnoredException("While reading Cache XML file"); - try { - testXml(cc); - fail("Instantiator should not have registered due to bad class."); - } catch(Exception e) { - } finally { - expectedException.remove(); - } - - sc = new SerializerCreation(); - sc.registerSerializer(BadSerializer.class); - closeCache(); - cc.setSerializerCreation(sc); - - IgnoredException expectedException1 = IgnoredException.addIgnoredException("While reading Cache XML file"); - try { - testXml(cc); - fail("Serializer should not have registered due to bad class."); - } catch(Exception e){ - } finally { - expectedException1.remove(); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/952ab6fa/geode-core/src/test/java/org/apache/geode/cache30/CacheXml61DUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/cache30/CacheXml61DUnitTest.java b/geode-core/src/test/java/org/apache/geode/cache30/CacheXml61DUnitTest.java deleted file mode 100644 index ea15c18..0000000 --- a/geode-core/src/test/java/org/apache/geode/cache30/CacheXml61DUnitTest.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.geode.cache30; - -import static org.junit.Assert.*; - -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import org.apache.geode.cache.Cache; -import org.apache.geode.cache.CacheException; -import org.apache.geode.cache.Region; -import org.apache.geode.cache.Scope; -import org.apache.geode.internal.cache.GemFireCacheImpl; -import org.apache.geode.internal.cache.xmlcache.CacheCreation; -import org.apache.geode.internal.cache.xmlcache.CacheXml; -import org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation; -import org.apache.geode.test.junit.categories.DistributedTest; - -/** - * Tests 6.1 cache.xml features. - * - * @since GemFire 6.1 - */ -@Category(DistributedTest.class) -public class CacheXml61DUnitTest extends CacheXml60DUnitTest { - - protected String getGemFireVersion() - { - return CacheXml.VERSION_6_1; - } - - - /** - * Tests that a region created with a named attributes set programmatically - * for delta propogation has the correct attributes. - * - */ - @Test - public void testRegionAttributesForRegionEntryCloning() throws CacheException - { - final String rNameBase = getUniqueName(); - final String r1 = rNameBase + "1"; - - // Setting multi-cast via nested region attributes - CacheCreation creation = new CacheCreation(); - RegionAttributesCreation attrs = new RegionAttributesCreation(creation); - attrs.setScope(Scope.LOCAL); - attrs.setEarlyAck(false); - attrs.setCloningEnable(false); - attrs.setMulticastEnabled(true); - creation.createRegion(r1, attrs); - - testXml(creation); - - Cache c = getCache(); - assertTrue(c instanceof GemFireCacheImpl); - c.loadCacheXml(generate(creation)); - - Region reg1 = c.getRegion(r1); - assertNotNull(reg1); - assertEquals(Scope.LOCAL, reg1.getAttributes().getScope()); - assertFalse(reg1.getAttributes().getEarlyAck()); - assertTrue(reg1.getAttributes().getMulticastEnabled()); - assertFalse(reg1.getAttributes().getCloningEnabled()); - - // changing Clonned setting - reg1.getAttributesMutator().setCloningEnabled(true); - assertTrue(reg1.getAttributes().getCloningEnabled()); - - reg1.getAttributesMutator().setCloningEnabled(false); - assertFalse(reg1.getAttributes().getCloningEnabled()); - - // for sub region - a child attribute should be inherited - String sub = "subRegion"; - RegionAttributesCreation attrsSub = new RegionAttributesCreation(creation); - attrsSub.setScope(Scope.LOCAL); - reg1.createSubregion(sub, attrsSub); - Region subRegion = reg1.getSubregion(sub); - assertFalse(subRegion.getAttributes().getCloningEnabled()); - subRegion.getAttributesMutator().setCloningEnabled(true); - assertTrue(subRegion.getAttributes().getCloningEnabled()); - } -}
