use of org.apache.geode.cache.CacheLoaderException in project geode by apache.
the class MultiVMRegionTestCase method testMirroredNetLoad.
/**
* Tests sure that a <code>netLoad</code> occurs, even with mirroring
*/
@Test
public void testMirroredNetLoad() throws Exception {
assumeTrue(supportsReplication());
final String name = this.getUniqueName();
final Object key = "KEY";
final Object value = "VALUE";
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
// use VMs on different gemfire systems
VM vm2 = host.getVM(2);
SerializableRunnable create = new CacheSerializableRunnable("Create region with loader") {
@Override
public void run2() throws CacheException {
RegionAttributes ra = getRegionAttributes();
AttributesFactory factory = new AttributesFactory(ra);
if (ra.getEvictionAttributes() == null || !ra.getEvictionAttributes().getAction().isOverflowToDisk()) {
factory.setDiskStoreName(null);
}
factory.setDataPolicy(DataPolicy.REPLICATE);
factory.setCacheLoader(new TestCacheLoader() {
@Override
public Object load2(LoaderHelper helper) throws CacheLoaderException {
return value;
}
});
createRegion(name, factory.create());
}
};
vm0.invoke(new CacheSerializableRunnable("Create region with bad loader") {
@Override
public void run2() throws CacheException {
RegionAttributes ra = getRegionAttributes();
AttributesFactory factory = new AttributesFactory(ra);
if (ra.getEvictionAttributes() == null || !ra.getEvictionAttributes().getAction().isOverflowToDisk()) {
factory.setDiskStoreName(null);
}
factory.setDataPolicy(DataPolicy.REPLICATE);
createRegion(name, factory.create());
}
});
vm2.invoke(create);
vm0.invoke(new CacheSerializableRunnable("Get") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
assertEquals(value, region.get(key));
}
});
}
use of org.apache.geode.cache.CacheLoaderException in project geode by apache.
the class ClientRegisterInterestDUnitTest method testRegisterInterestFailover.
/**
* Tests failover of register interest from client point of view. Related bugs include:
*
* <p>
* Bug 35654 "failed re-registration may never be detected and thus may never re-re-register"
*
* <p>
* Bug 35639 "registerInterest re-registration happens everytime a healthy server is detected"
*
* <p>
* Bug 35655 "a single failed re-registration causes all other pending re-registrations to be
* cancelled"
*/
@Ignore("TODO")
@Test
public void testRegisterInterestFailover() throws Exception {
// controller is bridge client
final Host host = Host.getHost(0);
final String name = this.getUniqueName();
final String regionName1 = name + "-1";
final String regionName2 = name + "-2";
final String regionName3 = name + "-3";
final String key1 = "KEY-" + regionName1 + "-1";
final String key2 = "KEY-" + regionName1 + "-2";
final String key3 = "KEY-" + regionName1 + "-3";
// 3 servers in this test
final int[] ports = new int[3];
// create first bridge server with region for client...
final int firstServerIdx = 0;
final VM firstServerVM = Host.getHost(0).getVM(firstServerIdx);
firstServerVM.invoke(new CacheSerializableRunnable("Create first bridge server") {
public void run2() throws CacheException {
LogWriterUtils.getLogWriter().info("[testRegisterInterestFailover] Create first bridge server");
getSystem();
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
Region region1 = createRootRegion(regionName1, factory.create());
Region region2 = createRootRegion(regionName2, factory.create());
Region region3 = createRootRegion(regionName3, factory.create());
region1.put(key1, "VAL-1");
region2.put(key2, "VAL-1");
region3.put(key3, "VAL-1");
try {
bridgeServerPort = startBridgeServer(0);
} catch (IOException e) {
LogWriterUtils.getLogWriter().error("startBridgeServer threw IOException", e);
fail("startBridgeServer threw IOException ", e);
}
assertTrue(bridgeServerPort != 0);
LogWriterUtils.getLogWriter().info("[testRegisterInterestFailover] " + "firstServer port=" + bridgeServerPort);
LogWriterUtils.getLogWriter().info("[testRegisterInterestFailover] " + "firstServer memberId=" + getMemberId());
}
});
// create second bridge server missing region for client...
final int secondServerIdx = 1;
final VM secondServerVM = Host.getHost(0).getVM(secondServerIdx);
secondServerVM.invoke(new CacheSerializableRunnable("Create second bridge server") {
public void run2() throws CacheException {
LogWriterUtils.getLogWriter().info("[testRegisterInterestFailover] Create second bridge server");
getSystem();
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
Region region1 = createRootRegion(regionName1, factory.create());
Region region3 = createRootRegion(regionName3, factory.create());
region1.put(key1, "VAL-2");
region3.put(key3, "VAL-2");
try {
bridgeServerPort = startBridgeServer(0);
} catch (IOException e) {
LogWriterUtils.getLogWriter().error("startBridgeServer threw IOException", e);
fail("startBridgeServer threw IOException ", e);
}
assertTrue(bridgeServerPort != 0);
LogWriterUtils.getLogWriter().info("[testRegisterInterestFailover] " + "secondServer port=" + bridgeServerPort);
LogWriterUtils.getLogWriter().info("[testRegisterInterestFailover] " + "secondServer memberId=" + getMemberId());
}
});
// get the bridge server ports...
ports[firstServerIdx] = firstServerVM.invoke(() -> ClientRegisterInterestDUnitTest.getBridgeServerPort());
assertTrue(ports[firstServerIdx] != 0);
ports[secondServerIdx] = secondServerVM.invoke(() -> ClientRegisterInterestDUnitTest.getBridgeServerPort());
assertTrue(ports[secondServerIdx] != 0);
assertTrue(ports[firstServerIdx] != ports[secondServerIdx]);
// stop second and third servers
secondServerVM.invoke(new CacheSerializableRunnable("Stop second bridge server") {
public void run2() throws CacheException {
stopBridgeServers(getCache());
}
});
// create the bridge client
LogWriterUtils.getLogWriter().info("[testBug35654] create bridge client");
Properties config = new Properties();
config.setProperty(MCAST_PORT, "0");
config.setProperty(LOCATORS, "");
getSystem(config);
getCache();
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
LogWriterUtils.getLogWriter().info("[testRegisterInterestFailover] creating connection pool");
boolean establishCallbackConnection = true;
final PoolImpl p = (PoolImpl) ClientServerTestCase.configureConnectionPool(factory, NetworkUtils.getServerHostName(host), ports, establishCallbackConnection, -1, -1, null);
final Region region1 = createRootRegion(regionName1, factory.create());
final Region region2 = createRootRegion(regionName2, factory.create());
final Region region3 = createRootRegion(regionName3, factory.create());
assertTrue(region1.getInterestList().isEmpty());
assertTrue(region2.getInterestList().isEmpty());
assertTrue(region3.getInterestList().isEmpty());
region1.registerInterest(key1);
region2.registerInterest(key2);
region3.registerInterest(key3);
assertTrue(region1.getInterestList().contains(key1));
assertTrue(region2.getInterestList().contains(key2));
assertTrue(region3.getInterestList().contains(key3));
assertTrue(region1.getInterestListRegex().isEmpty());
assertTrue(region2.getInterestListRegex().isEmpty());
assertTrue(region3.getInterestListRegex().isEmpty());
// get ConnectionProxy and wait until connected to first server
WaitCriterion ev = new WaitCriterion() {
public boolean done() {
return p.getPrimaryPort() != -1;
}
public String description() {
return "primary port remained invalid";
}
};
Wait.waitForCriterion(ev, 10 * 1000, 200, true);
assertEquals(ports[firstServerIdx], p.getPrimaryPort());
// assert intial values
assertEquals("VAL-1", region1.get(key1));
assertEquals("VAL-1", region2.get(key2));
assertEquals("VAL-1", region3.get(key3));
// do puts on server1 and make sure values come thru for all 3 registrations
firstServerVM.invoke(new CacheSerializableRunnable("Puts from first bridge server") {
public void run2() throws CacheException {
Region region1 = getCache().getRegion(regionName1);
region1.put(key1, "VAL-1-1");
Region region2 = getCache().getRegion(regionName2);
region2.put(key2, "VAL-1-1");
Region region3 = getCache().getRegion(regionName3);
region3.put(key3, "VAL-1-1");
}
});
ev = new WaitCriterion() {
public boolean done() {
if (!"VAL-1-1".equals(region1.get(key1)) || !"VAL-1-1".equals(region2.get(key2)) || !"VAL-1-1".equals(region3.get(key3)))
return false;
return true;
}
public String description() {
return null;
}
};
Wait.waitForCriterion(ev, 10 * 1000, 200, true);
assertEquals("VAL-1-1", region1.get(key1));
assertEquals("VAL-1-1", region2.get(key2));
assertEquals("VAL-1-1", region3.get(key3));
// force failover to server 2
secondServerVM.invoke(new CacheSerializableRunnable("Start second bridge server") {
public void run2() throws CacheException {
try {
startBridgeServer(ports[secondServerIdx]);
} catch (IOException e) {
LogWriterUtils.getLogWriter().error("startBridgeServer threw IOException", e);
fail("startBridgeServer threw IOException ", e);
}
}
});
firstServerVM.invoke(new CacheSerializableRunnable("Stop first bridge server") {
public void run2() throws CacheException {
stopBridgeServers(getCache());
}
});
// wait for failover to second server
ev = new WaitCriterion() {
public boolean done() {
return ports[secondServerIdx] == p.getPrimaryPort();
}
public String description() {
return "primary port never became " + ports[secondServerIdx];
}
};
Wait.waitForCriterion(ev, 100 * 1000, 200, true);
try {
assertEquals(null, region2.get(key2));
fail("CacheLoaderException expected");
} catch (CacheLoaderException e) {
}
// region2 registration should be gone now
// do puts on server2 and make sure values come thru for only 2 registrations
secondServerVM.invoke(new CacheSerializableRunnable("Puts from second bridge server") {
public void run2() throws CacheException {
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
createRootRegion(regionName2, factory.create());
}
});
// assert that there is no actively registered interest on region2
assertTrue(region2.getInterestList().isEmpty());
assertTrue(region2.getInterestListRegex().isEmpty());
region2.put(key2, "VAL-0");
secondServerVM.invoke(new CacheSerializableRunnable("Put from second bridge server") {
public void run2() throws CacheException {
Region region1 = getCache().getRegion(regionName1);
region1.put(key1, "VAL-2-2");
Region region2 = getCache().getRegion(regionName2);
region2.put(key2, "VAL-2-1");
Region region3 = getCache().getRegion(regionName3);
region3.put(key3, "VAL-2-2");
}
});
// wait for updates to come thru
ev = new WaitCriterion() {
public boolean done() {
if (!"VAL-2-2".equals(region1.get(key1)) || !"VAL-2-2".equals(region3.get(key3)))
return false;
return true;
}
public String description() {
return null;
}
};
Wait.waitForCriterion(ev, 100 * 1000, 200, true);
assertEquals("VAL-2-2", region1.get(key1));
assertEquals("VAL-0", region2.get(key2));
assertEquals("VAL-2-2", region3.get(key3));
// assert again that there is no actively registered interest on region2
assertTrue(region2.getInterestList().isEmpty());
// register interest again on region2 and make
region2.registerInterest(key2);
assertEquals("VAL-2-1", region2.get(key2));
secondServerVM.invoke(new CacheSerializableRunnable("Put from second bridge server") {
public void run2() throws CacheException {
Region region1 = getCache().getRegion(regionName1);
region1.put(key1, "VAL-2-3");
Region region2 = getCache().getRegion(regionName2);
region2.put(key2, "VAL-2-2");
Region region3 = getCache().getRegion(regionName3);
region3.put(key3, "VAL-2-3");
}
});
// wait for updates to come thru
ev = new WaitCriterion() {
public boolean done() {
if (!"VAL-2-3".equals(region1.get(key1)) || !"VAL-2-2".equals(region2.get(key2)) || !"VAL-2-3".equals(region3.get(key3)))
return false;
return true;
}
public String description() {
return null;
}
};
Wait.waitForCriterion(ev, 100 * 1000, 200, true);
assertEquals("VAL-2-3", region1.get(key1));
assertEquals("VAL-2-2", region2.get(key2));
assertEquals("VAL-2-3", region3.get(key3));
// assert public methods report actively registered interest on region2
assertTrue(region2.getInterestList().contains(key2));
}
use of org.apache.geode.cache.CacheLoaderException in project geode by apache.
the class MultiVMRegionTestCase method testCacheLoaderWithNetLoad.
@Test
public void testCacheLoaderWithNetLoad() throws Exception {
// replicated regions and partitioned regions make no sense for this
// test
assumeFalse(getRegionAttributes().getDataPolicy().withReplication());
assumeFalse(getRegionAttributes().getDataPolicy().isPreloaded());
assumeTrue(getRegionAttributes().getPartitionAttributes() == null);
final String name = this.getUniqueName();
final Object key = this.getUniqueName();
final Object value = new Integer(42);
Host host = Host.getHost(0);
// use vm on other gemfire system
VM vm1 = host.getVM(1);
vm1.invoke(new CacheSerializableRunnable("set up remote loader") {
@Override
public void run2() throws CacheException {
final TestCacheLoader remoteloader = new TestCacheLoader() {
@Override
public Object load2(LoaderHelper helper) throws CacheLoaderException {
assertEquals(key, helper.getKey());
assertEquals(name, helper.getRegion().getName());
return value;
}
};
AttributesFactory factory = new AttributesFactory(getRegionAttributes());
factory.setCacheLoader(remoteloader);
createRegion(name, factory.create());
}
});
final TestCacheLoader loader1 = new TestCacheLoader() {
@Override
public Object load2(LoaderHelper helper) throws CacheLoaderException {
assertEquals(key, helper.getKey());
assertEquals(name, helper.getRegion().getName());
try {
helper.getRegion().getAttributes();
Object result = helper.netSearch(true);
assertEquals(value, result);
return result;
} catch (TimeoutException ex) {
fail("Why did I time out?", ex);
}
return null;
}
};
AttributesFactory f = new AttributesFactory(getRegionAttributes());
f.setCacheLoader(loader1);
Region region = createRegion(name, f.create());
loader1.wasInvoked();
Region.Entry entry = region.getEntry(key);
assertNull(entry);
region.create(key, null);
entry = region.getEntry(key);
assertNotNull(entry);
assertNull(entry.getValue());
assertEquals(value, region.get(key));
assertTrue(loader1.wasInvoked());
assertEquals(value, region.getEntry(key).getValue());
}
use of org.apache.geode.cache.CacheLoaderException in project geode by apache.
the class MultiVMRegionTestCase method testTXUpdateLoadNoConflict.
/**
* Tests that the push of a loaded value does not cause a conflict on the side receiving the
* update
*/
@Ignore("TODO: this test always hits early out")
@Test
public void testTXUpdateLoadNoConflict() throws Exception {
/*
* this no longer holds true - we have load conflicts now
*
*/
if (true) {
return;
}
assumeTrue(supportsTransactions());
assumeFalse(getRegionAttributes().getScope().isGlobal());
assumeFalse(getRegionAttributes().getDataPolicy().withPersistence());
assertTrue(getRegionAttributes().getScope().isDistributed());
CacheTransactionManager txMgr = this.getCache().getCacheTransactionManager();
final String rgnName = getUniqueName();
SerializableRunnable create = new SerializableRunnable("testTXUpdateLoadNoConflict: Create Region & Load value") {
@Override
public void run() {
CacheTransactionManager txMgr2 = getCache().getCacheTransactionManager();
MyTransactionListener tl = new MyTransactionListener();
txMgr2.addListener(tl);
try {
Region rgn = createRegion(rgnName);
AttributesMutator mutator = rgn.getAttributesMutator();
mutator.setCacheLoader(new CacheLoader() {
int count = 0;
@Override
public Object load(LoaderHelper helper) throws CacheLoaderException {
count++;
return "LV " + count;
}
@Override
public void close() {
}
});
Object value = rgn.get("key");
assertEquals("LV 1", value);
getSystem().getLogWriter().info("testTXUpdateLoadNoConflict: loaded Key");
flushIfNecessary(rgn);
} catch (CacheException e) {
fail("While creating region", e);
}
}
};
VM vm0 = Host.getHost(0).getVM(0);
try {
MyTransactionListener tl = new MyTransactionListener();
txMgr.addListener(tl);
AttributesFactory rgnAtts = new AttributesFactory(getRegionAttributes());
rgnAtts.setDataPolicy(DataPolicy.REPLICATE);
Region rgn = createRegion(rgnName, rgnAtts.create());
txMgr.begin();
TransactionId myTXId = txMgr.getTransactionId();
rgn.create("key", "txValue");
vm0.invoke(create);
{
TXStateProxy tx = ((TXManagerImpl) txMgr).internalSuspend();
assertTrue(rgn.containsKey("key"));
assertEquals("LV 1", rgn.getEntry("key").getValue());
((TXManagerImpl) txMgr).internalResume(tx);
}
// make sure transactional view is still correct
assertEquals("txValue", rgn.getEntry("key").getValue());
txMgr.commit();
getSystem().getLogWriter().info("testTXUpdateLoadNoConflict: did commit");
assertEquals("txValue", rgn.getEntry("key").getValue());
{
Collection events = tl.lastEvent.getCreateEvents();
assertEquals(1, events.size());
EntryEvent ev = (EntryEvent) events.iterator().next();
assertEquals(myTXId, ev.getTransactionId());
assertTrue(ev.getRegion() == rgn);
assertEquals("key", ev.getKey());
assertEquals("txValue", ev.getNewValue());
assertEquals(null, ev.getOldValue());
assertTrue(!ev.getOperation().isLocalLoad());
assertTrue(!ev.getOperation().isNetLoad());
assertTrue(!ev.getOperation().isLoad());
assertTrue(!ev.getOperation().isNetSearch());
assertTrue(!ev.getOperation().isExpiration());
assertEquals(null, ev.getCallbackArgument());
assertEquals(true, ev.isCallbackArgumentAvailable());
assertTrue(!ev.isOriginRemote());
assertTrue(ev.getOperation().isDistributed());
}
// Now setup recreate the region in the controller with NONE
// so test can do local destroys.
rgn.localDestroyRegion();
rgnAtts.setDataPolicy(DataPolicy.NORMAL);
rgn = createRegion(rgnName, rgnAtts.create());
// now see if net loader is working
Object v2 = rgn.get("key2");
assertEquals("LV 2", v2);
// now confirm that netload does not cause a conflict
txMgr.begin();
myTXId = txMgr.getTransactionId();
rgn.create("key3", "txValue3");
{
TXStateProxy tx = ((TXManagerImpl) txMgr).internalSuspend();
// do a get outside of the transaction to force a net load
Object v3 = rgn.get("key3");
assertEquals("LV 3", v3);
((TXManagerImpl) txMgr).internalResume(tx);
}
// make sure transactional view is still correct
assertEquals("txValue3", rgn.getEntry("key3").getValue());
txMgr.commit();
getSystem().getLogWriter().info("testTXUpdateLoadNoConflict: did commit");
assertEquals("txValue3", rgn.getEntry("key3").getValue());
{
Collection events = tl.lastEvent.getCreateEvents();
assertEquals(1, events.size());
EntryEvent ev = (EntryEvent) events.iterator().next();
assertEquals(myTXId, ev.getTransactionId());
assertTrue(ev.getRegion() == rgn);
assertEquals("key3", ev.getKey());
assertEquals("txValue3", ev.getNewValue());
assertEquals(null, ev.getOldValue());
assertTrue(!ev.getOperation().isLocalLoad());
assertTrue(!ev.getOperation().isNetLoad());
assertTrue(!ev.getOperation().isLoad());
assertTrue(!ev.getOperation().isNetSearch());
assertTrue(!ev.getOperation().isExpiration());
assertEquals(null, ev.getCallbackArgument());
assertEquals(true, ev.isCallbackArgumentAvailable());
assertTrue(!ev.isOriginRemote());
assertTrue(ev.getOperation().isDistributed());
}
// now see if tx net loader is working
// now confirm that netload does not cause a conflict
txMgr.begin();
myTXId = txMgr.getTransactionId();
Object v4 = rgn.get("key4");
assertEquals("LV 4", v4);
assertEquals("LV 4", rgn.get("key4"));
assertEquals("LV 4", rgn.getEntry("key4").getValue());
txMgr.rollback();
// confirm that netLoad is transactional
assertEquals("LV 5", rgn.get("key4"));
assertEquals("LV 5", rgn.getEntry("key4").getValue());
// make sure non-tx netsearch works
assertEquals("txValue", rgn.get("key"));
assertEquals("txValue", rgn.getEntry("key").getValue());
// make sure net-search result does not conflict with commit
rgn.localInvalidate("key");
txMgr.begin();
myTXId = txMgr.getTransactionId();
rgn.put("key", "new txValue");
{
TXStateProxy tx = ((TXManagerImpl) txMgr).internalSuspend();
// do a get outside of the transaction to force a netsearch
// does a netsearch
assertEquals("txValue", rgn.get("key"));
assertEquals("txValue", rgn.getEntry("key").getValue());
((TXManagerImpl) txMgr).internalResume(tx);
}
// make sure transactional view is still correct
assertEquals("new txValue", rgn.getEntry("key").getValue());
txMgr.commit();
// give other side change to process commit
flushIfNecessary(rgn);
getSystem().getLogWriter().info("testTXUpdateLoadNoConflict: did commit");
assertEquals("new txValue", rgn.getEntry("key").getValue());
{
Collection events = tl.lastEvent.getPutEvents();
assertEquals(1, events.size());
EntryEvent ev = (EntryEvent) events.iterator().next();
assertEquals(myTXId, ev.getTransactionId());
assertTrue(ev.getRegion() == rgn);
assertEquals("key", ev.getKey());
assertEquals("new txValue", ev.getNewValue());
assertEquals(null, ev.getOldValue());
assertTrue(!ev.getOperation().isLocalLoad());
assertTrue(!ev.getOperation().isNetLoad());
assertTrue(!ev.getOperation().isLoad());
assertTrue(!ev.getOperation().isNetSearch());
assertTrue(!ev.getOperation().isExpiration());
assertEquals(null, ev.getCallbackArgument());
assertEquals(true, ev.isCallbackArgumentAvailable());
assertTrue(!ev.isOriginRemote());
assertTrue(ev.getOperation().isDistributed());
}
// make sure tx local invalidate allows netsearch
Object localCmtValue = rgn.getEntry("key").getValue();
txMgr.begin();
assertSame(localCmtValue, rgn.getEntry("key").getValue());
rgn.localInvalidate("key");
assertNull(rgn.getEntry("key").getValue());
// now make sure a get will do a netsearch and find the value
// in the other vm instead of the one in local cmt state
Object txValue = rgn.get("key");
assertNotSame(localCmtValue, txValue);
assertSame(txValue, rgn.get("key"));
assertNotSame(localCmtValue, rgn.getEntry("key").getValue());
// make sure we did a search and not a load
assertEquals(localCmtValue, rgn.getEntry("key").getValue());
// now make sure that if we do a tx distributed invalidate
// that we will do a load and not a search
rgn.invalidate("key");
assertNull(rgn.getEntry("key").getValue());
txValue = rgn.get("key");
assertEquals("LV 6", txValue);
assertSame(txValue, rgn.get("key"));
assertEquals("LV 6", rgn.getEntry("key").getValue());
// now make sure after rollback that local cmt state has not changed
txMgr.rollback();
assertSame(localCmtValue, rgn.getEntry("key").getValue());
} catch (Exception e) {
CacheFactory.getInstance(getSystem()).close();
getSystem().getLogWriter().fine("testTXUpdateLoadNoConflict: Caused exception in createRegion");
throw e;
}
}
use of org.apache.geode.cache.CacheLoaderException in project geode by apache.
the class MultiVMRegionTestCase method testCacheLoaderModifyingArgument.
/**
* Tests that when a <code>CacheLoader</code> modifies the callback argument in place, the change
* is visible to the <code>CacheWriter</code> even if it is in another VM.
*/
@Test
public void testCacheLoaderModifyingArgument() throws Exception {
assertTrue(getRegionAttributes().getScope().isDistributed());
final String name = this.getUniqueName();
final Object key = "KEY";
final Object value = "VALUE";
final Object one = "ONE";
final Object two = "TWO";
SerializableRunnable create = new CacheSerializableRunnable("Create Region") {
@Override
public void run2() throws CacheException {
createRegion(name);
}
};
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
vm0.invoke(create);
vm1.invoke(create);
CacheSerializableRunnable setLoader = new CacheSerializableRunnable("Set CacheLoader") {
@Override
public void run2() throws CacheException {
final Region region = getRootRegion().getSubregion(name);
loader = new TestCacheLoader() {
@Override
public Object load2(LoaderHelper helper) throws CacheLoaderException {
Object[] array = (Object[]) helper.getArgument();
assertEquals(one, array[0]);
array[0] = two;
return value;
}
};
region.getAttributesMutator().setCacheLoader(loader);
flushIfNecessary(region);
}
};
vm0.invoke(setLoader);
// if this is a partitioned region, we need the loader in both vms
vm1.invoke(new CacheSerializableRunnable("Conditionally create second loader") {
@Override
public void run2() throws CacheException {
final Region region = getRootRegion().getSubregion(name);
if (region.getAttributes().getPartitionAttributes() != null) {
loader = new TestCacheLoader() {
@Override
public Object load2(LoaderHelper helper) throws CacheLoaderException {
Object[] array = (Object[]) helper.getArgument();
assertEquals(one, array[0]);
array[0] = two;
return value;
}
};
region.getAttributesMutator().setCacheLoader(loader);
}
}
});
vm1.invoke(new CacheSerializableRunnable("Set CacheWriter") {
@Override
public void run2() throws CacheException {
final Region region = getRootRegion().getSubregion(name);
writer = new TestCacheWriter() {
@Override
public void beforeCreate2(EntryEvent event) throws CacheWriterException {
Object[] array = (Object[]) event.getCallbackArgument();
assertEquals(two, array[0]);
}
};
region.getAttributesMutator().setCacheWriter(writer);
flushIfNecessary(region);
}
});
vm0.invoke(new CacheSerializableRunnable("Create entry") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
Object[] array = { one };
Object result = region.get(key, array);
assertTrue(loader.wasInvoked());
assertEquals(value, result);
}
});
vm1.invoke(new CacheSerializableRunnable("Validate callback") {
@Override
public void run2() throws CacheException {
assertTrue(writer.wasInvoked());
}
});
}
Aggregations