SGF-216: Fixed bug in FunctionContextInjectingArgumentResolver
This commit is contained in:
@@ -28,7 +28,6 @@ import com.gemstone.gemfire.cache.execute.FunctionContext;
|
||||
import com.gemstone.gemfire.cache.execute.RegionFunctionContext;
|
||||
import com.gemstone.gemfire.cache.execute.ResultSender;
|
||||
import com.gemstone.gemfire.cache.partition.PartitionRegionHelper;
|
||||
|
||||
|
||||
/**
|
||||
* @author David Turanski
|
||||
@@ -36,77 +35,83 @@ import com.gemstone.gemfire.cache.partition.PartitionRegionHelper;
|
||||
*
|
||||
*/
|
||||
class FunctionContextInjectingArgumentResolver extends DefaultFunctionArgumentResolver {
|
||||
|
||||
|
||||
private static Log logger = LogFactory.getLog(FunctionContextInjectingArgumentResolver.class);
|
||||
|
||||
|
||||
private final int regionParameterPosition;
|
||||
private final int filterParameterPosition;
|
||||
private final int functionContextParameterPosition;
|
||||
private final int resultSenderParameterPosition;
|
||||
private final Method method;
|
||||
|
||||
|
||||
public FunctionContextInjectingArgumentResolver(Method method) {
|
||||
|
||||
this.method = method;
|
||||
int annotatedRegionDataParameterPosition = GemfireFunctionUtils.getAnnotationParameterPosition(method, RegionData.class, new Class[]{Map.class});
|
||||
int regionTypeParameterPosition = getArgumentTypePosition(method,Region.class);
|
||||
|
||||
if (annotatedRegionDataParameterPosition >=0 && regionTypeParameterPosition >= 0) {
|
||||
Assert.isTrue(annotatedRegionDataParameterPosition == regionTypeParameterPosition,
|
||||
String.format("Function method signature for method %s cannot contain an @RegionData parameter and a different Region type parameter", method.getName()));
|
||||
}
|
||||
|
||||
int tempRegionParameterPosition = -1;
|
||||
|
||||
if (annotatedRegionDataParameterPosition >=0 ) {
|
||||
tempRegionParameterPosition = annotatedRegionDataParameterPosition;
|
||||
} else if (regionTypeParameterPosition >=0) {
|
||||
tempRegionParameterPosition = regionTypeParameterPosition;
|
||||
}
|
||||
|
||||
regionParameterPosition = tempRegionParameterPosition;
|
||||
filterParameterPosition = GemfireFunctionUtils.getAnnotationParameterPosition(method, Filter.class, new Class[]{Set.class});
|
||||
functionContextParameterPosition = getArgumentTypePosition(method,FunctionContext.class);
|
||||
resultSenderParameterPosition = getArgumentTypePosition(method,ResultSender.class);
|
||||
|
||||
if (regionParameterPosition >=0 && filterParameterPosition >=0) {
|
||||
Assert.state(regionParameterPosition != filterParameterPosition, "region parameter and filter parameter must be different");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.method = method;
|
||||
int annotatedRegionDataParameterPosition = GemfireFunctionUtils.getAnnotationParameterPosition(method,
|
||||
RegionData.class, new Class[] { Map.class });
|
||||
int regionTypeParameterPosition = getArgumentTypePosition(method, Region.class);
|
||||
|
||||
if (annotatedRegionDataParameterPosition >= 0 && regionTypeParameterPosition >= 0) {
|
||||
Assert.isTrue(
|
||||
annotatedRegionDataParameterPosition == regionTypeParameterPosition,
|
||||
String.format(
|
||||
"Function method signature for method %s cannot contain an @RegionData parameter and a different Region type parameter",
|
||||
method.getName()));
|
||||
}
|
||||
|
||||
int tempRegionParameterPosition = -1;
|
||||
|
||||
if (annotatedRegionDataParameterPosition >= 0) {
|
||||
tempRegionParameterPosition = annotatedRegionDataParameterPosition;
|
||||
} else if (regionTypeParameterPosition >= 0) {
|
||||
tempRegionParameterPosition = regionTypeParameterPosition;
|
||||
}
|
||||
|
||||
regionParameterPosition = tempRegionParameterPosition;
|
||||
filterParameterPosition = GemfireFunctionUtils.getAnnotationParameterPosition(method, Filter.class,
|
||||
new Class[] { Set.class });
|
||||
functionContextParameterPosition = getArgumentTypePosition(method, FunctionContext.class);
|
||||
resultSenderParameterPosition = getArgumentTypePosition(method, ResultSender.class);
|
||||
|
||||
if (regionParameterPosition >= 0 && filterParameterPosition >= 0) {
|
||||
Assert.state(regionParameterPosition != filterParameterPosition,
|
||||
"region parameter and filter parameter must be different");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] resolveFunctionArguments(FunctionContext functionContext) {
|
||||
|
||||
Object[] args = super.resolveFunctionArguments(functionContext);
|
||||
|
||||
if (functionContext instanceof RegionFunctionContext) {
|
||||
if (this.regionParameterPosition >= 0) {
|
||||
args = ArrayUtils.insert(args, regionParameterPosition, getRegionForContext((RegionFunctionContext)functionContext));
|
||||
}
|
||||
|
||||
if (this.filterParameterPosition >= 0) {
|
||||
args = ArrayUtils.insert(args, filterParameterPosition, ((RegionFunctionContext)functionContext).getFilter());
|
||||
}
|
||||
|
||||
if (this.functionContextParameterPosition >= 0) {
|
||||
args = ArrayUtils.insert(args, functionContextParameterPosition, functionContext);
|
||||
}
|
||||
|
||||
if (this.resultSenderParameterPosition >=0 ) {
|
||||
args = ArrayUtils.insert(args, resultSenderParameterPosition, functionContext.getResultSender());
|
||||
}
|
||||
|
||||
Object[] args = super.resolveFunctionArguments(functionContext);
|
||||
|
||||
if (functionContext instanceof RegionFunctionContext) {
|
||||
if (this.regionParameterPosition >= 0) {
|
||||
args = ArrayUtils.insert(args, regionParameterPosition,
|
||||
getRegionForContext((RegionFunctionContext) functionContext));
|
||||
}
|
||||
|
||||
if (this.filterParameterPosition >= 0) {
|
||||
args = ArrayUtils.insert(args, filterParameterPosition,
|
||||
((RegionFunctionContext) functionContext).getFilter());
|
||||
}
|
||||
}
|
||||
|
||||
Assert.isTrue(args.length == method.getParameterTypes().length,
|
||||
String.format("wrong number of arguments for method %s. Expected :%d, actual: %d", method.getName(),
|
||||
method.getParameterTypes().length, args.length));
|
||||
|
||||
if (this.functionContextParameterPosition >= 0) {
|
||||
args = ArrayUtils.insert(args, functionContextParameterPosition, functionContext);
|
||||
}
|
||||
|
||||
if (this.resultSenderParameterPosition >= 0) {
|
||||
args = ArrayUtils.insert(args, resultSenderParameterPosition, functionContext.getResultSender());
|
||||
}
|
||||
|
||||
Assert.isTrue(args.length == method.getParameterTypes().length, String.format(
|
||||
"wrong number of arguments for method %s. Expected :%d, actual: %d", method.getName(),
|
||||
method.getParameterTypes().length, args.length));
|
||||
|
||||
return args;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @param regionFunctionContext
|
||||
* @return
|
||||
@@ -127,19 +132,20 @@ class FunctionContextInjectingArgumentResolver extends DefaultFunctionArgumentRe
|
||||
}
|
||||
|
||||
private static int getArgumentTypePosition(Method method, Class<?> requiredType) {
|
||||
int position = -1;
|
||||
int i = 0;
|
||||
for (Class<?> clazz: method.getParameterTypes()) {
|
||||
int position = -1;
|
||||
int i = 0;
|
||||
for (Class<?> clazz : method.getParameterTypes()) {
|
||||
if (requiredType.equals(clazz)) {
|
||||
Assert.state(position < 0, String.format("Method %s signature cannot contain more than one parameter of type %s."
|
||||
,method.getName(),requiredType.getName()));
|
||||
Assert.state(
|
||||
position < 0,
|
||||
String.format("Method %s signature cannot contain more than one parameter of type %s.",
|
||||
method.getName(), requiredType.getName()));
|
||||
position = i;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return position;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -34,288 +34,313 @@ import com.gemstone.gemfire.cache.execute.ResultSender;
|
||||
|
||||
/**
|
||||
* @author David Turanski
|
||||
*
|
||||
*/
|
||||
public class FunctionArgumentResolverTest {
|
||||
|
||||
@Test
|
||||
public void testDefaultFunctionArgumentResolverSingleArg() {
|
||||
FunctionArgumentResolver far = new DefaultFunctionArgumentResolver();
|
||||
@Test
|
||||
public void testDefaultFunctionArgumentResolverSingleArg() {
|
||||
FunctionArgumentResolver far = new DefaultFunctionArgumentResolver();
|
||||
|
||||
FunctionContext functionContext = mock(FunctionContext.class);
|
||||
FunctionContext functionContext = mock(FunctionContext.class);
|
||||
|
||||
when(functionContext.getArguments()).thenReturn("hello");
|
||||
when(functionContext.getArguments()).thenReturn("hello");
|
||||
|
||||
Object[] args = far.resolveFunctionArguments(functionContext);
|
||||
Object[] args = far.resolveFunctionArguments(functionContext);
|
||||
|
||||
assertEquals(1, args.length);
|
||||
assertEquals("hello", args[0]);
|
||||
}
|
||||
assertEquals(1, args.length);
|
||||
assertEquals("hello", args[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultFunctionArgumentResolverSingleArgAsArray() {
|
||||
FunctionArgumentResolver far = new DefaultFunctionArgumentResolver();
|
||||
@Test
|
||||
public void testDefaultFunctionArgumentResolverSingleArgAsArray() {
|
||||
FunctionArgumentResolver far = new DefaultFunctionArgumentResolver();
|
||||
|
||||
FunctionContext functionContext = mock(FunctionContext.class);
|
||||
FunctionContext functionContext = mock(FunctionContext.class);
|
||||
|
||||
when(functionContext.getArguments()).thenReturn(new String[] { "hello" });
|
||||
when(functionContext.getArguments()).thenReturn(new String[]{"hello"});
|
||||
|
||||
Object[] args = far.resolveFunctionArguments(functionContext);
|
||||
Object[] args = far.resolveFunctionArguments(functionContext);
|
||||
|
||||
assertEquals(1, args.length);
|
||||
assertEquals("hello", args[0]);
|
||||
}
|
||||
assertEquals(1, args.length);
|
||||
assertEquals("hello", args[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodWithNoSpecialArgs() throws SecurityException, NoSuchMethodException {
|
||||
RegionFunctionContext functionContext = mock(RegionFunctionContext.class);
|
||||
@Test
|
||||
public void testMethodWithNoSpecialArgs() throws SecurityException, NoSuchMethodException {
|
||||
RegionFunctionContext functionContext = mock(RegionFunctionContext.class);
|
||||
|
||||
Method method = TestFunction.class.getDeclaredMethod("methodWithNoSpecialArgs", String.class, int.class,
|
||||
boolean.class);
|
||||
FunctionArgumentResolver far = new FunctionContextInjectingArgumentResolver(method);
|
||||
Method method = TestFunction.class.getDeclaredMethod("methodWithNoSpecialArgs", String.class, int.class,
|
||||
boolean.class);
|
||||
FunctionArgumentResolver far = new FunctionContextInjectingArgumentResolver(method);
|
||||
|
||||
Object[] originalArgs = new Object[] { "hello", 0, false };
|
||||
when(functionContext.getArguments()).thenReturn(originalArgs);
|
||||
Object[] originalArgs = new Object[]{"hello", 0, false};
|
||||
when(functionContext.getArguments()).thenReturn(originalArgs);
|
||||
|
||||
Object[] args = far.resolveFunctionArguments(functionContext);
|
||||
Object[] args = far.resolveFunctionArguments(functionContext);
|
||||
|
||||
assertEquals(originalArgs.length, args.length);
|
||||
assertEquals(originalArgs.length, args.length);
|
||||
|
||||
int i = 0;
|
||||
for (Object arg : args) {
|
||||
assertSame(originalArgs[i++], arg);
|
||||
}
|
||||
int i = 0;
|
||||
for (Object arg : args) {
|
||||
assertSame(originalArgs[i++], arg);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodWithRegionType() throws SecurityException, NoSuchMethodException {
|
||||
RegionFunctionContext functionContext = mock(RegionFunctionContext.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
Region<Object, Object> region = mock(Region.class);
|
||||
@Test
|
||||
public void testMethodWithRegionType() throws SecurityException, NoSuchMethodException {
|
||||
RegionFunctionContext functionContext = mock(RegionFunctionContext.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
Region<Object, Object> region = mock(Region.class);
|
||||
|
||||
Method method = TestFunction.class.getDeclaredMethod("methodWithRegionType", String.class, Region.class);
|
||||
FunctionArgumentResolver far = new FunctionContextInjectingArgumentResolver(method);
|
||||
Method method = TestFunction.class.getDeclaredMethod("methodWithRegionType", String.class, Region.class);
|
||||
FunctionArgumentResolver far = new FunctionContextInjectingArgumentResolver(method);
|
||||
|
||||
Object[] originalArgs = new Object[] { "hello" };
|
||||
when(functionContext.getArguments()).thenReturn(originalArgs);
|
||||
when(functionContext.getDataSet()).thenReturn(region);
|
||||
Object[] originalArgs = new Object[]{"hello"};
|
||||
when(functionContext.getArguments()).thenReturn(originalArgs);
|
||||
when(functionContext.getDataSet()).thenReturn(region);
|
||||
|
||||
Object[] args = far.resolveFunctionArguments(functionContext);
|
||||
Object[] args = far.resolveFunctionArguments(functionContext);
|
||||
|
||||
assertEquals(originalArgs.length + 1, args.length);
|
||||
assertEquals(originalArgs.length + 1, args.length);
|
||||
|
||||
int i = 0;
|
||||
for (Object arg : args) {
|
||||
if (i != 1) {
|
||||
assertSame(originalArgs[i++], arg);
|
||||
} else {
|
||||
assertSame(region, arg);
|
||||
}
|
||||
}
|
||||
int i = 0;
|
||||
for (Object arg : args) {
|
||||
if (i != 1) {
|
||||
assertSame(originalArgs[i++], arg);
|
||||
} else {
|
||||
assertSame(region, arg);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodWithOneArgRegionType() throws SecurityException, NoSuchMethodException {
|
||||
RegionFunctionContext functionContext = mock(RegionFunctionContext.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
Region<Object, Object> region = mock(Region.class);
|
||||
@Test
|
||||
public void testMethodWithOneArgRegionType() throws SecurityException, NoSuchMethodException {
|
||||
RegionFunctionContext functionContext = mock(RegionFunctionContext.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
Region<Object, Object> region = mock(Region.class);
|
||||
|
||||
Method method = TestFunction.class.getDeclaredMethod("methodWithOneArgRegionType", Region.class);
|
||||
FunctionArgumentResolver far = new FunctionContextInjectingArgumentResolver(method);
|
||||
Method method = TestFunction.class.getDeclaredMethod("methodWithOneArgRegionType", Region.class);
|
||||
FunctionArgumentResolver far = new FunctionContextInjectingArgumentResolver(method);
|
||||
|
||||
Object[] originalArgs = new Object[] {};
|
||||
when(functionContext.getArguments()).thenReturn(originalArgs);
|
||||
when(functionContext.getDataSet()).thenReturn(region);
|
||||
Object[] originalArgs = new Object[]{};
|
||||
when(functionContext.getArguments()).thenReturn(originalArgs);
|
||||
when(functionContext.getDataSet()).thenReturn(region);
|
||||
|
||||
Object[] args = far.resolveFunctionArguments(functionContext);
|
||||
Object[] args = far.resolveFunctionArguments(functionContext);
|
||||
|
||||
assertEquals(1, args.length);
|
||||
assertSame(region, args[0]);
|
||||
assertEquals(1, args.length);
|
||||
assertSame(region, args[0]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodWithAnnotatedRegion() throws SecurityException, NoSuchMethodException {
|
||||
RegionFunctionContext functionContext = mock(RegionFunctionContext.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
Region<Object, Object> region = mock(Region.class);
|
||||
@Test
|
||||
public void testMethodWithAnnotatedRegion() throws SecurityException, NoSuchMethodException {
|
||||
RegionFunctionContext functionContext = mock(RegionFunctionContext.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
Region<Object, Object> region = mock(Region.class);
|
||||
|
||||
Method method = TestFunction.class.getDeclaredMethod("methodWithAnnotatedRegion", Region.class, String.class);
|
||||
FunctionArgumentResolver far = new FunctionContextInjectingArgumentResolver(method);
|
||||
Method method = TestFunction.class.getDeclaredMethod("methodWithAnnotatedRegion", Region.class, String.class);
|
||||
FunctionArgumentResolver far = new FunctionContextInjectingArgumentResolver(method);
|
||||
|
||||
Object[] originalArgs = new Object[] { "hello" };
|
||||
when(functionContext.getArguments()).thenReturn(originalArgs);
|
||||
when(functionContext.getDataSet()).thenReturn(region);
|
||||
Object[] originalArgs = new Object[]{"hello"};
|
||||
when(functionContext.getArguments()).thenReturn(originalArgs);
|
||||
when(functionContext.getDataSet()).thenReturn(region);
|
||||
|
||||
Object[] args = far.resolveFunctionArguments(functionContext);
|
||||
Object[] args = far.resolveFunctionArguments(functionContext);
|
||||
|
||||
assertEquals(2, args.length);
|
||||
assertSame(region, args[0]);
|
||||
assertSame(originalArgs[0], args[1]);
|
||||
assertEquals(2, args.length);
|
||||
assertSame(region, args[0]);
|
||||
assertSame(originalArgs[0], args[1]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodWithFunctionContext() throws SecurityException, NoSuchMethodException {
|
||||
RegionFunctionContext functionContext = mock(RegionFunctionContext.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
Region<Object, Object> region = mock(Region.class);
|
||||
@Test
|
||||
public void testMethodWithFunctionContext() throws SecurityException, NoSuchMethodException {
|
||||
RegionFunctionContext functionContext = mock(RegionFunctionContext.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
Region<Object, Object> region = mock(Region.class);
|
||||
|
||||
Method method = TestFunction.class.getDeclaredMethod("methodWithFunctionContext", Map.class, String.class,
|
||||
FunctionContext.class);
|
||||
FunctionArgumentResolver far = new FunctionContextInjectingArgumentResolver(method);
|
||||
Method method = TestFunction.class.getDeclaredMethod("methodWithFunctionContext", Map.class, String.class,
|
||||
FunctionContext.class);
|
||||
FunctionArgumentResolver far = new FunctionContextInjectingArgumentResolver(method);
|
||||
|
||||
Object[] originalArgs = new Object[] { "hello" };
|
||||
when(functionContext.getArguments()).thenReturn(originalArgs);
|
||||
when(functionContext.getDataSet()).thenReturn(region);
|
||||
Object[] originalArgs = new Object[]{"hello"};
|
||||
when(functionContext.getArguments()).thenReturn(originalArgs);
|
||||
when(functionContext.getDataSet()).thenReturn(region);
|
||||
|
||||
Object[] args = far.resolveFunctionArguments(functionContext);
|
||||
Object[] args = far.resolveFunctionArguments(functionContext);
|
||||
|
||||
assertEquals(3, args.length);
|
||||
assertSame(region, args[0]);
|
||||
assertSame(originalArgs[0], args[1]);
|
||||
assertSame(functionContext, args[2]);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Test
|
||||
public void testMethodWithResultSender () throws SecurityException, NoSuchMethodException {
|
||||
RegionFunctionContext functionContext = mock(RegionFunctionContext.class);
|
||||
ResultSender resultSender = mock(ResultSender.class);
|
||||
Region<Object, Object> region = mock(Region.class);
|
||||
assertEquals(3, args.length);
|
||||
assertSame(region, args[0]);
|
||||
assertSame(originalArgs[0], args[1]);
|
||||
assertSame(functionContext, args[2]);
|
||||
}
|
||||
|
||||
Method method = TestFunction.class.getDeclaredMethod("methodWithResultSender", Map.class, ResultSender.class);
|
||||
FunctionArgumentResolver far = new FunctionContextInjectingArgumentResolver(method);
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@Test
|
||||
public void testMethodWithResultSender() throws SecurityException, NoSuchMethodException {
|
||||
RegionFunctionContext functionContext = mock(RegionFunctionContext.class);
|
||||
ResultSender resultSender = mock(ResultSender.class);
|
||||
Region<Object, Object> region = mock(Region.class);
|
||||
|
||||
Object[] originalArgs = new Object[] { };
|
||||
when(functionContext.getArguments()).thenReturn(originalArgs);
|
||||
when(functionContext.getDataSet()).thenReturn(region);
|
||||
when(functionContext.getResultSender()).thenReturn(resultSender);
|
||||
Method method = TestFunction.class.getDeclaredMethod("methodWithResultSender", Map.class, ResultSender.class);
|
||||
FunctionArgumentResolver far = new FunctionContextInjectingArgumentResolver(method);
|
||||
|
||||
Object[] args = far.resolveFunctionArguments(functionContext);
|
||||
Object[] originalArgs = new Object[]{};
|
||||
when(functionContext.getArguments()).thenReturn(originalArgs);
|
||||
when(functionContext.getDataSet()).thenReturn(region);
|
||||
when(functionContext.getResultSender()).thenReturn(resultSender);
|
||||
|
||||
assertEquals(2, args.length);
|
||||
assertSame(region, args[0]);
|
||||
assertSame(resultSender, args[1]);
|
||||
}
|
||||
Object[] args = far.resolveFunctionArguments(functionContext);
|
||||
|
||||
assertEquals(2, args.length);
|
||||
assertSame(region, args[0]);
|
||||
assertSame(resultSender, args[1]);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testMethodWithFilterAndRegion() throws SecurityException, NoSuchMethodException {
|
||||
RegionFunctionContext functionContext = mock(RegionFunctionContext.class);
|
||||
Region<Object, Object> region = mock(Region.class);
|
||||
|
||||
Method method = TestFunction.class.getDeclaredMethod("methodWithFilterAndRegion", Map.class, Set.class,
|
||||
Object.class);
|
||||
FunctionArgumentResolver far = new FunctionContextInjectingArgumentResolver(method);
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testMethodWithFilterAndRegion() throws SecurityException, NoSuchMethodException {
|
||||
RegionFunctionContext functionContext = mock(RegionFunctionContext.class);
|
||||
Region<Object, Object> region = mock(Region.class);
|
||||
|
||||
Object[] originalArgs = new Object[] { new Object() };
|
||||
when(functionContext.getArguments()).thenReturn(originalArgs);
|
||||
when(functionContext.getDataSet()).thenReturn(region);
|
||||
@SuppressWarnings("rawtypes")
|
||||
Set keys = new HashSet<String>();
|
||||
when(functionContext.getFilter()).thenReturn(keys);
|
||||
Method method = TestFunction.class.getDeclaredMethod("methodWithFilterAndRegion", Map.class, Set.class,
|
||||
Object.class);
|
||||
FunctionArgumentResolver far = new FunctionContextInjectingArgumentResolver(method);
|
||||
|
||||
Object[] args = far.resolveFunctionArguments(functionContext);
|
||||
Object[] originalArgs = new Object[]{new Object()};
|
||||
when(functionContext.getArguments()).thenReturn(originalArgs);
|
||||
when(functionContext.getDataSet()).thenReturn(region);
|
||||
@SuppressWarnings("rawtypes")
|
||||
Set keys = new HashSet<String>();
|
||||
when(functionContext.getFilter()).thenReturn(keys);
|
||||
|
||||
assertEquals(3, args.length);
|
||||
assertSame(region, args[0]);
|
||||
assertSame(originalArgs[0], args[2]);
|
||||
assertSame(keys, args[1]);
|
||||
}
|
||||
Object[] args = far.resolveFunctionArguments(functionContext);
|
||||
|
||||
@Test
|
||||
public void testMethodWithMultipleRegionData() throws SecurityException, NoSuchMethodException {
|
||||
assertEquals(3, args.length);
|
||||
assertSame(region, args[0]);
|
||||
assertSame(originalArgs[0], args[2]);
|
||||
assertSame(keys, args[1]);
|
||||
}
|
||||
|
||||
Method method = TestFunction.class.getDeclaredMethod("methodWithMultipleRegionData", Map.class, Map.class);
|
||||
@Test
|
||||
public void testMethodWithMultipleRegionData() throws SecurityException, NoSuchMethodException {
|
||||
|
||||
try {
|
||||
new FunctionContextInjectingArgumentResolver(method);
|
||||
fail("Should throw exception");
|
||||
} catch (Exception e) {
|
||||
Method method = TestFunction.class.getDeclaredMethod("methodWithMultipleRegionData", Map.class, Map.class);
|
||||
|
||||
}
|
||||
try {
|
||||
new FunctionContextInjectingArgumentResolver(method);
|
||||
fail("Should throw exception");
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodWithMultipleRegions() throws SecurityException, NoSuchMethodException {
|
||||
}
|
||||
|
||||
Method method = TestFunction.class.getDeclaredMethod("methodWithMultipleRegions", Region.class, Map.class);
|
||||
@Test
|
||||
public void testMethodWithMultipleRegions() throws SecurityException, NoSuchMethodException {
|
||||
|
||||
try {
|
||||
new FunctionContextInjectingArgumentResolver(method);
|
||||
fail("Should throw exception");
|
||||
} catch (Exception e) {
|
||||
Method method = TestFunction.class.getDeclaredMethod("methodWithMultipleRegions", Region.class, Map.class);
|
||||
|
||||
}
|
||||
}
|
||||
try {
|
||||
new FunctionContextInjectingArgumentResolver(method);
|
||||
fail("Should throw exception");
|
||||
} catch (Exception e) {
|
||||
|
||||
@Test
|
||||
public void testMethodWithInvalidTypeForAnnotation() throws SecurityException, NoSuchMethodException {
|
||||
}
|
||||
}
|
||||
|
||||
Method method = TestFunction.class.getDeclaredMethod("methodWithInvalidTypeForAnnotation", Region.class);
|
||||
@Test
|
||||
public void testMethodWithInvalidTypeForAnnotation() throws SecurityException, NoSuchMethodException {
|
||||
|
||||
try {
|
||||
new FunctionContextInjectingArgumentResolver(method);
|
||||
fail("Should throw exception");
|
||||
} catch (Exception e) {
|
||||
Method method = TestFunction.class.getDeclaredMethod("methodWithInvalidTypeForAnnotation", Region.class);
|
||||
|
||||
}
|
||||
}
|
||||
try {
|
||||
new FunctionContextInjectingArgumentResolver(method);
|
||||
fail("Should throw exception");
|
||||
} catch (Exception e) {
|
||||
|
||||
@Test
|
||||
public void testMethodWithMultipleFunctionContext() throws SecurityException, NoSuchMethodException {
|
||||
}
|
||||
}
|
||||
|
||||
Method method = TestFunction.class.getDeclaredMethod("methodWithMultipleFunctionContext",
|
||||
FunctionContext.class, FunctionContext.class);
|
||||
@Test
|
||||
public void testMethodWithMultipleFunctionContext() throws SecurityException, NoSuchMethodException {
|
||||
|
||||
try {
|
||||
new FunctionContextInjectingArgumentResolver(method);
|
||||
fail("Should throw exception");
|
||||
} catch (Exception e) {
|
||||
Method method = TestFunction.class.getDeclaredMethod("methodWithMultipleFunctionContext",
|
||||
FunctionContext.class, FunctionContext.class);
|
||||
|
||||
}
|
||||
}
|
||||
try {
|
||||
new FunctionContextInjectingArgumentResolver(method);
|
||||
fail("Should throw exception");
|
||||
} catch (Exception e) {
|
||||
|
||||
static class TestFunction {
|
||||
public void methodWithNoSpecialArgs(String s1, int i1, boolean b1) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void methodWithRegionType(String s1, Region<?, ?> region) {
|
||||
}
|
||||
@Test
|
||||
public void testMethodWithFunctionContextAndResultSender() throws NoSuchMethodException {
|
||||
|
||||
public void methodWithOneArgRegionType(Region<?, ?> region) {
|
||||
}
|
||||
FunctionContext functionContext = mock(FunctionContext.class);
|
||||
ResultSender resultSender = mock(ResultSender.class);
|
||||
Method method = TestFunction.class.getDeclaredMethod("methodWithFunctionContextAndResultSender",
|
||||
FunctionContext.class, ResultSender.class);
|
||||
|
||||
public void methodWithAnnotatedRegion(@RegionData Region<?, ?> data, String s1) {
|
||||
}
|
||||
FunctionArgumentResolver far = new FunctionContextInjectingArgumentResolver(method);
|
||||
|
||||
public void methodWithFunctionContext(@RegionData Map<?, ?> data, String s1, FunctionContext fc) {
|
||||
}
|
||||
|
||||
public void methodWithResultSender(@RegionData Map<?, ?> data, ResultSender<?> resultSender) {
|
||||
}
|
||||
Object[] originalArgs = new Object[]{};
|
||||
when(functionContext.getArguments()).thenReturn(originalArgs);
|
||||
when(functionContext.getResultSender()).thenReturn(resultSender);
|
||||
|
||||
public void methodWithFilterAndRegion(@RegionData Map<String, Object> region, @Filter Set<String> keys,
|
||||
Object arg) {
|
||||
}
|
||||
Object[] args = far.resolveFunctionArguments(functionContext);
|
||||
|
||||
//Invalid Method Signatures
|
||||
public void methodWithMultipleRegionData(@RegionData Map<?, ?> r1, @RegionData Map<?, ?> r2) {
|
||||
}
|
||||
assertEquals(2, args.length);
|
||||
assertSame(functionContext, args[0]);
|
||||
assertSame(resultSender, args[1]);
|
||||
|
||||
public void methodWithMultipleRegions(Region<?, ?> r1, @RegionData Map<?, ?> r2) {
|
||||
}
|
||||
}
|
||||
|
||||
public void methodWithInvalidTypeForAnnotation(@Filter Region<?, ?> r1) {
|
||||
}
|
||||
static class TestFunction {
|
||||
public void methodWithNoSpecialArgs(String s1, int i1, boolean b1) {
|
||||
}
|
||||
|
||||
public void methodWithMultipleFunctionContext(FunctionContext fc1, FunctionContext fc2) {
|
||||
}
|
||||
public void methodWithRegionType(String s1, Region<?, ?> region) {
|
||||
}
|
||||
|
||||
}
|
||||
public void methodWithOneArgRegionType(Region<?, ?> region) {
|
||||
}
|
||||
|
||||
public void methodWithAnnotatedRegion(@RegionData Region<?, ?> data, String s1) {
|
||||
}
|
||||
|
||||
public void methodWithFunctionContext(@RegionData Map<?, ?> data, String s1, FunctionContext fc) {
|
||||
}
|
||||
|
||||
public void methodWithResultSender(@RegionData Map<?, ?> data, ResultSender<?> resultSender) {
|
||||
}
|
||||
|
||||
public void methodWithFilterAndRegion(@RegionData Map<String, Object> region, @Filter Set<String> keys,
|
||||
Object arg) {
|
||||
}
|
||||
|
||||
//Invalid Method Signatures
|
||||
public void methodWithMultipleRegionData(@RegionData Map<?, ?> r1, @RegionData Map<?, ?> r2) {
|
||||
}
|
||||
|
||||
public void methodWithMultipleRegions(Region<?, ?> r1, @RegionData Map<?, ?> r2) {
|
||||
}
|
||||
|
||||
public void methodWithInvalidTypeForAnnotation(@Filter Region<?, ?> r1) {
|
||||
}
|
||||
|
||||
public void methodWithMultipleFunctionContext(FunctionContext fc1, FunctionContext fc2) {
|
||||
}
|
||||
|
||||
public void methodWithFunctionContextAndResultSender(FunctionContext fc1, ResultSender<?> rs) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user