+ replicated cache tests

SGF-10
SGF-12
This commit is contained in:
costin
2010-08-27 16:21:49 +03:00
parent d29af98333
commit c06ccce02a
5 changed files with 136 additions and 2 deletions

View File

@@ -0,0 +1,26 @@
/*
* Copyright 2010 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;
import com.gemstone.gemfire.cache.util.CacheListenerAdapter;
/**
* @author Costin Leau
*/
public class SimpleCacheListener extends CacheListenerAdapter {
}

View File

@@ -0,0 +1,34 @@
/*
* Copyright 2010 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;
import com.gemstone.gemfire.cache.CacheLoader;
import com.gemstone.gemfire.cache.CacheLoaderException;
import com.gemstone.gemfire.cache.LoaderHelper;
/**
* @author Costin Leau
*/
public class SimpleCacheLoader implements CacheLoader {
public Object load(LoaderHelper helper) throws CacheLoaderException {
return null;
}
public void close() {
}
}

View File

@@ -0,0 +1,26 @@
/*
* Copyright 2010 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;
import com.gemstone.gemfire.cache.util.CacheWriterAdapter;
/**
* @author Costin Leau
*/
public class SimpleCacheWriter extends CacheWriterAdapter {
}

View File

@@ -16,14 +16,25 @@
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.TestUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.ObjectUtils;
import com.gemstone.gemfire.cache.CacheListener;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.RegionAttributes;
import com.gemstone.gemfire.cache.Scope;
/**
* @author Costin Leau
@@ -36,7 +47,31 @@ public class ReplicatedRegionNamespaceTest {
private ApplicationContext context;
@Test
public void testBasicCache() throws Exception {
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.REPLICATE, TestUtils.readField("dataPolicy", fb));
assertEquals(Scope.DISTRIBUTED_ACK, TestUtils.readField("scope", fb));
RegionAttributes attrs = TestUtils.readField("attributes", fb);
assertTrue(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));
}
}

View File

@@ -14,4 +14,17 @@
<gfe:replicated-region id="pub" publisher="true"/>
<gfe:replicated-region id="complex">
<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:replicated-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"/>
</beans>