use of org.apache.geode.cache.CacheClosedException in project geode by apache.
the class PersistentRecoveryOrderDUnitTest method createDataAsyncTX.
public AsyncInvocation createDataAsyncTX(VM vm1, final int member) {
SerializableCallable createData1 = new SerializableCallable() {
public Object call() {
Cache cache = getCache();
Region region = cache.getRegion(REGION_NAME);
int i = 0;
TXManagerImpl txManager = (TXManagerImpl) cache.getCacheTransactionManager();
while (true) {
try {
txManager.begin();
region.put(member, i);
txManager.commit();
i++;
} catch (RegionDestroyedException e) {
break;
} catch (CacheClosedException e) {
break;
} catch (IllegalArgumentException e) {
if (!e.getMessage().contains("Invalid txLockId")) {
throw e;
}
break;
} catch (LockServiceDestroyedException e) {
break;
}
}
return i - 1;
}
};
AsyncInvocation asyncCreate1 = vm1.invokeAsync(createData1);
return asyncCreate1;
}
use of org.apache.geode.cache.CacheClosedException in project geode by apache.
the class ListDiskStoresFunctionJUnitTest method testExecuteOnMemberWithNoCache.
@Test(expected = CacheClosedException.class)
public void testExecuteOnMemberWithNoCache() throws Throwable {
final FunctionContext mockFunctionContext = mockContext.mock(FunctionContext.class, "MockFunctionContext");
final ListDiskStoresFunction testListDiskStoresFunction = new TestListDiskStoresFunction(mockContext.mock(Cache.class, "MockCache")) {
@Override
protected Cache getCache() {
throw new CacheClosedException("Expected");
}
};
final TestResultSender testResultSender = new TestResultSender();
mockContext.checking(new Expectations() {
{
oneOf(mockFunctionContext).getResultSender();
will(returnValue(testResultSender));
}
});
testListDiskStoresFunction.execute(mockFunctionContext);
try {
testResultSender.getResults();
} catch (CacheClosedException expected) {
assertEquals("Expected", expected.getMessage());
throw expected;
}
}
use of org.apache.geode.cache.CacheClosedException in project geode by apache.
the class LuceneEventListener method process.
protected boolean process(final List<AsyncEvent> events) {
// Try to get a PDX instance if possible, rather than a deserialized object
DefaultQuery.setPdxReadSerialized(true);
Set<IndexRepository> affectedRepos = new HashSet<IndexRepository>();
try {
for (AsyncEvent event : events) {
Region region = event.getRegion();
Object key = event.getKey();
Object callbackArgument = event.getCallbackArgument();
IndexRepository repository = repositoryManager.getRepository(region, key, callbackArgument);
Object value = getValue(region.getEntry(key));
if (value != null) {
repository.update(key, value);
} else {
repository.delete(key);
}
affectedRepos.add(repository);
}
for (IndexRepository repo : affectedRepos) {
repo.commit();
}
return true;
} catch (BucketNotFoundException | RegionDestroyedException | PrimaryBucketException e) {
logger.debug("Bucket not found while saving to lucene index: " + e.getMessage(), e);
return false;
} catch (CacheClosedException e) {
logger.debug("Unable to save to lucene index, cache has been closed", e);
return false;
} catch (AlreadyClosedException e) {
logger.debug("Unable to commit, the lucene index is already closed", e);
return false;
} catch (IOException e) {
throw new InternalGemFireError("Unable to save to lucene index", e);
} finally {
DefaultQuery.setPdxReadSerialized(false);
}
}
use of org.apache.geode.cache.CacheClosedException in project geode by apache.
the class OffHeapTestUtil method checkOrphans.
public static void checkOrphans() {
MemoryAllocatorImpl allocator = null;
try {
allocator = MemoryAllocatorImpl.getAllocator();
} catch (CacheClosedException ignore) {
// no off-heap memory so no orphans
return;
}
long end = System.currentTimeMillis() + 5000;
List<MemoryBlock> orphans = allocator.getOrphans();
// Wait for the orphans to go away
while (orphans != null && !orphans.isEmpty() && System.currentTimeMillis() < end) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
orphans = allocator.getOrphans();
}
if (orphans != null && !orphans.isEmpty()) {
List<RefCountChangeInfo> info = ReferenceCountHelper.getRefCountInfo(orphans.get(0).getAddress());
System.out.println("FOUND ORPHAN!!");
System.out.println("Sample orphan: " + orphans.get(0));
System.out.println("Orphan info: " + info);
}
assertEquals(Collections.emptyList(), orphans);
}
use of org.apache.geode.cache.CacheClosedException in project geode by apache.
the class PRClientServerRegionFunctionExecutionNoSingleHopDUnitTest method executeFunction.
public static void executeFunction() throws ServerException, InterruptedException {
Region region = cache.getRegion(PartitionedRegionName);
assertNotNull(region);
final HashSet testKeysSet = new HashSet();
for (int i = (totalNumBuckets.intValue() * 10); i > 0; i--) {
testKeysSet.add("execKey-" + i);
}
DistributedSystem.setThreadsSocketPolicy(false);
Function function = new TestFunction(true, TEST_FUNCTION2);
FunctionService.registerFunction(function);
Execution dataSet = FunctionService.onRegion(region);
try {
ResultCollector rc1 = dataSet.withFilter(testKeysSet).setArguments(Boolean.TRUE).execute(function.getId());
HashMap resultMap = ((HashMap) rc1.getResult());
assertEquals(3, resultMap.size());
Iterator mapIterator = resultMap.entrySet().iterator();
Map.Entry entry = null;
DistributedMember key = null;
ArrayList resultListForMember = null;
while (mapIterator.hasNext()) {
entry = (Map.Entry) mapIterator.next();
key = (DistributedMember) entry.getKey();
resultListForMember = (ArrayList) entry.getValue();
for (Object result : resultListForMember) {
assertEquals(Boolean.TRUE, result);
}
}
} catch (Exception e) {
LogWriterUtils.getLogWriter().info("Got an exception : " + e.getMessage());
assertTrue(e instanceof EOFException || e instanceof SocketException || e instanceof SocketTimeoutException || e instanceof ServerException || e instanceof IOException || e instanceof CacheClosedException);
}
}
Aggregations