use of org.apache.geode.cache.TimeoutException in project geode by apache.
the class SearchAndLoadDUnitTest method testLocalLoad.
@Test
public void testLocalLoad() throws CacheException, InterruptedException {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
final String name = this.getUniqueName() + "-ACK";
final String objectName = "C";
final Integer value = new Integer(44);
remoteLoaderInvoked = false;
loaderInvoked = false;
vm0.invoke(new SerializableRunnable("Create ACK Region") {
public void run() {
remoteLoaderInvoked = false;
loaderInvoked = false;
try {
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setEarlyAck(false);
factory.setCacheLoader(new CacheLoader() {
public Object load(LoaderHelper helper) {
loaderInvoked = true;
return value;
}
public void close() {
}
});
Region region = createRegion(name, factory.create());
region.create(objectName, null);
} catch (CacheException ex) {
Assert.fail("While creating ACK region", ex);
}
}
});
vm1.invoke(new SerializableRunnable("Create ACK Region") {
public void run() {
remoteLoaderInvoked = false;
loaderInvoked = false;
try {
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setEarlyAck(false);
factory.setCacheLoader(new CacheLoader() {
public Object load(LoaderHelper helper) {
remoteLoaderInvoked = true;
return value;
}
public void close() {
}
});
createRegion(name, factory.create());
} catch (CacheException ex) {
Assert.fail("While creating ACK region", ex);
}
}
});
vm0.invoke(new SerializableRunnable("Get a value from local loader") {
public void run() {
try {
Object result = getRootRegion().getSubregion(name).get(objectName);
assertEquals(value, result);
assertEquals(new Boolean(loaderInvoked), Boolean.TRUE);
assertEquals(new Boolean(remoteLoaderInvoked), Boolean.FALSE);
} catch (CacheLoaderException cle) {
} catch (TimeoutException te) {
}
}
});
}
use of org.apache.geode.cache.TimeoutException in project geode by apache.
the class SearchAndLoadDUnitTest method testNetSearch.
@Test
public void testNetSearch() throws CacheException, InterruptedException {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
final String name = this.getUniqueName() + "-ACK";
final String objectName = "NetSearchKey";
final Integer value = new Integer(440);
vm0.invoke(new SerializableRunnable("Create ACK Region") {
public void run() {
try {
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setEarlyAck(false);
factory.setStatisticsEnabled(true);
Region region = createRegion(name, factory.create());
region.create(objectName, null);
} catch (CacheException ex) {
Assert.fail("While creating ACK region", ex);
}
}
});
vm1.invoke(new SerializableRunnable("Create ACK Region") {
public void run() {
try {
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setEarlyAck(false);
factory.setStatisticsEnabled(true);
Region region = createRegion(name, factory.create());
region.put(objectName, value);
} catch (CacheException ex) {
Assert.fail("While creating ACK region", ex);
}
}
});
vm2.invoke(new SerializableRunnable("Create ACK Region") {
public void run() {
try {
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setEarlyAck(false);
factory.setStatisticsEnabled(true);
Region region = createRegion(name, factory.create());
region.create(objectName, null);
} catch (CacheException ex) {
Assert.fail("While creating ACK region", ex);
}
}
});
vm0.invoke(new SerializableRunnable("Get a value") {
public void run() {
try {
Object result = null;
result = getRootRegion().getSubregion(name).get(objectName);
assertEquals(value, result);
// System.err.println("Results is " + result.toString() + " Key is " +
// objectName.toString());
} catch (CacheLoaderException cle) {
Assert.fail("While Get a value", cle);
} catch (TimeoutException te) {
Assert.fail("While Get a value", te);
}
}
});
}
use of org.apache.geode.cache.TimeoutException in project geode by apache.
the class SearchAndLoadDUnitTest method testEmptyNetLoad.
/**
* Confirm that a netLoad that returns null will NOT allow other netLoad methods to be called.
*/
@Test
public void testEmptyNetLoad() throws CacheException, InterruptedException {
disconnectAllFromDS();
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
final String name = this.getUniqueName() + "-ACK";
final String objectName = "B";
loaderInvoked = false;
remoteLoaderInvoked = false;
remoteLoaderInvokedCount = 0;
vm0.invoke(new SerializableRunnable("Create ACK Region") {
public void run() {
loaderInvoked = false;
remoteLoaderInvoked = false;
remoteLoaderInvokedCount = 0;
try {
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setEarlyAck(false);
// factory.setCacheLoader(new CacheLoader() {
// public Object load(LoaderHelper helper) {
/// loaderInvoked = true;
// return value;
// }
//
// public void close() {
//
// }
// });
Region region = createRegion(name, factory.create());
region.create(objectName, null);
} catch (CacheException ex) {
Assert.fail("While creating ACK region", ex);
}
}
});
SerializableRunnable installLoader = new SerializableRunnable("Create ACK Region") {
public void run() {
loaderInvoked = false;
remoteLoaderInvoked = false;
remoteLoaderInvokedCount = 0;
try {
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setEarlyAck(false);
factory.setCacheLoader(new CacheLoader() {
public Object load(LoaderHelper helper) {
remoteLoaderInvoked = true;
remoteLoaderInvokedCount++;
return null;
}
public void close() {
}
});
createRegion(name, factory.create());
} catch (CacheException ex) {
Assert.fail("While creating ACK region", ex);
}
}
};
vm1.invoke(installLoader);
vm2.invoke(installLoader);
vm0.invoke(new SerializableRunnable("Get a value from remote loader") {
public void run() {
for (int i = 0; i < 1; i++) {
try {
Object result = getRootRegion().getSubregion(name).get(objectName);
assertEquals(null, result);
assertEquals(false, loaderInvoked);
// getRootRegion().getSubregion(name).invalidate(objectName);
} catch (CacheLoaderException cle) {
Assert.fail("While getting value for ACK region", cle);
}/*
* catch(EntryNotFoundException enfe) { fail("While getting value for ACK region", enfe);
*
* }
*/
catch (TimeoutException te) {
Assert.fail("While getting value for ACK region", te);
}
}
}
});
// we only invoke one netLoad loader even when they return null.
boolean xor = vmRemoteLoaderInvoked(vm1) ^ vmRemoteLoaderInvoked(vm2);
assertEquals("vm1=" + vmRemoteLoaderInvoked(vm1) + " vm2=" + vmRemoteLoaderInvoked(vm2) + " vm1Count=" + vmRemoteLoaderInvokedCount(vm1) + " vm2Count=" + vmRemoteLoaderInvokedCount(vm2), true, xor);
int total = vmRemoteLoaderInvokedCount(vm1) + vmRemoteLoaderInvokedCount(vm2);
assertEquals("vm1=" + vmRemoteLoaderInvokedCount(vm1) + " vm2=" + vmRemoteLoaderInvokedCount(vm2), 1, total);
}
use of org.apache.geode.cache.TimeoutException in project geode by apache.
the class RemoveGlobalDUnitTest method testRemoveGlobalSingleVM.
// test methods
@Test
public void testRemoveGlobalSingleVM() throws Throwable {
SerializableRunnable createRegionWithWriter = new CacheSerializableRunnable("create region with cache writer") {
public void run2() throws CacheException {
cache.setLockTimeout(5);
CacheWriter cacheWriter = new CacheWriterCallBack();
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.GLOBAL);
factory.setCacheWriter(cacheWriter);
region = cache.createRegion("map", factory.create());
}
};
vm0.invoke(createRegionWithWriter);
AsyncInvocation async = vm0.invokeAsync(new CacheSerializableRunnable("put object") {
public void run2() throws CacheException {
for (int i = 1; i < 5; i++) {
region.put(new Integer(i), java.lang.Integer.toString(i));
}
region.remove(new Integer(2));
}
});
vm0.invoke(new CacheSerializableRunnable("verify locking") {
public void run2() throws CacheException {
synchronized (RemoveGlobalDUnitTest.class) {
if (!lockedForRemove) {
try {
RemoveGlobalDUnitTest.class.wait();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
try {
// getLogWriter().fine("000000000000000");
region.put(new Integer(2), "newEntry");
fail("Should have thrown TimeoutException");
} catch (TimeoutException tme) {
// pass
}
}
});
ThreadUtils.join(async, 30 * 1000);
if (async.exceptionOccurred())
throw async.getException();
}
use of org.apache.geode.cache.TimeoutException in project geode by apache.
the class GlobalLockingDUnitTest method testDestroyLockTimeout.
/**
* get lock in one VM, try to destroy in other
*/
@Test
public void testDestroyLockTimeout() {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
final String name = this.getUniqueName();
final Object key = new Integer(5);
vm0.invoke(new CacheSerializableRunnable("Get lock") {
public void run2() throws CacheException {
Region r = getOrCreateRootRegion().createSubregion(name, getGlobalAttrs());
Lock lock = r.getDistributedLock(key);
lock.lock();
r.put(key, "value");
}
});
vm1.invoke(new CacheSerializableRunnable("Lock timeout destroying entry") {
public void run2() throws CacheException {
getOrCreateRootRegion().getCache().setLockTimeout(2);
Region r = getOrCreateRootRegion().createSubregion(name, getGlobalAttrs());
r.get(key);
try {
r.destroy(key);
fail("destroy() should have thrown TimeoutException");
} catch (TimeoutException ex) {
// pass
}
}
});
}
Aggregations