Complete disk store refactoring and added region attributes
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user