use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.
the class SnapshotByteArrayDUnitTest method loadCache.
public void loadCache() throws Exception {
SerializableCallable setup = new SerializableCallable() {
@Override
public Object call() throws Exception {
CacheFactory cf = new CacheFactory().setPdxSerializer(new MyPdxSerializer()).setPdxPersistent(true);
Cache cache = getCache(cf);
RegionGenerator rgen = new RegionGenerator();
rgen.createRegion(cache, null, RegionType.REPLICATE, "snapshot-ops");
return null;
}
};
SnapshotDUnitTest.forEachVm(setup, true);
}
use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.
the class SnapshotDUnitTest method testExportAndImport.
@Test
public void testExportAndImport() throws Exception {
File dir = new File(getDiskDirs()[0], "snap");
dir.mkdir();
// save all regions
getCache().getSnapshotService().save(dir, SnapshotFormat.GEMFIRE);
// update regions with data to be overwritten by import
updateRegions();
SerializableCallable callbacks = new SerializableCallable() {
@Override
public Object call() throws Exception {
for (final RegionType rt : RegionType.values()) {
for (final SerializationType st : SerializationType.values()) {
String name = "test-" + rt.name() + "-" + st.name();
Cache c = getCache();
Region<Integer, MyObject> region = c.getRegion(name);
region.getAttributesMutator().setCacheWriter(new CacheWriterAdapter<Integer, MyObject>() {
@Override
public void beforeUpdate(EntryEvent<Integer, MyObject> event) {
fail("CacheWriter invoked during import");
}
});
region.getAttributesMutator().addCacheListener(new CacheListenerAdapter<Integer, MyObject>() {
@Override
public void afterUpdate(EntryEvent<Integer, MyObject> event) {
fail("CacheListener invoked during import");
}
});
}
}
return null;
}
};
// add callbacks
forEachVm(callbacks, true);
// load all regions
loadRegions(dir, null);
}
use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.
the class SnapshotDUnitTest method testExportAndImportWithInvokeCallbacksEnabled.
@Test
public void testExportAndImportWithInvokeCallbacksEnabled() throws Exception {
File dir = new File(getDiskDirs()[0], "callbacks");
dir.mkdir();
// save all regions
CacheSnapshotService service = getCache().getSnapshotService();
service.save(dir, SnapshotFormat.GEMFIRE);
// update regions with data to be overwritten by import
updateRegions();
SerializableCallable callbacks = new SerializableCallable() {
@Override
public Object call() throws Exception {
for (final RegionType rt : RegionType.values()) {
for (final SerializationType st : SerializationType.values()) {
String name = "test-" + rt.name() + "-" + st.name();
Cache cache = getCache();
Region<Integer, MyObject> region = cache.getRegion(name);
// add CacheWriter and CacheListener
AttributesMutator mutator = region.getAttributesMutator();
mutator.setCacheWriter(new CountingCacheWriter());
mutator.addCacheListener(new CountingCacheListener());
// add AsyncEventQueue
addAsyncEventQueue(region, name);
}
}
return null;
}
};
// add callbacks
forEachVm(callbacks, true);
// load all regions with invoke callbacks enabled
SnapshotOptions options = service.createOptions();
options.invokeCallbacks(true);
loadRegions(dir, options);
// verify callbacks were invoked
verifyCallbacksInvoked();
}
use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.
the class ConnectionPoolAndLoaderDUnitTest method testPoolLoadAndPeer.
/**
* Test that we can have a peer, a server, and a bridge loader for the same region.
*
* Expected order 1 localCache 2 peer 3 server 4 loader
*/
@Test
public void testPoolLoadAndPeer() throws Exception {
final String regionName = this.getName();
final Host host = Host.getHost(0);
VM server = host.getVM(0);
VM client1 = host.getVM(1);
VM client2 = host.getVM(2);
final int serverPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
server.invoke(new SerializableCallable() {
public Object call() throws IOException {
Cache cache = getCache();
AttributesFactory af = new AttributesFactory();
RegionAttributes attrs = af.create();
cache.createRegion(regionName, attrs);
startBridgeServer(serverPort, true);
return null;
}
});
SerializableCallable createClient1 = new SerializableCallable() {
public Object call() {
// Make sure we get a distributed system that has the locator
useLocator = true;
Cache cache = getCache();
useLocator = false;
PoolFactory factory = PoolManager.createFactory();
factory.addServer(NetworkUtils.getServerHostName(host), serverPort);
factory.create("pool1");
AttributesFactory af = new AttributesFactory();
af.setDataPolicy(DataPolicy.NORMAL);
af.setScope(Scope.DISTRIBUTED_ACK);
af.setPoolName("pool1");
af.setCacheLoader(new MyCacheLoader("loaded1"));
RegionAttributes attrs = af.create();
cache.createRegion(regionName, attrs);
return null;
}
};
client1.invoke(createClient1);
SerializableCallable createClient2 = new SerializableCallable() {
public Object call() {
// Make sure we get a distributed system that has the locator
useLocator = true;
Cache cache = getCache();
useLocator = false;
PoolFactory factory = PoolManager.createFactory();
factory.addServer(NetworkUtils.getServerHostName(host), serverPort);
factory.create("pool1");
AttributesFactory af = new AttributesFactory();
af.setDataPolicy(DataPolicy.NORMAL);
af.setScope(Scope.DISTRIBUTED_ACK);
af.setCacheLoader(new MyCacheLoader("loaded2"));
af.setPoolName("pool1");
RegionAttributes attrs = af.create();
cache.createRegion(regionName, attrs);
return null;
}
};
client2.invoke(createClient2);
// We need to test what happens when
// we do a load in client1 in each of these cases:
// Case On Server On Client 1 On Client 2 Expected
// a X server
// b X X client1
// c X X X client1
// d X X client2
// e X client1
// f X X client1
// g X client2 (loader does a netSearch)
// h client1 loader
// Setup scenarios
client1.invoke(new SerializableRunnable() {
public void run() {
Region region = getRootRegion(regionName);
region.put("b", "client1-b");
region.put("c", "client1-c");
region.put("e", "client1-e");
region.put("f", "client1-f");
}
});
client2.invoke(new SerializableRunnable() {
public void run() {
Region region = getRootRegion(regionName);
assertEquals("client1-c", region.get("c"));
region.put("d", "client2-d");
assertEquals("client1-f", region.get("f"));
region.put("g", "client2-g");
}
});
server.invoke(new SerializableRunnable() {
public void run() {
Region region = getRootRegion(regionName);
region.put("a", "server-a");
region.localDestroy("e");
region.localDestroy("f");
region.localDestroy("g");
}
});
// Test the scenarios
client1.invoke(new SerializableRunnable() {
public void run() {
Region region = getRootRegion(regionName);
assertEquals("server-a", region.get("a"));
assertEquals("client1-b", region.get("b"));
assertEquals("client1-c", region.get("c"));
assertEquals("client2-d", region.get("d"));
assertEquals("client1-e", region.get("e"));
assertEquals("client1-f", region.get("f"));
assertEquals("client2-g", region.get("g"));
assertEquals("loaded1-h", region.get("h"));
}
});
server.invoke(new SerializableRunnable() {
public void run() {
Region region = getRootRegion(regionName);
assertEquals("server-a", region.get("a"));
assertEquals("client1-b", region.get("b"));
assertEquals("client1-c", region.get("c"));
assertEquals("client2-d", region.get("d"));
assertEquals(null, region.get("e"));
assertEquals(null, region.get("f"));
// dsmith - This result seems somewhat suspect. client1 did a net load
// which found a value in client2, but it never propagated that result
// to the server. After talking with Darrel we decided to keep it this
// way for now.
assertEquals(null, region.get("g"));
assertEquals("loaded1-h", region.get("h"));
}
});
}
use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.
the class SelectStarQueryDUnitTest method startReplicatedCacheServer.
private int startReplicatedCacheServer(VM vm) {
final int port = (Integer) vm.invoke(new SerializableCallable("Create Server1") {
@Override
public Object call() throws Exception {
Region r1 = getCache().createRegionFactory(RegionShortcut.REPLICATE).create(regName);
Region r2 = getCache().createRegionFactory(RegionShortcut.REPLICATE).create(regName2);
// put domain objects
for (int i = 0; i < 10; i++) {
r1.put("key-" + i, new PortfolioPdx(i));
r2.put("key-" + i, new PortfolioPdx(i));
}
CacheServer server = getCache().addCacheServer();
int port = AvailablePortHelper.getRandomAvailablePortForDUnitSite();
server.setPort(port);
server.start();
return port;
}
});
return port;
}
Aggregations