added dynamic region and jndi binding support

This commit is contained in:
David Turanski
2012-07-03 10:01:49 -04:00
parent 1467ec0668
commit bb34beb224
13 changed files with 490 additions and 157 deletions

View File

@@ -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
*/

View File

@@ -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;
};
}
}

View File

@@ -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);
}
}

View File

@@ -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());
}
}

View File

@@ -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());
}
}