Upgrades Spring Data GemFire 1.5 to GemFire 7.5.
This commit is contained in:
@@ -12,6 +12,8 @@ description = 'Spring Data GemFire'
|
||||
group = 'org.springframework.data'
|
||||
|
||||
repositories {
|
||||
//mavenLocal();
|
||||
//maven { url "http://nexus.gemstone.com:8081/nexus/content/repositories/snapshots" }
|
||||
maven { url "http://dist.gemstone.com.s3.amazonaws.com/maven/release"}
|
||||
maven { url "http://repo.spring.io/libs-snapshot" }
|
||||
maven { url "http://repo.spring.io/plugins-release"}
|
||||
@@ -71,8 +73,9 @@ dependencies {
|
||||
runtime("antlr:antlr:$antlrVersion")
|
||||
|
||||
compile "org.aspectj:aspectjweaver:$aspectjVersion"
|
||||
compile "org.codehaus.jackson:jackson-core-asl:$jacksonVersion"
|
||||
compile "org.codehaus.jackson:jackson-mapper-asl:$jacksonVersion"
|
||||
compile "com.fasterxml.jackson.core:jackson-core:$jacksonVersion"
|
||||
compile "com.fasterxml.jackson.core:jackson-annotations:$jacksonVersion"
|
||||
compile "com.fasterxml.jackson.core:jackson-databind:$jacksonVersion"
|
||||
compile "org.slf4j:slf4j-api:$slf4jVersion"
|
||||
compile "org.slf4j:jcl-over-slf4j:$slf4jVersion"
|
||||
|
||||
@@ -250,7 +253,7 @@ task wrapper(type: Wrapper) {
|
||||
|
||||
doLast() {
|
||||
def gradleOpts = "-XX:MaxPermSize=1024m -Xms256m -Xmx1024m"
|
||||
def gradleBatOpts = "$gradleOpts -XX:MaxHeapSize=256m"
|
||||
def gradleBatOpts = "$gradleOpts -XX:MaxHeapSize=1024m"
|
||||
File wrapperFile = file("gradlew")
|
||||
wrapperFile.text = wrapperFile.text.replace("DEFAULT_JVM_OPTS=",
|
||||
"GRADLE_OPTS=\"$gradleOpts \$GRADLE_OPTS\"\nDEFAULT_JVM_OPTS=")
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
antlrVersion=2.7.7
|
||||
aspectjVersion=1.7.4
|
||||
gemfire.range="[6.5, 8.0)"
|
||||
gemfireVersion=7.0.2
|
||||
#gemfireVersion=7.5.Beta-SNAPSHOT
|
||||
gemfireVersion=7.5
|
||||
hamcrestVersion=1.3
|
||||
jacksonVersion=1.9.12
|
||||
jacksonVersion=2.4.1
|
||||
junitVersion=4.11
|
||||
log4jVersion=1.2.17
|
||||
mockitoVersion=1.9.5
|
||||
|
||||
@@ -29,7 +29,8 @@ import com.gemstone.gemfire.cache.Region;
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author John Blum
|
||||
*
|
||||
* @see org.springframework.cache.Cache
|
||||
* @see com.gemstone.gemfire.cache.Region
|
||||
*/
|
||||
public class GemfireCache implements Cache {
|
||||
|
||||
@@ -41,7 +42,7 @@ public class GemfireCache implements Cache {
|
||||
*
|
||||
* @param region backing GemFire region
|
||||
*/
|
||||
public GemfireCache(Region<?, ?> region) {
|
||||
public GemfireCache(final Region<?, ?> region) {
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
@@ -57,22 +58,22 @@ public class GemfireCache implements Cache {
|
||||
region.clear();
|
||||
}
|
||||
|
||||
public void evict(Object key) {
|
||||
public void evict(final Object key) {
|
||||
region.destroy(key);
|
||||
}
|
||||
|
||||
public ValueWrapper get(Object key) {
|
||||
public ValueWrapper get(final Object key) {
|
||||
Object value = region.get(key);
|
||||
|
||||
return (value == null ? null : new SimpleValueWrapper(value));
|
||||
}
|
||||
|
||||
public <T> T get(final Object key, final Class<T> type) {
|
||||
return type.cast(region.get(key));
|
||||
}
|
||||
public <T> T get(final Object key, final Class<T> type) {
|
||||
return type.cast(region.get(key));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void put(Object key, Object value) {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void put(final Object key, final Object value) {
|
||||
region.put(key, value);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
* 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.support;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -25,10 +26,10 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
import org.springframework.data.gemfire.GemfireTemplate;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
import com.gemstone.gemfire.cache.query.SelectResults;
|
||||
import com.gemstone.gemfire.cache.query.internal.ResultsBag;
|
||||
@@ -37,45 +38,53 @@ import com.gemstone.gemfire.pdx.PdxInstance;
|
||||
|
||||
/**
|
||||
* @author David Turanski
|
||||
*
|
||||
*/
|
||||
@Aspect
|
||||
@SuppressWarnings("unused")
|
||||
public class JSONRegionAdvice {
|
||||
private static Log log = LogFactory.getLog(JSONRegionAdvice.class);
|
||||
private List<String> includedRegions;
|
||||
|
||||
private boolean convertReturnedCollections = true;
|
||||
private boolean prettyPrint = false;
|
||||
|
||||
/**
|
||||
* Sets names of regions to be included for JSON conversion. By default, all regions will be included
|
||||
* @param regionNames a List of region names to include
|
||||
*/
|
||||
public void setIncludedRegionNames(List<String> regionNames) {
|
||||
this.includedRegions = regionNames;
|
||||
}
|
||||
private List<String> includedRegions;
|
||||
|
||||
protected final Log log = LogFactory.getLog(JSONRegionAdvice.class);
|
||||
|
||||
/**
|
||||
* Sets regions to be included for JSON conversion. By default, all regions will be included
|
||||
* @param regions a List of region names to include
|
||||
*/
|
||||
public void setIncludedRegions(List<Region<?,?>> regions) {
|
||||
this.includedRegions = new ArrayList<String>();
|
||||
for (Region<?,?> region: regions) {
|
||||
includedRegions.add(region.getName());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Flag to convert collections returned from cache from @{link PdxInstance} to JSON String. If the returned
|
||||
* collections are very large, overhead will be incurred to covert all the values from from
|
||||
* Region.getAll() and Region.values()
|
||||
* Flag to convert collections returned from cache from @{link PdxInstance} to JSON String. If the returned
|
||||
* collections are very large, overhead will be incurred to covert all the values from from
|
||||
* Region.getAll() and Region.values()
|
||||
*
|
||||
* @param convertReturnedCollections true by default
|
||||
*/
|
||||
public void setConvertReturnedCollections(boolean convertReturnedCollections) {
|
||||
this.convertReturnedCollections = convertReturnedCollections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets regions to be included for JSON conversion. By default, all regions will be included
|
||||
*
|
||||
* @param regions a List of region names to include
|
||||
*/
|
||||
public void setIncludedRegions(List<Region<?, ?>> regions) {
|
||||
this.includedRegions = new ArrayList<String>();
|
||||
for (Region<?, ?> region : regions) {
|
||||
includedRegions.add(region.getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets names of regions to be included for JSON conversion. By default, all regions will be included
|
||||
*
|
||||
* @param regionNames a List of region names to include
|
||||
*/
|
||||
public void setIncludedRegionNames(List<String> regionNames) {
|
||||
this.includedRegions = regionNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flag to print JSON Strings with proper indentation, etc.
|
||||
*
|
||||
* @param prettyPrint false be default
|
||||
*/
|
||||
public void setPrettyPrint(boolean prettyPrint) {
|
||||
@@ -83,35 +92,38 @@ public class JSONRegionAdvice {
|
||||
}
|
||||
|
||||
@Around("execution(* com.gemstone.gemfire.cache.Region.put(..)) || "
|
||||
+ "execution(* com.gemstone.gemfire.cache.Region.create(..)) ||"
|
||||
+ "execution(* com.gemstone.gemfire.cache.Region.putIfAbsent(..)) ||"
|
||||
+ "execution(* com.gemstone.gemfire.cache.Region.replace(..))")
|
||||
+ "execution(* com.gemstone.gemfire.cache.Region.create(..)) ||"
|
||||
+ "execution(* com.gemstone.gemfire.cache.Region.putIfAbsent(..)) ||"
|
||||
+ "execution(* com.gemstone.gemfire.cache.Region.replace(..))")
|
||||
public Object put(ProceedingJoinPoint pjp) {
|
||||
|
||||
boolean JSONRegion = isIncludedSONRegion(pjp.getTarget());
|
||||
Object retVal = null;
|
||||
Object returnValue = null;
|
||||
|
||||
try {
|
||||
if (JSONRegion) {
|
||||
Object[] newArgs = Arrays.copyOf(pjp.getArgs(), pjp.getArgs().length);
|
||||
Object val = newArgs[1];
|
||||
newArgs[1] = convertArgumentToPdxInstance(val);
|
||||
retVal = pjp.proceed(newArgs);
|
||||
log.debug("converting " + retVal + " to JSON string");
|
||||
retVal = convertPdxInstanceToJSONString(retVal);
|
||||
} else {
|
||||
retVal = pjp.proceed();
|
||||
returnValue = pjp.proceed(newArgs);
|
||||
log.debug("converting " + returnValue + " to JSON string");
|
||||
returnValue = convertPdxInstanceToJSONString(returnValue);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
else {
|
||||
returnValue = pjp.proceed();
|
||||
}
|
||||
}
|
||||
catch (Throwable t) {
|
||||
handleThrowable(t);
|
||||
}
|
||||
return retVal;
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
@Around("execution(* com.gemstone.gemfire.cache.Region.putAll(..))")
|
||||
public Object putAll(ProceedingJoinPoint pjp) {
|
||||
boolean JSONRegion = isIncludedSONRegion(pjp.getTarget());
|
||||
Object returnValue = null;
|
||||
|
||||
Object retVal = null;
|
||||
try {
|
||||
if (JSONRegion) {
|
||||
Object[] newArgs = Arrays.copyOf(pjp.getArgs(), pjp.getArgs().length);
|
||||
@@ -121,52 +133,64 @@ public class JSONRegionAdvice {
|
||||
newArg.put(entry.getKey(), convertArgumentToPdxInstance(entry.getValue()));
|
||||
}
|
||||
newArgs[0] = newArg;
|
||||
retVal = pjp.proceed(newArgs);
|
||||
} else {
|
||||
retVal = pjp.proceed();
|
||||
returnValue = pjp.proceed(newArgs);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
else {
|
||||
returnValue = pjp.proceed();
|
||||
}
|
||||
}
|
||||
catch (Throwable t) {
|
||||
handleThrowable(t);
|
||||
}
|
||||
return retVal;
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
@Around("execution(* com.gemstone.gemfire.cache.Region.get(..)) "
|
||||
+ "|| execution(* com.gemstone.gemfire.cache.Region.selectValue(..))"
|
||||
+ "|| execution(* com.gemstone.gemfire.cache.Region.remove(..))")
|
||||
+ "|| execution(* com.gemstone.gemfire.cache.Region.selectValue(..))"
|
||||
+ "|| execution(* com.gemstone.gemfire.cache.Region.remove(..))")
|
||||
public Object get(ProceedingJoinPoint pjp) {
|
||||
Object retVal = null;
|
||||
Object returnValue = null;
|
||||
|
||||
try {
|
||||
if (isIncludedSONRegion(pjp.getTarget())) {
|
||||
retVal = pjp.proceed();
|
||||
log.debug("converting " + retVal + " to JSON string");
|
||||
retVal = convertPdxInstanceToJSONString(retVal);
|
||||
} else {
|
||||
retVal = pjp.proceed();
|
||||
returnValue = pjp.proceed();
|
||||
log.debug("converting " + returnValue + " to JSON string");
|
||||
returnValue = convertPdxInstanceToJSONString(returnValue);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
else {
|
||||
returnValue = pjp.proceed();
|
||||
}
|
||||
}
|
||||
catch (Throwable t) {
|
||||
handleThrowable(t);
|
||||
}
|
||||
return retVal;
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Around("execution(* com.gemstone.gemfire.cache.Region.getAll(..))")
|
||||
public Map<Object, Object> getAll(ProceedingJoinPoint pjp) {
|
||||
Map<Object, Object> result = null;
|
||||
|
||||
try {
|
||||
Map<Object, Object> retVal = (Map<Object, Object>) pjp.proceed();
|
||||
if (!convertReturnedCollections || CollectionUtils.isEmpty(retVal) || !isIncludedSONRegion(pjp.getTarget())) {
|
||||
if (!convertReturnedCollections || CollectionUtils.isEmpty(retVal) || !isIncludedSONRegion(
|
||||
pjp.getTarget())) {
|
||||
result = retVal;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
result = new HashMap<Object, Object>();
|
||||
for (Entry<Object, Object> entry : retVal.entrySet()) {
|
||||
result.put(entry.getKey(), convertPdxInstanceToJSONString(entry.getValue()));
|
||||
}
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
}
|
||||
catch (Throwable t) {
|
||||
handleThrowable(t);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -174,89 +198,107 @@ public class JSONRegionAdvice {
|
||||
@Around("execution(* com.gemstone.gemfire.cache.Region.values(..))")
|
||||
public Collection<Object> values(ProceedingJoinPoint pjp) {
|
||||
Collection<Object> result = null;
|
||||
|
||||
try {
|
||||
Collection<Object> retVal = (Collection<Object>) pjp.proceed();
|
||||
if (!convertReturnedCollections || CollectionUtils.isEmpty(retVal) || !isIncludedSONRegion(pjp.getTarget())) {
|
||||
if (!convertReturnedCollections || CollectionUtils.isEmpty(retVal) || !isIncludedSONRegion(
|
||||
pjp.getTarget())) {
|
||||
result = retVal;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
result = new ArrayList<Object>();
|
||||
for (Object obj : retVal) {
|
||||
result.add(convertArgumentToPdxInstance(obj));
|
||||
}
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
}
|
||||
catch (Throwable t) {
|
||||
handleThrowable(t);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Around("execution(* org.springframework.data.gemfire.GemfireOperations.find(..)) " +
|
||||
"|| execution(* org.springframework.data.gemfire.GemfireOperations.findUnique(..)) " +
|
||||
"|| execution(* org.springframework.data.gemfire.GemfireOperations.query(..))")
|
||||
|
||||
@Around("execution(* org.springframework.data.gemfire.GemfireOperations.find(..)) " +
|
||||
"|| execution(* org.springframework.data.gemfire.GemfireOperations.findUnique(..)) " +
|
||||
"|| execution(* org.springframework.data.gemfire.GemfireOperations.query(..))")
|
||||
public Object templateQuery(ProceedingJoinPoint pjp) {
|
||||
GemfireTemplate template = (GemfireTemplate) pjp.getTarget();
|
||||
boolean jsonRegion = isIncludedSONRegion(template.getRegion());
|
||||
Object retVal = null;
|
||||
Object returnValue = null;
|
||||
|
||||
try {
|
||||
if (jsonRegion) {
|
||||
retVal = pjp.proceed();
|
||||
if (retVal instanceof SelectResults && convertReturnedCollections ) {
|
||||
returnValue = pjp.proceed();
|
||||
if (returnValue instanceof SelectResults && convertReturnedCollections) {
|
||||
ResultsBag resultsBag = new ResultsBag();
|
||||
for (Object obj: (SelectResults<?>)retVal) {
|
||||
for (Object obj : (SelectResults<?>) returnValue) {
|
||||
resultsBag.add(convertPdxInstanceToJSONString(obj));
|
||||
}
|
||||
retVal = resultsBag;
|
||||
} else {
|
||||
retVal = convertPdxInstanceToJSONString(retVal);
|
||||
returnValue = resultsBag;
|
||||
}
|
||||
else {
|
||||
returnValue = convertPdxInstanceToJSONString(returnValue);
|
||||
}
|
||||
} else {
|
||||
retVal = pjp.proceed();
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
else {
|
||||
returnValue = pjp.proceed();
|
||||
}
|
||||
}
|
||||
catch (Throwable t) {
|
||||
handleThrowable(t);
|
||||
}
|
||||
return retVal;
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
private PdxInstance convertArgumentToPdxInstance(Object value) {
|
||||
PdxInstance val = null;
|
||||
PdxInstance pdx = null;
|
||||
|
||||
if (value instanceof PdxInstance) {
|
||||
val = (PdxInstance) value;
|
||||
} else if (value instanceof String) {
|
||||
val = JSONFormatter.fromJSON((String) value);
|
||||
} else {
|
||||
pdx = (PdxInstance) value;
|
||||
}
|
||||
else if (value instanceof String) {
|
||||
pdx = JSONFormatter.fromJSON((String) value);
|
||||
}
|
||||
else {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
try {
|
||||
String json = mapper.writeValueAsString(value);
|
||||
val = JSONFormatter.fromJSON(json);
|
||||
} catch (Throwable t) {
|
||||
pdx = JSONFormatter.fromJSON(json);
|
||||
}
|
||||
catch (Throwable t) {
|
||||
handleThrowable(t);
|
||||
}
|
||||
}
|
||||
return val;
|
||||
|
||||
return pdx;
|
||||
}
|
||||
|
||||
private boolean isIncludedSONRegion(Object target) {
|
||||
Region<?, ?> region = (Region<?, ?>) target;
|
||||
boolean result = false;
|
||||
|
||||
if (includedRegions == null || includedRegions.contains(region.getName())) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(region.getName() + " is included for JSON conversion");
|
||||
}
|
||||
result = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private Object convertPdxInstanceToJSONString(Object retVal) {
|
||||
Object result = retVal;
|
||||
if (retVal != null && retVal instanceof PdxInstance) {
|
||||
result = JSONFormatter.toJSON((PdxInstance) retVal);
|
||||
private Object convertPdxInstanceToJSONString(Object returnValue) {
|
||||
Object result = returnValue;
|
||||
|
||||
if (returnValue != null && returnValue instanceof PdxInstance) {
|
||||
result = JSONFormatter.toJSON((PdxInstance) returnValue);
|
||||
if (!prettyPrint) {
|
||||
result = flattenString(result);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -265,15 +307,18 @@ public class JSONRegionAdvice {
|
||||
String json = (String) result;
|
||||
return json.replaceAll("\\s*", "");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void handleThrowable(Throwable t) {
|
||||
if (t instanceof RuntimeException) {
|
||||
throw (RuntimeException) t;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
throw new RuntimeException(t);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.springframework.util.Assert;
|
||||
|
||||
import com.gemstone.gemfire.cache.util.Gateway;
|
||||
import com.gemstone.gemfire.cache.wan.GatewayEventFilter;
|
||||
import com.gemstone.gemfire.cache.wan.GatewayEventSubstitutionFilter;
|
||||
import com.gemstone.gemfire.cache.wan.GatewaySender;
|
||||
import com.gemstone.gemfire.cache.wan.GatewayTransportFilter;
|
||||
|
||||
@@ -23,8 +24,8 @@ public class GatewaySenderWrapper implements GatewaySender {
|
||||
|
||||
public GatewaySenderWrapper(final GatewaySender gatewaySender) {
|
||||
Assert.notNull(gatewaySender, "The target Gateway Sender must not be null.");
|
||||
this.delegate = gatewaySender;
|
||||
}
|
||||
this.delegate = gatewaySender;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
@@ -126,7 +127,11 @@ public class GatewaySenderWrapper implements GatewaySender {
|
||||
return delegate.getGatewayEventFilters();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GatewayEventSubstitutionFilter getGatewayEventSubstitutionFilter() {
|
||||
return delegate.getGatewayEventSubstitutionFilter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GatewayTransportFilter> getGatewayTransportFilters() {
|
||||
return delegate.getGatewayTransportFilters();
|
||||
}
|
||||
@@ -160,6 +165,11 @@ public class GatewaySenderWrapper implements GatewaySender {
|
||||
this.manualStart = manualStart;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxParallelismForReplicatedRegion() {
|
||||
return delegate.getMaxParallelismForReplicatedRegion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.delegate.toString();
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.data.gemfire;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -33,9 +34,12 @@ public class DataPolicyConverterTest {
|
||||
protected int getDataPolicyEnumerationSize() {
|
||||
for (byte ordinal = 0; ordinal < Byte.MAX_VALUE; ordinal++) {
|
||||
try {
|
||||
DataPolicy.fromOrdinal(ordinal);
|
||||
assertNotNull(DataPolicy.fromOrdinal(ordinal));
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (Exception ignore) {
|
||||
return ordinal;
|
||||
}
|
||||
catch (Error ignore) {
|
||||
return ordinal;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,111 +19,106 @@ package org.springframework.data.gemfire;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
|
||||
/**
|
||||
* Utility for forking Java processes.
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author John Blum
|
||||
*/
|
||||
public class ForkUtil {
|
||||
private static OutputStream os;
|
||||
private static String TEMP_DIR = System.getProperty("java.io.tmpdir");
|
||||
|
||||
|
||||
|
||||
private static OutputStream cloneJVM(String arguments) {
|
||||
String cp = System.getProperty("java.class.path");
|
||||
String home = System.getProperty("java.home");
|
||||
private static OutputStream processStandardInStream;
|
||||
|
||||
Process proc = null;
|
||||
String sp = System.getProperty("file.separator");
|
||||
String java = home + sp + "bin" + sp + "java";
|
||||
|
||||
private static String JAVA_CLASSPATH = System.getProperty("java.class.path");
|
||||
private static String JAVA_HOME = System.getProperty("java.home");
|
||||
private static String JAVA_EXE = JAVA_HOME.concat(File.separator).concat("bin").concat(File.separator).concat("java");
|
||||
private static String TEMP_DIRECTORY = System.getProperty("java.io.tmpdir");
|
||||
|
||||
private static OutputStream cloneJVM(final String arguments) {
|
||||
String[] args = arguments.split("\\s+");
|
||||
String[] cmd = new String[args.length + 3];
|
||||
cmd[0]=java;
|
||||
cmd[1]="-cp";
|
||||
cmd[2]=cp;
|
||||
for (int i=3; i< cmd.length; i++) {
|
||||
cmd[i] = args[i-3];
|
||||
}
|
||||
|
||||
|
||||
List<String> command = new ArrayList<String>(args.length + 5);
|
||||
|
||||
command.add(JAVA_EXE);
|
||||
command.add("-classpath");
|
||||
command.add(JAVA_CLASSPATH);
|
||||
//command.add("-Xms256m");
|
||||
//command.add("-Xmx512m");
|
||||
command.addAll(Arrays.asList(args));
|
||||
|
||||
Process javaProcess;
|
||||
|
||||
try {
|
||||
proc = Runtime.getRuntime().exec(cmd);
|
||||
} catch (IOException ioe) {
|
||||
System.out.println("[FORK-ERROR] " + ioe.getMessage());
|
||||
throw new IllegalStateException("Cannot start command " + StringUtils.arrayToDelimitedString(cmd," "), ioe);
|
||||
javaProcess = Runtime.getRuntime().exec(command.toArray(new String[command.size()]));
|
||||
}
|
||||
catch (IOException e) {
|
||||
System.out.println("[FORK-ERROR] " + e.getMessage());
|
||||
throw new IllegalStateException(String.format("Cannot start command %1$s",
|
||||
StringUtils.arrayToDelimitedString(command.toArray(), " ")), e);
|
||||
}
|
||||
|
||||
System.out.println("Started fork from command\n" + StringUtils.arrayToDelimitedString(cmd," "));
|
||||
final Process p = proc;
|
||||
System.out.println("Started fork from command: \n" + StringUtils.arrayToDelimitedString(command.toArray()," "));
|
||||
|
||||
final BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
||||
final BufferedReader er = new BufferedReader(new InputStreamReader(p.getErrorStream()));
|
||||
final AtomicBoolean run = new AtomicBoolean(true);
|
||||
final AtomicBoolean runCondition = new AtomicBoolean(true);
|
||||
final Process p = javaProcess;
|
||||
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
String line = null;
|
||||
do {
|
||||
while ((line = er.readLine()) != null) {
|
||||
System.out.println("[FORK-ERROR] " + line);
|
||||
}
|
||||
Thread.sleep(200);
|
||||
} while (run.get());
|
||||
} catch (Exception ex) {
|
||||
// ignore and exit
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
|
||||
|
||||
new Thread(new Runnable() {
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
String line = null;
|
||||
do {
|
||||
while ((line = br.readLine()) != null) {
|
||||
System.out.println("[FORK] " + line);
|
||||
}
|
||||
Thread.sleep(200);
|
||||
} while (run.get());
|
||||
} catch (Exception ex) {
|
||||
// ignore and exit
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
new Thread(newProcessStreamReaderRunnable(runCondition, p.getErrorStream(), "[FORK-ERROR]")).start();
|
||||
new Thread(newProcessStreamReaderRunnable(runCondition, p.getInputStream(), "[FORK]")).start();
|
||||
|
||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
System.out.println("Stopping fork...");
|
||||
run.set(false);
|
||||
os = null;
|
||||
if (p != null)
|
||||
p.destroy();
|
||||
runCondition.set(false);
|
||||
processStandardInStream = null;
|
||||
|
||||
try {
|
||||
p.destroy();
|
||||
p.waitFor();
|
||||
} catch (InterruptedException e) {
|
||||
// ignore
|
||||
}
|
||||
catch (InterruptedException ignore) {
|
||||
}
|
||||
|
||||
System.out.println("Fork stopped");
|
||||
}
|
||||
});
|
||||
|
||||
os = proc.getOutputStream();
|
||||
return os;
|
||||
processStandardInStream = javaProcess.getOutputStream();
|
||||
|
||||
return processStandardInStream;
|
||||
}
|
||||
|
||||
|
||||
protected static Runnable newProcessStreamReaderRunnable(final AtomicBoolean runCondition, final InputStream processStream, final String label) {
|
||||
final BufferedReader processStreamReader = new BufferedReader(new InputStreamReader(processStream));
|
||||
|
||||
return new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
do {
|
||||
for (String line = "Reading..."; line != null; line = processStreamReader.readLine()) {
|
||||
System.out.printf("%1$s %2$s%n ", label, line);
|
||||
}
|
||||
|
||||
Thread.sleep(200);
|
||||
}
|
||||
while (runCondition.get());
|
||||
}
|
||||
catch (Exception ignore) {
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static OutputStream cacheServer(Class<?> clazz) {
|
||||
return startCacheServer(clazz.getName());
|
||||
}
|
||||
@@ -162,25 +157,27 @@ public class ForkUtil {
|
||||
|
||||
public static void sendSignal() {
|
||||
try {
|
||||
os.write("\n".getBytes());
|
||||
os.flush();
|
||||
} catch (IOException ex) {
|
||||
processStandardInStream.write("\n".getBytes());
|
||||
processStandardInStream.flush();
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new IllegalStateException("Cannot communicate with forked VM", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean deleteControlFile(String name) {
|
||||
String path = TEMP_DIR + File.separator + name;
|
||||
String path = TEMP_DIRECTORY + File.separator + name;
|
||||
return new File(path).delete();
|
||||
}
|
||||
|
||||
public static boolean createControlFile(String name) throws IOException {
|
||||
String path = TEMP_DIR + File.separator + name;
|
||||
String path = TEMP_DIRECTORY + File.separator + name;
|
||||
return new File(path).createNewFile();
|
||||
}
|
||||
|
||||
public static boolean controlFileExists(String name) {
|
||||
String path = TEMP_DIR + File.separator + name;
|
||||
String path = TEMP_DIRECTORY + File.separator + name;
|
||||
return new File(path).exists();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ public class ClientRegionNamespaceTest {
|
||||
Region region = context.getBean("persistent", Region.class);
|
||||
RegionAttributes attrs = region.getAttributes();
|
||||
assertEquals("diskStore", attrs.getDiskStoreName());
|
||||
assertEquals(1, attrs.getDiskDirSizes()[0]);
|
||||
assertEquals(10, attrs.getDiskDirSizes()[0]);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
* 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.function.execution;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -17,12 +18,10 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
@@ -42,132 +41,139 @@ import com.gemstone.gemfire.cache.Region;
|
||||
|
||||
/**
|
||||
* @author David Turanski
|
||||
*
|
||||
* @author John Blum
|
||||
*/
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
@SuppressWarnings("unused")
|
||||
public class FunctionIntegrationTests {
|
||||
@Resource(name="test-region")
|
||||
Region<String,Integer> region;
|
||||
|
||||
|
||||
@Resource(name = "test-region")
|
||||
private Region<String, Integer> region;
|
||||
|
||||
@BeforeClass
|
||||
public static void startUp() throws Exception {
|
||||
ForkUtil.startCacheServer(SpringCacheServerProcess.class.getName() +
|
||||
" /org/springframework/data/gemfire/function/execution/FunctionIntegrationTests-server-context.xml");
|
||||
public static void startup() throws Exception {
|
||||
ForkUtil.startCacheServer(SpringCacheServerProcess.class.getName() +
|
||||
" /org/springframework/data/gemfire/function/execution/FunctionIntegrationTests-server-context.xml");
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanUp() {
|
||||
public static void shutdown() {
|
||||
ForkUtil.sendSignal();
|
||||
}
|
||||
|
||||
@Before
|
||||
|
||||
@Before
|
||||
public void initializeRegion() {
|
||||
region.put("one", 1);
|
||||
region.put("two", 2);
|
||||
region.put("three",3);
|
||||
region.put("three", 3);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
//@Ignore
|
||||
public void testVoidReturnType() {
|
||||
GemfireOnRegionOperations template = new GemfireOnRegionFunctionTemplate(region);
|
||||
//Either way should work but the first one traps an exception if there is a result.
|
||||
// Should work either way but the first invocation traps an exception if there is a result.
|
||||
template.execute("noResult");
|
||||
template.executeWithNoResult("noResult");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnRegionFunctionExecution() {
|
||||
|
||||
GemfireOnRegionOperations template = new GemfireOnRegionFunctionTemplate(region);
|
||||
|
||||
Iterable<Integer> results;
|
||||
results = template.execute("oneArg","two");
|
||||
assertEquals(2, results.iterator().next().intValue());
|
||||
|
||||
Set<String> filter = new HashSet<String>();
|
||||
filter.add("one");
|
||||
results = template.execute("oneArg",filter,"two");
|
||||
assertFalse(results.iterator().hasNext());
|
||||
|
||||
results = template.execute("twoArg","two","three");
|
||||
assertEquals(5, results.iterator().next().intValue());
|
||||
|
||||
Integer result = template.executeAndExtract("twoArg","two","three");
|
||||
assertEquals(5,result.intValue());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
//@Ignore
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testCollectionReturnTypes() {
|
||||
GemfireOnRegionOperations template = new GemfireOnRegionFunctionTemplate(region);
|
||||
|
||||
|
||||
Object result = template.executeAndExtract("getMapWithNoArgs");
|
||||
assertTrue(result instanceof Map);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String,Integer> map = (Map<String,Integer>)result;
|
||||
assertEquals(1,map.get("one").intValue());
|
||||
assertEquals(2,map.get("two").intValue());
|
||||
assertEquals(3,map.get("three").intValue());
|
||||
|
||||
result = template.executeAndExtract("collections",Arrays.asList(new Integer[]{1,2,3,4,5}));
|
||||
assertTrue(result.getClass().getName(),result instanceof List);
|
||||
|
||||
List<?> list = (List<?>)result;
|
||||
|
||||
assertTrue(result.getClass().getName(), result instanceof Map);
|
||||
|
||||
Map<String, Integer> map = (Map<String, Integer>) result;
|
||||
|
||||
assertEquals(1, map.get("one").intValue());
|
||||
assertEquals(2, map.get("two").intValue());
|
||||
assertEquals(3, map.get("three").intValue());
|
||||
|
||||
result = template.executeAndExtract("collections", Arrays.asList(1, 2, 3, 4, 5));
|
||||
|
||||
assertTrue(result.getClass().getName(), result instanceof List);
|
||||
|
||||
List<?> list = (List<?>) result;
|
||||
|
||||
assertFalse(list.isEmpty());
|
||||
assertEquals(5, list.size());
|
||||
for (int i=1; i<= list.size(); i++) {
|
||||
assertEquals(i,list.get(i-1));
|
||||
|
||||
int expectedNumber = 1;
|
||||
|
||||
for (Object actualNumber : list) {
|
||||
assertEquals(expectedNumber++, actualNumber);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@Test
|
||||
public void testArrayReturnTypes() {
|
||||
GemfireOnRegionOperations template = new GemfireOnRegionFunctionTemplate(region);
|
||||
Object result = template.executeAndExtract("arrays",new int[]{1,2,3,4,5});
|
||||
assertTrue(result.getClass().getName(),result instanceof int[]);
|
||||
Object result = new GemfireOnRegionFunctionTemplate(region).executeAndExtract("arrays",
|
||||
new int[] { 1, 2, 3, 4, 5 });
|
||||
assertTrue(result.getClass().getName(), result instanceof int[]);
|
||||
assertEquals(5, ((int[]) result).length);
|
||||
}
|
||||
|
||||
@Test
|
||||
//@Ignore
|
||||
public void testOnRegionFunctionExecution() {
|
||||
GemfireOnRegionOperations template = new GemfireOnRegionFunctionTemplate(region);
|
||||
|
||||
assertEquals(2, template.<Integer>execute("oneArg", "two").iterator().next().intValue());
|
||||
assertFalse(template.<Integer>execute("oneArg", Collections.singleton("one"), "two").iterator().hasNext());
|
||||
assertEquals(5, template.<Integer>execute("twoArg", "two", "three").iterator().next().intValue());
|
||||
assertEquals(5, template.<Integer>executeAndExtract("twoArg", "two", "three").intValue());
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* This gets wrapped in a GemFire Function and registered on the forked server.
|
||||
*/
|
||||
@Component
|
||||
public static class Foo {
|
||||
@SuppressWarnings("unused")
|
||||
public static class Foo {
|
||||
|
||||
@GemfireFunction(id="oneArg")
|
||||
public Integer oneArg(String key, @RegionData Map<String,Integer> dataSet) {
|
||||
return dataSet.get(key);
|
||||
@GemfireFunction(id = "oneArg")
|
||||
public Integer oneArg(String key, @RegionData Map<String, Integer> region) {
|
||||
return region.get(key);
|
||||
}
|
||||
|
||||
@GemfireFunction(id="twoArg")
|
||||
public Integer twoArg(String akey, String bkey, @RegionData Map<String,Integer> dataSet) {
|
||||
if (dataSet.get(akey) != null && dataSet.get(bkey) != null) {
|
||||
return dataSet.get(akey) + dataSet.get(bkey);
|
||||
|
||||
@GemfireFunction(id = "twoArg")
|
||||
public Integer twoArg(String keyOne, String keyTwo, @RegionData Map<String, Integer> region) {
|
||||
if (region.get(keyOne) != null && region.get(keyTwo) != null) {
|
||||
return region.get(keyOne) + region.get(keyTwo);
|
||||
}
|
||||
return null;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@GemfireFunction(id="collections")
|
||||
|
||||
@GemfireFunction(id = "collections")
|
||||
public List<Integer> collections(List<Integer> args) {
|
||||
return args;
|
||||
}
|
||||
|
||||
@GemfireFunction(id="getMapWithNoArgs")
|
||||
public Map<String, Integer> getMapWithNoArgs(@RegionData Map<String,Integer> dataSet) {
|
||||
if (dataSet.size() == 0) {
|
||||
@GemfireFunction(id = "getMapWithNoArgs")
|
||||
public Map<String, Integer> getMapWithNoArgs(@RegionData Map<String, Integer> region) {
|
||||
if (region.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
return new HashMap<String, Integer>(dataSet);
|
||||
|
||||
return new HashMap<String, Integer>(region);
|
||||
}
|
||||
|
||||
@GemfireFunction(id = "arrays")
|
||||
// TODO causes OOME!
|
||||
//@GemfireFunction(id = "arrays", batchSize = 2)
|
||||
public int[] collections(int[] args) {
|
||||
return args;
|
||||
}
|
||||
|
||||
@GemfireFunction
|
||||
public void noResult() {
|
||||
}
|
||||
|
||||
@GemfireFunction(id="arrays",batchSize=2)
|
||||
public int[] collections(int[] args) {
|
||||
return args;
|
||||
}
|
||||
|
||||
@GemfireFunction
|
||||
public void noResult() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,9 +31,10 @@ import org.springframework.cache.Cache;
|
||||
*/
|
||||
public abstract class AbstractNativeCacheTest<T> {
|
||||
|
||||
protected static final String CACHE_NAME = "testCache";
|
||||
|
||||
private T nativeCache;
|
||||
private Cache cache;
|
||||
protected final static String CACHE_NAME = "testCache";
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@@ -42,12 +43,10 @@ public abstract class AbstractNativeCacheTest<T> {
|
||||
cache.clear();
|
||||
}
|
||||
|
||||
|
||||
protected abstract T createNativeCache() throws Exception;
|
||||
|
||||
protected abstract Cache createCache(T nativeCache);
|
||||
|
||||
|
||||
@Test
|
||||
public void testCacheName() throws Exception {
|
||||
assertEquals(CACHE_NAME, cache.getName());
|
||||
@@ -60,7 +59,6 @@ public abstract class AbstractNativeCacheTest<T> {
|
||||
|
||||
@Test
|
||||
public void testCachePut() throws Exception {
|
||||
|
||||
Object key = "enescu";
|
||||
Object value = "george";
|
||||
|
||||
@@ -80,4 +78,19 @@ public abstract class AbstractNativeCacheTest<T> {
|
||||
assertNull(cache.get("enescu"));
|
||||
}
|
||||
|
||||
}
|
||||
@Test
|
||||
public void testCacheGetForClassType() {
|
||||
cache.put("one", Boolean.TRUE);
|
||||
cache.put("two", 'X');
|
||||
cache.put("three", 101);
|
||||
cache.put("four", Math.PI);
|
||||
cache.put("five", "TEST");
|
||||
|
||||
assertEquals(Boolean.TRUE, cache.get("one", Boolean.class));
|
||||
assertEquals(new Character('X'), cache.get("two", Character.class));
|
||||
assertEquals(new Integer(101), cache.get("three", Integer.class));
|
||||
assertEquals(new Double(Math.PI), cache.get("four", Double.class));
|
||||
assertEquals("TEST", cache.get("five", String.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,7 +26,10 @@ import com.gemstone.gemfire.distributed.DistributedSystem;
|
||||
|
||||
/**
|
||||
* @author Costin Leau
|
||||
* @author John Blum
|
||||
*/
|
||||
// TODO avoid using actual GemFire Cache and Region instances, thereby creating a distributed system, for this test!
|
||||
// TODO Use Mocks!
|
||||
public class GemfireCacheTest extends AbstractNativeCacheTest<Region<Object, Object>> {
|
||||
|
||||
@Override
|
||||
@@ -38,21 +41,25 @@ public class GemfireCacheTest extends AbstractNativeCacheTest<Region<Object, Obj
|
||||
@SuppressWarnings({"deprecation", "unchecked" })
|
||||
protected Region<Object, Object> createNativeCache() throws Exception {
|
||||
com.gemstone.gemfire.cache.Cache instance = null;
|
||||
|
||||
try {
|
||||
instance = CacheFactory.getAnyInstance();
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
catch (Exception ignore) {
|
||||
}
|
||||
|
||||
if (instance == null) {
|
||||
DistributedSystem ds = DistributedSystem.connect(new Properties());
|
||||
instance = CacheFactory.create(ds);
|
||||
}
|
||||
Region reg = instance.getRegion(CACHE_NAME);
|
||||
if (reg == null) {
|
||||
reg = instance.createRegion(CACHE_NAME, new com.gemstone.gemfire.cache.AttributesFactory().create());
|
||||
|
||||
Region region = instance.getRegion(CACHE_NAME);
|
||||
|
||||
if (region == null) {
|
||||
region = instance.createRegion(CACHE_NAME, new com.gemstone.gemfire.cache.AttributesFactory().create());
|
||||
}
|
||||
|
||||
return reg;
|
||||
return region;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
* 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.support;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -35,82 +36,90 @@ import com.gemstone.gemfire.cache.query.SelectResults;
|
||||
|
||||
/**
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
@SuppressWarnings("unchecked")
|
||||
public class JSONRegionAdviceTest {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Resource(name="someRegion")
|
||||
private Region region;
|
||||
|
||||
// TODO figure out why auto-proxying the Region for JSON support prevents the GemfireTemplate from being "auto-wired",
|
||||
// as a GemfireTemplate rather than GemfireOperations, resulting in a NoSuchBeanDefinitionException thrown by the
|
||||
// Spring container!?!?!?!?
|
||||
@Autowired
|
||||
GemfireOperations template;
|
||||
|
||||
private GemfireOperations template;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Resource(name = "jsonRegion")
|
||||
private Region jsonRegion;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
region.clear();
|
||||
public void setup() {
|
||||
jsonRegion.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPutString() {
|
||||
String json = "{\"hello\":\"world\"}";
|
||||
|
||||
region.put("key",json);
|
||||
Object result = region.put("key",json);
|
||||
assertEquals(json,result);
|
||||
|
||||
region.create("key2",json);
|
||||
|
||||
System.out.println(region.get("key"));
|
||||
assertEquals(json,region.get("key"));
|
||||
|
||||
jsonRegion.put("key", json);
|
||||
|
||||
assertEquals(json, jsonRegion.put("key", json));
|
||||
|
||||
jsonRegion.create("key2", json);
|
||||
|
||||
System.out.println(jsonRegion.get("key"));
|
||||
|
||||
assertEquals(json, jsonRegion.get("key"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testPutAll() {
|
||||
Map<String,String> map = new HashMap<String,String>();
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("key1", "{\"hello1\":\"world1\"}");
|
||||
map.put("key2", "{\"hello2\":\"world2\"}");
|
||||
region.putAll(map);
|
||||
jsonRegion.putAll(map);
|
||||
List<String> keys = Arrays.asList("key1", "key2");
|
||||
Map<String,String> results = region.getAll(keys);
|
||||
assertEquals("{\"hello1\":\"world1\"}",results.get("key1"));
|
||||
assertEquals("{\"hello2\":\"world2\"}",results.get("key2"));
|
||||
Map<String, String> results = jsonRegion.getAll(keys);
|
||||
assertEquals("{\"hello1\":\"world1\"}", results.get("key1"));
|
||||
assertEquals("{\"hello2\":\"world2\"}", results.get("key2"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testObjectToJSon() throws IOException {
|
||||
Person dave = new Person(1L,"Dave","Turanski");
|
||||
region.put("dave",dave);
|
||||
String json = (String)region.get("dave");
|
||||
assertEquals(json,"{\"id\":1,\"firstname\":\"Dave\",\"lastname\":\"Turanski\",\"address\":null}",json);
|
||||
Object result = region.put("dave",dave);
|
||||
assertEquals("{\"id\":1,\"firstname\":\"Dave\",\"lastname\":\"Turanski\",\"address\":null}",result);
|
||||
Person dave = new Person(1L, "Dave", "Turanski");
|
||||
jsonRegion.put("dave", dave);
|
||||
String json = (String) jsonRegion.get("dave");
|
||||
assertEquals(json, "{\"id\":1,\"firstname\":\"Dave\",\"lastname\":\"Turanski\",\"address\":null}", json);
|
||||
Object result = jsonRegion.put("dave", dave);
|
||||
assertEquals("{\"id\":1,\"firstname\":\"Dave\",\"lastname\":\"Turanski\",\"address\":null}", result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTemplateFindUnique() {
|
||||
Person dave = new Person(1L,"Dave","Turanski");
|
||||
region.put("dave",dave);
|
||||
String json = (String) template.findUnique("Select * from /someRegion where firstname=$1","Dave");
|
||||
assertEquals("{\"id\":1,\"firstname\":\"Dave\",\"lastname\":\"Turanski\",\"address\":null}",json);
|
||||
Person dave = new Person(1L, "Dave", "Turanski");
|
||||
jsonRegion.put("dave", dave);
|
||||
String json = (String) template.findUnique("SELECT * FROM /jsonRegion WHERE firstname=$1", "Dave");
|
||||
assertEquals("{\"id\":1,\"firstname\":\"Dave\",\"lastname\":\"Turanski\",\"address\":null}", json);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTemplateFind() {
|
||||
Person dave = new Person(1L,"Dave","Turanski");
|
||||
region.put("dave",dave);
|
||||
SelectResults<String> results = template.find("Select * from /someRegion where firstname=$1","Dave");
|
||||
assertEquals("{\"id\":1,\"firstname\":\"Dave\",\"lastname\":\"Turanski\",\"address\":null}",results.iterator().next());
|
||||
Person dave = new Person(1L, "Dave", "Turanski");
|
||||
jsonRegion.put("dave", dave);
|
||||
SelectResults<String> results = template.find("SELECT * FROM /jsonRegion WHERE firstname=$1", "Dave");
|
||||
assertEquals("{\"id\":1,\"firstname\":\"Dave\",\"lastname\":\"Turanski\",\"address\":null}",
|
||||
results.iterator().next());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTemplateQuery() {
|
||||
Person dave = new Person(1L,"Dave","Turanski");
|
||||
region.put("dave",dave);
|
||||
SelectResults<String> results = template.query("firstname='Dave'");
|
||||
assertEquals("{\"id\":1,\"firstname\":\"Dave\",\"lastname\":\"Turanski\",\"address\":null}",results.iterator().next());
|
||||
Person dave = new Person(1L, "Dave", "Turanski");
|
||||
jsonRegion.put("dave", dave);
|
||||
SelectResults<String> results = template.query("firstname='Dave'");
|
||||
assertEquals("{\"id\":1,\"firstname\":\"Dave\",\"lastname\":\"Turanski\",\"address\":null}",
|
||||
results.iterator().next());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,51 +15,52 @@ package org.springframework.data.gemfire.test;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.gemstone.gemfire.cache.asyncqueue.AsyncEventListener;
|
||||
import com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueue;
|
||||
import com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueueFactory;
|
||||
import com.gemstone.gemfire.cache.util.Gateway.OrderPolicy;
|
||||
import com.gemstone.gemfire.cache.wan.GatewayEventFilter;
|
||||
import com.gemstone.gemfire.cache.wan.GatewayEventSubstitutionFilter;
|
||||
import com.gemstone.gemfire.cache.wan.GatewaySender;
|
||||
|
||||
/**
|
||||
* @author David Turanski
|
||||
*
|
||||
* @author John Blum
|
||||
*/
|
||||
@SuppressWarnings("deprecated")
|
||||
public class StubAsyncEventQueueFactory implements AsyncEventQueueFactory {
|
||||
|
||||
private AsyncEventListener listener;
|
||||
|
||||
private AsyncEventQueue asyncEventQueue = mock(AsyncEventQueue.class);
|
||||
|
||||
private boolean persistent;
|
||||
private int maxQueueMemory;
|
||||
private String diskStoreName;
|
||||
private int batchSize;
|
||||
|
||||
private String name;
|
||||
|
||||
private boolean parallel;
|
||||
|
||||
private boolean diskSynchronous;
|
||||
|
||||
private boolean batchConflationEnabled;
|
||||
private boolean diskSynchronous;
|
||||
private boolean parallel;
|
||||
private boolean persistent;
|
||||
|
||||
private int batchSize;
|
||||
private int batchTimeInterval;
|
||||
private int dispatcherThreads = GatewaySender.DEFAULT_DISPATCHER_THREADS;
|
||||
private int maxQueueMemory;
|
||||
|
||||
private GatewayEventSubstitutionFilter<?, ?> gatewayEventSubstitutionFilter;
|
||||
|
||||
private OrderPolicy orderPolicy;
|
||||
|
||||
private int batchTimeInterval;
|
||||
private List<GatewayEventFilter> gatewayEventFilters = new ArrayList<GatewayEventFilter>();
|
||||
|
||||
private String diskStoreName;
|
||||
|
||||
@Override
|
||||
public AsyncEventQueue create(String name, AsyncEventListener listener) {
|
||||
this.name = name;
|
||||
this.listener = listener;
|
||||
|
||||
when(asyncEventQueue.getAsyncEventListener()).thenReturn(this.listener);
|
||||
public AsyncEventQueue create(final String name, final AsyncEventListener listener) {
|
||||
when(asyncEventQueue.getAsyncEventListener()).thenReturn(listener);
|
||||
when(asyncEventQueue.getBatchSize()).thenReturn(this.batchSize);
|
||||
when(asyncEventQueue.getDiskStoreName()).thenReturn(this.diskStoreName);
|
||||
when(asyncEventQueue.isPersistent()).thenReturn(this.persistent);
|
||||
when(asyncEventQueue.getId()).thenReturn(this.name);
|
||||
when(asyncEventQueue.getId()).thenReturn(name);
|
||||
when(asyncEventQueue.getMaximumQueueMemory()).thenReturn(this.maxQueueMemory);
|
||||
when(asyncEventQueue.isParallel()).thenReturn(this.parallel);
|
||||
when(asyncEventQueue.isBatchConflationEnabled()).thenReturn(this.batchConflationEnabled);
|
||||
@@ -67,6 +68,8 @@ public class StubAsyncEventQueueFactory implements AsyncEventQueueFactory {
|
||||
when(asyncEventQueue.getBatchTimeInterval()).thenReturn(this.batchTimeInterval);
|
||||
when(asyncEventQueue.getOrderPolicy()).thenReturn(this.orderPolicy);
|
||||
when(asyncEventQueue.getDispatcherThreads()).thenReturn(this.dispatcherThreads);
|
||||
when(asyncEventQueue.getGatewayEventSubstitutionFilter()).thenReturn(this.gatewayEventSubstitutionFilter);
|
||||
when(asyncEventQueue.getGatewayEventFilters()).thenReturn(Collections.unmodifiableList(gatewayEventFilters));
|
||||
|
||||
return this.asyncEventQueue;
|
||||
}
|
||||
@@ -126,4 +129,23 @@ public class StubAsyncEventQueueFactory implements AsyncEventQueueFactory {
|
||||
this.orderPolicy = arg0;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AsyncEventQueueFactory addGatewayEventFilter(final GatewayEventFilter gatewayEventFilter) {
|
||||
gatewayEventFilters.add(gatewayEventFilter);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AsyncEventQueueFactory removeGatewayEventFilter(final GatewayEventFilter gatewayEventFilter) {
|
||||
gatewayEventFilters.remove(gatewayEventFilter);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AsyncEventQueueFactory setGatewayEventSubstitutionListener(final GatewayEventSubstitutionFilter gatewayEventSubstitutionFilter) {
|
||||
this.gatewayEventSubstitutionFilter = gatewayEventSubstitutionFilter;
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.naming.Context;
|
||||
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
@@ -60,62 +61,51 @@ import com.gemstone.gemfire.pdx.PdxInstance;
|
||||
import com.gemstone.gemfire.pdx.PdxInstanceFactory;
|
||||
import com.gemstone.gemfire.pdx.PdxSerializer;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@SuppressWarnings({ "deprecation", "unused" })
|
||||
public class StubCache implements Cache {
|
||||
|
||||
protected static final String NOT_IMPLEMENTED = "Not Implemented!";
|
||||
|
||||
private Properties properties;
|
||||
|
||||
private DistributedSystem distributedSystem;
|
||||
|
||||
private CacheTransactionManager cacheTransactionManager;
|
||||
|
||||
private boolean closed;
|
||||
private boolean copyOnRead;
|
||||
private boolean pdxIgnoreUnreadFields;
|
||||
private boolean pdxPersistent;
|
||||
private boolean pdxReadSerialized;
|
||||
private boolean server;
|
||||
|
||||
private Declarable initializer;
|
||||
private int lockLease;
|
||||
private int lockTimeout;
|
||||
private int messageSyncInterval;
|
||||
private int searchTimeout;
|
||||
|
||||
private Context jndiContext;
|
||||
|
||||
private LogWriter logWriter;
|
||||
private Declarable initializer;
|
||||
|
||||
private String name;
|
||||
|
||||
private String pdxDiskStore;
|
||||
|
||||
private boolean pdxIgnoreUnreadFields;
|
||||
|
||||
private boolean pdxPersistent;
|
||||
|
||||
private boolean pdxReadSerialized;
|
||||
|
||||
private PdxSerializer pdxSerializer;
|
||||
|
||||
private ResourceManager resourceManager;
|
||||
|
||||
private LogWriter securityLogger;
|
||||
|
||||
private boolean closed;
|
||||
private DistributedSystem distributedSystem;
|
||||
|
||||
private GatewayConflictResolver gatewayConflictResolver;
|
||||
|
||||
private HashMap<String, Region> allRegions;
|
||||
|
||||
private List<GatewayHub> gatewayHubs;
|
||||
|
||||
private Set<GatewayReceiver> gatewayReceivers;
|
||||
private LogWriter logWriter;
|
||||
private LogWriter securityLogWriter;
|
||||
|
||||
private PdxSerializer pdxSerializer;
|
||||
|
||||
private Properties properties;
|
||||
|
||||
private ResourceManager resourceManager;
|
||||
|
||||
private Set<GatewayReceiver> gatewayReceivers;
|
||||
private Set<GatewaySender> gatewaySenders;
|
||||
|
||||
private int lockLease;
|
||||
|
||||
private int lockTimeout;
|
||||
|
||||
private int messageSyncInterval;
|
||||
|
||||
private int searchTimeout;
|
||||
|
||||
private boolean server;
|
||||
|
||||
private HashMap<String, Region> allRegions;
|
||||
private String pdxDiskStore;
|
||||
private String name;
|
||||
|
||||
public StubCache(){
|
||||
this.allRegions = new HashMap<String,Region>();
|
||||
@@ -134,7 +124,7 @@ public class StubCache implements Cache {
|
||||
*/
|
||||
@Override
|
||||
public DiskStore findDiskStore(String name) {
|
||||
return StubDiskStore.diskStores.get(name);
|
||||
return StubDiskStore.getDiskStore(name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -271,7 +261,7 @@ public class StubCache implements Cache {
|
||||
*/
|
||||
@Override
|
||||
public LogWriter getSecurityLogger() {
|
||||
return this.securityLogger;
|
||||
return this.securityLogWriter;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -882,4 +872,23 @@ public class StubCache implements Cache {
|
||||
this.properties = props;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReconnecting() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cache getReconnectedCache() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean waitUntilReconnected(final long l, final TimeUnit timeUnit) throws InterruptedException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopReconnecting() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ public class StubCacheServer implements CacheServer {
|
||||
|
||||
private boolean isRunning;
|
||||
private boolean notifyBySubscription;
|
||||
private boolean tcpNoDelay;
|
||||
|
||||
private int maxConnections;
|
||||
private int maximumMessageCount;
|
||||
@@ -349,7 +350,23 @@ public class StubCacheServer implements CacheServer {
|
||||
return null;
|
||||
}
|
||||
|
||||
ClientSubscriptionConfig mockClientSubscriptionConfig() {
|
||||
/* (non-Javadoc)
|
||||
* @see com.gemstone.gemfire.cache.server.CacheServer#getTcpNoDelay()
|
||||
*/
|
||||
@Override
|
||||
public boolean getTcpNoDelay() {
|
||||
return tcpNoDelay;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.gemstone.gemfire.cache.server.CacheServer#setTcpNoDelay(boolean)
|
||||
*/
|
||||
@Override
|
||||
public void setTcpNoDelay(final boolean tcpNoDelay) {
|
||||
this.tcpNoDelay = tcpNoDelay;
|
||||
}
|
||||
|
||||
ClientSubscriptionConfig mockClientSubscriptionConfig() {
|
||||
return new MockClientSubscriptionConfig();
|
||||
}
|
||||
|
||||
|
||||
@@ -12,147 +12,52 @@
|
||||
*/
|
||||
package org.springframework.data.gemfire.test;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.gemstone.gemfire.cache.DiskStore;
|
||||
import com.gemstone.gemfire.cache.DiskStoreFactory;
|
||||
|
||||
/**
|
||||
* @author David Turanski
|
||||
*
|
||||
* @author John Blum
|
||||
*/
|
||||
public class StubDiskStore implements DiskStore, DiskStoreFactory {
|
||||
static Map<String,DiskStore> diskStores = new HashMap<String,DiskStore>();
|
||||
|
||||
public class StubDiskStore implements DiskStoreFactory {
|
||||
|
||||
private static Map<String, DiskStore> diskStores = new HashMap<String, DiskStore>();
|
||||
|
||||
private String name;
|
||||
private boolean autoCompact;
|
||||
private int compactionThreshold;
|
||||
private boolean allowForceCompaction;
|
||||
private boolean autoCompact;
|
||||
|
||||
private float diskUsageCriticalPercentage;
|
||||
private float diskUsageWarningPercentage;
|
||||
|
||||
private int compactionThreshold;
|
||||
private int queueSize;
|
||||
private int writeBufferSize;
|
||||
|
||||
private int[] diskDirSizes;
|
||||
|
||||
private long maxOpLogSize;
|
||||
private long timeInterval;
|
||||
private int writeBufferSize;
|
||||
|
||||
private File[] diskDirs;
|
||||
private int[] diskDirSizes;
|
||||
private UUID diskStoreUUID;
|
||||
private int queueSize;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.gemstone.gemfire.cache.DiskStore#getName()
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
public static DiskStore getDiskStore(final String name) {
|
||||
return diskStores.get(name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.gemstone.gemfire.cache.DiskStore#getAutoCompact()
|
||||
* @see com.gemstone.gemfire.cache.DiskStoreFactory#setAllowForceCompaction(boolean)
|
||||
*/
|
||||
@Override
|
||||
public boolean getAutoCompact() {
|
||||
return this.autoCompact;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.gemstone.gemfire.cache.DiskStore#getCompactionThreshold()
|
||||
*/
|
||||
@Override
|
||||
public int getCompactionThreshold() {
|
||||
return this.compactionThreshold;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.gemstone.gemfire.cache.DiskStore#getAllowForceCompaction()
|
||||
*/
|
||||
@Override
|
||||
public boolean getAllowForceCompaction() {
|
||||
return this.allowForceCompaction;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.gemstone.gemfire.cache.DiskStore#getMaxOplogSize()
|
||||
*/
|
||||
@Override
|
||||
public long getMaxOplogSize() {
|
||||
return this.maxOpLogSize;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.gemstone.gemfire.cache.DiskStore#getTimeInterval()
|
||||
*/
|
||||
@Override
|
||||
public long getTimeInterval() {
|
||||
return this.timeInterval;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.gemstone.gemfire.cache.DiskStore#getWriteBufferSize()
|
||||
*/
|
||||
@Override
|
||||
public int getWriteBufferSize() {
|
||||
return this.writeBufferSize;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.gemstone.gemfire.cache.DiskStore#getDiskDirs()
|
||||
*/
|
||||
@Override
|
||||
public File[] getDiskDirs() {
|
||||
return this.diskDirs;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.gemstone.gemfire.cache.DiskStore#getDiskDirSizes()
|
||||
*/
|
||||
@Override
|
||||
public int[] getDiskDirSizes() {
|
||||
return this.diskDirSizes;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.gemstone.gemfire.cache.DiskStore#getDiskStoreUUID()
|
||||
*/
|
||||
@Override
|
||||
public UUID getDiskStoreUUID() {
|
||||
return this.diskStoreUUID;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.gemstone.gemfire.cache.DiskStore#getQueueSize()
|
||||
*/
|
||||
@Override
|
||||
public int getQueueSize() {
|
||||
return this.queueSize;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.gemstone.gemfire.cache.DiskStore#flush()
|
||||
*/
|
||||
@Override
|
||||
public void flush() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.gemstone.gemfire.cache.DiskStore#forceRoll()
|
||||
*/
|
||||
@Override
|
||||
public void forceRoll() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.gemstone.gemfire.cache.DiskStore#forceCompaction()
|
||||
*/
|
||||
@Override
|
||||
public boolean forceCompaction() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
public DiskStoreFactory setAllowForceCompaction(boolean allowForceCompaction) {
|
||||
this.allowForceCompaction = allowForceCompaction;
|
||||
return this;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -173,15 +78,6 @@ public class StubDiskStore implements DiskStore, DiskStoreFactory {
|
||||
return this;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.gemstone.gemfire.cache.DiskStoreFactory#setAllowForceCompaction(boolean)
|
||||
*/
|
||||
@Override
|
||||
public DiskStoreFactory setAllowForceCompaction(boolean allowForceCompaction) {
|
||||
this.allowForceCompaction = allowForceCompaction;
|
||||
return this;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.gemstone.gemfire.cache.DiskStoreFactory#setMaxOplogSize(long)
|
||||
*/
|
||||
@@ -238,12 +134,46 @@ public class StubDiskStore implements DiskStore, DiskStoreFactory {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.gemstone.gemfire.cache.DiskStoreFactory#create(java.lang.String)
|
||||
* @see com.gemstone.gemfire.cache.DiskStoreFactory#setDiskUsageCriticalPercentage(float)
|
||||
*/
|
||||
@Override
|
||||
public DiskStore create(String name) {
|
||||
this.name = name;
|
||||
diskStores.put(name,this);
|
||||
public DiskStoreFactory setDiskUsageCriticalPercentage(final float diskUsageCriticalPercentage) {
|
||||
this.diskUsageCriticalPercentage = diskUsageCriticalPercentage;
|
||||
return this;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.gemstone.gemfire.cache.DiskStoreFactory#setDiskUsageWarningPercentage(float)
|
||||
*/
|
||||
@Override
|
||||
public DiskStoreFactory setDiskUsageWarningPercentage(final float diskUsageWarningPercentage) {
|
||||
this.diskUsageWarningPercentage = diskUsageWarningPercentage;
|
||||
return this;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.gemstone.gemfire.cache.DiskStoreFactory#create(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public DiskStore create(final String name) {
|
||||
DiskStore mockDiskStore = mock(DiskStore.class, name);
|
||||
|
||||
when(mockDiskStore.getName()).thenReturn(name);
|
||||
when(mockDiskStore.getAllowForceCompaction()).thenReturn(allowForceCompaction);
|
||||
when(mockDiskStore.getAutoCompact()).thenReturn(autoCompact);
|
||||
when(mockDiskStore.getCompactionThreshold()).thenReturn(compactionThreshold);
|
||||
when(mockDiskStore.getDiskUsageCriticalPercentage()).thenReturn(diskUsageCriticalPercentage);
|
||||
when(mockDiskStore.getDiskUsageWarningPercentage()).thenReturn(diskUsageWarningPercentage);
|
||||
when(mockDiskStore.getDiskDirs()).thenReturn(diskDirs);
|
||||
when(mockDiskStore.getDiskDirSizes()).thenReturn(diskDirSizes);
|
||||
when(mockDiskStore.getMaxOplogSize()).thenReturn(maxOpLogSize);
|
||||
when(mockDiskStore.getQueueSize()).thenReturn(queueSize);
|
||||
when(mockDiskStore.getTimeInterval()).thenReturn(timeInterval);
|
||||
when(mockDiskStore.getWriteBufferSize()).thenReturn(writeBufferSize);
|
||||
|
||||
diskStores.put(name, mockDiskStore);
|
||||
|
||||
return mockDiskStore;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,8 +24,10 @@ import com.gemstone.gemfire.cache.wan.GatewayTransportFilter;
|
||||
|
||||
/**
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class StubGatewayReceiverFactory implements GatewayReceiverFactory {
|
||||
|
||||
private int endPort;
|
||||
@@ -37,6 +39,7 @@ public class StubGatewayReceiverFactory implements GatewayReceiverFactory {
|
||||
|
||||
private String bindAddress;
|
||||
private String hostnameForClients;
|
||||
private String hostnameForSenders;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.gemstone.gemfire.cache.wan.GatewayReceiverFactory#setStartPort(int)
|
||||
@@ -112,9 +115,18 @@ public class StubGatewayReceiverFactory implements GatewayReceiverFactory {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.gemstone.gemfire.cache.wan.GatewayReceiverFactory#create()
|
||||
* @see com.gemstone.gemfire.cache.wan.GatewayReceiverFactory#setHostnameForSenders(String)
|
||||
*/
|
||||
@Override
|
||||
public GatewayReceiverFactory setHostnameForSenders(final String hostnameForSenders) {
|
||||
this.hostnameForSenders = hostnameForSenders;
|
||||
return this;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.gemstone.gemfire.cache.wan.GatewayReceiverFactory#create()
|
||||
*/
|
||||
@Override
|
||||
public GatewayReceiver create() {
|
||||
GatewayReceiver gatewayReceiver = mock(GatewayReceiver.class);
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.mockito.stubbing.Answer;
|
||||
|
||||
import com.gemstone.gemfire.cache.util.Gateway.OrderPolicy;
|
||||
import com.gemstone.gemfire.cache.wan.GatewayEventFilter;
|
||||
import com.gemstone.gemfire.cache.wan.GatewayEventSubstitutionFilter;
|
||||
import com.gemstone.gemfire.cache.wan.GatewaySender;
|
||||
import com.gemstone.gemfire.cache.wan.GatewaySenderFactory;
|
||||
import com.gemstone.gemfire.cache.wan.GatewayTransportFilter;
|
||||
@@ -32,37 +33,40 @@ import com.gemstone.gemfire.cache.wan.GatewayTransportFilter;
|
||||
* The StubGatewaySenderFactory class for testing purposes.
|
||||
*
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
* @see com.gemstone.gemfire.cache.wan.GatewaySenderFactory
|
||||
*/
|
||||
@SuppressWarnings({ "deprecation", "unused" })
|
||||
public class StubGatewaySenderFactory implements GatewaySenderFactory {
|
||||
|
||||
private int alertThreshold;
|
||||
private boolean batchConflationEnabled;
|
||||
private int batchSize;
|
||||
private int batchTimeInterval;
|
||||
private String diskStoreName;
|
||||
private boolean diskSynchronous;
|
||||
private int dispatcherThreads;
|
||||
private boolean manualStart;
|
||||
private int maxQueueMemory;
|
||||
private OrderPolicy orderPolicy;
|
||||
private boolean parallel;
|
||||
private boolean persistenceEnabled;
|
||||
private boolean running = true;
|
||||
|
||||
private int alertThreshold;
|
||||
private int batchSize;
|
||||
private int batchTimeInterval;
|
||||
private int dispatcherThreads;
|
||||
private int maxQueueMemory;
|
||||
private int parallelFactorForReplicatedRegion;
|
||||
private int socketBufferSize;
|
||||
private int socketReadTimeout;
|
||||
|
||||
private GatewayEventSubstitutionFilter<?, ?> gatewayEventSubstitutionFilter;
|
||||
|
||||
private List<GatewayEventFilter> eventFilters;
|
||||
private List<GatewayTransportFilter> transportFilters;
|
||||
|
||||
private String name;
|
||||
private OrderPolicy orderPolicy;
|
||||
|
||||
private boolean running = true;
|
||||
|
||||
private int remoteSystemId;
|
||||
private String diskStoreName;
|
||||
|
||||
public StubGatewaySenderFactory() {
|
||||
this.eventFilters = new ArrayList<GatewayEventFilter>();
|
||||
this.transportFilters = new ArrayList<GatewayTransportFilter>();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -78,18 +82,18 @@ public class StubGatewaySenderFactory implements GatewaySenderFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public GatewaySender create(String name, int remoteSystemId) {
|
||||
public GatewaySender create(final String name, final int remoteSystemId) {
|
||||
GatewaySender gatewaySender = mock(GatewaySender.class);
|
||||
this.name = name;
|
||||
this.remoteSystemId = remoteSystemId;
|
||||
when(gatewaySender.getId()).thenReturn(this.name);
|
||||
when(gatewaySender.getRemoteDSId()).thenReturn(this.remoteSystemId);
|
||||
|
||||
when(gatewaySender.getId()).thenReturn(name);
|
||||
when(gatewaySender.getRemoteDSId()).thenReturn(remoteSystemId);
|
||||
when(gatewaySender.getAlertThreshold()).thenReturn(this.alertThreshold);
|
||||
when(gatewaySender.getBatchSize()).thenReturn(this.batchSize);
|
||||
when(gatewaySender.getBatchTimeInterval()).thenReturn(this.batchTimeInterval);
|
||||
when(gatewaySender.getDiskStoreName()).thenReturn(this.diskStoreName);
|
||||
when(gatewaySender.getDispatcherThreads()).thenReturn(this.dispatcherThreads);
|
||||
when(gatewaySender.getGatewayEventFilters()).thenReturn(this.eventFilters);
|
||||
when(gatewaySender.getGatewayEventSubstitutionFilter()).thenReturn(gatewayEventSubstitutionFilter);
|
||||
when(gatewaySender.getGatewayTransportFilters()).thenReturn(this.transportFilters);
|
||||
when(gatewaySender.getMaximumQueueMemory()).thenReturn(this.maxQueueMemory);
|
||||
when(gatewaySender.getOrderPolicy()).thenReturn(this.orderPolicy);
|
||||
@@ -100,18 +104,19 @@ public class StubGatewaySenderFactory implements GatewaySenderFactory {
|
||||
when(gatewaySender.isDiskSynchronous()).thenReturn(this.diskSynchronous);
|
||||
when(gatewaySender.isParallel()).thenReturn(this.parallel);
|
||||
when(gatewaySender.isPersistenceEnabled()).thenReturn(this.persistenceEnabled);
|
||||
doAnswer(new Answer<Void>() {
|
||||
when(gatewaySender.isRunning()).thenAnswer(new Answer<Boolean>() {
|
||||
@Override
|
||||
public Boolean answer(InvocationOnMock invocation) throws Throwable {
|
||||
return running;
|
||||
}
|
||||
});
|
||||
doAnswer(new Answer<Void>() {
|
||||
public Void answer(InvocationOnMock invocation) {
|
||||
running = true;
|
||||
return null;
|
||||
running = true;
|
||||
return null;
|
||||
}
|
||||
}).when(gatewaySender).start();
|
||||
when(gatewaySender.isRunning()).thenAnswer(new Answer<Boolean>(){
|
||||
@Override
|
||||
public Boolean answer(InvocationOnMock invocation) throws Throwable {
|
||||
return running;
|
||||
}
|
||||
});
|
||||
|
||||
return gatewaySender;
|
||||
}
|
||||
|
||||
@@ -206,9 +211,20 @@ public class StubGatewaySenderFactory implements GatewaySenderFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public GatewaySenderFactory removeGatewayTransportFilter(GatewayTransportFilter arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
public GatewaySenderFactory removeGatewayTransportFilter(GatewayTransportFilter gatewayTransportFilter) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GatewaySenderFactory setParallelFactorForReplicatedRegion(final int parallelFactorForReplicatedRegion) {
|
||||
this.parallelFactorForReplicatedRegion = parallelFactorForReplicatedRegion;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GatewaySenderFactory setGatewayEventSubstitutionFilter(final GatewayEventSubstitutionFilter gatewayEventSubstitutionFilter) {
|
||||
this.gatewayEventSubstitutionFilter = gatewayEventSubstitutionFilter;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,11 +36,12 @@ import org.springframework.util.StringUtils;
|
||||
import com.gemstone.gemfire.cache.asyncqueue.AsyncEvent;
|
||||
import com.gemstone.gemfire.cache.asyncqueue.AsyncEventListener;
|
||||
import com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueue;
|
||||
import com.gemstone.gemfire.cache.wan.GatewaySender;
|
||||
|
||||
/**
|
||||
* The AsyncEvenntQueueWithListenerTest class is a test suite of test cases testing the circular references between
|
||||
* an Async Event Queue and a registered AsyncEventListener that refers back to the Async Event Queue on which the
|
||||
* listener registered.
|
||||
* The AsyncEventQueueWithListenerIntegrationTest class is a test suite of test cases testing the circular references
|
||||
* between an Async Event Queue and a registered AsyncEventListener that refers back to the Async Event Queue
|
||||
* on which the listener is registered.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
@@ -50,9 +51,8 @@ import com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueue;
|
||||
* @see com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueue
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@ContextConfiguration(value = "asyncEventQueueWithListener.xml",
|
||||
initializers = GemfireTestApplicationContextInitializer.class)
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(value = "asyncEventQueueWithListener.xml", initializers = GemfireTestApplicationContextInitializer.class)
|
||||
@SuppressWarnings("unused")
|
||||
public class AsyncEventQueueWithListenerIntegrationTest {
|
||||
|
||||
@@ -83,7 +83,7 @@ public class AsyncEventQueueWithListenerIntegrationTest {
|
||||
assertFalse(queueTwo.isPersistent());
|
||||
assertTrue(queueTwo.isParallel());
|
||||
assertEquals(150, queueTwo.getMaximumQueueMemory());
|
||||
assertEquals(1, queueTwo.getDispatcherThreads());
|
||||
assertEquals(GatewaySender.DEFAULT_DISPATCHER_THREADS, queueTwo.getDispatcherThreads());
|
||||
assertTrue(queueTwo.getAsyncEventListener() instanceof TestAsyncEventListener);
|
||||
assertEquals("ListenerTwo", ((TestAsyncEventListener) queueTwo.getAsyncEventListener()).getName());
|
||||
}
|
||||
|
||||
@@ -32,8 +32,8 @@
|
||||
|
||||
<gfe:client-region id="persistent" name="PersistentRegion" pool-name="gemfire-pool" persistent="true" disk-store-ref="diskStore" disk-synchronous="true"/>
|
||||
|
||||
<gfe:disk-store id="diskStore" queue-size="50" auto-compact="true" max-oplog-size="10" time-interval="9999">
|
||||
<gfe:disk-dir location="./" max-size="1"/>
|
||||
<gfe:disk-store id="diskStore" queue-size="50" auto-compact="true" max-oplog-size="5" time-interval="9999">
|
||||
<gfe:disk-dir location="./" max-size="10"/>
|
||||
</gfe:disk-store>
|
||||
|
||||
<gfe:client-region id="overflow" name="OverflowRegion" pool-name="gemfire-pool" disk-store-ref="diskStore">
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:gfe="http://www.springframework.org/schema/gemfire"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
|
||||
xmlns:gfe="http://www.springframework.org/schema/gemfire"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
">
|
||||
|
||||
|
||||
<gfe:client-cache/>
|
||||
|
||||
<gfe:client-region id="test-region"/>
|
||||
|
||||
<gfe:pool>
|
||||
<gfe:server host="localhost" port="40404"/>
|
||||
<gfe:pool id="serverBasedPool">
|
||||
<gfe:server host="localhost" port="15243"/>
|
||||
</gfe:pool>
|
||||
|
||||
|
||||
<gfe:client-cache pool-name="serverBasedPool"/>
|
||||
|
||||
<gfe:client-region id="test-region" pool-name="serverBasedPool" shortcut="PROXY"/>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -1,17 +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:gfe="http://www.springframework.org/schema/gemfire"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
|
||||
xmlns:gfe="http://www.springframework.org/schema/gemfire"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
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">
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
|
||||
http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
|
||||
">
|
||||
|
||||
<util:properties id="gemfireProperties">
|
||||
<prop key="name">FunctionIntegrationTestsServer</prop>
|
||||
<prop key="statistic-sampling-enabled">false</prop>
|
||||
<prop key="mcast-port">0</prop>
|
||||
<prop key="log-level">config</prop>
|
||||
</util:properties>
|
||||
|
||||
<gfe:cache properties-ref="gemfireProperties"/>
|
||||
<gfe:cache-server port="15243"/>
|
||||
<gfe:partitioned-region id="test-region"/>
|
||||
<gfe:annotation-driven/>
|
||||
|
||||
<context:component-scan base-package="org.springframework.data.gemfire.function.execution"/>
|
||||
|
||||
<gfe:annotation-driven/>
|
||||
<gfe:cache/>
|
||||
<gfe:cache-server/>
|
||||
<gfe:partitioned-region id="test-region"/>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -1,30 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:gfe="http://www.springframework.org/schema/gemfire"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xmlns:gfe-data="http://www.springframework.org/schema/data/gemfire"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
|
||||
xmlns:gfe="http://www.springframework.org/schema/gemfire"
|
||||
xmlns:gfe-data="http://www.springframework.org/schema/data/gemfire"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
|
||||
http://www.springframework.org/schema/data/gemfire http://www.springframework.org/schema/data/gemfire/spring-data-gemfire.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
|
||||
http://www.springframework.org/schema/data/gemfire http://www.springframework.org/schema/data/gemfire/spring-data-gemfire.xsd">
|
||||
">
|
||||
|
||||
<util:properties id="props">
|
||||
<prop key="bind-address">127.0.0.1</prop>
|
||||
<util:properties id="gemfireProperties">
|
||||
<prop key="name">JSONRegionAdviceTest</prop>
|
||||
<prop key="mcast-port">0</prop>
|
||||
<prop key="log-level">config</prop>
|
||||
</util:properties>
|
||||
|
||||
<gfe-data:json-region-autoproxy
|
||||
pretty-print="false"
|
||||
convert-returned-collections="true"
|
||||
region-refs="someRegion"/>
|
||||
<!-- Above replaces -->
|
||||
<!-- <aop:aspectj-autoproxy /> -->
|
||||
<!-- <bean class="org.springframework.data.gemfire.support.JSONRegionAdvice" /> -->
|
||||
<gfe:cache properties-ref="gemfireProperties"/>
|
||||
|
||||
<gfe:replicated-region id="jsonRegion"/>
|
||||
|
||||
<gfe-data:json-region-autoproxy pretty-print="false" convert-returned-collections="true" region-refs="jsonRegion"/>
|
||||
<!-- gfe-data:json-region-autoproxy replaces... -->
|
||||
<!--
|
||||
<aop:aspectj-autoproxy/>
|
||||
<bean class="org.springframework.data.gemfire.support.JSONRegionAdvice"/>
|
||||
-->
|
||||
|
||||
<bean class="org.springframework.data.gemfire.GemfireTemplate" p:region-ref="jsonRegion"/>
|
||||
|
||||
<gfe:cache properties-ref="props"/>
|
||||
<gfe:replicated-region id="someRegion"/>
|
||||
|
||||
<bean id="template" class="org.springframework.data.gemfire.GemfireTemplate">
|
||||
<constructor-arg ref="someRegion"/>
|
||||
</bean>
|
||||
</beans>
|
||||
|
||||
Reference in New Issue
Block a user