http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/33cdf688/geode-core/src/test/java/org/apache/geode/cache30/CacheXml66DUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/cache30/CacheXml66DUnitTest.java b/geode-core/src/test/java/org/apache/geode/cache30/CacheXml66DUnitTest.java index ededb8d..432c772 100644 --- a/geode-core/src/test/java/org/apache/geode/cache30/CacheXml66DUnitTest.java +++ b/geode-core/src/test/java/org/apache/geode/cache30/CacheXml66DUnitTest.java @@ -16,48 +16,139 @@ */ package org.apache.geode.cache30; +import static org.apache.geode.distributed.ConfigurationProperties.ROLES; import static org.junit.Assert.*; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.DataInput; +import java.io.DataOutput; +import java.io.File; +import java.io.FileInputStream; +import java.io.FilenameFilter; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.io.Serializable; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.UnknownHostException; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Properties; +import org.junit.Ignore; import org.junit.Test; import org.junit.experimental.categories.Category; +import org.xml.sax.SAXException; +import com.company.app.DBLoader; + +import org.apache.geode.DataSerializable; +import org.apache.geode.DataSerializer; +import org.apache.geode.cache.AttributesFactory; +import org.apache.geode.cache.AttributesMutator; import org.apache.geode.cache.Cache; import org.apache.geode.cache.CacheException; import org.apache.geode.cache.CacheFactory; +import org.apache.geode.cache.CacheListener; +import org.apache.geode.cache.CacheLoader; +import org.apache.geode.cache.CacheLoaderException; import org.apache.geode.cache.CacheTransactionManager; +import org.apache.geode.cache.CacheWriter; +import org.apache.geode.cache.CacheXmlException; +import org.apache.geode.cache.CustomExpiry; +import org.apache.geode.cache.DataPolicy; import org.apache.geode.cache.Declarable; +import org.apache.geode.cache.DiskStore; +import org.apache.geode.cache.DiskStoreFactory; +import org.apache.geode.cache.DiskWriteAttributesFactory; +import org.apache.geode.cache.DynamicRegionFactory; +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.FixedPartitionAttributes; +import org.apache.geode.cache.InterestPolicy; +import org.apache.geode.cache.LoaderHelper; +import org.apache.geode.cache.LossAction; +import org.apache.geode.cache.MembershipAttributes; +import org.apache.geode.cache.MirrorType; 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.RegionExistsException; +import org.apache.geode.cache.RegionShortcut; +import org.apache.geode.cache.ResumptionAction; +import org.apache.geode.cache.Scope; +import org.apache.geode.cache.SubscriptionAttributes; +import org.apache.geode.cache.TransactionListener; +import org.apache.geode.cache.TransactionWriter; +import org.apache.geode.cache.Region.Entry; import org.apache.geode.cache.client.ClientCache; +import org.apache.geode.cache.client.ClientRegionShortcut; +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.execute.Function; +import org.apache.geode.cache.execute.FunctionService; +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.cache.util.ObjectSizer; import org.apache.geode.cache.util.TransactionListenerAdapter; +import org.apache.geode.internal.AvailablePort; +import org.apache.geode.internal.AvailablePortHelper; +import org.apache.geode.internal.InternalDataSerializer; +import org.apache.geode.internal.InternalInstantiator; +import org.apache.geode.internal.cache.DiskWriteAttributesImpl; +import org.apache.geode.internal.cache.DistributedRegion; import org.apache.geode.internal.cache.FixedPartitionAttributesImpl; import org.apache.geode.internal.cache.GemFireCacheImpl; +import org.apache.geode.internal.cache.LocalRegion; +import org.apache.geode.internal.cache.PartitionedRegion; +import org.apache.geode.internal.cache.PoolFactoryImpl; +import org.apache.geode.internal.cache.functions.TestFunction; +import org.apache.geode.internal.cache.lru.MemLRUCapacityController; import org.apache.geode.internal.cache.partitioned.fixed.QuarterPartitionResolver; import org.apache.geode.internal.cache.xmlcache.CacheCreation; import org.apache.geode.internal.cache.xmlcache.CacheTransactionManagerCreation; import org.apache.geode.internal.cache.xmlcache.CacheXml; +import org.apache.geode.internal.cache.xmlcache.CacheXmlGenerator; +import org.apache.geode.internal.cache.xmlcache.CacheXmlParser; import org.apache.geode.internal.cache.xmlcache.ClientCacheCreation; +import org.apache.geode.internal.cache.xmlcache.Declarable2; +import org.apache.geode.internal.cache.xmlcache.FunctionServiceCreation; import org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation; +import org.apache.geode.internal.cache.xmlcache.RegionCreation; +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.Assert; +import org.apache.geode.test.dunit.Host; import org.apache.geode.test.dunit.IgnoredException; +import org.apache.geode.test.dunit.LogWriterUtils; +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; +import org.apache.geode.util.test.TestUtil; /** * Tests 7.0 cache.xml feature : Fixed Partitioning. * * @since GemFire 6.6 */ -@Category(DistributedTest.class) -public class CacheXml66DUnitTest extends CacheXml65DUnitTest{ - +public abstract class CacheXml66DUnitTest extends CacheXmlTestCase{ + //////// Constructors public CacheXml66DUnitTest() { @@ -66,323 +157,4667 @@ public class CacheXml66DUnitTest extends CacheXml65DUnitTest{ // ////// Helper methods - protected String getGemFireVersion() - { - return CacheXml.VERSION_6_6; - } + protected abstract String getGemFireVersion(); + + + private final static String ALIAS1; + private final static String ALIAS2; + + static { + String tmp_alias1 = "localhost"; + String tmp_alias2 = "localhost"; +// try { +// tmp_alias1 = getServerHostName(Host.getHost(0)); +// InetSocketAddress addr = createINSA(tmp_alias1, 10000); +// tmp_alias2 = addr.getHostName(); +// } +// catch (IllegalArgumentException suppress) { +// // The runnables dont have a Host object initialized, but they dont need +// // access to the aliases so its ok to suppress this. +// } +// finally { + ALIAS1 = tmp_alias1; + ALIAS2 = tmp_alias2; +// } + } + + 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; + } + } + /** - * Tests that a partitioned region is created with FixedPartitionAttributes - * set programatically and correct cache.xml is generated with the same - * FixedPartitionAttributes - * + * test for checking default value of PR_Single_Hop feature. + * Test for checking default value of multiuser-authentication attribute. */ @Test - public void testFixedPartitioning() throws CacheException { - + public void testDefaultConnectionPool() throws CacheException { + getSystem(); CacheCreation cache = new CacheCreation(); - RegionAttributesCreation attrs = new RegionAttributesCreation(); - FixedPartitionAttributes fpa1 = FixedPartitionAttributes - .createFixedPartition("Q1"); - FixedPartitionAttributes fpa2 = FixedPartitionAttributes - .createFixedPartition("Q2", true); - FixedPartitionAttributes fpa3 = FixedPartitionAttributes - .createFixedPartition("Q3", 3); - FixedPartitionAttributes fpa4 = FixedPartitionAttributes - .createFixedPartition("Q4", false, 3); - List<FixedPartitionAttributes> fpattrsList = new ArrayList<FixedPartitionAttributes>(); - fpattrsList.add(fpa1); - fpattrsList.add(fpa2); - fpattrsList.add(fpa3); - fpattrsList.add(fpa4); - - QuarterPartitionResolver resolver = new QuarterPartitionResolver(); + 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_PR_SINGLE_HOP_ENABLED, cp + .getPRSingleHopEnabled()); + assertEquals(PoolFactory.DEFAULT_SUBSCRIPTION_REDUNDANCY, cp + .getSubscriptionRedundancy()); + assertEquals(PoolFactory.DEFAULT_SUBSCRIPTION_MESSAGE_TRACKING_TIMEOUT, cp + .getSubscriptionMessageTrackingTimeout()); + assertEquals(PoolFactory.DEFAULT_SUBSCRIPTION_ACK_INTERVAL, cp + .getSubscriptionAckInterval()); + assertEquals(PoolFactory.DEFAULT_MULTIUSER_AUTHENTICATION, cp + .getMultiuserAuthentication()); + } - PartitionAttributesFactory paf = new PartitionAttributesFactory(); - paf.setRedundantCopies(1).setPartitionResolver(resolver) - .addFixedPartitionAttributes(fpa1).addFixedPartitionAttributes(fpa2) - .addFixedPartitionAttributes(fpa3).addFixedPartitionAttributes(fpa4); + @Test + public void testDiskStore() throws CacheException { + CacheCreation cache = new CacheCreation(); + DiskStoreFactory dsf = cache.createDiskStoreFactory(); + File[] dirs1 = new File[] {new File("").getAbsoluteFile()}; + DiskStore ds1 = dsf.setAllowForceCompaction(true) + .setAutoCompact(true) + .setCompactionThreshold(100) + .setMaxOplogSize(2) + .setTimeInterval(10) + .setWriteBufferSize(15) + .setQueueSize(12) + .setDiskDirsAndSizes(dirs1, new int[] {1024*20}) + .create(getUniqueName()+1); + File[] dirs2 = new File[] {new File("").getAbsoluteFile()}; + DiskStore ds2 = dsf.setAllowForceCompaction(false) + .setAutoCompact(false) + .setCompactionThreshold(99) + .setMaxOplogSize(1) + .setTimeInterval(9) + .setWriteBufferSize(14) + .setQueueSize(11) + .setDiskDirsAndSizes(dirs2, new int[] {1024*40}) + .create(getUniqueName()+2); + + RegionAttributesCreation attrs = new RegionAttributesCreation(cache); + attrs.setScope(Scope.DISTRIBUTED_ACK); + attrs.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE); + attrs.setDiskStoreName(getUniqueName()+1); + attrs.setDiskSynchronous(true); + RegionCreation root = (RegionCreation) + cache.createRegion("root", attrs); + { + attrs = new RegionAttributesCreation(cache); + attrs.setScope(Scope.DISTRIBUTED_ACK); + attrs.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE); + attrs.setDiskStoreName(getUniqueName()+2); + Region subwithdiskstore = root.createSubregion("subwithdiskstore", attrs); + } - attrs.setPartitionAttributes(paf.create()); - cache.createRegion("Quarter", attrs); - Region r = cache.getRegion("Quarter"); - validateAttributes(r, fpattrsList, resolver, false); + { + attrs = new RegionAttributesCreation(cache); + attrs.setScope(Scope.DISTRIBUTED_ACK); + attrs.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE); + Region subwithdefaultdiskstore = root.createSubregion("subwithdefaultdiskstore", attrs); + } testXml(cache); + } + /** + * test for enabling PRsingleHop feature. + * Test for enabling multiuser-authentication attribute. + */ + @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) + .setPRSingleHopEnabled(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) + .setMultiuserAuthentication(true); + f.create("mypool"); + RegionAttributesCreation attrs = new RegionAttributesCreation(cache); + attrs.setPoolName("mypool"); + attrs.setDataPolicy(DataPolicy.EMPTY); // required for multiuser mode + cache.createVMRegion("rootNORMAL", attrs); + IgnoredException.addIgnoredException("Connection refused: connect"); + testXml(cache); Cache c = getCache(); assertNotNull(c); - Region region = c.getRegion("Quarter"); - assertNotNull(region); - validateAttributes(region, fpattrsList, resolver, false); + 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(true, cp.getPRSingleHopEnabled()); + 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()); + assertEquals(true, cp.getMultiuserAuthentication()); + } + + @Test + public void testDiskStoreValidation() throws CacheException { + CacheCreation cache = new CacheCreation(); + DiskStoreFactory dsf = cache.createDiskStoreFactory(); + DiskStore ds1 = dsf.create(getUniqueName()); + + RegionAttributesCreation attrs = new RegionAttributesCreation(cache); + attrs.setScope(Scope.DISTRIBUTED_ACK); + attrs.setDataPolicy(DataPolicy.REPLICATE); + attrs.setDiskStoreName(getUniqueName()); + RegionCreation root; + try { + root = (RegionCreation)cache.createRegion("root", attrs); + } catch (IllegalStateException e) { + assertTrue(e.getMessage().contains(LocalizedStrings.DiskStore_IS_USED_IN_NONPERSISTENT_REGION.toLocalizedString())); + } catch (Exception ex) { + Assert.fail("Unexpected exception", ex); + } + + EvictionAttributes ea = EvictionAttributes.createLRUEntryAttributes(1000, EvictionAction.OVERFLOW_TO_DISK); + attrs.setEvictionAttributes(ea); + try { + root = (RegionCreation)cache.createRegion("root", attrs); + } catch (IllegalStateException e) { + Assert.fail("With eviction of overflow to disk, region can specify disk store name", e); + } catch (Exception ex) { + Assert.fail("Unexpected exception", ex); + } + + File dir = new File("testDiskStoreValidation"); + dir.mkdir(); + dir.deleteOnExit(); + + File[] dirs2 = new File[] { dir, new File("").getAbsoluteFile()}; + try { + AttributesFactory factory = new AttributesFactory(); + factory.setDiskDirs(dirs2); + factory.setDiskStoreName(getUniqueName()); + RegionAttributes ra = factory.create(); + } catch (IllegalStateException e) { + assertTrue(e.getMessage().contains(LocalizedStrings.DiskStore_Deprecated_API_0_Cannot_Mix_With_DiskStore_1 + .toLocalizedString(new Object[] {"setDiskDirs or setDiskWriteAttributes", getUniqueName()}))); + } catch (Exception ex) { + Assert.fail("Unexpected exception", ex); + } + + try { + AttributesFactory factory = new AttributesFactory(); + factory.setDiskStoreName(getUniqueName()); + factory.setDiskDirs(dirs2); + RegionAttributes ra = factory.create(); + } catch (IllegalStateException e) { + assertTrue(e.getMessage().contains(LocalizedStrings.DiskStore_Deprecated_API_0_Cannot_Mix_With_DiskStore_1 + .toLocalizedString(new Object[] {"setDiskDirs", getUniqueName()}))); + } catch (Exception ex) { + Assert.fail("Unexpected exception", ex); + } + + testXml(cache); } @Test - public void testFixedPartitioning_colocation_WithAttributes() - throws CacheException { + public void testDiskStoreFactory() throws CacheException { CacheCreation cache = new CacheCreation(); - FixedPartitionAttributes fpa1 = FixedPartitionAttributes - .createFixedPartition("Q1"); - FixedPartitionAttributes fpa2 = FixedPartitionAttributes - .createFixedPartition("Q2", true); - FixedPartitionAttributes fpa3 = FixedPartitionAttributes - .createFixedPartition("Q3", 3); - FixedPartitionAttributes fpa4 = FixedPartitionAttributes - .createFixedPartition("Q4", false, 3); - List<FixedPartitionAttributes> fpattrsList = new ArrayList<FixedPartitionAttributes>(); - fpattrsList.add(fpa1); - fpattrsList.add(fpa2); - fpattrsList.add(fpa3); - fpattrsList.add(fpa4); - QuarterPartitionResolver resolver = new QuarterPartitionResolver(); - Region customerRegion = null; - Region orderRegion = null; + DiskStoreFactory dsf = cache.createDiskStoreFactory(); - { - RegionAttributesCreation attrs = new RegionAttributesCreation(); - PartitionAttributesFactory paf = new PartitionAttributesFactory(); - paf.setRedundantCopies(1).setPartitionResolver(resolver) - .addFixedPartitionAttributes(fpa1).addFixedPartitionAttributes(fpa2) - .addFixedPartitionAttributes(fpa3).addFixedPartitionAttributes(fpa4); - attrs.setPartitionAttributes(paf.create()); - cache.createRegion("Customer", attrs); + DiskStore ds1; + try { + dsf.setDiskDirs(new File[] {new File("non_exist_dir")}); + ds1 = dsf.create(getUniqueName()); + //NOT required any more as we create the disk store directory during disk-store creation + //fail("Expected IllegalStateException"); + } catch (IllegalArgumentException e) { + // got expected exception } - customerRegion = cache.getRegion("Customer"); - validateAttributes(customerRegion, fpattrsList, resolver, false); + dsf.setDiskDirs(new File[] {new File(".")}); + ds1 = dsf.create(getUniqueName()); + + RegionAttributesCreation attrs = new RegionAttributesCreation(cache); + attrs.setScope(Scope.DISTRIBUTED_ACK); + attrs.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE); + attrs.setDiskStoreName(getUniqueName()); + AttributesFactory factory = new AttributesFactory(attrs); + RegionAttributes ra = factory.create(); + + RegionCreation root; try { - RegionAttributesCreation attrs = new RegionAttributesCreation(); - PartitionAttributesFactory paf = new PartitionAttributesFactory(); - paf.setRedundantCopies(1).setPartitionResolver(resolver) - .addFixedPartitionAttributes(fpa1).addFixedPartitionAttributes(fpa2) - .addFixedPartitionAttributes(fpa3).addFixedPartitionAttributes(fpa4) - .setColocatedWith("Customer"); + root = (RegionCreation)cache.createRegion("root", ra); + } catch (Exception ex) { + Assert.fail("Unexpected exception", ex); + } + + factory = new AttributesFactory(); + factory.setDiskStoreName(getUniqueName()); + factory.setScope(Scope.DISTRIBUTED_ACK); + factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE); - attrs.setPartitionAttributes(paf.create()); - cache.createRegion("Order", attrs); - orderRegion = cache.getRegion("Order"); - validateAttributes(orderRegion, fpattrsList, resolver, true); + ra = factory.create(); + + RegionCreation root2; + try { + root2 = (RegionCreation)cache.createRegion("root2", ra); + } catch (Exception ex) { + Assert.fail("Unexpected exception", ex); } - catch (Exception illegal) { - if (!((illegal instanceof IllegalStateException) && (illegal.getMessage() - .contains("can not be specified in PartitionAttributesFactory")))) { - Assert.fail("Expected IllegalStateException ", illegal); - } - RegionAttributesCreation attrs = new RegionAttributesCreation(); - PartitionAttributesFactory paf = new PartitionAttributesFactory(); - paf.setRedundantCopies(1).setPartitionResolver(resolver) - .setColocatedWith("Customer"); + factory = new AttributesFactory(); + factory.setDiskStoreName(null); + factory.setScope(Scope.DISTRIBUTED_ACK); + factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE); - attrs.setPartitionAttributes(paf.create()); - cache.createRegion("Order", attrs); - orderRegion = cache.getRegion("Order"); - validateAttributes(orderRegion, fpattrsList, resolver, true); + ra = factory.create(); + + RegionCreation root3; + try { + root3 = (RegionCreation)cache.createRegion("root3", ra); + } catch (Exception ex) { + Assert.fail("Unexpected exception", ex); + } + + testXml(cache); + } + @Test + public void testRedefineOfDefaultDiskStore() throws CacheException { + CacheCreation cache = new CacheCreation(); + DiskStoreFactory dsf = cache.createDiskStoreFactory(); + dsf.setAutoCompact(!DiskStoreFactory.DEFAULT_AUTO_COMPACT); + DiskStore ds1 = dsf.create(DiskStoreFactory.DEFAULT_DISK_STORE_NAME); + + RegionAttributesCreation attrs = new RegionAttributesCreation(cache); + attrs.setScope(Scope.DISTRIBUTED_ACK); + attrs.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE); + AttributesFactory factory = new AttributesFactory(attrs); + RegionAttributes ra = factory.create(); + + RegionCreation root; + try { + root = (RegionCreation)cache.createRegion("root", ra); + } catch (Exception ex) { + Assert.fail("Unexpected exception", ex); } testXml(cache); Cache c = getCache(); assertNotNull(c); - customerRegion = c.getRegion("Customer"); - assertNotNull(customerRegion); - validateAttributes(customerRegion, fpattrsList, resolver, false); - orderRegion = c.getRegion("Order"); - assertNotNull(orderRegion); - validateAttributes(orderRegion, fpattrsList, resolver, true); + DiskStore ds2 = c.findDiskStore(DiskStoreFactory.DEFAULT_DISK_STORE_NAME); + assertNotNull(ds2); + assertEquals(ds1.getAutoCompact(), ds2.getAutoCompact()); } - private void validateAttributes(Region region, - List<FixedPartitionAttributes> fpattrsList, - QuarterPartitionResolver resolver, boolean isColocated) { - RegionAttributes regionAttrs = region.getAttributes(); - PartitionAttributes pa = regionAttrs.getPartitionAttributes(); + /** + * Make sure you can create a persistent partitioned region from xml. + */ + @Test + public void testPersistentPartition() throws CacheException { + CacheCreation cache = new CacheCreation(); + RegionAttributesCreation attrs = new RegionAttributesCreation(cache); + attrs.setDataPolicy(DataPolicy.PERSISTENT_PARTITION); + + cache.createRegion("parRoot", attrs); + + Region r = cache.getRegion("parRoot"); + assertEquals(DataPolicy.PERSISTENT_PARTITION, r.getAttributes().getDataPolicy()); + + testXml(cache); + + Cache c = getCache(); + assertNotNull(c); - assertEquals(pa.getRedundantCopies(), 1); - assertNotNull(pa.getPartitionResolver().getClass()); - assertEquals(pa.getPartitionResolver(), resolver); - List<FixedPartitionAttributesImpl> fixedPartitionsList = pa - .getFixedPartitionAttributes(); - if (isColocated) { - assertNull(fixedPartitionsList); - assertNotNull(pa.getColocatedWith()); - } - else { - assertNull(pa.getColocatedWith()); - assertEquals(fixedPartitionsList.size(), 4); - assertEquals(fixedPartitionsList.containsAll(fpattrsList), true); - for (FixedPartitionAttributes fpa : fixedPartitionsList) { - if (fpa.getPartitionName().equals("Q1")) { - assertEquals(fpa.getNumBuckets(), 1); - assertEquals(fpa.isPrimary(), false); - } - if (fpa.getPartitionName().equals("Q2")) { - assertEquals(fpa.getNumBuckets(), 1); - assertEquals(fpa.isPrimary(), true); - } - if (fpa.getPartitionName().equals("Q3")) { - assertEquals(fpa.getNumBuckets(), 3); - assertEquals(fpa.isPrimary(), false); - } - if (fpa.getPartitionName().equals("Q4")) { - assertEquals(fpa.getNumBuckets(), 3); - assertEquals(fpa.isPrimary(), false); - } - } - } + Region region = c.getRegion("parRoot"); + assertNotNull(region); + assertEquals(DataPolicy.PERSISTENT_PARTITION, region.getAttributes().getDataPolicy()); + // since CacheTestCase remoteTearDown does not destroy PartitionedRegion + region.localDestroyRegion(); } - @Test - public void testPdxDefaults() { - CacheCreation creation = new CacheCreation(); - testXml(creation); + public void testBridgeAttributesRelatedToHAOverFlow65() 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()); + File overflowDirectory = new File("overFlow"); + overflowDirectory.mkdirs(); + DiskStoreFactory dsf = cache.createDiskStoreFactory(); + File[] dirs1 = new File[] {overflowDirectory}; + DiskStore ds1 = dsf.setDiskDirs(dirs1).create(getUniqueName()); + csc.setDiskStoreName(getUniqueName()); + try { + csc.setOverflowDirectory("overFlow"); + } catch (IllegalStateException e) { + assertTrue(e.getMessage().contains( + LocalizedStrings.DiskStore_Deprecated_API_0_Cannot_Mix_With_DiskStore_1 + .toLocalizedString(new Object[] {"setOverflowDirectory", getUniqueName()}))); + } catch (Exception ex) { + Assert.fail("Unexpected exception", ex); + } + cache.getLogger().config( + "Eviction disk store : " + + csc.getDiskStoreName()); + bs.setPort(AvailablePortHelper.getRandomAvailableTCPPort()); + RegionAttributesCreation attrs = new RegionAttributesCreation(cache); + attrs.setDataPolicy(DataPolicy.NORMAL); + cache.createVMRegion("rootNORMAL", attrs); + testXml(cache); Cache c = getCache(); - assertTrue(c instanceof GemFireCacheImpl); - c.loadCacheXml(generate(creation)); - - assertEquals(null, c.getPdxDiskStore()); - assertEquals(null, c.getPdxSerializer()); - assertEquals(false, c.getPdxPersistent()); - assertEquals(false, c.getPdxReadSerialized()); - assertEquals(false, c.getPdxIgnoreUnreadFields()); + assertNotNull(c); + CacheServer server = (CacheServer)cache.getCacheServers().iterator() + .next(); + assertNotNull(server); + ClientSubscriptionConfig chaqf = server.getClientSubscriptionConfig(); + assertEquals("entry", chaqf.getEvictionPolicy()); + assertEquals(501, chaqf.getCapacity()); + DiskStore dsi = cache.findDiskStore(chaqf.getDiskStoreName()); + assertEquals("overFlow", dsi.getDiskDirs()[0].toString()); } @Test - public void testPdxAttributes() { + public void testClientSubscriptionQueueUsingDefaultDS() 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); + // don't set diskstore or overflowdir + cache.getLogger().config( + "EvictionCapacity : " + csc.getCapacity()); + cache.getLogger().config( + "Eviction disk store : " + + csc.getDiskStoreName()); + 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()); + File curDir = new File(".").getAbsoluteFile(); + File lockFile = new File(curDir, "DRLK_IF" + GemFireCacheImpl.DEFAULT_DS_NAME +".lk"); + assertTrue(lockFile.exists()); + } + + /** + * Tests that a region created with a named attributes set programmatically + * for delta propogation has the correct attributes. + * + */ + @Test + public void testTransactionWriter() throws CacheException + { CacheCreation creation = new CacheCreation(); - creation.setPdxPersistent(true); - creation.setPdxReadSerialized(true); - creation.setPdxIgnoreUnreadFields(true); - creation.setPdxDiskStore("my_disk_store"); - TestPdxSerializer serializer = new TestPdxSerializer(); - Properties props = new Properties(); - props.setProperty("hello", "there"); - serializer.init(props); - creation.setPdxSerializer(serializer); + CacheTransactionManagerCreation ctmc = new CacheTransactionManagerCreation(); + ctmc.setWriter(new TestTransactionWriter()); + creation.addCacheTransactionManagerCreation(ctmc); testXml(creation); Cache c = getCache(); assertTrue(c instanceof GemFireCacheImpl); c.loadCacheXml(generate(creation)); - assertEquals("my_disk_store", c.getPdxDiskStore()); - assertEquals(serializer, c.getPdxSerializer()); - assertEquals(true, c.getPdxPersistent()); - assertEquals(true, c.getPdxReadSerialized()); - assertEquals(true, c.getPdxIgnoreUnreadFields()); + TransactionWriter tw = c.getCacheTransactionManager().getWriter(); + assertTrue("tw should be TransactionWriter, but it is:"+tw,tw instanceof TestTransactionWriter); + } + + + /** + * Tests that a region created with a named attributes with diskstore + */ + @Test + public void testDiskStoreInTemplates() throws CacheException + { + File dir = new File("west"); + dir.mkdir(); + dir.deleteOnExit(); + + dir = new File("east"); + dir.mkdir(); + dir.deleteOnExit(); + + setXmlFile(findFile("ewtest.xml")); + + String regionName_west = "orders/west"; + String regionName_east = "orders/east"; + + Cache cache = getCache(); + + // verify diskstores + DiskStore ds = cache.findDiskStore("persistentDiskStore1"); + assertNotNull(ds); + assertEquals(500, ds.getQueueSize()); + File[] dirs = ds.getDiskDirs(); + assertEquals("west", dirs[0].getPath()); + + ds = cache.findDiskStore("persistentDiskStore2"); + assertNotNull(ds); + assertEquals(500, ds.getQueueSize()); + dirs = ds.getDiskDirs(); + assertEquals("east", dirs[0].getPath()); + + // verify templates + assertNotNull(cache.getRegionAttributes("nack")); + RegionAttributes attrs = cache.getRegionAttributes("persistent"); + assertEquals(DataPolicy.PERSISTENT_REPLICATE, attrs.getDataPolicy()); + assertEquals(false, attrs.isDiskSynchronous()); + assertEquals("persistentDiskStore1", attrs.getDiskStoreName()); + + Region region = cache.getRegion(regionName_west); + assertNotNull(region); + + attrs = region.getAttributes(); + assertEquals(DataPolicy.PERSISTENT_REPLICATE, attrs.getDataPolicy()); + assertEquals(false, attrs.isDiskSynchronous()); + assertEquals("persistentDiskStore1", attrs.getDiskStoreName()); + + region = cache.getRegion(regionName_east); + assertNotNull(region); + + // Make sure that attributes can be "overridden" + attrs = region.getAttributes(); + assertEquals(DataPolicy.PERSISTENT_REPLICATE, attrs.getDataPolicy()); + assertEquals(false, attrs.isDiskSynchronous()); + assertEquals("persistentDiskStore2", attrs.getDiskStoreName()); + + // bug 41934 + String regionName_datap = "data-p"; + region = cache.getRegion(regionName_datap); + assertNotNull(region); + attrs = region.getAttributes(); + PartitionAttributes pa = attrs.getPartitionAttributes(); + assertEquals(1, pa.getRedundantCopies()); + assertEquals(3, pa.getTotalNumBuckets()); + assertEquals(DataPolicy.PERSISTENT_PARTITION, attrs.getDataPolicy()); + } + + @Test + public void testBackupFiles() throws CacheException + { + CacheCreation cache = new CacheCreation(); + File backup1 = new File("/back/me/up"); + File backup2 = new File("/me/too/please"); + cache.addBackup(backup1); + cache.addBackup(backup2); + testXml(cache); + GemFireCacheImpl c = (GemFireCacheImpl) getCache(); + assertEquals(Arrays.asList(new File[] {backup1, backup2}), c.getBackupFiles()); + } + + @Test + public void testClientCache() throws CacheException { + ClientCacheCreation cache = new ClientCacheCreation(); + cache.setCopyOnRead(true); + testXml(cache); + GemFireCacheImpl c = (GemFireCacheImpl) getCache(); + assertEquals(true, c.getCopyOnRead()); + assertEquals(true, c.isClient()); + for (ClientRegionShortcut pra: ClientRegionShortcut.values()) { + assertNotNull(c.getRegionAttributes(pra.name())); + } + assertEquals(ClientRegionShortcut.values().length, + c.listRegionAttributes().size()); + } + @Test + public void testNormalCache() throws CacheException { + CacheCreation cache = new CacheCreation(); + cache.setCopyOnRead(true); + testXml(cache); + GemFireCacheImpl c = (GemFireCacheImpl) getCache(); + assertEquals(true, c.getCopyOnRead()); + assertEquals(false, c.isClient()); + for (RegionShortcut pra: RegionShortcut.values()) { + assertNotNull(c.getRegionAttributes(pra.name())); + } + assertEquals(RegionShortcut.values().length, + c.listRegionAttributes().size()); + } + @Test + public void testPARTITION() throws CacheException { + CacheCreation cache = new CacheCreation(); + RegionCreation root = (RegionCreation) + cache.createRegion("partition", "PARTITION"); + testXml(cache); + GemFireCacheImpl c = (GemFireCacheImpl) getCache(); + Region r = c.getRegion("partition"); + assertNotNull(r); + RegionAttributes ra = r.getAttributes(); + assertEquals(DataPolicy.PARTITION, ra.getDataPolicy()); + assertNotNull(ra.getPartitionAttributes()); + assertEquals(0, ra.getPartitionAttributes().getRedundantCopies()); + } + @Test + public void testPARTITION_REDUNDANT() throws CacheException { + CacheCreation cache = new CacheCreation(); + RegionCreation root = (RegionCreation) + cache.createRegion("rpartition", "PARTITION_REDUNDANT"); + testXml(cache); + GemFireCacheImpl c = (GemFireCacheImpl) getCache(); + Region r = c.getRegion("rpartition"); + assertNotNull(r); + RegionAttributes ra = r.getAttributes(); + assertEquals(DataPolicy.PARTITION, ra.getDataPolicy()); + assertNotNull(ra.getPartitionAttributes()); + assertEquals(1, ra.getPartitionAttributes().getRedundantCopies()); + } + @Test + public void testPARTITION_PERSISTENT() throws CacheException { + CacheCreation cache = new CacheCreation(); + RegionCreation root = (RegionCreation) + cache.createRegion("ppartition", "PARTITION_PERSISTENT"); + testXml(cache); + GemFireCacheImpl c = (GemFireCacheImpl) getCache(); + Region r = c.getRegion("ppartition"); + assertNotNull(r); + RegionAttributes ra = r.getAttributes(); + assertEquals(DataPolicy.PERSISTENT_PARTITION, ra.getDataPolicy()); + assertNotNull(ra.getPartitionAttributes()); + assertEquals(0, ra.getPartitionAttributes().getRedundantCopies()); + } + @Test + public void testPARTITION_REDUNDANT_PERSISTENT() throws CacheException { + CacheCreation cache = new CacheCreation(); + RegionCreation root = (RegionCreation) + cache.createRegion("prpartition", "PARTITION_REDUNDANT_PERSISTENT"); + testXml(cache); + GemFireCacheImpl c = (GemFireCacheImpl) getCache(); + Region r = c.getRegion("prpartition"); + assertNotNull(r); + RegionAttributes ra = r.getAttributes(); + assertEquals(DataPolicy.PERSISTENT_PARTITION, ra.getDataPolicy()); + assertNotNull(ra.getPartitionAttributes()); + assertEquals(1, ra.getPartitionAttributes().getRedundantCopies()); + } + @Test + public void testPARTITION_OVERFLOW() throws CacheException { + CacheCreation cache = new CacheCreation(); + ResourceManagerCreation rmc = new ResourceManagerCreation(); + rmc.setEvictionHeapPercentage(55.0f); + rmc.setCriticalHeapPercentage(80.0f); + cache.setResourceManagerCreation(rmc); + RegionCreation root = (RegionCreation) + cache.createRegion("partitionoverflow", "PARTITION_OVERFLOW"); + testXml(cache); + GemFireCacheImpl c = (GemFireCacheImpl) getCache(); + Region r = c.getRegion("partitionoverflow"); + assertNotNull(r); + RegionAttributes ra = r.getAttributes(); + assertEquals(DataPolicy.PARTITION, ra.getDataPolicy()); + assertNotNull(ra.getPartitionAttributes()); + assertEquals(0, ra.getPartitionAttributes().getRedundantCopies()); + assertEquals(EvictionAttributes.createLRUHeapAttributes(null, EvictionAction.OVERFLOW_TO_DISK), ra.getEvictionAttributes()); + assertEquals(55.0f, + c.getResourceManager().getEvictionHeapPercentage(),0); + assertEquals(80.0f, + c.getResourceManager().getCriticalHeapPercentage(),0); + } + @Test + public void testPARTITION_REDUNDANT_OVERFLOW() throws CacheException { + CacheCreation cache = new CacheCreation(); + RegionCreation root = (RegionCreation) + cache.createRegion("rpartitionoverflow", "PARTITION_REDUNDANT_OVERFLOW"); + testXml(cache); + GemFireCacheImpl c = (GemFireCacheImpl) getCache(); + Region r = c.getRegion("rpartitionoverflow"); + assertNotNull(r); + RegionAttributes ra = r.getAttributes(); + assertEquals(DataPolicy.PARTITION, ra.getDataPolicy()); + assertNotNull(ra.getPartitionAttributes()); + assertEquals(1, ra.getPartitionAttributes().getRedundantCopies()); + assertEquals(EvictionAttributes.createLRUHeapAttributes(null, EvictionAction.OVERFLOW_TO_DISK), ra.getEvictionAttributes()); + assertEquals(LocalRegion.DEFAULT_HEAPLRU_EVICTION_HEAP_PERCENTAGE, + c.getResourceManager().getEvictionHeapPercentage(),0); + } + @Test + public void testPARTITION_PERSISTENT_OVERFLOW() throws CacheException { + CacheCreation cache = new CacheCreation(); + ResourceManagerCreation rmc = new ResourceManagerCreation(); + rmc.setCriticalHeapPercentage(80.0f); + cache.setResourceManagerCreation(rmc); + RegionCreation root = (RegionCreation) + cache.createRegion("ppartitionoverflow", "PARTITION_PERSISTENT_OVERFLOW"); + testXml(cache); + GemFireCacheImpl c = (GemFireCacheImpl) getCache(); + Region r = c.getRegion("ppartitionoverflow"); + assertNotNull(r); + RegionAttributes ra = r.getAttributes(); + assertEquals(DataPolicy.PERSISTENT_PARTITION, ra.getDataPolicy()); + assertNotNull(ra.getPartitionAttributes()); + assertEquals(0, ra.getPartitionAttributes().getRedundantCopies()); + assertEquals(EvictionAttributes.createLRUHeapAttributes(null, EvictionAction.OVERFLOW_TO_DISK), ra.getEvictionAttributes()); + assertEquals(80.0f, + c.getResourceManager().getCriticalHeapPercentage(),0); + assertEquals(75.0f, + c.getResourceManager().getEvictionHeapPercentage(),0); + } + @Test + public void testPARTITION_REDUNDANT_PERSISTENT_OVERFLOW() throws CacheException { + CacheCreation cache = new CacheCreation(); + ResourceManagerCreation rmc = new ResourceManagerCreation(); + rmc.setEvictionHeapPercentage(0.0f); // test bug 42130 + cache.setResourceManagerCreation(rmc); + RegionCreation root = (RegionCreation) + cache.createRegion("prpartitionoverflow", "PARTITION_REDUNDANT_PERSISTENT_OVERFLOW"); + testXml(cache); + GemFireCacheImpl c = (GemFireCacheImpl) getCache(); + Region r = c.getRegion("prpartitionoverflow"); + assertNotNull(r); + RegionAttributes ra = r.getAttributes(); + assertEquals(DataPolicy.PERSISTENT_PARTITION, ra.getDataPolicy()); + assertNotNull(ra.getPartitionAttributes()); + assertEquals(1, ra.getPartitionAttributes().getRedundantCopies()); + assertEquals(EvictionAttributes.createLRUHeapAttributes(null, EvictionAction.OVERFLOW_TO_DISK), ra.getEvictionAttributes()); + assertEquals(0.0f, + c.getResourceManager().getEvictionHeapPercentage(),0); + } + @Test + public void testPARTITION_HEAP_LRU() throws CacheException { + CacheCreation cache = new CacheCreation(); + RegionCreation root = (RegionCreation) + cache.createRegion("partitionlru", "PARTITION_HEAP_LRU"); + testXml(cache); + GemFireCacheImpl c = (GemFireCacheImpl) getCache(); + Region r = c.getRegion("partitionlru"); + assertNotNull(r); + RegionAttributes ra = r.getAttributes(); + assertEquals(DataPolicy.PARTITION, ra.getDataPolicy()); + assertNotNull(ra.getPartitionAttributes()); + assertEquals(0, ra.getPartitionAttributes().getRedundantCopies()); + assertEquals(EvictionAttributes.createLRUHeapAttributes(), ra.getEvictionAttributes()); + assertEquals(LocalRegion.DEFAULT_HEAPLRU_EVICTION_HEAP_PERCENTAGE, + c.getResourceManager().getEvictionHeapPercentage(),0); + } + @Test + public void testPARTITION_REDUNDANT_HEAP_LRU() throws CacheException { + CacheCreation cache = new CacheCreation(); + RegionCreation root = (RegionCreation) + cache.createRegion("rpartitionlru", "PARTITION_REDUNDANT_HEAP_LRU"); + testXml(cache); + GemFireCacheImpl c = (GemFireCacheImpl) getCache(); + Region r = c.getRegion("rpartitionlru"); + assertNotNull(r); + RegionAttributes ra = r.getAttributes(); + assertEquals(DataPolicy.PARTITION, ra.getDataPolicy()); + assertNotNull(ra.getPartitionAttributes()); + assertEquals(1, ra.getPartitionAttributes().getRedundantCopies()); + assertEquals(EvictionAttributes.createLRUHeapAttributes(), ra.getEvictionAttributes()); + assertEquals(LocalRegion.DEFAULT_HEAPLRU_EVICTION_HEAP_PERCENTAGE, + c.getResourceManager().getEvictionHeapPercentage(),0); + } + + @Test + public void testREPLICATE() throws CacheException { + CacheCreation cache = new CacheCreation(); + RegionCreation root = (RegionCreation) + cache.createRegion("replicate", "REPLICATE"); + testXml(cache); + GemFireCacheImpl c = (GemFireCacheImpl) getCache(); + Region r = c.getRegion("replicate"); + assertNotNull(r); + RegionAttributes ra = r.getAttributes(); + assertEquals(DataPolicy.REPLICATE, ra.getDataPolicy()); + assertEquals(Scope.DISTRIBUTED_ACK, ra.getScope()); + } + @Test + public void testREPLICATE_PERSISTENT() throws CacheException { + CacheCreation cache = new CacheCreation(); + RegionCreation root = (RegionCreation) + cache.createRegion("preplicate", "REPLICATE_PERSISTENT"); + testXml(cache); + GemFireCacheImpl c = (GemFireCacheImpl) getCache(); + Region r = c.getRegion("preplicate"); + assertNotNull(r); + RegionAttributes ra = r.getAttributes(); + assertEquals(DataPolicy.PERSISTENT_REPLICATE, ra.getDataPolicy()); + assertEquals(Scope.DISTRIBUTED_ACK, ra.getScope()); + } + @Test + public void testREPLICATE_OVERFLOW() throws CacheException { + CacheCreation cache = new CacheCreation(); + RegionCreation root = (RegionCreation) + cache.createRegion("replicateoverflow", "REPLICATE_OVERFLOW"); + testXml(cache); + GemFireCacheImpl c = (GemFireCacheImpl) getCache(); + Region r = c.getRegion("replicateoverflow"); + assertNotNull(r); + RegionAttributes ra = r.getAttributes(); + assertEquals(DataPolicy.REPLICATE, ra.getDataPolicy()); + assertEquals(Scope.DISTRIBUTED_ACK, ra.getScope()); + assertEquals(EvictionAttributes.createLRUHeapAttributes(null, EvictionAction.OVERFLOW_TO_DISK), ra.getEvictionAttributes()); + assertEquals(LocalRegion.DEFAULT_HEAPLRU_EVICTION_HEAP_PERCENTAGE, + c.getResourceManager().getEvictionHeapPercentage(),0); + } + @Test + public void testREPLICATE_PERSISTENT_OVERFLOW() throws CacheException { + CacheCreation cache = new CacheCreation(); + RegionCreation root = (RegionCreation) + cache.createRegion("preplicateoverflow", "REPLICATE_PERSISTENT_OVERFLOW"); + testXml(cache); + GemFireCacheImpl c = (GemFireCacheImpl) getCache(); + Region r = c.getRegion("preplicateoverflow"); + assertNotNull(r); + RegionAttributes ra = r.getAttributes(); + assertEquals(DataPolicy.PERSISTENT_REPLICATE, ra.getDataPolicy()); + assertEquals(Scope.DISTRIBUTED_ACK, ra.getScope()); + assertEquals(EvictionAttributes.createLRUHeapAttributes(null, EvictionAction.OVERFLOW_TO_DISK), ra.getEvictionAttributes()); + assertEquals(LocalRegion.DEFAULT_HEAPLRU_EVICTION_HEAP_PERCENTAGE, + c.getResourceManager().getEvictionHeapPercentage(),0); + } + @Test + public void testREPLICATE_HEAP_LRU() throws CacheException, IOException + { + CacheCreation cache = new CacheCreation(); + RegionCreation root = (RegionCreation) + cache.createRegion("replicatelru", "REPLICATE_HEAP_LRU"); + testXml(cache); + GemFireCacheImpl c = (GemFireCacheImpl) getCache(); + Region r = c.getRegion("replicatelru"); + assertNotNull(r); + RegionAttributes ra = r.getAttributes(); + assertEquals(DataPolicy.PRELOADED, ra.getDataPolicy()); + assertEquals(new SubscriptionAttributes(InterestPolicy.ALL), + ra.getSubscriptionAttributes()); + assertEquals(Scope.DISTRIBUTED_ACK, ra.getScope()); + assertEquals(EvictionAttributes.createLRUHeapAttributes(), ra.getEvictionAttributes()); + assertEquals(LocalRegion.DEFAULT_HEAPLRU_EVICTION_HEAP_PERCENTAGE, + c.getResourceManager().getEvictionHeapPercentage(),0); + } + @Test + public void testLOCAL() throws CacheException { + CacheCreation cache = new CacheCreation(); + RegionCreation root = (RegionCreation) + cache.createRegion("local", "LOCAL"); + testXml(cache); + GemFireCacheImpl c = (GemFireCacheImpl) getCache(); + Region r = c.getRegion("local"); + assertNotNull(r); + RegionAttributes ra = r.getAttributes(); + assertEquals(DataPolicy.NORMAL, ra.getDataPolicy()); + assertEquals(Scope.LOCAL, ra.getScope()); + } + @Test + public void testLOCAL_PERSISTENT() throws CacheException { + CacheCreation cache = new CacheCreation(); + RegionCreation root = (RegionCreation) + cache.createRegion("plocal", "LOCAL_PERSISTENT"); + testXml(cache); + GemFireCacheImpl c = (GemFireCacheImpl) getCache(); + Region r = c.getRegion("plocal"); + assertNotNull(r); + RegionAttributes ra = r.getAttributes(); + assertEquals(DataPolicy.PERSISTENT_REPLICATE, ra.getDataPolicy()); + assertEquals(Scope.LOCAL, ra.getScope()); + } + @Test + public void testLOCAL_HEAP_LRU() throws CacheException { + CacheCreation cache = new CacheCreation(); + RegionCreation root = (RegionCreation) + cache.createRegion("locallru", "LOCAL_HEAP_LRU"); + testXml(cache); + GemFireCacheImpl c = (GemFireCacheImpl) getCache(); + Region r = c.getRegion("locallru"); + assertNotNull(r); + RegionAttributes ra = r.getAttributes(); + assertEquals(DataPolicy.NORMAL, ra.getDataPolicy()); + assertEquals(Scope.LOCAL, ra.getScope()); + assertEquals(EvictionAttributes.createLRUHeapAttributes(), ra.getEvictionAttributes()); + assertEquals(LocalRegion.DEFAULT_HEAPLRU_EVICTION_HEAP_PERCENTAGE, + c.getResourceManager().getEvictionHeapPercentage(),0); + } + @Test + public void testLOCAL_OVERFLOW() throws CacheException { + CacheCreation cache = new CacheCreation(); + RegionCreation root = (RegionCreation) + cache.createRegion("localoverflow", "LOCAL_OVERFLOW"); + testXml(cache); + GemFireCacheImpl c = (GemFireCacheImpl) getCache(); + Region r = c.getRegion("localoverflow"); + assertNotNull(r); + RegionAttributes ra = r.getAttributes(); + assertEquals(DataPolicy.NORMAL, ra.getDataPolicy()); + assertEquals(Scope.LOCAL, ra.getScope()); + assertEquals(EvictionAttributes.createLRUHeapAttributes(null, EvictionAction.OVERFLOW_TO_DISK), ra.getEvictionAttributes()); + assertEquals(LocalRegion.DEFAULT_HEAPLRU_EVICTION_HEAP_PERCENTAGE, + c.getResourceManager().getEvictionHeapPercentage(),0); + } + @Test + public void testLOCAL_PERSISTENT_OVERFLOW() throws CacheException { + CacheCreation cache = new CacheCreation(); + RegionCreation root = (RegionCreation) + cache.createRegion("cpolocal", "LOCAL_PERSISTENT_OVERFLOW"); + testXml(cache); + GemFireCacheImpl c = (GemFireCacheImpl) getCache(); + Region r = c.getRegion("cpolocal"); + assertNotNull(r); + RegionAttributes ra = r.getAttributes(); + assertEquals(DataPolicy.PERSISTENT_REPLICATE, ra.getDataPolicy()); + assertEquals(Scope.LOCAL, ra.getScope()); + assertEquals(EvictionAttributes.createLRUHeapAttributes(null, EvictionAction.OVERFLOW_TO_DISK), ra.getEvictionAttributes()); + assertEquals(LocalRegion.DEFAULT_HEAPLRU_EVICTION_HEAP_PERCENTAGE, + c.getResourceManager().getEvictionHeapPercentage(),0); + } + + @Test + public void testPARTITION_PROXY() throws CacheException { + CacheCreation cache = new CacheCreation(); + RegionCreation root = (RegionCreation) + cache.createRegion("partitionProxy", "PARTITION_PROXY"); + testXml(cache); + GemFireCacheImpl c = (GemFireCacheImpl) getCache(); + Region r = c.getRegion("partitionProxy"); + assertNotNull(r); + RegionAttributes ra = r.getAttributes(); + assertEquals(DataPolicy.PARTITION, ra.getDataPolicy()); + assertNotNull(ra.getPartitionAttributes()); + assertEquals(0, ra.getPartitionAttributes().getRedundantCopies()); + assertEquals(0, ra.getPartitionAttributes().getLocalMaxMemory()); + } + @Test + public void testPARTITION_PROXY_REDUNDANT() throws CacheException { + CacheCreation cache = new CacheCreation(); + RegionCreation root = (RegionCreation) + cache.createRegion("rpartitionProxy", "PARTITION_PROXY_REDUNDANT"); + testXml(cache); + GemFireCacheImpl c = (GemFireCacheImpl) getCache(); + Region r = c.getRegion("rpartitionProxy"); + assertNotNull(r); + RegionAttributes ra = r.getAttributes(); + assertEquals(DataPolicy.PARTITION, ra.getDataPolicy()); + assertNotNull(ra.getPartitionAttributes()); + assertEquals(1, ra.getPartitionAttributes().getRedundantCopies()); + assertEquals(0, ra.getPartitionAttributes().getLocalMaxMemory()); + } + @Test + public void testREPLICATE_PROXY() throws CacheException { + CacheCreation cache = new CacheCreation(); + RegionCreation root = (RegionCreation) + cache.createRegion("replicateProxy", "REPLICATE_PROXY"); + testXml(cache); + GemFireCacheImpl c = (GemFireCacheImpl) getCache(); + Region r = c.getRegion("replicateProxy"); + assertNotNull(r); + RegionAttributes ra = r.getAttributes(); + assertEquals(DataPolicy.EMPTY, ra.getDataPolicy()); + assertEquals(Scope.DISTRIBUTED_ACK, ra.getScope()); + } + + @Test + public void testPROXY() throws CacheException { + ClientCacheCreation cache = new ClientCacheCreation(); + RegionCreation root = (RegionCreation) + cache.createRegion("proxy", "PROXY"); + testXml(cache); + GemFireCacheImpl c = (GemFireCacheImpl) getCache(); + assertEquals(true, c.isClient()); + Region r = c.getRegion("proxy"); + assertNotNull(r); + RegionAttributes ra = r.getAttributes(); + assertEquals(DataPolicy.EMPTY, ra.getDataPolicy()); + assertEquals(Scope.LOCAL, ra.getScope()); + assertEquals("DEFAULT", ra.getPoolName()); + } + @Test + public void testCACHING_PROXY() throws CacheException { + ClientCacheCreation cache = new ClientCacheCreation(); + RegionCreation root = (RegionCreation) + cache.createRegion("cproxy", "CACHING_PROXY"); + testXml(cache); + GemFireCacheImpl c = (GemFireCacheImpl) getCache(); + assertEquals(true, c.isClient()); + Region r = c.getRegion("cproxy"); + assertNotNull(r); + RegionAttributes ra = r.getAttributes(); + assertEquals(DataPolicy.NORMAL, ra.getDataPolicy()); + assertEquals(Scope.LOCAL, ra.getScope()); + assertEquals("DEFAULT", ra.getPoolName()); + } + @Test + public void testCACHING_PROXY_HEAP_LRU() throws CacheException { + ClientCacheCreation cache = new ClientCacheCreation(); + RegionCreation root = (RegionCreation) + cache.createRegion("cproxylru", "CACHING_PROXY_HEAP_LRU"); + testXml(cache); + GemFireCacheImpl c = (GemFireCacheImpl) getCache(); + assertEquals(true, c.isClient()); + Region r = c.getRegion("cproxylru"); + assertNotNull(r); + RegionAttributes ra = r.getAttributes(); + assertEquals(DataPolicy.NORMAL, ra.getDataPolicy()); + assertEquals(Scope.LOCAL, ra.getScope()); + assertEquals("DEFAULT", ra.getPoolName()); + assertEquals(EvictionAttributes.createLRUHeapAttributes(), ra.getEvictionAttributes()); + assertEquals(LocalRegion.DEFAULT_HEAPLRU_EVICTION_HEAP_PERCENTAGE, + c.getResourceManager().getEvictionHeapPercentage(), 0); + } + @Test + public void testCACHING_PROXY_OVERFLOW() throws CacheException { + ClientCacheCreation cache = new ClientCacheCreation(); + RegionCreation root = (RegionCreation) + cache.createRegion("cproxyoverflow", "CACHING_PROXY_OVERFLOW"); + testXml(cache); + GemFireCacheImpl c = (GemFireCacheImpl) getCache(); + assertEquals(true, c.isClient()); + Region r = c.getRegion("cproxyoverflow"); + assertNotNull(r); + RegionAttributes ra = r.getAttributes(); + assertEquals(DataPolicy.NORMAL, ra.getDataPolicy()); + assertEquals(Scope.LOCAL, ra.getScope()); + assertEquals("DEFAULT", ra.getPoolName()); + assertEquals(EvictionAttributes.createLRUHeapAttributes(null, EvictionAction.OVERFLOW_TO_DISK), ra.getEvictionAttributes()); + assertEquals(LocalRegion.DEFAULT_HEAPLRU_EVICTION_HEAP_PERCENTAGE, + c.getResourceManager().getEvictionHeapPercentage(),0); + } + @Test + public void testClientLOCAL() throws CacheException { + ClientCacheCreation cache = new ClientCacheCreation(); + RegionCreation root = (RegionCreation) + cache.createRegion("local", "LOCAL"); + testXml(cache); + GemFireCacheImpl c = (GemFireCacheImpl) getCache(); + assertEquals(true, c.isClient()); + Region r = c.getRegion("local"); + assertNotNull(r); + RegionAttributes ra = r.getAttributes(); + assertEquals(DataPolicy.NORMAL, ra.getDataPolicy()); + assertEquals(Scope.LOCAL, ra.getScope()); + assertEquals(null, ra.getPoolName()); + } + @Test + public void testClientLOCAL_HEAP_LRU() throws CacheException { + ClientCacheCreation cache = new ClientCacheCreation(); + RegionCreation root = (RegionCreation) + cache.createRegion("locallru", "LOCAL_HEAP_LRU"); + testXml(cache); + GemFireCacheImpl c = (GemFireCacheImpl) getCache(); + assertEquals(true, c.isClient()); + Region r = c.getRegion("locallru"); + assertNotNull(r); + RegionAttributes ra = r.getAttributes(); + assertEquals(DataPolicy.NORMAL, ra.getDataPolicy()); + assertEquals(Scope.LOCAL, ra.getScope()); + assertEquals(null, ra.getPoolName()); + assertEquals(EvictionAttributes.createLRUHeapAttributes(), ra.getEvictionAttributes()); + assertEquals(LocalRegion.DEFAULT_HEAPLRU_EVICTION_HEAP_PERCENTAGE, + c.getResourceManager().getEvictionHeapPercentage(),0); + } + @Test + public void testClientLOCAL_OVERFLOW() throws CacheException { + ClientCacheCreation cache = new ClientCacheCreation(); + RegionCreation root = (RegionCreation) + cache.createRegion("localoverflow", "LOCAL_OVERFLOW"); + testXml(cache); + GemFireCacheImpl c = (GemFireCacheImpl) getCache(); + assertEquals(true, c.isClient()); + Region r = c.getRegion("localoverflow"); + assertNotNull(r); + RegionAttributes ra = r.getAttributes(); + assertEquals(DataPolicy.NORMAL, ra.getDataPolicy()); + assertEquals(Scope.LOCAL, ra.getScope()); + assertEquals(null, ra.getPoolName()); + assertEquals(EvictionAttributes.createLRUHeapAttributes(null, EvictionAction.OVERFLOW_TO_DISK), ra.getEvictionAttributes()); + assertEquals(LocalRegion.DEFAULT_HEAPLRU_EVICTION_HEAP_PERCENTAGE, + c.getResourceManager().getEvictionHeapPercentage(),0); + } + @Test + public void testClientLOCAL_PERSISTENT() throws CacheException { + ClientCacheCreation cache = new ClientCacheCreation(); + RegionCreation root = (RegionCreation) + cache.createRegion("cplocal", "LOCAL_PERSISTENT"); + testXml(cache); + GemFireCacheImpl c = (GemFireCacheImpl) getCache(); + assertEquals(true, c.isClient()); + Region r = c.getRegion("cplocal"); + assertNotNull(r); + RegionAttributes ra = r.getAttributes(); + assertEquals(DataPolicy.PERSISTENT_REPLICATE, ra.getDataPolicy()); + assertEquals(Scope.LOCAL, ra.getScope()); + assertEquals(null, ra.getPoolName()); + } + @Test + public void testClientLOCAL_PERSISTENT_OVERFLOW() throws CacheException { + ClientCacheCreation cache = new ClientCacheCreation(); + RegionCreation root = (RegionCreation) + cache.createRegion("cpolocal", "LOCAL_PERSISTENT_OVERFLOW"); + testXml(cache); + GemFireCacheImpl c = (GemFireCacheImpl) getCache(); + assertEquals(true, c.isClient()); + Region r = c.getRegion("cpolocal"); + assertNotNull(r); + RegionAttributes ra = r.getAttributes(); + assertEquals(DataPolicy.PERSISTENT_REPLICATE, ra.getDataPolicy()); + assertEquals(Scope.LOCAL, ra.getScope()); + assertEquals(null, ra.getPoolName()); + assertEquals(EvictionAttributes.createLRUHeapAttributes(null, EvictionAction.OVERFLOW_TO_DISK), ra.getEvictionAttributes()); + assertEquals(LocalRegion.DEFAULT_HEAPLRU_EVICTION_HEAP_PERCENTAGE, + c.getResourceManager().getEvictionHeapPercentage(),0); + } + + + + /** + * Tests that a partitioned region is created with FixedPartitionAttributes + * set programatically and correct cache.xml is generated with the same + * FixedPartitionAttributes + * + */ + @Test + public void testFixedPartitioning() throws CacheException { + + CacheCreation cache = new CacheCreation(); + RegionAttributesCreation attrs = new RegionAttributesCreation(); + FixedPartitionAttributes fpa1 = FixedPartitionAttributes + .createFixedPartition("Q1"); + FixedPartitionAttributes fpa2 = FixedPartitionAttributes + .createFixedPartition("Q2", true); + FixedPartitionAttributes fpa3 = FixedPartitionAttributes + .createFixedPartition("Q3", 3); + FixedPartitionAttributes fpa4 = FixedPartitionAttributes + .createFixedPartition("Q4", false, 3); + List<FixedPartitionAttributes> fpattrsList = new ArrayList<FixedPartitionAttributes>(); + fpattrsList.add(fpa1); + fpattrsList.add(fpa2); + fpattrsList.add(fpa3); + fpattrsList.add(fpa4); + + QuarterPartitionResolver resolver = new QuarterPartitionResolver(); + + PartitionAttributesFactory paf = new PartitionAttributesFactory(); + paf.setRedundantCopies(1).setPartitionResolver(resolver) + .addFixedPartitionAttributes(fpa1).addFixedPartitionAttributes(fpa2) + .addFixedPartitionAttributes(fpa3).addFixedPartitionAttributes(fpa4); + + attrs.setPartitionAttributes(paf.create()); + cache.createRegion("Quarter", attrs); + Region r = cache.getRegion("Quarter"); + validateAttributes(r, fpattrsList, resolver, false); + + testXml(cache); + + Cache c = getCache(); + assertNotNull(c); + Region region = c.getRegion("Quarter"); + assertNotNull(region); + validateAttributes(region, fpattrsList, resolver, false); + } + + @Test + public void testFixedPartitioning_colocation_WithAttributes() + throws CacheException { + CacheCreation cache = new CacheCreation(); + FixedPartitionAttributes fpa1 = FixedPartitionAttributes + .createFixedPartition("Q1"); + FixedPartitionAttributes fpa2 = FixedPartitionAttributes + .createFixedPartition("Q2", true); + FixedPartitionAttributes fpa3 = FixedPartitionAttributes + .createFixedPartition("Q3", 3); + FixedPartitionAttributes fpa4 = FixedPartitionAttributes + .createFixedPartition("Q4", false, 3); + List<FixedPartitionAttributes> fpattrsList = new ArrayList<FixedPartitionAttributes>(); + fpattrsList.add(fpa1); + fpattrsList.add(fpa2); + fpattrsList.add(fpa3); + fpattrsList.add(fpa4); + QuarterPartitionResolver resolver = new QuarterPartitionResolver(); + Region customerRegion = null; + Region orderRegion = null; + + { + RegionAttributesCreation attrs = new RegionAttributesCreation(); + PartitionAttributesFactory paf = new PartitionAttributesFactory(); + paf.setRedundantCopies(1).setPartitionResolver(resolver) + .addFixedPartitionAttributes(fpa1).addFixedPartitionAttributes(fpa2) + .addFixedPartitionAttributes(fpa3).addFixedPartitionAttributes(fpa4); + attrs.setPartitionAttributes(paf.create()); + cache.createRegion("Customer", attrs); + } + customerRegion = cache.getRegion("Customer"); + validateAttributes(customerRegion, fpattrsList, resolver, false); + + try { + RegionAttributesCreation attrs = new RegionAttributesCreation(); + PartitionAttributesFactory paf = new PartitionAttributesFactory(); + paf.setRedundantCopies(1).setPartitionResolver(resolver) + .addFixedPartitionAttributes(fpa1).addFixedPartitionAttributes(fpa2) + .addFixedPartitionAttributes(fpa3).addFixedPartitionAttributes(fpa4) + .setColocatedWith("Customer"); + + attrs.setPartitionAttributes(paf.create()); + cache.createRegion("Order", attrs); + orderRegion = cache.getRegion("Order"); + validateAttributes(orderRegion, fpattrsList, resolver, true); + } + catch (Exception illegal) { + if (!((illegal instanceof IllegalStateException) && (illegal.getMessage() + .contains("can not be specified in PartitionAttributesFactory")))) { + Assert.fail("Expected IllegalStateException ", illegal); + } + + RegionAttributesCreation attrs = new RegionAttributesCreation(); + PartitionAttributesFactory paf = new PartitionAttributesFactory(); + paf.setRedundantCopies(1).setPartitionResolver(resolver) + .setColocatedWith("Customer"); + + attrs.setPartitionAttributes(paf.create()); + cache.createRegion("Order", attrs); + orderRegion = cache.getRegion("Order"); + validateAttributes(orderRegion, fpattrsList, resolver, true); + } + + testXml(cache); + + Cache c = getCache(); + assertNotNull(c); + customerRegion = c.getRegion("Customer"); + assertNotNull(customerRegion); + validateAttributes(customerRegion, fpattrsList, resolver, false); + + orderRegion = c.getRegion("Order"); + assertNotNull(orderRegion); + validateAttributes(orderRegion, fpattrsList, resolver, true); + } + + private void validateAttributes(Region region, + List<FixedPartitionAttributes> fpattrsList, + QuarterPartitionResolver resolver, boolean isColocated) { + RegionAttributes regionAttrs = region.getAttributes(); + PartitionAttributes pa = regionAttrs.getPartitionAttributes(); + + assertEquals(pa.getRedundantCopies(), 1); + assertNotNull(pa.getPartitionResolver().getClass()); + assertEquals(pa.getPartitionResolver(), resolver); + List<FixedPartitionAttributesImpl> fixedPartitionsList = pa + .getFixedPartitionAttributes(); + if (isColocated) { + assertNull(fixedPartitionsList); + assertNotNull(pa.getColocatedWith()); + } + else { + assertNull(pa.getColocatedWith()); + assertEquals(fixedPartitionsList.size(), 4); + assertEquals(fixedPartitionsList.containsAll(fpattrsList), true); + for (FixedPartitionAttributes fpa : fixedPartitionsList) { + if (fpa.getPartitionName().equals("Q1")) { + assertEquals(fpa.getNumBuckets(), 1); + assertEquals(fpa.isPrimary(), false); + } + if (fpa.getPartitionName().equals("Q2")) { + assertEquals(fpa.getNumBuckets(), 1); + assertEquals(fpa.isPrimary(), true); + } + if (fpa.getPartitionName().equals("Q3")) { + assertEquals(fpa.getNumBuckets(), 3); + assertEquals(fpa.isPrimary(), false); + } + if (fpa.getPartitionName().equals("Q4")) { + assertEquals(fpa.getNumBuckets(), 3); + assertEquals(fpa.isPrimary(), false); + } + } + } + + } + + + @Test + public void testPdxDefaults() { + CacheCreation creation = new CacheCreation(); + testXml(creation); + + Cache c = getCache(); + assertTrue(c instanceof GemFireCacheImpl); + c.loadCacheXml(generate(creation)); + + assertEquals(null, c.getPdxDiskStore()); + assertEquals(null, c.getPdxSerializer()); + assertEquals(false, c.getPdxPersistent()); + assertEquals(false, c.getPdxReadSerialized()); + assertEquals(false, c.getPdxIgnoreUnreadFields()); + } + + @Test + public void testPdxAttributes() { + CacheCreation creation = new CacheCreation(); + creation.setPdxPersistent(true); + creation.setPdxReadSerialized(true); + creation.setPdxIgnoreUnreadFields(true); + creation.setPdxDiskStore("my_disk_store"); + TestPdxSerializer serializer = new TestPdxSerializer(); + Properties props = new Properties(); + props.setProperty("hello", "there"); + serializer.init(props); + creation.setPdxSerializer(serializer); + testXml(creation); + + Cache c = getCache(); + assertTrue(c instanceof GemFireCacheImpl); + c.loadCacheXml(generate(creation)); + + assertEquals("my_disk_store", c.getPdxDiskStore()); + assertEquals(serializer, c.getPdxSerializer()); + assertEquals(true, c.getPdxPersistent()); + assertEquals(true, c.getPdxReadSerialized()); + assertEquals(true, c.getPdxIgnoreUnreadFields()); + + //test that we can override the cache.xml attributes + { + closeCache(); + CacheFactory cf = new CacheFactory(); + cf.setPdxDiskStore("new disk store"); + c = getCache(cf); + assertTrue(c instanceof GemFireCacheImpl); + c.loadCacheXml(generate(creation)); + + assertEquals("new disk store", c.getPdxDiskStore()); + assertEquals(serializer, c.getPdxSerializer()); + assertEquals(true, c.getPdxPersistent()); + assertEquals(true, c.getPdxReadSerialized()); + assertEquals(true, c.getPdxIgnoreUnreadFields()); + } + + { + closeCache(); + CacheFactory cf = new CacheFactory(); + cf.setPdxPersistent(false); + cf.setPdxIgnoreUnreadFields(false); + c = getCache(cf); + assertTrue(c instanceof GemFireCacheImpl); + c.loadCacheXml(generate(creation)); + + assertEquals("my_disk_store", c.getPdxDiskStore()); + assertEquals(serializer, c.getPdxSerializer()); + assertEquals(false, c.getPdxPersistent()); + assertEquals(true, c.getPdxReadSerialized()); + assertEquals(false, c.getPdxIgnoreUnreadFields()); + } + + { + closeCache(); + CacheFactory cf = new CacheFactory(); + cf.setPdxSerializer(null); + c = getCache(cf); + assertTrue(c instanceof GemFireCacheImpl); + c.loadCacheXml(generate(creation)); + + assertEquals("my_disk_store", c.getPdxDiskStore()); + assertEquals(null, c.getPdxSerializer()); + assertEquals(true, c.getPdxPersistent()); + assertEquals(true, c.getPdxReadSerialized()); + assertEquals(true, c.getPdxIgnoreUnreadFields()); + } + + { + closeCache(); + CacheFactory cf = new CacheFactory(); + cf.setPdxReadSerialized(false); + c = getCache(cf); + assertTrue(c instanceof GemFireCacheImpl); + c.loadCacheXml(generate(creation)); + + assertEquals("my_disk_store", c.getPdxDiskStore()); + assertEquals(serializer, c.getPdxSerializer()); + assertEquals(true, c.getPdxPersistent()); + assertEquals(false, c.getPdxReadSerialized()); + assertEquals(true, c.getPdxIgnoreUnreadFields()); + } + + } + + @Test + public void testTXManagerOnClientCache() { + ClientCacheCreation cc = new ClientCacheCreation(); + //CacheCreation cc = new CacheCreation(); + CacheTransactionManagerCreation txMgrCreation = new CacheTransactionManagerCreation(); + txMgrCreation.addListener(new TestTXListener()); + cc.addCacheTransactionManagerCreation(txMgrCreation); + testXml(cc); + + Cache c = getCache(); + assertTrue(c instanceof ClientCache); + c.loadCacheXml(generate(cc)); + + ClientCache clientC = (ClientCache) c; + CacheTransactionManager mgr = clientC.getCacheTransactionManager(); + assertNotNull(mgr); + assertTrue(mgr.getListeners()[0] instanceof TestTXListener); + + } + + @Test + public void testNoTXWriterOnClient() { + //test writer is not created + ClientCacheCreation cc = new ClientCacheCreation(); + CacheTransactionManagerCreation txMgrCreation = new CacheTransactionManagerCreation(); + txMgrCreation.setWriter(new TestTransactionWriter()); + cc.addCacheTransactionManagerCreation(txMgrCreation); + IgnoredException expectedException = IgnoredException.addIgnoredException(LocalizedStrings.TXManager_NO_WRITER_ON_CLIENT.toLocalizedString()); + try { + testXml(cc); + fail("expected exception not thrown"); + } catch (IllegalStateException e) { + } finally { + expectedException.remove(); + } + } + + public static class TestTXListener extends TransactionListenerAdapter implements Declarable { + public void init(Properties props) { + } + @Override + public boolean equals(Object other) { + return other instanceof TestTXListener; + } + } + + /** + * 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()); + } + + /** + * 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(); + } + } + + /** + * 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 programmatic
<TRUNCATED>