Complete disk store refactoring and added region attributes

This commit is contained in:
David Turanski
2012-06-27 07:18:47 -04:00
parent 400fed1662
commit 7efa90800f
23 changed files with 1968 additions and 1802 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2010-2011 the original author or authors.
* Copyright 2010-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,8 +21,6 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.io.File;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -42,11 +40,13 @@ import com.gemstone.gemfire.cache.EvictionAction;
import com.gemstone.gemfire.cache.EvictionAlgorithm;
import com.gemstone.gemfire.cache.EvictionAttributes;
import com.gemstone.gemfire.cache.InterestResultPolicy;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.RegionAttributes;
import com.gemstone.gemfire.cache.util.ObjectSizer;
/**
* @author Costin Leau
* @author David Turanski
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("client-ns.xml")
@@ -72,7 +72,7 @@ public class ClientRegionNamespaceTest {
assertEquals(DataPolicy.EMPTY, TestUtils.readField("dataPolicy", fb));
}
//@Test
// @Test
public void testComplexClient() throws Exception {
assertTrue(context.containsBean("complex"));
ClientRegionFactoryBean fb = context.getBean("&complex", ClientRegionFactoryBean.class);
@@ -87,7 +87,8 @@ public class ClientRegionNamespaceTest {
Interest keyInt = ints[0];
assertTrue((Boolean) TestUtils.readField("durable", keyInt));
assertEquals(InterestResultPolicy.KEYS, TestUtils.readField("policy", keyInt));
//assertEquals(Object.class, TestUtils.readField("key", keyInt).getClass());
// assertEquals(Object.class, TestUtils.readField("key",
// keyInt).getClass());
// regex interest
RegexInterest regexInt = (RegexInterest) ints[1];
@@ -99,14 +100,10 @@ public class ClientRegionNamespaceTest {
@Test
public void testPersistent() throws Exception {
assertTrue(context.containsBean("persistent"));
ClientRegionFactoryBean fb = context.getBean("&persistent", ClientRegionFactoryBean.class);
assertEquals(DataPolicy.PERSISTENT_REPLICATE, TestUtils.readField("dataPolicy", fb));
RegionAttributes attrs = TestUtils.readField("attributes", fb);
File[] diskDirs = attrs.getDiskDirs();
assertEquals(1, diskDirs.length);
int[] diskDirSizes = attrs.getDiskDirSizes();
assertEquals(1, diskDirSizes.length);
assertEquals(1, diskDirSizes[0]);
Region region = context.getBean("persistent", Region.class);
RegionAttributes attrs = region.getAttributes();
assertEquals("diskStore", attrs.getDiskStoreName());
assertEquals(1, attrs.getDiskDirSizes()[0]);
}
@Test
@@ -116,10 +113,11 @@ public class ClientRegionNamespaceTest {
assertEquals(DataPolicy.NORMAL, TestUtils.readField("dataPolicy", fb));
RegionAttributes attrs = TestUtils.readField("attributes", fb);
EvictionAttributes evicAttr = attrs.getEvictionAttributes();
assertEquals(EvictionAction.LOCAL_DESTROY, evicAttr.getAction());
assertEquals(EvictionAction.OVERFLOW_TO_DISK, evicAttr.getAction());
assertEquals(EvictionAlgorithm.LRU_MEMORY, evicAttr.getAlgorithm());
// for some reason GemFire resets this to 56 on my machine (not sure why)
//assertEquals(10, evicAttr.getMaximum());
// for some reason GemFire resets this to 56 on my machine (not sure
// why)
// assertEquals(10, evicAttr.getMaximum());
ObjectSizer sizer = evicAttr.getObjectSizer();
assertEquals(SimpleObjectSizer.class, sizer.getClass());
}

View File

@@ -18,10 +18,13 @@ package org.springframework.data.gemfire.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.io.File;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -32,12 +35,16 @@ import org.springframework.data.gemfire.TestUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.DiskStore;
import com.gemstone.gemfire.cache.DiskStoreFactory;
import com.gemstone.gemfire.cache.EvictionAction;
import com.gemstone.gemfire.cache.EvictionAlgorithm;
import com.gemstone.gemfire.cache.EvictionAttributes;
import com.gemstone.gemfire.cache.ExpirationAction;
import com.gemstone.gemfire.cache.ExpirationAttributes;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.RegionAttributes;
import com.gemstone.gemfire.cache.Scope;
import com.gemstone.gemfire.cache.util.ObjectSizer;
@@ -52,20 +59,50 @@ public class DiskStoreAndEvictionRegionParsingTest {
@Autowired
private ApplicationContext context;
@Autowired
DiskStore diskStore1;
private static File diskStoreDir;
@BeforeClass
public static void setUp() {
String path = "./build/tmp";
diskStoreDir = new File(path);
if (!diskStoreDir.exists()) {
diskStoreDir.mkdir();
}
}
@AfterClass
public static void tearDown() {
for (File file : diskStoreDir.listFiles()) {
file.delete();
}
diskStoreDir.delete();
}
@Test
public void testDiskStore() {
assertEquals("diskStore1", diskStore1.getName());
assertEquals(50, diskStore1.getQueueSize());
assertEquals(true, diskStore1.getAutoCompact());
assertEquals(DiskStoreFactory.DEFAULT_COMPACTION_THRESHOLD, diskStore1.getCompactionThreshold());
assertEquals(9999, diskStore1.getTimeInterval());
assertEquals(10, diskStore1.getMaxOplogSize());
assertEquals(diskStoreDir, diskStore1.getDiskDirs()[0]);
Cache cache = context.getBean("gemfire-cache", Cache.class);
assertSame(diskStore1, cache.findDiskStore("diskStore1"));
}
@Test
public void testReplicaDataOptions() throws Exception {
assertTrue(context.containsBean("replicated-data"));
RegionFactoryBean fb = context.getBean("&replicated-data", RegionFactoryBean.class);
assertEquals(DataPolicy.PERSISTENT_REPLICATE, TestUtils.readField("dataPolicy", fb));
assertEquals(DataPolicy.REPLICATE, TestUtils.readField("dataPolicy", fb));
assertEquals(Scope.DISTRIBUTED_ACK, TestUtils.readField("scope", fb));
RegionAttributes attrs = TestUtils.readField("attributes", fb);
File[] diskDirs = attrs.getDiskDirs();
assertEquals(1, diskDirs.length);
int[] diskDirSizes = attrs.getDiskDirSizes();
assertEquals(1, diskDirSizes.length);
assertEquals(1, diskDirSizes[0]);
Region region = context.getBean("replicated-data", Region.class);
// eviction tests
RegionAttributes attrs = TestUtils.readField("attributes", fb);
EvictionAttributes evicAttr = attrs.getEvictionAttributes();
assertEquals(EvictionAction.OVERFLOW_TO_DISK, evicAttr.getAction());
assertEquals(EvictionAlgorithm.LRU_ENTRY, evicAttr.getAlgorithm());
@@ -77,13 +114,14 @@ public class DiskStoreAndEvictionRegionParsingTest {
public void testPartitionDataOptions() throws Exception {
assertTrue(context.containsBean("partition-data"));
RegionFactoryBean fb = context.getBean("&partition-data", RegionFactoryBean.class);
assertEquals(DataPolicy.PARTITION, TestUtils.readField("dataPolicy", fb));
assertEquals(DataPolicy.PERSISTENT_PARTITION, TestUtils.readField("dataPolicy", fb));
RegionAttributes attrs = TestUtils.readField("attributes", fb);
EvictionAttributes evicAttr = attrs.getEvictionAttributes();
assertEquals(EvictionAction.LOCAL_DESTROY, evicAttr.getAction());
assertEquals(EvictionAlgorithm.LRU_MEMORY, evicAttr.getAlgorithm());
// for some reason GemFire resets this to 56 on my machine (not sure why)
//assertEquals(10, evicAttr.getMaximum());
// for some reason GemFire resets this to 56 on my machine (not sure
// why)
// assertEquals(10, evicAttr.getMaximum());
ObjectSizer sizer = evicAttr.getObjectSizer();
assertEquals(SimpleObjectSizer.class, sizer.getClass());
}
@@ -109,6 +147,5 @@ public class DiskStoreAndEvictionRegionParsingTest {
ExpirationAttributes regionTTI = attrs.getRegionIdleTimeout();
assertEquals(400, regionTTI.getTimeout());
assertEquals(ExpirationAction.INVALIDATE, regionTTI.getAction());
}
}

View File

@@ -1,72 +0,0 @@
/*
* Copyright 2010-2012 the original author or authors.
*
* Licensed 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.springframework.data.gemfire.config;
import static org.junit.Assert.assertEquals;
import java.io.File;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.gemstone.gemfire.cache.DiskStore;
import com.gemstone.gemfire.cache.DiskStoreFactory;
/**
* @author David Turanski
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("diskstore-ns-new.xml")
public class DiskStoreNamespaceTest {
private static File diskStoreDir;
@Autowired
DiskStore diskStore1;
@Test
public void testDiskStore() {
assertEquals("diskStore1", diskStore1.getName());
assertEquals(50, diskStore1.getQueueSize());
assertEquals(true, diskStore1.getAutoCompact());
assertEquals(DiskStoreFactory.DEFAULT_COMPACTION_THRESHOLD, diskStore1.getCompactionThreshold());
assertEquals(9999, diskStore1.getTimeInterval());
assertEquals(10, diskStore1.getMaxOplogSize());
assertEquals(diskStoreDir, diskStore1.getDiskDirs()[0]);
}
@BeforeClass
public static void setUp() {
String path = "./build/tmp";
diskStoreDir = new File(path);
if (!diskStoreDir.exists()) {
diskStoreDir.mkdir();
}
}
@AfterClass
public static void tearDown() {
for (File file : diskStoreDir.listFiles()) {
file.delete();
}
diskStoreDir.delete();
}
}

View File

@@ -34,7 +34,6 @@ import org.springframework.util.ObjectUtils;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.CacheListener;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.RegionAttributes;
import com.gemstone.gemfire.cache.Scope;
@@ -50,15 +49,15 @@ public class LocalRegionNamespaceTest {
private ApplicationContext context;
@Test
public void testBasicReplica() throws Exception {
public void testBasicLocal() throws Exception {
assertTrue(context.containsBean("simple"));
}
@Test
public void testPublishingReplica() throws Exception {
public void testPublishingLocal() throws Exception {
assertTrue(context.containsBean("pub"));
RegionFactoryBean fb = context.getBean("&pub", RegionFactoryBean.class);
assertEquals(DataPolicy.NORMAL, TestUtils.readField("dataPolicy", fb));
assertEquals("NORMAL", TestUtils.readField("dataPolicyName", fb));
assertEquals(Scope.LOCAL, TestUtils.readField("scope", fb));
assertEquals("publisher", TestUtils.readField("name", fb));
RegionAttributes attrs = TestUtils.readField("attributes", fb);
@@ -66,7 +65,7 @@ public class LocalRegionNamespaceTest {
}
@Test
public void testComplexReplica() throws Exception {
public void testComplexLocal() throws Exception {
assertTrue(context.containsBean("complex"));
RegionFactoryBean fb = context.getBean("&complex", RegionFactoryBean.class);
CacheListener[] listeners = TestUtils.readField("cacheListeners", fb);
@@ -78,6 +77,19 @@ public class LocalRegionNamespaceTest {
assertSame(context.getBean("c-writer"), TestUtils.readField("cacheWriter", fb));
}
@Test
public void testLocalWithAttributes() throws Exception {
assertTrue(context.containsBean("local-with-attributes"));
Region region = context.getBean("local-with-attributes", Region.class);
RegionAttributes attrs = region.getAttributes();
assertEquals(10, attrs.getInitialCapacity());
assertEquals(true, attrs.getIgnoreJTA());
assertEquals(false, attrs.getIndexMaintenanceSynchronous());
assertEquals(String.class, attrs.getKeyConstraint());
assertEquals(String.class, attrs.getValueConstraint());
assertEquals(true, attrs.isDiskSynchronous());
}
@Test
public void testRegionLookup() throws Exception {
Cache cache = context.getBean(Cache.class);

View File

@@ -48,7 +48,7 @@ public class PartitionedRegionNamespaceTest {
private ApplicationContext context;
@Test
public void testBasicReplica() throws Exception {
public void testBasicPartition() throws Exception {
assertTrue(context.containsBean("simple"));
}

View File

@@ -78,6 +78,25 @@ public class ReplicatedRegionNamespaceTest {
assertSame(context.getBean("c-writer"), TestUtils.readField("cacheWriter", fb));
}
@Test
public void testReplicaWithAttributes() throws Exception {
assertTrue(context.containsBean("replicated-with-attributes"));
Region region = context.getBean("replicated-with-attributes", Region.class);
RegionAttributes attrs = region.getAttributes();
assertEquals(10, attrs.getInitialCapacity());
assertEquals(true, attrs.getIgnoreJTA());
assertEquals(false, attrs.getIndexMaintenanceSynchronous());
assertEquals(String.class, attrs.getKeyConstraint());
assertEquals(String.class, attrs.getValueConstraint());
assertEquals(true, attrs.isDiskSynchronous());
assertEquals(Scope.GLOBAL, attrs.getScope());
assertEquals(true, attrs.isLockGrantor());
assertEquals(true, attrs.getEnableAsyncConflation());
assertEquals(true, attrs.getEnableSubscriptionConflation());
assertEquals(0.50, attrs.getLoadFactor(), 0.001);
assertEquals(false, attrs.getCloningEnabled());
}
@Test
public void testRegionLookup() throws Exception {
Cache cache = context.getBean(Cache.class);

View File

@@ -32,18 +32,14 @@
<gfe:locator host="localhost" port="40403"/>
</gfe:pool>
<gfe:client-region id="persistent" pool-name="gemfire-pool" persistent="true">
<gfe:disk-store queue-size="50" auto-compact="true" max-oplog-size="10" time-interval="9999">
<gfe:disk-dir location="./" max-size="1"/>
</gfe:disk-store>
</gfe:client-region>
<gfe:client-region id="persistent" pool-name="gemfire-pool" persistent="true" disk-store-ref="diskStore" disk-synchronous="true"/>
<gfe:disk-store id="diskStore" queue-size="50" auto-compact="true" max-oplog-size="10" time-interval="9999">
<gfe:disk-dir location="./" max-size="1"/>
</gfe:disk-store>
<gfe:client-region id="overflow" pool-name="gemfire-pool">
<gfe:disk-store queue-size="50" auto-compact="true" max-oplog-size="10" time-interval="9999">
<gfe:disk-dir location="./" max-size="1"/>
</gfe:disk-store>
<gfe:eviction type="MEMORY_SIZE" threshold="10" action="LOCAL_DESTROY">
<gfe:client-region id="overflow" pool-name="gemfire-pool" disk-store-ref="diskStore">
<gfe:eviction type="MEMORY_SIZE" threshold="10" action="OVERFLOW_TO_DISK">
<gfe:object-sizer>
<bean class="org.springframework.data.gemfire.SimpleObjectSizer"/>
</gfe:object-sizer>

View File

@@ -1,29 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:gfe="http://www.springframework.org/schema/gemfire"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<gfe:cache/>
<util:properties id="props">
<prop key="location">./build/tmp</prop>
<prop key="queueSize">50</prop>
<prop key="autoCompact">true</prop>
<prop key="maxOpLogSize">10</prop>
<prop key="timeInterval">9999</prop>
<prop key="maxSize">1</prop>
</util:properties>
<context:property-placeholder properties-ref="props"/>
<gfe:disk-store id="diskStore1" queue-size="${queueSize}" auto-compact="${autoCompact}"
max-oplog-size="${maxOpLogSize}" time-interval="${timeInterval}">
<gfe:disk-dir location="${location}" max-size="${maxSize}"/>
</gfe:disk-store>
</beans>

View File

@@ -10,44 +10,48 @@
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<util:properties id="props">
<prop key="ttl">300</prop>
</util:properties>
<gfe:cache/>
<util:properties id="props">
<prop key="location">./build/tmp</prop>
<prop key="queueSize">50</prop>
<prop key="autoCompact">true</prop>
<prop key="maxOpLogSize">10</prop>
<prop key="timeInterval">9999</prop>
<prop key="maxSize">1</prop>
<prop key="ttl">300</prop>
</util:properties>
<context:property-placeholder properties-ref="props"/>
<gfe:cache />
<gfe:partitioned-region id="partitioned-data-with-timeout">
<gfe:entry-ttl timeout="${ttl}" action="DESTROY"/>
</gfe:partitioned-region>
<gfe:replicated-region id="replicated-data" persistent="true" close="true" destroy="false">
<gfe:disk-store queue-size="50" auto-compact="true" max-oplog-size="10" time-interval="9999">
<gfe:disk-dir location="./build/tmp" max-size="1"/>
</gfe:disk-store>
<gfe:disk-store id="diskStore1" queue-size="${queueSize}" auto-compact="${autoCompact}"
max-oplog-size="${maxOpLogSize}" time-interval="${timeInterval}">
<gfe:disk-dir location="${location}" max-size="${maxSize}"/>
</gfe:disk-store>
<!-- <gfe:partitioned-region id="partitioned-data-with-timeout" disk-store-ref="diskStore1" persistent="true"> -->
<!-- <gfe:entry-ttl timeout="${ttl}" action="DESTROY"/> -->
<!-- </gfe:partitioned-region> -->
<gfe:replicated-region id="replicated-data" close="true" destroy="false" disk-store-ref="diskStore1">
<gfe:region-ttl timeout="${ttl}" action="DESTROY"/>
<gfe:region-tti timeout="400" action="INVALIDATE"/>
<gfe:entry-ttl timeout="100" action="DESTROY"/>
<gfe:entry-tti timeout="200" action="INVALIDATE"/>
<gfe:eviction type="ENTRY_COUNT" threshold="50" />
<gfe:eviction type="ENTRY_COUNT" threshold="50" action="OVERFLOW_TO_DISK"/>
</gfe:replicated-region>
<gfe:partitioned-region id="partition-data" persistent="false">
<gfe:disk-store queue-size="50" auto-compact="true" max-oplog-size="10" time-interval="9999">
<gfe:disk-dir location="./" max-size="1"/>
</gfe:disk-store>
<gfe:partitioned-region id="partition-data" persistent="true" disk-store-ref="ds2">
<gfe:eviction type="MEMORY_SIZE" threshold="10" action="LOCAL_DESTROY">
<gfe:object-sizer>
<bean class="org.springframework.data.gemfire.SimpleObjectSizer"/>
</gfe:object-sizer>
</gfe:eviction>
</gfe:partitioned-region>
<gfe:disk-store id="ds2" queue-size="50" auto-compact="true" max-oplog-size="10" time-interval="9999">
<gfe:disk-dir location="./" max-size="1"/>
</gfe:disk-store>
</beans>

View File

@@ -22,6 +22,16 @@
<gfe:cache-loader ref="c-loader"/>
<gfe:cache-writer ref="c-writer"/>
</gfe:local-region>
<gfe:local-region id="local-with-attributes"
disk-synchronous="true"
ignore-jta="true"
index-update-type="asynchronous"
initial-capacity="10"
key-constraint="java.lang.String"
value-constraint="java.lang.String"
data-policy="PRELOADED"
/>
<bean id="c-listener" class="org.springframework.data.gemfire.SimpleCacheListener"/>
<bean id="c-loader" class="org.springframework.data.gemfire.SimpleCacheLoader"/>

View File

@@ -23,6 +23,21 @@
<gfe:cache-writer ref="c-writer"/>
</gfe:replicated-region>
<gfe:replicated-region id="replicated-with-attributes"
disk-synchronous="true"
ignore-jta="true"
index-update-type="asynchronous"
initial-capacity="10"
key-constraint="java.lang.String"
value-constraint="java.lang.String"
scope="global"
is-lock-grantor="true"
enable-async-conflation="true"
enable-subscription-conflation="true"
load-factor="0.5"
cloning-enabled="false"
/>
<bean id="c-listener" class="org.springframework.data.gemfire.SimpleCacheListener"/>
<bean id="c-loader" class="org.springframework.data.gemfire.SimpleCacheLoader"/>
<bean id="c-writer" class="org.springframework.data.gemfire.SimpleCacheWriter"/>