+ initial commit
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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 org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.annotation.DirtiesContext.ClassMode;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.gemstone.gemfire.cache.Cache;
|
||||
|
||||
/**
|
||||
* Integration test trying various basic configurations of Gemfire through Spring.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { "basic-cache.xml" })
|
||||
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
public class CacheIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext ctx;
|
||||
|
||||
@Test
|
||||
public void testBasicCache() throws Exception {
|
||||
ctx.getBean("default-cache");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCacheWithProps() throws Exception {
|
||||
Cache cache = ctx.getBean("cache-with-props", Cache.class);
|
||||
// the name property seems to be ignored
|
||||
// Assert.assertEquals("cache-with-props", cache.getDistributedSystem().getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNamedCache() throws Exception {
|
||||
ctx.getBean("named-cache");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCacheWithXml() throws Exception {
|
||||
Cache cache = ctx.getBean("cache-with-xml", Cache.class);
|
||||
//Assert.assertEquals("cache-with-props", cache.getDistributedSystem().getName());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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 static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.annotation.DirtiesContext.ClassMode;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
|
||||
/**
|
||||
* Integration test for declarable support (and GEF bean factory locator).
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { "cache-with-declarable-ctx.xml" })
|
||||
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
public class DeclarableSupportTest {
|
||||
|
||||
@Autowired
|
||||
private BeanFactory ctx;
|
||||
|
||||
@Test
|
||||
public void testUserObject() throws Exception {
|
||||
assertNotNull(UserObject.THIS);
|
||||
UserObject obj = UserObject.THIS;
|
||||
assertSame(ctx, obj.getBeanFactory());
|
||||
assertSame(ctx.getBean("bean"), obj.getProp2());
|
||||
assertEquals("Enescu", obj.getProp1());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* 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 static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.access.BeanFactoryReference;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.gemfire.GemfireBeanFactoryLocator;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Costin Leau
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { "locatorContext.xml" })
|
||||
public class GemfireBeanFactoryLocatorTest {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
private GemfireBeanFactoryLocator locator1, locator2;
|
||||
private String INSTANCE_1 = "instance1";
|
||||
private String INSTANCE_2 = "instance2";
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
locator1 = new GemfireBeanFactoryLocator();
|
||||
locator1.setBeanName(INSTANCE_1);
|
||||
locator1.setBeanFactory(applicationContext);
|
||||
locator1.afterPropertiesSet();
|
||||
|
||||
locator2 = new GemfireBeanFactoryLocator();
|
||||
locator2.setBeanName(INSTANCE_2);
|
||||
locator2.setBeanFactory(applicationContext);
|
||||
locator2.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@After
|
||||
public void destroy() {
|
||||
BeanFactoryReference ref1;
|
||||
try {
|
||||
ref1 = locator1.useBeanFactory(INSTANCE_1);
|
||||
ref1.release();
|
||||
BeanFactoryReference ref2 = locator2.useBeanFactory(INSTANCE_2);
|
||||
ref2.release();
|
||||
|
||||
} catch (IllegalArgumentException e) {
|
||||
// it's okay
|
||||
}
|
||||
locator1.destroy();
|
||||
locator2.destroy();
|
||||
locator1 = null;
|
||||
locator2 = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeanFactoryRelease() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFactoryLocator() throws Exception {
|
||||
BeanFactoryReference reference1 = locator1.useBeanFactory(INSTANCE_1);
|
||||
BeanFactoryReference reference2 = locator2.useBeanFactory(INSTANCE_2);
|
||||
BeanFactoryReference aliasRef1 = locator1.useBeanFactory("alias1");
|
||||
BeanFactoryReference aliasRef2 = locator1.useBeanFactory("alias2");
|
||||
|
||||
// verify the static map
|
||||
BeanFactory factory1 = reference1.getFactory();
|
||||
BeanFactory factory2 = reference2.getFactory();
|
||||
BeanFactory factory3 = reference2.getFactory();
|
||||
// get the alias from different factories
|
||||
BeanFactory alias1 = aliasRef1.getFactory();
|
||||
BeanFactory alias2 = aliasRef2.getFactory();
|
||||
|
||||
assertSame(factory1, factory2);
|
||||
assertSame(factory1, factory3);
|
||||
// verify it's the same bean factory as the application context
|
||||
assertSame(factory1, applicationContext);
|
||||
|
||||
// verify aliases
|
||||
assertSame(alias1, alias2);
|
||||
assertSame(factory1, alias1);
|
||||
|
||||
aliasRef1.release();
|
||||
aliasRef2.release();
|
||||
reference1.release();
|
||||
reference2.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultFactoryLocator() throws Exception {
|
||||
try {
|
||||
locator1.useBeanFactory(null);
|
||||
fail("there are more then one bean factories registered - should have thrown exception");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// it's okay
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFactoryLocatorContract() throws Exception {
|
||||
BeanFactoryReference factory1 = locator1.useBeanFactory(INSTANCE_1);
|
||||
assertNotNull(factory1.getFactory());
|
||||
|
||||
factory1.release();
|
||||
try {
|
||||
factory1.getFactory();
|
||||
fail("should have received exception");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// it's okay
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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 static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
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.ClientRegionFactoryBean;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.annotation.DirtiesContext.ClassMode;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.gemstone.gemfire.cache.CacheListener;
|
||||
import com.gemstone.gemfire.cache.CacheLoader;
|
||||
import com.gemstone.gemfire.cache.CacheLoaderException;
|
||||
import com.gemstone.gemfire.cache.LoaderHelper;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
import com.gemstone.gemfire.cache.util.CacheListenerAdapter;
|
||||
import com.gemstone.gemfire.cache.util.CacheWriterAdapter;
|
||||
|
||||
|
||||
/**
|
||||
* @author Costin Leau
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { "basic-region.xml" })
|
||||
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
public class RegionIntegrationTest {
|
||||
|
||||
private static class CacheList<K, V> extends CacheListenerAdapter<K, V> {
|
||||
}
|
||||
|
||||
private static class CacheLoad<K, V> implements CacheLoader<K, V> {
|
||||
|
||||
public V load(LoaderHelper<K, V> arg0) throws CacheLoaderException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
}
|
||||
}
|
||||
|
||||
private static class CacheWrite<K, V> extends CacheWriterAdapter<K, V> {
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext ctx;
|
||||
|
||||
@Test
|
||||
public void testBasicRegion() throws Exception {
|
||||
Region region = ctx.getBean("basic", Region.class);
|
||||
assertEquals("basic", region.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExistingRegion() throws Exception {
|
||||
Region region = ctx.getBean("root", Region.class);
|
||||
// the name property seems to be ignored
|
||||
assertEquals("root", region.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegionWithListeners() throws Exception {
|
||||
Region region = ctx.getBean("listeners", Region.class);
|
||||
assertEquals("listeners", region.getName());
|
||||
CacheListener[] listeners = region.getAttributes().getCacheListeners();
|
||||
assertEquals(2, listeners.length);
|
||||
assertSame(CacheList.class, listeners[0].getClass());
|
||||
assertSame(CacheLoad.class, region.getAttributes().getCacheLoader().getClass());
|
||||
assertSame(CacheWrite.class, region.getAttributes().getCacheWriter().getClass());
|
||||
}
|
||||
|
||||
//@Test
|
||||
//TODO: Disabled since for some reason in Spring, I get the bean rather then the client
|
||||
public void testRegionInterest() throws Exception {
|
||||
ClientRegionFactoryBean regionFB = (ClientRegionFactoryBean) ctx.getBean("&basic-client");
|
||||
System.out.println("**** interests are " + Arrays.toString(regionFB.getInterests()));
|
||||
//BeanDefinition bd = ((BeanDefinitionRegistry) ctx.getAutowireCapableBeanFactory()).getBeanDefinition("basic-client");
|
||||
// System.out.println(bd.getPropertyValues().getPropertyValue("interests").getValue());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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 static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.transaction.AfterTransaction;
|
||||
import org.springframework.test.context.transaction.BeforeTransaction;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* Simple TX integration test.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { "basic-tx-config.xml" })
|
||||
@Transactional
|
||||
public class TxIntegrationTest {
|
||||
|
||||
@Resource(name = "rollback-region")
|
||||
private Map<String, String> rollbackRegion;
|
||||
@Resource(name = "commit-region")
|
||||
private Map<String, String> commitRegion;
|
||||
|
||||
private boolean txCommit = false;
|
||||
|
||||
@BeforeTransaction
|
||||
public void addItemsToTheCache() {
|
||||
rollbackRegion.put("Vlaicu", "Aurel");
|
||||
rollbackRegion.put("Coanda", "Henri");
|
||||
commitRegion.put("Coanda", "Henri");
|
||||
commitRegion.put("Vlaicu", "Aurel");
|
||||
txCommit = false;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransactionRollback() throws Exception {
|
||||
rollbackRegion.remove("Coanda");
|
||||
rollbackRegion.put("Ciurcu", "Alexandru");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Rollback(value = false)
|
||||
public void testTransactionCommit() throws Exception {
|
||||
commitRegion.put("Poenaru", "Petrache");
|
||||
commitRegion.remove("Coanda");
|
||||
commitRegion.put("Vlaicu", "A");
|
||||
|
||||
txCommit = true;
|
||||
}
|
||||
|
||||
@AfterTransaction
|
||||
public void testTxOutcome() {
|
||||
if (txCommit) {
|
||||
assertFalse(commitRegion.containsKey("Coanda"));
|
||||
assertTrue(commitRegion.containsKey("Poenaru"));
|
||||
assertTrue(commitRegion.containsValue("A"));
|
||||
}
|
||||
assertTrue(rollbackRegion.containsKey("Coanda"));
|
||||
assertTrue(rollbackRegion.containsKey("Vlaicu"));
|
||||
assertFalse(rollbackRegion.containsKey("Ciurcu"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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 org.springframework.data.gemfire.WiringDeclarableSupport;
|
||||
|
||||
import com.gemstone.gemfire.cache.CacheLoader;
|
||||
import com.gemstone.gemfire.cache.CacheLoaderException;
|
||||
import com.gemstone.gemfire.cache.LoaderHelper;
|
||||
|
||||
/**
|
||||
* User object used for testing Spring wiring.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public class UserObject extends WiringDeclarableSupport implements CacheLoader {
|
||||
|
||||
public static UserObject THIS;
|
||||
|
||||
private String prop1;
|
||||
private Object prop2;
|
||||
|
||||
public UserObject() {
|
||||
System.out.println("Initialized");
|
||||
THIS = this;
|
||||
}
|
||||
|
||||
public Object load(LoaderHelper helper) throws CacheLoaderException {
|
||||
return new Object();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the prop1
|
||||
*/
|
||||
public String getProp1() {
|
||||
return prop1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param prop1 the prop1 to set
|
||||
*/
|
||||
public void setProp1(String prop1) {
|
||||
this.prop1 = prop1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the prop2
|
||||
*/
|
||||
public Object getProp2() {
|
||||
return prop2;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param prop2 the prop2 to set
|
||||
*/
|
||||
public void setProp2(Object prop2) {
|
||||
this.prop2 = prop2;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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.serialization;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.gemfire.serialization.AsmInstantiatorGenerator;
|
||||
|
||||
import com.gemstone.gemfire.DataSerializable;
|
||||
import com.gemstone.gemfire.Instantiator;
|
||||
|
||||
/**
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public class AsmInstantiatorFactoryTest {
|
||||
|
||||
public static class SomeClass implements DataSerializable {
|
||||
public static boolean instantiated = false;
|
||||
|
||||
public SomeClass() {
|
||||
instantiated = true;
|
||||
}
|
||||
|
||||
public void fromData(DataInput in) throws IOException, ClassNotFoundException {
|
||||
}
|
||||
|
||||
public void toData(DataOutput out) throws IOException {
|
||||
}
|
||||
}
|
||||
|
||||
private AsmInstantiatorGenerator asmFactory = null;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
SomeClass.instantiated = false;
|
||||
asmFactory = new AsmInstantiatorGenerator();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassGeneration() throws Exception {
|
||||
Instantiator instantiator = asmFactory.getInstantiator(SomeClass.class, 100);
|
||||
assertEquals(100, instantiator.getId());
|
||||
assertEquals(SomeClass.class, instantiator.getInstantiatedClass());
|
||||
Object instance = instantiator.newInstance();
|
||||
assertEquals(SomeClass.class, instance.getClass());
|
||||
assertTrue(SomeClass.instantiated);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGeneratedClassName() throws Exception {
|
||||
Instantiator instantiator = asmFactory.getInstantiator(SomeClass.class, 100);
|
||||
assertTrue(instantiator.getClass().getName().contains("$"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInterfaces() throws Exception {
|
||||
Instantiator instantiator = asmFactory.getInstantiator(SomeClass.class, 100);
|
||||
assertTrue(instantiator instanceof Serializable);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCacheInPlace() throws Exception {
|
||||
Instantiator instance1 = asmFactory.getInstantiator(SomeClass.class, 120);
|
||||
Instantiator instance2 = asmFactory.getInstantiator(SomeClass.class, 125);
|
||||
assertSame(instance1, instance2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* 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.serialization;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.Shape;
|
||||
import java.beans.Beans;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
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.serialization.AsmInstantiatorGenerator;
|
||||
import org.springframework.data.gemfire.serialization.WiringInstantiator;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.gemstone.gemfire.DataSerializable;
|
||||
|
||||
/**
|
||||
* @author Costin Leau
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("simple-config.xml")
|
||||
public class WiringInstantiatorTest {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext ctx;
|
||||
@Autowired
|
||||
private WiringInstantiator instantiator;
|
||||
|
||||
|
||||
public static class AnnotatedBean implements DataSerializable {
|
||||
@Autowired
|
||||
Point point;
|
||||
Shape shape;
|
||||
|
||||
@Autowired
|
||||
void initShape(Shape shape) {
|
||||
this.shape = shape;
|
||||
}
|
||||
|
||||
public void fromData(DataInput in) throws IOException, ClassNotFoundException {
|
||||
}
|
||||
|
||||
public void toData(DataOutput out) throws IOException {
|
||||
}
|
||||
}
|
||||
|
||||
public static class TemplateWiringBean implements DataSerializable {
|
||||
Point point;
|
||||
Beans beans;
|
||||
|
||||
public void setBeans(Beans bs) {
|
||||
this.beans = bs;
|
||||
}
|
||||
|
||||
public void fromData(DataInput in) throws IOException, ClassNotFoundException {
|
||||
}
|
||||
|
||||
public void toData(DataOutput out) throws IOException {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutowiredBean() throws Exception {
|
||||
Object instance = instantiator.newInstance();
|
||||
assertNotNull(instance);
|
||||
assertTrue(instance instanceof AnnotatedBean);
|
||||
AnnotatedBean bean = (AnnotatedBean) instance;
|
||||
|
||||
assertNotNull(bean.point);
|
||||
assertNotNull(bean.shape);
|
||||
|
||||
assertSame(bean.point, ctx.getBean("point"));
|
||||
assertSame(bean.shape, ctx.getBean("area"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTemplateBean() throws Exception {
|
||||
WiringInstantiator instantiator2 = new WiringInstantiator(
|
||||
new AsmInstantiatorGenerator().getInstantiator(
|
||||
TemplateWiringBean.class, 99));
|
||||
instantiator2.setBeanFactory(ctx.getAutowireCapableBeanFactory());
|
||||
instantiator2.afterPropertiesSet();
|
||||
|
||||
Object instance = instantiator2.newInstance();
|
||||
|
||||
assertTrue(instance instanceof TemplateWiringBean);
|
||||
TemplateWiringBean bean = (TemplateWiringBean) instance;
|
||||
|
||||
assertTrue(bean.point == null);
|
||||
assertNotNull(bean.beans);
|
||||
|
||||
assertSame(bean.beans, ctx.getBean("beans"));
|
||||
}
|
||||
}
|
||||
32
src/test/resources/cache-with-declarable.xml
Normal file
32
src/test/resources/cache-with-declarable.xml
Normal file
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE cache PUBLIC "-//GemStone Systems, Inc.//GemFire Declarative Caching 5.7//EN" "http://www.gemstone.com/dtd/cache5_7.dtd">
|
||||
<cache lock-lease="120" lock-timeout="60" search-timeout="300">
|
||||
<region-attributes id="attTemplate" scope="local" data-policy="normal" initial-capacity="16" load-factor="0.75" concurrency-level="16" statistics-enabled="true">
|
||||
<key-constraint>java.lang.String</key-constraint>
|
||||
<cache-loader>
|
||||
<class-name>org.springframework.data.gemfire.UserObject</class-name>
|
||||
</cache-loader>
|
||||
|
||||
</region-attributes>
|
||||
<region name="root">
|
||||
<region-attributes refid="attTemplate" scope="distributed-no-ack">
|
||||
<region-time-to-live>
|
||||
<expiration-attributes timeout="0" action="invalidate"/>
|
||||
</region-time-to-live>
|
||||
<region-idle-time>
|
||||
<expiration-attributes timeout="0" action="invalidate"/>
|
||||
</region-idle-time>
|
||||
<entry-time-to-live>
|
||||
<expiration-attributes timeout="0" action="invalidate"/>
|
||||
</entry-time-to-live>
|
||||
<entry-idle-time>
|
||||
<expiration-attributes timeout="0" action="invalidate"/>
|
||||
</entry-idle-time>
|
||||
</region-attributes>
|
||||
<entry>
|
||||
<key><string>Application Version</string></key>
|
||||
<value><string>1.0</string></value>
|
||||
</entry>
|
||||
</region>
|
||||
|
||||
</cache>
|
||||
39
src/test/resources/cache.xml
Normal file
39
src/test/resources/cache.xml
Normal file
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE cache PUBLIC "-//GemStone Systems, Inc.//GemFire Declarative Caching 5.7//EN" "http://www.gemstone.com/dtd/cache5_7.dtd">
|
||||
<cache lock-lease="120" lock-timeout="60" search-timeout="300">
|
||||
<region-attributes id="attTemplate" scope="local" data-policy="normal" initial-capacity="16" load-factor="0.75" concurrency-level="16" statistics-enabled="true">
|
||||
<key-constraint>java.lang.String</key-constraint>
|
||||
</region-attributes>
|
||||
<region name="root">
|
||||
<region-attributes refid="attTemplate" scope="distributed-no-ack">
|
||||
<region-time-to-live>
|
||||
<expiration-attributes timeout="0" action="invalidate"/>
|
||||
</region-time-to-live>
|
||||
<region-idle-time>
|
||||
<expiration-attributes timeout="0" action="invalidate"/>
|
||||
</region-idle-time>
|
||||
<entry-time-to-live>
|
||||
<expiration-attributes timeout="0" action="invalidate"/>
|
||||
</entry-time-to-live>
|
||||
<entry-idle-time>
|
||||
<expiration-attributes timeout="0" action="invalidate"/>
|
||||
</entry-idle-time>
|
||||
</region-attributes>
|
||||
<entry>
|
||||
<key><string>Application Version</string></key>
|
||||
<value><string>1.0</string></value>
|
||||
</entry>
|
||||
<region name="rlocal">
|
||||
<region-attributes refid="attTemplate">
|
||||
</region-attributes>
|
||||
</region>
|
||||
<region name="rdistnoack">
|
||||
<region-attributes refid="attTemplate" scope="distributed-no-ack">
|
||||
</region-attributes>
|
||||
</region>
|
||||
<region name="rglobalreplication">
|
||||
<region-attributes refid="attTemplate" scope="global" data-policy="replicate">
|
||||
</region-attributes>
|
||||
</region>
|
||||
</region>
|
||||
</cache>
|
||||
@@ -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:p="http://www.springframework.org/schema/p"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd" default-lazy-init="true">
|
||||
|
||||
<!-- all beans are lazy to allow the same config to be used between multiple tests -->
|
||||
<!-- as there can be only one cache per VM -->
|
||||
<bean id="default-cache" class="org.springframework.data.gemfire.CacheFactoryBean"/>
|
||||
|
||||
<bean id="cache-with-props" class="org.springframework.data.gemfire.CacheFactoryBean">
|
||||
<property name="properties">
|
||||
<props>
|
||||
<prop key="name">cache-with-props</prop>
|
||||
</props>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="named-cache" class="org.springframework.data.gemfire.CacheFactoryBean" p:name="named-cache">
|
||||
<property name="properties">
|
||||
<props>
|
||||
<prop key="name">cache-with-props</prop>
|
||||
</props>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="cache-with-xml" class="org.springframework.data.gemfire.CacheFactoryBean">
|
||||
<property name="cacheXml" value="classpath:cache.xml"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,38 @@
|
||||
<?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:p="http://www.springframework.org/schema/p"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd" default-lazy-init="true">
|
||||
|
||||
<!-- all beans are lazy to allow the same config to be used between multiple tests -->
|
||||
<!-- as there can be only one cache per VM -->
|
||||
<bean id="cache" class="org.springframework.data.gemfire.CacheFactoryBean"/>
|
||||
|
||||
<bean id="basic" class="org.springframework.data.gemfire.RegionFactoryBean" p:cache-ref="cache" p:name="basic"/>
|
||||
|
||||
<!-- find existing region -->
|
||||
<bean id="root" class="org.springframework.data.gemfire.RegionFactoryBean" p:cache-ref="cache" p:name="root"/>
|
||||
|
||||
<bean id="listeners" class="org.springframework.data.gemfire.RegionFactoryBean" p:cache-ref="cache" p:name="listeners">
|
||||
<property name="cacheListeners">
|
||||
<array>
|
||||
<bean class="org.springframework.data.gemfire.RegionIntegrationTest$CacheList"/>
|
||||
<bean class="org.springframework.data.gemfire.RegionIntegrationTest$CacheList"/>
|
||||
</array>
|
||||
</property>
|
||||
<property name="cacheLoader"><bean class="org.springframework.data.gemfire.RegionIntegrationTest$CacheLoad"/></property>
|
||||
<property name="cacheWriter"><bean class="org.springframework.data.gemfire.RegionIntegrationTest$CacheWrite"/></property>
|
||||
</bean>
|
||||
|
||||
<!-- client configurations -->
|
||||
<bean id="basic-client" class="org.springframework.data.gemfire.ClientRegionFactoryBean" p:cache-ref="cache" p:name="client-region" lazy-init="true">
|
||||
<property name="interests">
|
||||
<array>
|
||||
<bean class="org.springframework.data.gemfire.Interest" p:key="Vlaicu" p:policy="NONE"/>
|
||||
<bean class="org.springframework.data.gemfire.RegexInterest" p:key=".*" p:policy="KEYS" p:durable="true"/>
|
||||
</array>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?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:p="http://www.springframework.org/schema/p"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd" default-lazy-init="true">
|
||||
|
||||
<bean id="cache" class="org.springframework.data.gemfire.CacheFactoryBean"/>
|
||||
|
||||
<bean id="transactionManager" class="org.springframework.data.gemfire.GemfireTransactionManager" p:cache-ref="cache"/>
|
||||
|
||||
<bean id="rollback-region" class="org.springframework.data.gemfire.RegionFactoryBean" p:name="r-region" p:cache-ref="cache"/>
|
||||
<bean id="commit-region" class="org.springframework.data.gemfire.RegionFactoryBean" p:name="c-region" p:cache-ref="cache"/>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,15 @@
|
||||
<?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:p="http://www.springframework.org/schema/p"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<bean id="cache-with-declarable" class="org.springframework.data.gemfire.CacheFactoryBean">
|
||||
<property name="cacheXml" value="classpath:cache-with-declarable.xml"/>
|
||||
</bean>
|
||||
|
||||
<bean id="bean" class="java.lang.Object"/>
|
||||
|
||||
<bean abstract="true" class="org.springframework.data.gemfire.UserObject" p:prop1="Enescu" p:prop2-ref="bean"/>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
|
||||
|
||||
<!--
|
||||
Context used for testing GemfireBFLocator - usually, one doesn't have to declare the them inside
|
||||
the context. see the javadocs for more details.
|
||||
-->
|
||||
<beans>
|
||||
<bean id="instance1" name="alias1, alias2" class="java.lang.Object"/>
|
||||
<bean id="instance2" class="java.lang.Object"/>
|
||||
</beans>
|
||||
@@ -0,0 +1,28 @@
|
||||
<?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:context="http://www.springframework.org/schema/context"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
|
||||
<context:annotation-config/>
|
||||
|
||||
<bean id="point" class="java.awt.Point"/>
|
||||
|
||||
<bean id="area" class="java.awt.geom.Area"/>
|
||||
<bean id="beans" class="java.beans.Beans"/>
|
||||
|
||||
<bean id="generator" class="org.springframework.data.gemfire.serialization.AsmInstantiatorGenerator"/>
|
||||
|
||||
<bean id="instantiator" class="org.springframework.data.gemfire.serialization.WiringInstantiator">
|
||||
<constructor-arg>
|
||||
<bean factory-bean="generator" factory-method="getInstantiator">
|
||||
<constructor-arg value="org.springframework.data.gemfire.serialization.WiringInstantiatorTest$AnnotatedBean"/>
|
||||
<constructor-arg value="95"/>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.data.gemfire.serialization.WiringInstantiatorTest$TemplateWiringBean" abstract="true" p:beans-ref="beans"/>
|
||||
</beans>
|
||||
Reference in New Issue
Block a user