renaming classes, etc

This commit is contained in:
David Turanski
2012-12-22 09:55:40 -05:00
parent e18e603000
commit 074eee56fd
40 changed files with 237 additions and 176 deletions

View File

@@ -5,7 +5,7 @@ log4jVersion = 1.2.16
slf4jVersion = 1.6.4
# Common libraries
springVersion = 3.2.0.RC1
springVersion = 3.2.0.RELEASE
springDataCommonsVersion = 1.5.0.BUILD-SNAPSHOT
gemfireVersion = 7.0

View File

@@ -72,6 +72,7 @@ public class ClientCacheFactoryBean extends CacheFactoryBean {
if (pdxReadSerialized != null) {
factory.setPdxReadSerialized(pdxReadSerialized);
}
}
}

View File

@@ -179,7 +179,7 @@ public class PoolFactoryBean implements FactoryBean<Pool>, InitializingBean,
.setSubscriptionMessageTrackingTimeout(subscriptionMessageTrackingTimeout);
poolFactory.setSubscriptionRedundancy(subscriptionRedundancy);
poolFactory.setThreadLocalConnections(threadLocalConnections);
pool = poolFactory.create(name);
}
}

View File

@@ -19,7 +19,6 @@ import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;
@@ -57,7 +56,7 @@ public class PojoFunctionWrapper implements Function {
this.functionArgumentResolver = new FunctionContextInjectingArgumentResolver(method);
this.id = StringUtils.hasText(id) ? id : ClassUtils.getQualifiedMethodName(method);
this.id = StringUtils.hasText(id) ? id : method.getName();
this.target = target;
this.method = method;

View File

@@ -20,6 +20,7 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* Base class for function execution bean definition builders
* @author David Turanski
@@ -54,16 +55,18 @@ abstract class AbstractFunctionExecutionBeanDefinitionBuilder {
BeanDefinitionBuilder functionTemplateBuilder = getGemfireOperationsBeanDefinitionBuilder(registry);
functionTemplateBuilder.setLazyInit(true);
String resultCollectorRef = (String)configuration.getAttribute("resultCollector");
if (StringUtils.hasText(resultCollectorRef)){
functionTemplateBuilder.addPropertyReference("resultCollector",resultCollectorRef);
}
AbstractBeanDefinition functionTemplate = functionTemplateBuilder
.getBeanDefinition();
String functionTemplateName = BeanDefinitionReaderUtils.registerWithGeneratedName(functionTemplate, registry);
builder.addConstructorArgReference(functionTemplateName);
builder.addPropertyValue("functionId", (String)configuration.getAttribute("id"));
return builder.getBeanDefinition();
}

View File

@@ -69,6 +69,7 @@ public class FunctionExecutionBeanDefinitionRegistrar implements ImportBeanDefin
if (!StringUtils.hasLength(beanName)) {
beanName = BeanDefinitionReaderUtils.generateBeanName(beanDefinition, registry);
}
AbstractFunctionExecutionBeanDefinitionBuilder builder = FunctionExecutionBeanDefinitionBuilderFactory
.newInstance(new FunctionExecutionConfiguration(beanDefinition, functionExecutionAnnotation));

View File

@@ -26,7 +26,6 @@ import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.AbstractTypeHierarchyTraversingFilter;
import org.springframework.core.type.filter.TypeFilter;
import org.springframework.data.gemfire.function.execution.FunctionExecution;
import org.springframework.util.Assert;
/**
@@ -68,7 +67,7 @@ class FunctionExecutionComponentProvider extends ClassPathScanningCandidateCompo
/**
* Custom extension of {@link #addIncludeFilter(TypeFilter)} to extend the added {@link TypeFilter}. For the
* {@link TypeFilter} handed we'll have two filters registered: one additionally enforcing the
* {@link FunctionExecutionDefinition} annotation, the other one forcing the extension of {@link FunctionExecution}.
* {@link FunctionExecutionDefinition} annotation, the other one forcing the extension of {@link AbstractFunctionExecution}.
*
* @see ClassPathScanningCandidateComponentProvider#addIncludeFilter(TypeFilter)
*/

View File

@@ -28,8 +28,7 @@ import java.lang.annotation.Target;
@Target({ElementType.METHOD})
public @interface GemfireFunction {
/**
* The name of the registered function. If not provided the fully qualified method name will be used,
* e.g., 'com.example.SomeClass.someMethod'
* The name of the registered function. If not provided the simple method name will be used
* @return the function id
*/
String id() default "";

View File

@@ -28,12 +28,14 @@ import java.lang.annotation.Target;
public @interface OnMember {
/**
* The bean name and also the default name of the registered function, if single method on the interface.
* If multiple methods declared use the (@link FunctionId) annotation on each method
* @return the function id
* The bean name
*/
String id() default "";
/**
* Optional ResultCollector bean reference
*/
String resultCollector() default "";
//TODO SpEL expression for DistributedMember?

View File

@@ -27,12 +27,15 @@ import java.lang.annotation.Target;
public @interface OnMembers {
/**
* The bean name and also the default name of the registered function, if single method on the interface.
* If multiple methods declared use the (@link FunctionId) annotation on each method
* @return the function id
* The bean name
*/
String id() default "";
/**
* Optional ResultCollector bean reference
*/
String resultCollector() default "";
//TODO SpEL expression for DistributedMembers?
/**

View File

@@ -27,12 +27,15 @@ import java.lang.annotation.Target;
public @interface OnRegion {
/**
* The bean name and also the default name of the registered function, if single method on the interface.
* If multiple methods declared use the (@link FunctionId) annotation on each method
* @return the function id
* The bean name
*/
String id() default "";
/**
* Optional ResultCollector bean reference
*/
String resultCollector() default "";
/**
* The reference to the bean id of the region
* @return the region id

View File

@@ -27,12 +27,15 @@ import java.lang.annotation.Target;
public @interface OnServer {
/**
* The bean name and also the default name of the registered function, if single method on the interface.
* If multiple methods declared use the (@link FunctionId) annotation on each method
* @return the function id
* The bean name
*/
String id() default "";
/**
* Optional ResultCollector bean reference
*/
String resultCollector() default "";
/**
* The pool bean id (optional)
* @return

View File

@@ -27,12 +27,15 @@ import java.lang.annotation.Target;
public @interface OnServers {
/**
* The bean name and also the default name of the registered function, if single method on the interface.
* If multiple methods declared use the (@link FunctionId) annotation on each method
* @return the function id
* The bean name
*/
String id() default "";
/**
* Optional ResultCollector bean reference
*/
String resultCollector() default "";
/**
* The pool bean name (optional)
* @return

View File

@@ -30,61 +30,57 @@ import com.gemstone.gemfire.cache.execute.ResultCollector;
/**
* Base class for * Creating a GemFire {@link Execution} using {@link FunctionService}
* Protected setters support method chaining
* @author David Turanski
*/
public abstract class FunctionExecution {
abstract class AbstractFunctionExecution {
protected final Log logger = LogFactory.getLog(this.getClass());
private volatile ResultCollector<?, ?> collector;
private volatile ResultCollector<?, ?> resultCollector;
private Object[] args;
private Function function;
private String functionId;
private long timeout;
public FunctionExecution(Function function, Object... args) {
public AbstractFunctionExecution(Function function, Object... args) {
Assert.notNull(function,"function cannot be null");
this.function = function;
this.functionId = function.getId();
this.args = args;
}
public FunctionExecution(String functionId, Object... args) {
public AbstractFunctionExecution(String functionId, Object... args) {
Assert.isTrue(StringUtils.hasLength(functionId),"functionId cannot be null or empty");
this.functionId = functionId;
this.args = args;
}
protected FunctionExecution() {
AbstractFunctionExecution() {
}
ResultCollector<?, ?> getCollector() {
return resultCollector;
}
public ResultCollector<?, ?> getCollector() {
return collector;
}
public Object[] getArgs() {
Object[] getArgs() {
return args;
}
public String getFunctionId() {
String getFunctionId() {
return functionId;
}
public Function getFunction() {
Function getFunction() {
return function;
}
public void setCollector(ResultCollector<?,?> collector) {
this.collector = collector;
}
long getTimeout() {
return timeout;
}
@SuppressWarnings("unchecked")
public <T> Iterable<T> execute() {
<T> Iterable<T> execute() {
Execution execution = this.getExecution();
if (getKeys() != null) {
execution = execution.withFilter(getKeys());
@@ -93,22 +89,24 @@ public abstract class FunctionExecution {
execution = execution.withCollector(getCollector());
}
ResultCollector<?,?> resultsCollector = null;
ResultCollector<?,?> resultCollector = null;
execution = execution.withArgs(getArgs());
if (isRegisteredFunction()){
resultsCollector = (ResultCollector<?,?>) execution.execute(functionId);
resultCollector = (ResultCollector<?,?>) execution.execute(functionId);
} else {
resultsCollector = (ResultCollector<?,?>) execution.execute(function);
resultCollector = (ResultCollector<?,?>) execution.execute(function);
}
logger.debug("ResultsCollector:" + resultCollector.getClass().getName());
Iterable<T> results = null;
if (this.timeout > 0 ){
try {
results= (Iterable<T>)resultsCollector.getResult(this.timeout, TimeUnit.MILLISECONDS);
results= (Iterable<T>)resultCollector.getResult(this.timeout, TimeUnit.MILLISECONDS);
}
catch (FunctionException e) {
throw new RuntimeException(e);
@@ -118,14 +116,14 @@ public abstract class FunctionExecution {
}
} else {
results = (Iterable<T>) resultsCollector.getResult();
results = (Iterable<T>) resultCollector.getResult();
}
return replaceSingletonNullCollectionWithEmptyList(results);
}
public <T> T executeAndExtract() {
<T> T executeAndExtract() {
Iterable<T> results = this.execute();
if (results == null || !results.iterator().hasNext()) {
return null;
@@ -136,17 +134,17 @@ public abstract class FunctionExecution {
protected abstract Execution getExecution();
protected FunctionExecution setFunctionId(String functionId) {
protected AbstractFunctionExecution setFunctionId(String functionId) {
this.functionId = functionId;
return this;
}
protected FunctionExecution setFunction(Function function) {
protected AbstractFunctionExecution setFunction(Function function) {
this.function = function;
return this;
}
protected FunctionExecution setArgs(Object... args) {
protected AbstractFunctionExecution setArgs(Object... args) {
this.args = args;
return this;
}
@@ -155,14 +153,16 @@ public abstract class FunctionExecution {
return null;
}
public FunctionExecution setTimeout(long timeout) {
protected AbstractFunctionExecution setTimeout(long timeout) {
this.timeout = timeout;
return this;
}
protected AbstractFunctionExecution setResultCollector(ResultCollector<?,?> resultCollector) {
this.resultCollector = resultCollector;
return this;
}
public long getTimeout() {
return timeout;
}
/**
* @return

View File

@@ -17,6 +17,7 @@ import org.apache.commons.logging.LogFactory;
import com.gemstone.gemfire.cache.execute.Execution;
import com.gemstone.gemfire.cache.execute.Function;
import com.gemstone.gemfire.cache.execute.ResultCollector;
/**
*
@@ -29,40 +30,38 @@ abstract class AbstractFunctionTemplate implements GemfireFunctionOperations {
protected Log log = LogFactory.getLog(this.getClass());
protected long timeout;
protected volatile ResultCollector<?, ?> resultCollector;
@Override
public <T> Iterable<T> execute(Function function, Object... args) {
FunctionExecution functionExecution = getFunctionExecution()
AbstractFunctionExecution functionExecution = getFunctionExecution()
.setArgs(args)
.setFunction(function)
.setTimeout(timeout);
.setFunction(function);
return execute(functionExecution);
}
@Override
public <T> T executeAndExtract(Function function, Object... args) {
FunctionExecution functionExecution = getFunctionExecution()
AbstractFunctionExecution functionExecution = getFunctionExecution()
.setArgs(args)
.setFunction(function)
.setTimeout(timeout);
.setFunction(function);
return executeAndExtract(functionExecution);
}
@Override
public <T> Iterable<T> execute(String functionId, Object... args) {
FunctionExecution functionExecution = getFunctionExecution()
AbstractFunctionExecution functionExecution = getFunctionExecution()
.setArgs(args)
.setFunctionId(functionId)
.setTimeout(timeout);
.setFunctionId(functionId);
return execute(functionExecution);
}
@Override
public <T> T executeAndExtract(String functionId, Object... args) {
FunctionExecution functionExecution = getFunctionExecution()
AbstractFunctionExecution functionExecution = getFunctionExecution()
.setArgs(args)
.setFunctionId(functionId)
.setTimeout(timeout);
.setFunctionId(functionId);
return executeAndExtract(functionExecution);
}
@@ -73,13 +72,15 @@ abstract class AbstractFunctionTemplate implements GemfireFunctionOperations {
}
protected <T> Iterable<T> execute(FunctionExecution execution) {
execution.setTimeout(timeout);
protected <T> Iterable<T> execute(AbstractFunctionExecution execution) {
execution.setTimeout(timeout)
.setResultCollector(resultCollector);
return execution.execute();
}
protected <T> T executeAndExtract(FunctionExecution execution) {
execution.setTimeout(timeout);
protected <T> T executeAndExtract(AbstractFunctionExecution execution) {
execution.setTimeout(timeout)
.setResultCollector(resultCollector);
return execution.executeAndExtract();
}
@@ -87,5 +88,13 @@ abstract class AbstractFunctionTemplate implements GemfireFunctionOperations {
this.timeout = timeout;
}
protected abstract FunctionExecution getFunctionExecution();
public void setResultCollector(ResultCollector<?,?> resultCollector) {
this.resultCollector = resultCollector;
}
public ResultCollector<?,?> getResultCollector() {
return this.resultCollector;
}
protected abstract AbstractFunctionExecution getFunctionExecution();
}

View File

@@ -19,7 +19,7 @@ import com.gemstone.gemfire.cache.execute.FunctionService;
* @author David Turanski
*
*/
public class AllMembersFunctionExecution extends FunctionExecution {
public class AllMembersFunctionExecution extends AbstractFunctionExecution {
@Override
protected Execution getExecution() {

View File

@@ -19,7 +19,7 @@ import com.gemstone.gemfire.cache.execute.FunctionService;
* @author David Turanski
*
*/
public class DefaultMemberFunctionExecution extends FunctionExecution {
public class DefaultMemberFunctionExecution extends AbstractFunctionExecution {
@Override
protected Execution getExecution() {

View File

@@ -22,7 +22,7 @@ import com.gemstone.gemfire.distributed.DistributedMember;
* @author David Turanski
*
*/
public class DistributedMemberFunctionExecution extends FunctionExecution {
public class DistributedMemberFunctionExecution extends AbstractFunctionExecution {
private final DistributedMember distributedMember;

View File

@@ -22,7 +22,7 @@ import com.gemstone.gemfire.distributed.DistributedMember;
* @author David Turanski
*
*/
public class DistributedMembersFunctionExecution extends FunctionExecution {
public class DistributedMembersFunctionExecution extends AbstractFunctionExecution {
private final Set<DistributedMember> distributedMembers;
/**

View File

@@ -41,7 +41,7 @@ abstract class FunctionExecutionMethodMetadata<T extends MethodMetadata > {
public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
T mmd = newMetadataInstance(method);
if (mmd.getFunctionId() == null) {
mmd.setFunctionId(serviceInterface.getName() + "." + method.getName());
mmd.setFunctionId(method.getName());
}
methodMetadata.put(method, mmd);

View File

@@ -22,12 +22,11 @@ import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.data.gemfire.function.config.FunctionId;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import com.gemstone.gemfire.cache.execute.FunctionException;
import com.gemstone.gemfire.cache.execute.FunctionService;
/**
* A proxy Factory Bean for all non-region function execution interfaces
@@ -35,7 +34,7 @@ import com.gemstone.gemfire.cache.execute.FunctionException;
* @author David Turanski
*
*/
public class GemfireFunctionProxyFactoryBean implements FactoryBean<Object>, MethodInterceptor, BeanClassLoaderAware, InitializingBean {
public class GemfireFunctionProxyFactoryBean implements FactoryBean<Object>, MethodInterceptor, BeanClassLoaderAware {
protected volatile ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader();
@@ -45,7 +44,7 @@ public class GemfireFunctionProxyFactoryBean implements FactoryBean<Object>, Met
private volatile boolean initialized;
protected String functionId;
//protected String functionId;
protected Log logger = LogFactory.getLog(this.getClass());
@@ -123,20 +122,6 @@ public class GemfireFunctionProxyFactoryBean implements FactoryBean<Object>, Met
this.serviceProxy = proxyFactory.getProxy(this.beanClassLoader);
this.initialized = true;
}
protected String annotatedFunctionId(Method method) {
FunctionId functionIdAnnotation = method.getAnnotation(FunctionId.class);
return (functionIdAnnotation == null) ? null: functionIdAnnotation.value();
}
/**
* Optional to set a default function Id for a single method interface with no {code}@FunctionId{code} annotations
* @param functionId
*/
public void setFunctionId(String functionId) {
this.functionId = functionId;
}
/*
* Match the result to the declared return type
@@ -164,16 +149,4 @@ public class GemfireFunctionProxyFactoryBean implements FactoryBean<Object>, Met
}
return result;
}
/* (non-Javadoc)
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
*/
@Override
public void afterPropertiesSet() throws Exception {
if (this.functionId != null) {
if (this.methodMetadata.isSingletonInterface()) {
this.methodMetadata.getSingletonMethodMetada().setFunctionId(this.functionId);
}
}
}
}

View File

@@ -41,7 +41,7 @@ public class GemfireOnMemberFunctionTemplate extends AbstractFunctionTemplate {
}
protected FunctionExecution getFunctionExecution() {
protected AbstractFunctionExecution getFunctionExecution() {
if (distributedMember == null && groups == null) {
return new DefaultMemberFunctionExecution();
} else if (distributedMember == null) {

View File

@@ -42,7 +42,7 @@ public class GemfireOnMembersFunctionTemplate extends AbstractFunctionTemplate
}
protected FunctionExecution getFunctionExecution() {
protected AbstractFunctionExecution getFunctionExecution() {
if (distributedMembers == null && groups == null) {
return new AllMembersFunctionExecution();
} else if (distributedMembers == null) {

View File

@@ -66,7 +66,7 @@ public class GemfireOnRegionFunctionTemplate extends AbstractFunctionTemplate i
}
@Override
protected FunctionExecution getFunctionExecution() {
protected AbstractFunctionExecution getFunctionExecution() {
return new RegionFunctionExecution(this.region);
}

View File

@@ -37,7 +37,7 @@ public class GemfireOnServerFunctionTemplate extends AbstractFunctionTemplate {
}
@Override
protected FunctionExecution getFunctionExecution() {
protected AbstractFunctionExecution getFunctionExecution() {
if (this.pool == null) {
return new ServerFunctionExecution(this.cache);
}

View File

@@ -37,7 +37,7 @@ public class GemfireOnServersFunctionTemplate extends AbstractFunctionTemplate
}
@Override
protected FunctionExecution getFunctionExecution() {
protected AbstractFunctionExecution getFunctionExecution() {
if (this.pool == null) {
return new ServersFunctionExecution(this.cache);
}

View File

@@ -21,7 +21,7 @@ import com.gemstone.gemfire.cache.execute.FunctionService;
* @author David Turanski
*
*/
public class GroupMemberFunctionExecution extends FunctionExecution {
public class GroupMemberFunctionExecution extends AbstractFunctionExecution {
private final String groups[];

View File

@@ -21,7 +21,7 @@ import com.gemstone.gemfire.cache.execute.FunctionService;
* @author David Turanski
*
*/
public class GroupMembersFunctionExecution extends FunctionExecution {
public class GroupMembersFunctionExecution extends AbstractFunctionExecution {
private final String groups[];

View File

@@ -26,7 +26,7 @@ import com.gemstone.gemfire.cache.execute.FunctionService;
* @author David Turanski
*
*/
public class PoolServerFunctionExecution extends FunctionExecution implements InitializingBean {
public class PoolServerFunctionExecution extends AbstractFunctionExecution implements InitializingBean {
private Pool pool;

View File

@@ -23,7 +23,7 @@ import com.gemstone.gemfire.cache.execute.FunctionService;
* @author David Turanski
*
*/
public class PoolServersFunctionExecution extends FunctionExecution {
public class PoolServersFunctionExecution extends AbstractFunctionExecution {
private final Pool pool;

View File

@@ -25,7 +25,7 @@ import com.gemstone.gemfire.cache.execute.FunctionService;
* @author David Turanski
*
*/
public class RegionFunctionExecution extends FunctionExecution {
public class RegionFunctionExecution extends AbstractFunctionExecution {
private final Region<?, ?> region;

View File

@@ -23,7 +23,7 @@ import com.gemstone.gemfire.cache.execute.FunctionService;
* @author David Turanski
*
*/
public class ServerFunctionExecution extends FunctionExecution {
public class ServerFunctionExecution extends AbstractFunctionExecution {
private RegionService regionService;

View File

@@ -23,7 +23,7 @@ import com.gemstone.gemfire.cache.execute.FunctionService;
* @author David Turanski
*
*/
public class ServersFunctionExecution extends FunctionExecution {
public class ServersFunctionExecution extends AbstractFunctionExecution {
private final RegionService regionService;

View File

@@ -43,21 +43,21 @@ public class AnnotationDrivenFunctionsTest {
@Test
public void testAnnotatedFunctions() {
assertTrue(FunctionService.isRegistered(FooFunction.class.getName()+".foo"));
assertTrue(FunctionService.isRegistered("foo"));
Function function = FunctionService.getFunction(FooFunction.class.getName()+".foo");
Function function = FunctionService.getFunction("foo");
assertFalse(function.isHA());
assertFalse(function.optimizeForWrite());
assertFalse(function.hasResult());
assertTrue(FunctionService.isRegistered(FooFunction.class.getName()+".bar"));
function = FunctionService.getFunction(FooFunction.class.getName()+".bar");
assertTrue(FunctionService.isRegistered("bar"));
function = FunctionService.getFunction("bar");
assertTrue(function.isHA());
assertFalse(function.optimizeForWrite());
assertTrue(function.hasResult());
assertTrue(FunctionService.isRegistered("foo"));
function = FunctionService.getFunction("foo");
assertTrue(FunctionService.isRegistered("foo2"));
function = FunctionService.getFunction("foo2");
assertTrue(function.isHA());
assertTrue(function.optimizeForWrite());
assertTrue(function.hasResult());
@@ -84,7 +84,7 @@ public class AnnotationDrivenFunctionsTest {
@Component
public static class Foo2Function {
@GemfireFunction(id="foo", HA=true,optimizeForWrite=true)
@GemfireFunction(id="foo2", HA=true,optimizeForWrite=true)
public List<String> foo (Object someVal, @RegionData Map<?,?> region, Object someOtherValue) {
return null;
}

View File

@@ -13,19 +13,27 @@
package org.springframework.data.gemfire.function.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.data.gemfire.function.execution.GemfireOnServerFunctionTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.client.ClientCache;
import com.gemstone.gemfire.cache.client.Pool;
import com.gemstone.gemfire.cache.execute.FunctionException;
import com.gemstone.gemfire.cache.execute.ResultCollector;
import com.gemstone.gemfire.distributed.DistributedMember;
/**
* @author David Turanski
@@ -47,6 +55,9 @@ public class FunctionExecutionClientCacheTests {
assertEquals(pool.getServers().get(0), cache.getDefaultPool().getServers().get(0));
context.getBean("r1",Region.class);
GemfireOnServerFunctionTemplate template = context.getBean(GemfireOnServerFunctionTemplate.class);
assertTrue(template.getResultCollector() instanceof MyResultCollector);
}
}
@@ -61,8 +72,60 @@ public class FunctionExecutionClientCacheTests {
)
@Configuration
class TestClientCacheConfig {
@Bean
MyResultCollector myResultCollector() {
return new MyResultCollector();
}
}
@SuppressWarnings("rawtypes")
class MyResultCollector implements ResultCollector {
/* (non-Javadoc)
* @see com.gemstone.gemfire.cache.execute.ResultCollector#addResult(com.gemstone.gemfire.distributed.DistributedMember, java.lang.Object)
*/
@Override
public void addResult(DistributedMember arg0, Object arg1) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see com.gemstone.gemfire.cache.execute.ResultCollector#clearResults()
*/
@Override
public void clearResults() {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see com.gemstone.gemfire.cache.execute.ResultCollector#endResults()
*/
@Override
public void endResults() {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see com.gemstone.gemfire.cache.execute.ResultCollector#getResult()
*/
@Override
public Object getResult() throws FunctionException {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see com.gemstone.gemfire.cache.execute.ResultCollector#getResult(long, java.util.concurrent.TimeUnit)
*/
@Override
public Object getResult(long arg0, TimeUnit arg1) throws FunctionException, InterruptedException {
// TODO Auto-generated method stub
return null;
}
}

View File

@@ -31,41 +31,43 @@ import org.springframework.data.gemfire.function.config.one.TestFunctionExecutio
*
*/
public class FunctionExecutionComponentProviderTest {
@Test
public void testDiscovery() throws ClassNotFoundException {
List<TypeFilter> includeFilters = new ArrayList<TypeFilter>();
FunctionExecutionComponentProvider provider = new FunctionExecutionComponentProvider(includeFilters,AnnotationFunctionExecutionConfigurationSource.getFunctionExecutionAnnotationTypes());
Set<BeanDefinition> candidates = provider.findCandidateComponents(this.getClass().getPackage().getName()+".one");
ScannedGenericBeanDefinition bd = null;
for (BeanDefinition candidate: candidates) {
if (candidate.getBeanClassName().equals(TestFunctionExecution.class.getName())) {
bd = (ScannedGenericBeanDefinition)candidate;
}
}
assertNotNull(bd);
}
@Test
public void testExcludeFilter() throws ClassNotFoundException {
List<TypeFilter> includeFilters = new ArrayList<TypeFilter>();
FunctionExecutionComponentProvider provider = new FunctionExecutionComponentProvider(includeFilters,AnnotationFunctionExecutionConfigurationSource.getFunctionExecutionAnnotationTypes());
provider.addExcludeFilter(new AssignableTypeFilter(TestFunctionExecution.class));
Set<BeanDefinition> candidates = provider.findCandidateComponents(this.getClass().getPackage().getName()+".one");
for (BeanDefinition candidate: candidates) {
if (candidate.getBeanClassName().equals(TestFunctionExecution.class.getName())) {
fail(TestFunctionExecution.class.getName() + " not excluded");
}
}
}
@Test
public void testDiscovery() throws ClassNotFoundException {
List<TypeFilter> includeFilters = new ArrayList<TypeFilter>();
FunctionExecutionComponentProvider provider = new FunctionExecutionComponentProvider(includeFilters,
AnnotationFunctionExecutionConfigurationSource.getFunctionExecutionAnnotationTypes());
Set<BeanDefinition> candidates = provider.findCandidateComponents(this.getClass().getPackage().getName()
+ ".one");
ScannedGenericBeanDefinition bd = null;
for (BeanDefinition candidate : candidates) {
if (candidate.getBeanClassName().equals(TestFunctionExecution.class.getName())) {
bd = (ScannedGenericBeanDefinition) candidate;
}
}
assertNotNull(bd);
}
@Test
public void testExcludeFilter() throws ClassNotFoundException {
List<TypeFilter> includeFilters = new ArrayList<TypeFilter>();
FunctionExecutionComponentProvider provider = new FunctionExecutionComponentProvider(includeFilters,
AnnotationFunctionExecutionConfigurationSource.getFunctionExecutionAnnotationTypes());
provider.addExcludeFilter(new AssignableTypeFilter(TestFunctionExecution.class));
Set<BeanDefinition> candidates = provider.findCandidateComponents(this.getClass().getPackage().getName()
+ ".one");
for (BeanDefinition candidate : candidates) {
if (candidate.getBeanClassName().equals(TestFunctionExecution.class.getName())) {
fail(TestFunctionExecution.class.getName() + " not excluded");
}
}
}
}

View File

@@ -22,7 +22,7 @@ import org.springframework.data.gemfire.function.config.OnServer;
* @author David Turanski
*
*/
@OnServer(id="testClientOnServerFunction",pool="gemfirePool")
@OnServer(id="testClientOnServerFunction",pool="gemfirePool",resultCollector="myResultCollector")
public interface TestClientOnServerFunction {
@FunctionId("f1")
public String getString(Object arg1, @Filter Set<Object> keys) ;

View File

@@ -95,7 +95,7 @@ public class FunctionExecutionTests {
private void verifyfunctionExecution(FunctionExecution functionExecution) {
private void verifyfunctionExecution(AbstractFunctionExecution functionExecution) {
Iterable<String> results = functionExecution
.setArgs("1","2","3")
.setFunctionId("echoFunction")

View File

@@ -55,7 +55,6 @@ public class GemfireFunctionProxyFactoryBeanTests {
GemfireFunctionProxyFactoryBean proxy = new GemfireFunctionProxyFactoryBean(IFoo.class,functionOperations);
proxy.setFunctionId(IFoo.class.getName());
MethodInvocation invocation = new TestInvocation(IFoo.class).withMethodNameAndArgTypes("oneArg",String.class);
@@ -75,13 +74,12 @@ public class GemfireFunctionProxyFactoryBeanTests {
GemfireFunctionProxyFactoryBean proxy = new GemfireFunctionProxyFactoryBean(IFoo.class, functionOperations);
proxy.setFunctionId(IFoo.class.getName());
MethodInvocation invocation = new TestInvocation(IFoo.class).withMethodNameAndArgTypes("collections",List.class);
List results = Arrays.asList(new Integer[]{1,2,3});
when(functionOperations.execute(IFoo.class.getName() + ".collections",invocation.getArguments())).thenReturn(results);
when(functionOperations.execute("collections",invocation.getArguments())).thenReturn(results);
Object result = proxy.invoke(invocation);
assertTrue(result instanceof List);

View File

@@ -11,7 +11,7 @@
<gfe:client-region id="r1" pool-name="gemfirePool" />
<gfe:pool id="gemfirePool">
<gfe:pool id="gemfirePool" >
<gfe:server host="localhost" port="12345"/>
</gfe:pool>