use of org.apache.geode.cache.TimeoutException in project geode by apache.
the class CqServiceImpl method closeCq.
@Override
public void closeCq(String cqName, ClientProxyMembershipID clientProxyId) throws CqException {
String serverCqName = cqName;
if (clientProxyId != null) {
serverCqName = this.constructServerCqName(cqName, clientProxyId);
removeFromCacheForServerToConstructedCQName(cqName, clientProxyId);
}
ServerCQImpl cQuery = null;
StringId errMsg = null;
Exception ex = null;
try {
HashMap<String, CqQueryImpl> cqMap = cqQueryMap;
if (!cqMap.containsKey(serverCqName)) {
/*
* gregp 052808: We should silently fail here instead of throwing error. This is to deal
* with races in recovery
*/
return;
}
cQuery = (ServerCQImpl) cqMap.get(serverCqName);
} catch (CacheLoaderException e1) {
errMsg = LocalizedStrings.CqService_CQ_NOT_FOUND_IN_THE_CQ_META_REGION_CQNAME_0;
ex = e1;
} catch (TimeoutException e2) {
errMsg = LocalizedStrings.CqService_TIMEOUT_WHILE_TRYING_TO_GET_CQ_FROM_META_REGION_CQNAME_0;
ex = e2;
} finally {
if (ex != null) {
String s = errMsg.toLocalizedString(cqName);
if (logger.isDebugEnabled()) {
logger.debug(s);
}
throw new CqException(s, ex);
}
}
try {
cQuery.close(false);
// CqBaseRegion
try {
LocalRegion baseRegion = cQuery.getCqBaseRegion();
if (baseRegion != null && !baseRegion.isDestroyed()) {
// Server specific clean up.
if (isServer()) {
FilterProfile fp = baseRegion.getFilterProfile();
if (fp != null) {
fp.closeCq(cQuery);
}
CacheClientProxy clientProxy = cQuery.getCacheClientNotifier().getClientProxy(clientProxyId);
clientProxy.decCqCount();
if (clientProxy.hasNoCq()) {
this.stats.decClientsWithCqs();
}
}
}
} catch (Exception e) {
// May be cache is being shutdown
if (logger.isDebugEnabled()) {
logger.debug("Failed to remove CQ from the base region. CqName : {}", cqName);
}
}
if (isServer()) {
removeFromBaseRegionToCqNameMap(cQuery.getRegionName(), serverCqName);
}
LocalRegion baseRegion = cQuery.getCqBaseRegion();
if (baseRegion.getFilterProfile().getCqCount() <= 0) {
if (logger.isDebugEnabled()) {
logger.debug("Should update the profile for this partitioned region {} for not requiring old value", baseRegion);
}
}
} catch (CqClosedException cce) {
throw new CqException(cce.getMessage());
} finally {
this.removeFromMatchingCqMap(cQuery);
}
}
use of org.apache.geode.cache.TimeoutException in project geode by apache.
the class PutAllGlobalDUnitTest method testputAllGlobalRemoteVM.
// test methods
@Test
public void testputAllGlobalRemoteVM() throws Throwable {
// Test Fails: AssertionError: Should have thrown TimeoutException
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
final int socketPort = vm0.invoke(() -> this.openSocket());
AsyncInvocation async1 = vm0.invokeAsync(() -> this.putAllMethod());
AsyncInvocation async2 = vm1.invokeAsync(new CacheSerializableRunnable("put from another vm") {
public void run2() throws CacheException {
long endTime = System.currentTimeMillis() + 5000;
boolean connected = false;
while (!connected && (System.currentTimeMillis() < endTime)) {
try {
Socket sock = new Socket(InetAddress.getLocalHost(), socketPort);
connected = true;
sock.close();
} catch (IOException ioe) {
// ignored - will time out using 'endTime'
try {
Thread.sleep(500);
} catch (InterruptedException ie) {
fail("Interrupted while waiting for async1 invocation");
}
}
}
if (!connected) {
fail("unable to connect to async1 invocation");
}
long startTime = 0;
try {
Thread.sleep(500);
LogWriterUtils.getLogWriter().info("async2 proceeding with put operation");
startTime = System.currentTimeMillis();
region.put(new Integer(1), "mapVal");
LogWriterUtils.getLogWriter().info("async2 done with put operation");
fail("Should have thrown TimeoutException");
} catch (TimeoutException Tx) {
// Tx.printStackTrace();
LogWriterUtils.getLogWriter().info("PASS: As expected Caught TimeoutException ");
if (startTime + TIMEOUT_PERIOD + DLockGrantor.GRANTOR_THREAD_MAX_WAIT < /* slop of grantor max wait ms */
System.currentTimeMillis()) {
LogWriterUtils.getLogWriter().warning("though this test passed, the put() timed out in " + (System.currentTimeMillis() - startTime) + " instead of the expected " + TIMEOUT_PERIOD + " milliseconds");
}
} catch (Exception ex) {
Assert.fail("async2 threw unexpected exception", ex);
// ex.printStackTrace();
}
}
});
ThreadUtils.join(async2, 30 * 1000);
if (async2.exceptionOccurred()) {
ThreadUtils.join(async1, 30 * 1000);
Assert.fail("async2 failed", async2.getException());
}
ThreadUtils.join(async1, 30 * 1000);
if (async1.exceptionOccurred()) {
Assert.fail("async1 failed", async1.getException());
}
}
use of org.apache.geode.cache.TimeoutException in project geode by apache.
the class RemoveGlobalDUnitTest method testRemoveGlobalMultiVM.
// end of testRemoveGlobalSingleVM
@Test
public void testRemoveGlobalMultiVM() throws Throwable {
// Commented the Test.As it is failing @ line no 145 : AssertionError
SerializableRunnable createSimpleRegion = new CacheSerializableRunnable("create region with cache writer") {
public void run2() throws CacheException {
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.GLOBAL);
region = cache.createRegion("map", factory.create());
}
};
SerializableRunnable createRegionWithWriter = new CacheSerializableRunnable("create region with capacity controller") {
public void run2() throws CacheException {
CacheWriter cw = new CacheWriterCallBack();
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.GLOBAL);
factory.setCacheWriter(cw);
region = cache.createRegion("map", factory.create());
}
};
vm0.invoke(createSimpleRegion);
vm1.invoke(createRegionWithWriter);
vm0.invoke(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));
}
}
});
vm1.invoke(new CacheSerializableRunnable("get object") {
public void run2() throws CacheException {
for (int i = 1; i < 5; i++) {
region.get(new Integer(i));
}
}
});
AsyncInvocation async = vm0.invokeAsync(new CacheSerializableRunnable("remove object") {
public void run2() throws CacheException {
region.remove(new Integer(2));
}
});
vm1.invoke(new CacheSerializableRunnable("verify locking") {
public void run2() throws CacheException {
cache.setLockTimeout(5);
synchronized (RemoveGlobalDUnitTest.class) {
if (!lockedForRemove) {
try {
RemoveGlobalDUnitTest.class.wait();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
try {
// getLogWriter().fine("11111111111111");
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();
}
Aggregations