diff --git a/build.gradle b/build.gradle index 1b45f114..423c711c 100644 --- a/build.gradle +++ b/build.gradle @@ -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=") diff --git a/gradle.properties b/gradle.properties index 431e3d12..eda77df3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/src/main/java/org/springframework/data/gemfire/support/GemfireCache.java b/src/main/java/org/springframework/data/gemfire/support/GemfireCache.java index 8c418948..adfea5b9 100644 --- a/src/main/java/org/springframework/data/gemfire/support/GemfireCache.java +++ b/src/main/java/org/springframework/data/gemfire/support/GemfireCache.java @@ -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 get(final Object key, final Class type) { - return type.cast(region.get(key)); - } + public T get(final Object key, final Class 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); } diff --git a/src/main/java/org/springframework/data/gemfire/support/JSONRegionAdvice.java b/src/main/java/org/springframework/data/gemfire/support/JSONRegionAdvice.java index 57511226..4c64db39 100644 --- a/src/main/java/org/springframework/data/gemfire/support/JSONRegionAdvice.java +++ b/src/main/java/org/springframework/data/gemfire/support/JSONRegionAdvice.java @@ -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 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 regionNames) { - this.includedRegions = regionNames; - } + private List 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> regions) { - this.includedRegions = new ArrayList(); - 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> regions) { + this.includedRegions = new ArrayList(); + 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 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 getAll(ProceedingJoinPoint pjp) { Map result = null; + try { Map retVal = (Map) 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(); for (Entry 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 values(ProceedingJoinPoint pjp) { Collection result = null; + try { Collection retVal = (Collection) 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(); 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); } } + } diff --git a/src/main/java/org/springframework/data/gemfire/wan/GatewaySenderWrapper.java b/src/main/java/org/springframework/data/gemfire/wan/GatewaySenderWrapper.java index f8f3e4e3..b8d0887b 100644 --- a/src/main/java/org/springframework/data/gemfire/wan/GatewaySenderWrapper.java +++ b/src/main/java/org/springframework/data/gemfire/wan/GatewaySenderWrapper.java @@ -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 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(); diff --git a/src/test/java/org/springframework/data/gemfire/DataPolicyConverterTest.java b/src/test/java/org/springframework/data/gemfire/DataPolicyConverterTest.java index ee1ea18d..21ca8f88 100644 --- a/src/test/java/org/springframework/data/gemfire/DataPolicyConverterTest.java +++ b/src/test/java/org/springframework/data/gemfire/DataPolicyConverterTest.java @@ -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; } } diff --git a/src/test/java/org/springframework/data/gemfire/ForkUtil.java b/src/test/java/org/springframework/data/gemfire/ForkUtil.java index 505dbf25..97fec026 100644 --- a/src/test/java/org/springframework/data/gemfire/ForkUtil.java +++ b/src/test/java/org/springframework/data/gemfire/ForkUtil.java @@ -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 command = new ArrayList(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(); } -} \ No newline at end of file + +} diff --git a/src/test/java/org/springframework/data/gemfire/config/ClientRegionNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/ClientRegionNamespaceTest.java index 58db8dcd..cd72f4aa 100644 --- a/src/test/java/org/springframework/data/gemfire/config/ClientRegionNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/ClientRegionNamespaceTest.java @@ -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") diff --git a/src/test/java/org/springframework/data/gemfire/function/execution/FunctionIntegrationTests.java b/src/test/java/org/springframework/data/gemfire/function/execution/FunctionIntegrationTests.java index 987d5b63..8d439347 100644 --- a/src/test/java/org/springframework/data/gemfire/function/execution/FunctionIntegrationTests.java +++ b/src/test/java/org/springframework/data/gemfire/function/execution/FunctionIntegrationTests.java @@ -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 region; - + + @Resource(name = "test-region") + private Region 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 results; - results = template.execute("oneArg","two"); - assertEquals(2, results.iterator().next().intValue()); - - Set filter = new HashSet(); - 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 map = (Map)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 map = (Map) 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.execute("oneArg", "two").iterator().next().intValue()); + assertFalse(template.execute("oneArg", Collections.singleton("one"), "two").iterator().hasNext()); + assertEquals(5, template.execute("twoArg", "two", "three").iterator().next().intValue()); + assertEquals(5, template.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 dataSet) { - return dataSet.get(key); + @GemfireFunction(id = "oneArg") + public Integer oneArg(String key, @RegionData Map region) { + return region.get(key); } - - @GemfireFunction(id="twoArg") - public Integer twoArg(String akey, String bkey, @RegionData Map 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 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 collections(List args) { return args; } - @GemfireFunction(id="getMapWithNoArgs") - public Map getMapWithNoArgs(@RegionData Map dataSet) { - if (dataSet.size() == 0) { + @GemfireFunction(id = "getMapWithNoArgs") + public Map getMapWithNoArgs(@RegionData Map region) { + if (region.size() == 0) { return null; } - return new HashMap(dataSet); + + return new HashMap(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() { - - } } + } diff --git a/src/test/java/org/springframework/data/gemfire/support/AbstractNativeCacheTest.java b/src/test/java/org/springframework/data/gemfire/support/AbstractNativeCacheTest.java index c19a6a59..493fd279 100644 --- a/src/test/java/org/springframework/data/gemfire/support/AbstractNativeCacheTest.java +++ b/src/test/java/org/springframework/data/gemfire/support/AbstractNativeCacheTest.java @@ -31,9 +31,10 @@ import org.springframework.cache.Cache; */ public abstract class AbstractNativeCacheTest { + 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 { 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 { @Test public void testCachePut() throws Exception { - Object key = "enescu"; Object value = "george"; @@ -80,4 +78,19 @@ public abstract class AbstractNativeCacheTest { assertNull(cache.get("enescu")); } -} \ No newline at end of file + @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)); + } + +} diff --git a/src/test/java/org/springframework/data/gemfire/support/GemfireCacheTest.java b/src/test/java/org/springframework/data/gemfire/support/GemfireCacheTest.java index 5c16999d..8121316d 100644 --- a/src/test/java/org/springframework/data/gemfire/support/GemfireCacheTest.java +++ b/src/test/java/org/springframework/data/gemfire/support/GemfireCacheTest.java @@ -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> { @Override @@ -38,21 +41,25 @@ public class GemfireCacheTest extends AbstractNativeCacheTest 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; } } diff --git a/src/test/java/org/springframework/data/gemfire/support/JSONRegionAdviceTest.java b/src/test/java/org/springframework/data/gemfire/support/JSONRegionAdviceTest.java index ac3b9c06..b52f1a16 100644 --- a/src/test/java/org/springframework/data/gemfire/support/JSONRegionAdviceTest.java +++ b/src/test/java/org/springframework/data/gemfire/support/JSONRegionAdviceTest.java @@ -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 map = new HashMap(); + Map map = new HashMap(); map.put("key1", "{\"hello1\":\"world1\"}"); map.put("key2", "{\"hello2\":\"world2\"}"); - region.putAll(map); + jsonRegion.putAll(map); List keys = Arrays.asList("key1", "key2"); - Map results = region.getAll(keys); - assertEquals("{\"hello1\":\"world1\"}",results.get("key1")); - assertEquals("{\"hello2\":\"world2\"}",results.get("key2")); + Map 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 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 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 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 results = template.query("firstname='Dave'"); + assertEquals("{\"id\":1,\"firstname\":\"Dave\",\"lastname\":\"Turanski\",\"address\":null}", + results.iterator().next()); } } diff --git a/src/test/java/org/springframework/data/gemfire/test/StubAsyncEventQueueFactory.java b/src/test/java/org/springframework/data/gemfire/test/StubAsyncEventQueueFactory.java index f982d387..ea132eed 100644 --- a/src/test/java/org/springframework/data/gemfire/test/StubAsyncEventQueueFactory.java +++ b/src/test/java/org/springframework/data/gemfire/test/StubAsyncEventQueueFactory.java @@ -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 gatewayEventFilters = new ArrayList(); + + 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; + } + } diff --git a/src/test/java/org/springframework/data/gemfire/test/StubCache.java b/src/test/java/org/springframework/data/gemfire/test/StubCache.java index ca76a482..9eefb77b 100644 --- a/src/test/java/org/springframework/data/gemfire/test/StubCache.java +++ b/src/test/java/org/springframework/data/gemfire/test/StubCache.java @@ -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 allRegions; + private List gatewayHubs; - private Set gatewayReceivers; + private LogWriter logWriter; + private LogWriter securityLogWriter; + private PdxSerializer pdxSerializer; + + private Properties properties; + + private ResourceManager resourceManager; + + private Set gatewayReceivers; private Set gatewaySenders; - private int lockLease; - - private int lockTimeout; - - private int messageSyncInterval; - - private int searchTimeout; - - private boolean server; - - private HashMap allRegions; + private String pdxDiskStore; + private String name; public StubCache(){ this.allRegions = new HashMap(); @@ -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() { + } + } diff --git a/src/test/java/org/springframework/data/gemfire/test/StubCacheServer.java b/src/test/java/org/springframework/data/gemfire/test/StubCacheServer.java index 14688f4e..b2578227 100644 --- a/src/test/java/org/springframework/data/gemfire/test/StubCacheServer.java +++ b/src/test/java/org/springframework/data/gemfire/test/StubCacheServer.java @@ -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(); } diff --git a/src/test/java/org/springframework/data/gemfire/test/StubDiskStore.java b/src/test/java/org/springframework/data/gemfire/test/StubDiskStore.java index a96253f0..007515f1 100644 --- a/src/test/java/org/springframework/data/gemfire/test/StubDiskStore.java +++ b/src/test/java/org/springframework/data/gemfire/test/StubDiskStore.java @@ -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 diskStores = new HashMap(); - +public class StubDiskStore implements DiskStoreFactory { + + private static Map diskStores = new HashMap(); - 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; + } + } diff --git a/src/test/java/org/springframework/data/gemfire/test/StubGatewayReceiverFactory.java b/src/test/java/org/springframework/data/gemfire/test/StubGatewayReceiverFactory.java index 8c15f4f7..c7b6317b 100644 --- a/src/test/java/org/springframework/data/gemfire/test/StubGatewayReceiverFactory.java +++ b/src/test/java/org/springframework/data/gemfire/test/StubGatewayReceiverFactory.java @@ -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); diff --git a/src/test/java/org/springframework/data/gemfire/test/StubGatewaySenderFactory.java b/src/test/java/org/springframework/data/gemfire/test/StubGatewaySenderFactory.java index 060ead1a..609b5fdf 100644 --- a/src/test/java/org/springframework/data/gemfire/test/StubGatewaySenderFactory.java +++ b/src/test/java/org/springframework/data/gemfire/test/StubGatewaySenderFactory.java @@ -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 eventFilters; private List transportFilters; - private String name; + private OrderPolicy orderPolicy; - private boolean running = true; - - private int remoteSystemId; + private String diskStoreName; public StubGatewaySenderFactory() { this.eventFilters = new ArrayList(); this.transportFilters = new ArrayList(); - } @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() { + when(gatewaySender.isRunning()).thenAnswer(new Answer() { + @Override + public Boolean answer(InvocationOnMock invocation) throws Throwable { + return running; + } + }); + doAnswer(new Answer() { public Void answer(InvocationOnMock invocation) { - running = true; - return null; + running = true; + return null; } }).when(gatewaySender).start(); - when(gatewaySender.isRunning()).thenAnswer(new Answer(){ - @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; } } diff --git a/src/test/java/org/springframework/data/gemfire/wan/AsyncEventQueueWithListenerIntegrationTest.java b/src/test/java/org/springframework/data/gemfire/wan/AsyncEventQueueWithListenerIntegrationTest.java index 2772a7dd..ba39c75d 100644 --- a/src/test/java/org/springframework/data/gemfire/wan/AsyncEventQueueWithListenerIntegrationTest.java +++ b/src/test/java/org/springframework/data/gemfire/wan/AsyncEventQueueWithListenerIntegrationTest.java @@ -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()); } diff --git a/src/test/resources/org/springframework/data/gemfire/config/client-ns.xml b/src/test/resources/org/springframework/data/gemfire/config/client-ns.xml index 1c3bc2a7..5ba6b6ef 100644 --- a/src/test/resources/org/springframework/data/gemfire/config/client-ns.xml +++ b/src/test/resources/org/springframework/data/gemfire/config/client-ns.xml @@ -32,8 +32,8 @@ - - + + diff --git a/src/test/resources/org/springframework/data/gemfire/function/execution/FunctionIntegrationTests-context.xml b/src/test/resources/org/springframework/data/gemfire/function/execution/FunctionIntegrationTests-context.xml index 416eb654..aa73f33a 100644 --- a/src/test/resources/org/springframework/data/gemfire/function/execution/FunctionIntegrationTests-context.xml +++ b/src/test/resources/org/springframework/data/gemfire/function/execution/FunctionIntegrationTests-context.xml @@ -1,19 +1,18 @@ +"> - - - - - - - + + - + + + + + diff --git a/src/test/resources/org/springframework/data/gemfire/function/execution/FunctionIntegrationTests-server-context.xml b/src/test/resources/org/springframework/data/gemfire/function/execution/FunctionIntegrationTests-server-context.xml index a00f671f..45b43530 100644 --- a/src/test/resources/org/springframework/data/gemfire/function/execution/FunctionIntegrationTests-server-context.xml +++ b/src/test/resources/org/springframework/data/gemfire/function/execution/FunctionIntegrationTests-server-context.xml @@ -1,17 +1,28 @@ + 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 +"> + + + FunctionIntegrationTestsServer + false + 0 + config + + + + + + - - - - - diff --git a/src/test/resources/org/springframework/data/gemfire/support/JSONRegionAdviceTest-context.xml b/src/test/resources/org/springframework/data/gemfire/support/JSONRegionAdviceTest-context.xml index 49fa2de3..f14bb5f3 100644 --- a/src/test/resources/org/springframework/data/gemfire/support/JSONRegionAdviceTest-context.xml +++ b/src/test/resources/org/springframework/data/gemfire/support/JSONRegionAdviceTest-context.xml @@ -1,30 +1,34 @@ +"> - - 127.0.0.1 + + JSONRegionAdviceTest + 0 + config - - - - + + + + + + + + + - - - - - -