added dynamic region and jndi binding support
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.data.gemfire;
|
||||
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -24,9 +23,10 @@ import org.junit.Test;
|
||||
import com.gemstone.gemfire.cache.Cache;
|
||||
|
||||
/**
|
||||
* Integration test trying various basic configurations of GemFire through Spring.
|
||||
* Integration test trying various basic configurations of GemFire through
|
||||
* Spring.
|
||||
*
|
||||
* Made abstract to avoid multiple caches running at the same time.
|
||||
* Made abstract to avoid multiple caches running at the same time.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
|
||||
@@ -1,94 +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.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.BeanNameAware;
|
||||
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.Cache;
|
||||
import com.gemstone.gemfire.cache.Declarable;
|
||||
|
||||
/**
|
||||
* @author David Turanski
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("cache-with-initializer.xml")
|
||||
public class CacheInitializerTest {
|
||||
@Autowired
|
||||
TestInitializer cacheInitializer;
|
||||
|
||||
@Resource(name = "gemfire-cache")
|
||||
Cache cache;
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
assertNotNull(cache.getInitializer());
|
||||
assertSame(cacheInitializer, cache.getInitializer());
|
||||
// assertEquals("cacheInitializer", cacheInitializer.value);
|
||||
|
||||
}
|
||||
|
||||
public static class TestInitializer implements Declarable, BeanNameAware {
|
||||
|
||||
private String name;
|
||||
|
||||
public String value;
|
||||
|
||||
private String first;
|
||||
|
||||
private String last;
|
||||
|
||||
@Override
|
||||
public void setBeanName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getFirst() {
|
||||
return first;
|
||||
}
|
||||
|
||||
public void setFirst(String first) {
|
||||
this.first = first;
|
||||
}
|
||||
|
||||
public String getLast() {
|
||||
return last;
|
||||
}
|
||||
|
||||
public void setLast(String last) {
|
||||
this.last = last;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(Properties props) {
|
||||
this.value = this.name;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,8 +16,13 @@
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.io.Resource;
|
||||
@@ -79,7 +84,8 @@ public class CacheNamespaceTest extends RecreatingContextTest {
|
||||
try {
|
||||
assertNotNull(locator.useBeanFactory("cache-with-name"));
|
||||
locator.useBeanFactory("no-bl");
|
||||
} finally {
|
||||
}
|
||||
finally {
|
||||
locator.destroy();
|
||||
}
|
||||
}
|
||||
@@ -99,4 +105,14 @@ public class CacheNamespaceTest extends RecreatingContextTest {
|
||||
Resource res = TestUtils.readField("cacheXml", cfb);
|
||||
assertEquals("gemfire-client-cache.xml", res.getFilename());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHeapTunedCache() throws Exception {
|
||||
assertTrue(ctx.containsBean("heap-tuned-cache"));
|
||||
CacheFactoryBean cfb = (CacheFactoryBean) ctx.getBean("&heap-tuned-cache");
|
||||
Float chp = (Float) TestUtils.readField("criticalHeapPercentage", cfb);
|
||||
Float ehp = (Float) TestUtils.readField("evictionHeapPercentage", cfb);
|
||||
assertEquals(70, chp, 0.0001);
|
||||
assertEquals(60, ehp, 0.0001);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.gemfire.RecreatingContextTest;
|
||||
|
||||
import com.gemstone.gemfire.cache.Cache;
|
||||
import com.gemstone.gemfire.cache.DynamicRegionFactory;
|
||||
|
||||
/**
|
||||
* @author David Turanski
|
||||
*/
|
||||
public class DynamicRegionNamespaceTest extends RecreatingContextTest {
|
||||
|
||||
@Override
|
||||
protected String location() {
|
||||
return "org/springframework/data/gemfire/config/dynamic-region-ns.xml";
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicCache() throws Exception {
|
||||
DynamicRegionFactory drf = DynamicRegionFactory.get();
|
||||
assertFalse(drf.isOpen());
|
||||
assertNull(drf.getConfig());
|
||||
ctx.getBean("gemfire-cache", Cache.class);
|
||||
assertTrue(drf.isOpen());
|
||||
DynamicRegionFactory.Config config = drf.getConfig();
|
||||
assertFalse(config.persistBackup);
|
||||
assertFalse(config.registerInterest);
|
||||
assertEquals("/foo", config.diskDir.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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.assertNotNull;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.gemfire.RecreatingContextTest;
|
||||
|
||||
import com.gemstone.gemfire.cache.Cache;
|
||||
import com.gemstone.gemfire.internal.datasource.GemFireBasicDataSource;
|
||||
|
||||
/**
|
||||
* @author David Turanski
|
||||
*
|
||||
*/
|
||||
public class JndiBindingsTest extends RecreatingContextTest {
|
||||
|
||||
@Override
|
||||
protected String location() {
|
||||
return "org/springframework/data/gemfire/config/jndi-binding-ns.xml";
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJndiBindings() throws Exception {
|
||||
Cache cache = ctx.getBean("gemfire-cache", Cache.class);
|
||||
assertNotNull(cache.getJNDIContext().lookup("java:/SimpleDataSource"));
|
||||
GemFireBasicDataSource ds = (GemFireBasicDataSource) cache.getJNDIContext().lookup("java:/SimpleDataSource");
|
||||
assertEquals("org.apache.derby.jdbc.EmbeddedDriver", ds.getJDBCDriver());
|
||||
assertEquals(60, ds.getLoginTimeout());
|
||||
}
|
||||
}
|
||||
@@ -27,4 +27,6 @@
|
||||
<gfe:client-cache id="client-cache"/>
|
||||
|
||||
<gfe:client-cache id="client-cache-with-xml" cache-xml-location="classpath:gemfire-client-cache.xml"/>
|
||||
|
||||
<gfe:cache id="heap-tuned-cache" critical-heap-percentage="70.0" eviction-heap-percentage="60.0"/>
|
||||
</beans>
|
||||
@@ -9,17 +9,7 @@
|
||||
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">
|
||||
|
||||
<!-- all beans are lazy to allow the same config to be used between multiple tests -->
|
||||
<!-- as there can be only one cache per VM -->
|
||||
|
||||
<gfe:cache>
|
||||
<gfe:initializer ref="cacheInitializer"/>
|
||||
</gfe:cache>
|
||||
<gfe:local-region id="local"/>
|
||||
<bean id="cacheInitializer" class="org.springframework.data.gemfire.config.CacheInitializerTest.TestInitializer">
|
||||
<property name="first" value="David"/>
|
||||
<property name="last" value="Turanski"/>
|
||||
</bean>
|
||||
|
||||
|
||||
<gfe:dynamic-region-factory persistent="false" register-interest="false" disk-dir="/foo"/>
|
||||
</gfe:cache>
|
||||
</beans>
|
||||
@@ -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"
|
||||
default-lazy-init="true"
|
||||
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">
|
||||
|
||||
<gfe:cache>
|
||||
<gfe:jndi-binding type="SimpleDataSource" jndi-name="SimpleDataSource"
|
||||
jdbc-driver-class="org.apache.derby.jdbc.EmbeddedDriver"
|
||||
init-pool-size="2" max-pool-size="7"
|
||||
idle-timeout-seconds="40"
|
||||
blocking-timeout-seconds="40"
|
||||
login-timeout-seconds="60"
|
||||
conn-pooled-datasource-class="org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource"
|
||||
xa-datasource-class="org.apache.derby.jdbc.EmbeddedXADataSource"
|
||||
user-name="mitul"
|
||||
password="83f0069202c571faf1ae6c42b4ad46030e4e31c17409e19a"
|
||||
connection-url="jdbc:derby:newDB;create=true"
|
||||
>
|
||||
<gfe:jndi-prop key="description">hi</gfe:jndi-prop>
|
||||
<gfe:jndi-prop key="databaseName">newDB</gfe:jndi-prop>
|
||||
</gfe:jndi-binding>
|
||||
</gfe:cache>
|
||||
</beans>
|
||||
Reference in New Issue
Block a user