Refactored to use DiskStoreFactory
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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 static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.gemfire.RegionFactoryBean;
|
||||
import org.springframework.data.gemfire.RegionLookupFactoryBean;
|
||||
import org.springframework.data.gemfire.TestUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author Costin Leau
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("local-ns.xml")
|
||||
public class LocalRegionNamespaceTest {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void testBasicReplica() throws Exception {
|
||||
assertTrue(context.containsBean("simple"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPublishingReplica() throws Exception {
|
||||
assertTrue(context.containsBean("pub"));
|
||||
RegionFactoryBean fb = context.getBean("&pub", RegionFactoryBean.class);
|
||||
assertEquals(DataPolicy.NORMAL, TestUtils.readField("dataPolicy", fb));
|
||||
assertEquals(Scope.LOCAL, TestUtils.readField("scope", fb));
|
||||
assertEquals("publisher", TestUtils.readField("name", fb));
|
||||
RegionAttributes attrs = TestUtils.readField("attributes", fb);
|
||||
assertFalse(attrs.getPublisher());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testComplexReplica() throws Exception {
|
||||
assertTrue(context.containsBean("complex"));
|
||||
RegionFactoryBean fb = context.getBean("&complex", RegionFactoryBean.class);
|
||||
CacheListener[] listeners = TestUtils.readField("cacheListeners", fb);
|
||||
assertFalse(ObjectUtils.isEmpty(listeners));
|
||||
assertEquals(2, listeners.length);
|
||||
assertSame(listeners[0], context.getBean("c-listener"));
|
||||
|
||||
assertSame(context.getBean("c-loader"), TestUtils.readField("cacheLoader", fb));
|
||||
assertSame(context.getBean("c-writer"), TestUtils.readField("cacheWriter", fb));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegionLookup() throws Exception {
|
||||
Cache cache = context.getBean(Cache.class);
|
||||
Region existing = cache.createRegionFactory().create("existing");
|
||||
assertTrue(context.containsBean("lookup"));
|
||||
RegionLookupFactoryBean lfb = context.getBean("&lookup", RegionLookupFactoryBean.class);
|
||||
assertEquals("existing", TestUtils.readField("name", lfb));
|
||||
assertEquals(existing, context.getBean("lookup"));
|
||||
}
|
||||
}
|
||||
@@ -33,13 +33,13 @@
|
||||
</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" synchronous-write="false" time-interval="9999">
|
||||
<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="overflow" pool-name="gemfire-pool">
|
||||
<gfe:disk-store queue-size="50" auto-compact="true" max-oplog-size="10" synchronous-write="false" time-interval="9999">
|
||||
<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>
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?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>
|
||||
@@ -24,7 +24,7 @@
|
||||
</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" synchronous-write="false" time-interval="9999">
|
||||
<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>
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
|
||||
|
||||
<gfe:partitioned-region id="partition-data" persistent="false">
|
||||
<gfe:disk-store queue-size="50" auto-compact="true" max-oplog-size="10" synchronous-write="false" time-interval="9999">
|
||||
<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>
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?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: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" default-lazy-init="true">
|
||||
|
||||
<gfe:cache />
|
||||
|
||||
<gfe:local-region id="simple" />
|
||||
|
||||
<gfe:local-region id="pub" name="publisher"/>
|
||||
|
||||
<gfe:local-region id="complex" close="true" destroy="false">
|
||||
<gfe:cache-listener>
|
||||
<ref bean="c-listener"/>
|
||||
<bean class="org.springframework.data.gemfire.SimpleCacheListener"/>
|
||||
</gfe:cache-listener>
|
||||
<gfe:cache-loader ref="c-loader"/>
|
||||
<gfe:cache-writer ref="c-writer"/>
|
||||
</gfe:local-region>
|
||||
|
||||
<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"/>
|
||||
|
||||
<gfe:lookup-region id="lookup" name="existing"/>
|
||||
</beans>
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
<gfe:replicated-region id="replicatedParent">
|
||||
<gfe:lookup-region name="lookupChild">
|
||||
<gfe:partitioned-region name="partitionedGrandchild"/>
|
||||
<gfe:partitioned-region name="partitionedGrandchild"/>
|
||||
</gfe:lookup-region>
|
||||
</gfe:replicated-region>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user