Search in sources :

Example 76 with CacheClosedException

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;
}
Also used : TXManagerImpl(org.apache.geode.internal.cache.TXManagerImpl) LockServiceDestroyedException(org.apache.geode.distributed.LockServiceDestroyedException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) DiskRegion(org.apache.geode.internal.cache.DiskRegion) Region(org.apache.geode.cache.Region) CacheClosedException(org.apache.geode.cache.CacheClosedException) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) Cache(org.apache.geode.cache.Cache)

Example 77 with CacheClosedException

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;
    }
}
Also used : Expectations(org.jmock.Expectations) CacheClosedException(org.apache.geode.cache.CacheClosedException) FunctionContext(org.apache.geode.cache.execute.FunctionContext) InternalCache(org.apache.geode.internal.cache.InternalCache) Cache(org.apache.geode.cache.Cache) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 78 with CacheClosedException

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);
    }
}
Also used : RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) CacheClosedException(org.apache.geode.cache.CacheClosedException) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) IOException(java.io.IOException) AsyncEvent(org.apache.geode.cache.asyncqueue.AsyncEvent) PrimaryBucketException(org.apache.geode.internal.cache.PrimaryBucketException) IndexRepository(org.apache.geode.cache.lucene.internal.repository.IndexRepository) Region(org.apache.geode.cache.Region) BucketNotFoundException(org.apache.geode.internal.cache.BucketNotFoundException) HashSet(java.util.HashSet) InternalGemFireError(org.apache.geode.InternalGemFireError)

Example 79 with CacheClosedException

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);
}
Also used : MemoryBlock(org.apache.geode.internal.offheap.MemoryBlock) MemoryAllocatorImpl(org.apache.geode.internal.offheap.MemoryAllocatorImpl) CacheClosedException(org.apache.geode.cache.CacheClosedException) RefCountChangeInfo(org.apache.geode.internal.offheap.RefCountChangeInfo)

Example 80 with CacheClosedException

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);
    }
}
Also used : SocketException(java.net.SocketException) ServerException(java.rmi.ServerException) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) CacheClosedException(org.apache.geode.cache.CacheClosedException) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) ServerException(java.rmi.ServerException) FunctionException(org.apache.geode.cache.execute.FunctionException) SocketException(java.net.SocketException) CacheClosedException(org.apache.geode.cache.CacheClosedException) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException) EOFException(java.io.EOFException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) Function(org.apache.geode.cache.execute.Function) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) Execution(org.apache.geode.cache.execute.Execution) SocketTimeoutException(java.net.SocketTimeoutException) Iterator(java.util.Iterator) DistributedMember(org.apache.geode.distributed.DistributedMember) EOFException(java.io.EOFException) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) ResultCollector(org.apache.geode.cache.execute.ResultCollector) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

CacheClosedException (org.apache.geode.cache.CacheClosedException)95 Cache (org.apache.geode.cache.Cache)26 Test (org.junit.Test)21 IOException (java.io.IOException)20 ArrayList (java.util.ArrayList)20 FunctionException (org.apache.geode.cache.execute.FunctionException)20 FunctionInvocationTargetException (org.apache.geode.cache.execute.FunctionInvocationTargetException)20 CancelException (org.apache.geode.CancelException)18 Region (org.apache.geode.cache.Region)18 Host (org.apache.geode.test.dunit.Host)17 VM (org.apache.geode.test.dunit.VM)17 InternalCache (org.apache.geode.internal.cache.InternalCache)16 IgnoredException (org.apache.geode.test.dunit.IgnoredException)16 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)16 DistributedMember (org.apache.geode.distributed.DistributedMember)14 ReplyException (org.apache.geode.distributed.internal.ReplyException)14 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)12 Execution (org.apache.geode.cache.execute.Execution)11 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)11 HashMap (java.util.HashMap)10