Upgrades Spring Data GemFire 1.5 to GemFire 7.5.
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user