Search in sources :

Example 6 with ServerOperationException

use of org.apache.geode.cache.client.ServerOperationException in project geode by apache.

the class AbstractOp method processObjResponse.

/**
   * Process a response that contains a single Object result.
   * 
   * @param msg the message containing the response
   * @param opName text describing this op
   * @return the result of the response
   * @throws Exception if response could not be processed or we received a response with a server
   *         exception.
   */
protected Object processObjResponse(Message msg, String opName) throws Exception {
    Part part = msg.getPart(0);
    final int msgType = msg.getMessageType();
    if (msgType == MessageType.RESPONSE) {
        return part.getObject();
    } else {
        if (msgType == MessageType.EXCEPTION) {
            String s = "While performing a remote " + opName;
            throw new ServerOperationException(s, (Throwable) part.getObject());
        // Get the exception toString part.
        // This was added for c++ thin client and not used in java
        // Part exceptionToStringPart = msg.getPart(1);
        } else if (isErrorResponse(msgType)) {
            throw new ServerOperationException(part.getString());
        } else {
            throw new InternalGemFireError("Unexpected message type " + MessageType.getString(msgType));
        }
    }
}
Also used : Part(org.apache.geode.internal.cache.tier.sockets.Part) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) InternalGemFireError(org.apache.geode.InternalGemFireError)

Example 7 with ServerOperationException

use of org.apache.geode.cache.client.ServerOperationException in project geode by apache.

the class LocalRegion method basicPutAll.

// TODO: refactor basicPutAll
public VersionedObjectList basicPutAll(final Map<?, ?> map, final DistributedPutAllOperation putAllOp, final Map<Object, VersionTag> retryVersions) {
    final boolean isDebugEnabled = logger.isDebugEnabled();
    final EntryEventImpl event = putAllOp.getBaseEvent();
    EventID eventId = event.getEventId();
    if (eventId == null && generateEventID()) {
        // We need to "reserve" the eventIds for the entries in map here
        event.reserveNewEventId(this.cache.getDistributedSystem(), map.size());
        eventId = event.getEventId();
    }
    verifyPutAllMap(map);
    VersionedObjectList proxyResult = null;
    boolean partialResult = false;
    RuntimeException runtimeException = null;
    if (hasServerProxy()) {
        // send message to bridge server
        if (isTX()) {
            TXStateProxyImpl txState = (TXStateProxyImpl) this.cache.getTxManager().getTXState();
            txState.getRealDeal(null, this);
        }
        try {
            proxyResult = getServerProxy().putAll(map, eventId, !event.isGenerateCallbacks(), event.getCallbackArgument());
            if (isDebugEnabled) {
                logger.debug("PutAll received response from server: {}", proxyResult);
            }
        } catch (PutAllPartialResultException e) {
            // adjust the map to only add succeeded entries, then apply the adjustedMap
            proxyResult = e.getSucceededKeysAndVersions();
            partialResult = true;
            if (isDebugEnabled) {
                logger.debug("putAll in client encountered a PutAllPartialResultException:{}{}. Adjusted keys are: {}", e.getMessage(), getLineSeparator(), proxyResult.getKeys());
            }
            Throwable txException = e.getFailure();
            while (txException != null) {
                if (txException instanceof TransactionException) {
                    runtimeException = (RuntimeException) txException;
                    break;
                }
                txException = txException.getCause();
            }
            if (runtimeException == null) {
                // for cache close
                runtimeException = getCancelCriterion().generateCancelledException(e.getFailure());
                if (runtimeException == null) {
                    runtimeException = new ServerOperationException(LocalizedStrings.Region_PutAll_Applied_PartialKeys_At_Server_0.toLocalizedString(getFullPath()), e.getFailure());
                }
            }
        }
    }
    final VersionedObjectList succeeded = new VersionedObjectList(map.size(), true, this.concurrencyChecksEnabled);
    // if this is a transactional putAll, we will not have version information as it is only
    // generated at commit
    // so treat transactional putAll as if the server is not versioned
    final boolean serverIsVersioned = proxyResult != null && proxyResult.regionIsVersioned() && !isTX() && this.dataPolicy != DataPolicy.EMPTY;
    if (!serverIsVersioned && !partialResult) {
        // we don't need server information if it isn't versioned or if the region is empty
        proxyResult = null;
    }
    lockRVVForBulkOp();
    try {
        try {
            int size = proxyResult == null ? map.size() : proxyResult.size();
            if (isDebugEnabled) {
                logger.debug("size of put result is {} maps is {} proxyResult is {}", size, map, proxyResult);
            }
            final PutAllPartialResult partialKeys = new PutAllPartialResult(size);
            final Iterator iterator;
            final boolean isVersionedResults;
            if (proxyResult != null) {
                iterator = proxyResult.iterator();
                isVersionedResults = true;
            } else {
                iterator = map.entrySet().iterator();
                isVersionedResults = false;
            }
            // TODO: refactor this mess
            Runnable task = new Runnable() {

                @Override
                public void run() {
                    int offset = 0;
                    VersionTagHolder tagHolder = new VersionTagHolder();
                    while (iterator.hasNext()) {
                        stopper.checkCancelInProgress(null);
                        Map.Entry mapEntry = (Map.Entry) iterator.next();
                        Object key = mapEntry.getKey();
                        VersionTag versionTag = null;
                        tagHolder.setVersionTag(null);
                        final Object value;
                        boolean overwritten = false;
                        if (isVersionedResults) {
                            versionTag = ((VersionedObjectList.Entry) mapEntry).getVersionTag();
                            value = map.get(key);
                            if (isDebugEnabled) {
                                logger.debug("putAll key {} -> {} version={}", key, value, versionTag);
                            }
                            if (versionTag == null && serverIsVersioned && concurrencyChecksEnabled && dataPolicy.withStorage()) {
                                // entry since we don't know what its state should be (but the server should)
                                if (isDebugEnabled) {
                                    logger.debug("server returned no version information for {}", key);
                                }
                                localDestroyNoCallbacks(key);
                                // to be consistent we need to fetch the current entry
                                get(key, event.getCallbackArgument(), false, null);
                                overwritten = true;
                            }
                        } else {
                            value = mapEntry.getValue();
                            if (isDebugEnabled) {
                                logger.debug("putAll {} -> {}", key, value);
                            }
                        }
                        try {
                            if (serverIsVersioned) {
                                if (isDebugEnabled) {
                                    logger.debug("associating version tag with {} version={}", key, versionTag);
                                }
                                // If we have received a version tag from a server, add it to the event
                                tagHolder.setVersionTag(versionTag);
                                tagHolder.setFromServer(true);
                            } else if (retryVersions != null && retryVersions.containsKey(key)) {
                                // If this is a retried event, and we have a version tag for the retry,
                                // add it to the event.
                                tagHolder.setVersionTag(retryVersions.get(key));
                            }
                            if (!overwritten) {
                                basicEntryPutAll(key, value, putAllOp, offset, tagHolder);
                            }
                            // now we must check again since the cache may have closed during
                            // distribution (causing this process to not receive and queue the
                            // event for clients
                            stopper.checkCancelInProgress(null);
                            succeeded.addKeyAndVersion(key, tagHolder.getVersionTag());
                        } catch (Exception ex) {
                            if (isDebugEnabled) {
                                logger.debug("PutAll operation encountered exception for key {}", key, ex);
                            }
                            partialKeys.saveFailedKey(key, ex);
                        }
                        offset++;
                    }
                }
            };
            syncBulkOp(task, eventId);
            if (partialKeys.hasFailure()) {
                // Bug 51725: Now succeeded contains an order key list, may be missing the version tags.
                // Save reference of succeeded into partialKeys. The succeeded may be modified by
                // postPutAll() to fill in the version tags.
                partialKeys.setSucceededKeysAndVersions(succeeded);
                logger.info(LocalizedMessage.create(LocalizedStrings.Region_PutAll_Applied_PartialKeys_0_1, new Object[] { getFullPath(), partialKeys }));
                if (isDebugEnabled) {
                    logger.debug(partialKeys.detailString());
                }
                if (runtimeException == null) {
                    // if received exception from server first, ignore local exception
                    if (putAllOp.isBridgeOperation()) {
                        if (partialKeys.getFailure() instanceof CancelException) {
                            runtimeException = (RuntimeException) partialKeys.getFailure();
                        } else if (partialKeys.getFailure() instanceof LowMemoryException) {
                            // fix for #43589
                            throw partialKeys.getFailure();
                        } else {
                            runtimeException = new PutAllPartialResultException(partialKeys);
                            if (isDebugEnabled) {
                                logger.debug("basicPutAll:" + partialKeys.detailString());
                            }
                        }
                    } else {
                        throw partialKeys.getFailure();
                    }
                }
            }
        } catch (LowMemoryException lme) {
            throw lme;
        } catch (RuntimeException ex) {
            runtimeException = ex;
        } catch (Exception ex) {
            runtimeException = new RuntimeException(ex);
        } finally {
            putAllOp.getBaseEvent().release();
            putAllOp.freeOffHeapResources();
        }
        getDataView().postPutAll(putAllOp, succeeded, this);
    } finally {
        unlockRVVForBulkOp();
    }
    if (runtimeException != null) {
        throw runtimeException;
    }
    return succeeded;
}
Also used : VersionedObjectList(org.apache.geode.internal.cache.tier.sockets.VersionedObjectList) PutAllPartialResult(org.apache.geode.internal.cache.PutAllPartialResultException.PutAllPartialResult) Endpoint(org.apache.geode.cache.client.internal.Endpoint) TimeoutException(org.apache.geode.cache.TimeoutException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) InternalGemFireException(org.apache.geode.InternalGemFireException) ConflictingPersistentDataException(org.apache.geode.cache.persistence.ConflictingPersistentDataException) CacheRuntimeException(org.apache.geode.cache.CacheRuntimeException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) EntryDestroyedException(org.apache.geode.cache.EntryDestroyedException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) ExecutionException(java.util.concurrent.ExecutionException) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) EntryExistsException(org.apache.geode.cache.EntryExistsException) PartitionedRegionStorageException(org.apache.geode.cache.PartitionedRegionStorageException) StatisticsDisabledException(org.apache.geode.cache.StatisticsDisabledException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) FailedSynchronizationException(org.apache.geode.cache.FailedSynchronizationException) NoSuchElementException(java.util.NoSuchElementException) QueryException(org.apache.geode.cache.query.QueryException) RedundancyAlreadyMetException(org.apache.geode.internal.cache.partitioned.RedundancyAlreadyMetException) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) LowMemoryException(org.apache.geode.cache.LowMemoryException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) SystemException(javax.transaction.SystemException) SubscriptionNotEnabledException(org.apache.geode.cache.client.SubscriptionNotEnabledException) RegionExistsException(org.apache.geode.cache.RegionExistsException) RegionReinitializedException(org.apache.geode.cache.RegionReinitializedException) CancelException(org.apache.geode.CancelException) DiskAccessException(org.apache.geode.cache.DiskAccessException) CacheWriterException(org.apache.geode.cache.CacheWriterException) IndexMaintenanceException(org.apache.geode.cache.query.IndexMaintenanceException) TransactionException(org.apache.geode.cache.TransactionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) RollbackException(javax.transaction.RollbackException) ConcurrentCacheModificationException(org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException) MultiIndexCreationException(org.apache.geode.cache.query.MultiIndexCreationException) DeltaSerializationException(org.apache.geode.DeltaSerializationException) LRUEntry(org.apache.geode.internal.cache.lru.LRUEntry) CacheRuntimeException(org.apache.geode.cache.CacheRuntimeException) TransactionException(org.apache.geode.cache.TransactionException) Iterator(java.util.Iterator) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) StoredObject(org.apache.geode.internal.offheap.StoredObject) CancelException(org.apache.geode.CancelException) Map(java.util.Map) IndexMap(org.apache.geode.internal.cache.persistence.query.IndexMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashMap(java.util.HashMap) LowMemoryException(org.apache.geode.cache.LowMemoryException)

Example 8 with ServerOperationException

use of org.apache.geode.cache.client.ServerOperationException in project geode by apache.

the class LocalRegion method basicRemoveAll.

VersionedObjectList basicRemoveAll(final Collection<Object> keys, final DistributedRemoveAllOperation removeAllOp, final List<VersionTag> retryVersions) {
    final boolean isDebugEnabled = logger.isDebugEnabled();
    final boolean isTraceEnabled = logger.isTraceEnabled();
    final EntryEventImpl event = removeAllOp.getBaseEvent();
    EventID eventId = event.getEventId();
    if (eventId == null && generateEventID()) {
        // We need to "reserve" the eventIds for the entries in map here
        event.reserveNewEventId(this.cache.getDistributedSystem(), keys.size());
        eventId = event.getEventId();
    }
    verifyRemoveAllKeys(keys);
    VersionedObjectList proxyResult = null;
    boolean partialResult = false;
    RuntimeException runtimeException = null;
    if (hasServerProxy()) {
        // send message to bridge server
        if (isTX()) {
            TXStateProxyImpl txState = (TXStateProxyImpl) this.cache.getTxManager().getTXState();
            txState.getRealDeal(null, this);
        }
        try {
            proxyResult = getServerProxy().removeAll(keys, eventId, event.getCallbackArgument());
            if (isDebugEnabled) {
                logger.debug("removeAll received response from server: {}", proxyResult);
            }
        } catch (PutAllPartialResultException e) {
            // adjust the map to only add succeeded entries, then apply the adjustedMap
            proxyResult = e.getSucceededKeysAndVersions();
            partialResult = true;
            if (isDebugEnabled) {
                logger.debug("removeAll in client encountered a BulkOpPartialResultException: {}{}. Adjusted keys are: {}", e.getMessage(), getLineSeparator(), proxyResult.getKeys());
            }
            Throwable txException = e.getFailure();
            while (txException != null) {
                if (txException instanceof TransactionException) {
                    runtimeException = (RuntimeException) txException;
                    break;
                }
                txException = txException.getCause();
            }
            if (runtimeException == null) {
                runtimeException = new ServerOperationException(LocalizedStrings.Region_RemoveAll_Applied_PartialKeys_At_Server_0.toLocalizedString(getFullPath()), e.getFailure());
            }
        }
    }
    final VersionedObjectList succeeded = new VersionedObjectList(keys.size(), true, this.concurrencyChecksEnabled);
    // If this is a transactional removeAll, we will not have version information as it is only
    // generated at commit
    // so treat transactional removeAll as if the server is not versioned.
    // If we have no storage then act as if the server is not versioned.
    final boolean serverIsVersioned = proxyResult != null && proxyResult.regionIsVersioned() && !isTX() && getDataPolicy().withStorage();
    if (!serverIsVersioned && !partialResult) {
        // since the server is not versioned and we do not have a partial result
        // get rid of the proxyResult info returned by the server.
        proxyResult = null;
    }
    lockRVVForBulkOp();
    try {
        try {
            int size = proxyResult == null ? keys.size() : proxyResult.size();
            if (isInternalRegion()) {
                if (isTraceEnabled) {
                    logger.trace("size of removeAll result is {} keys are {} proxyResult is {}", size, keys, proxyResult);
                } else {
                    if (isTraceEnabled) {
                        logger.trace("size of removeAll result is {} keys are {} proxyResult is {}", size, keys, proxyResult);
                    }
                }
            } else {
                if (isTraceEnabled) {
                    logger.trace("size of removeAll result is {} keys are {} proxyResult is {}", size, keys, proxyResult);
                }
            }
            final PutAllPartialResult partialKeys = new PutAllPartialResult(size);
            final Iterator iterator;
            final boolean isVersionedResults;
            if (proxyResult != null) {
                iterator = proxyResult.iterator();
                isVersionedResults = true;
            } else {
                iterator = keys.iterator();
                isVersionedResults = false;
            }
            // TODO: refactor this mess
            Runnable task = new Runnable() {

                @Override
                public void run() {
                    int offset = 0;
                    VersionTagHolder tagHolder = new VersionTagHolder();
                    while (iterator.hasNext()) {
                        stopper.checkCancelInProgress(null);
                        tagHolder.setVersionTag(null);
                        Object key;
                        VersionTag versionTag = null;
                        if (isVersionedResults) {
                            Map.Entry mapEntry = (Map.Entry) iterator.next();
                            key = mapEntry.getKey();
                            versionTag = ((VersionedObjectList.Entry) mapEntry).getVersionTag();
                            if (isDebugEnabled) {
                                logger.debug("removeAll key {} version={}", key, versionTag);
                            }
                            if (versionTag == null) {
                                if (isDebugEnabled) {
                                    logger.debug("removeAll found invalid version tag, which means the entry is not found at server for key={}.", key);
                                }
                                succeeded.addKeyAndVersion(key, null);
                                continue;
                            }
                        // No need for special handling here in removeAll.
                        // We can just remove this key from the client with versionTag set to null.
                        } else {
                            key = iterator.next();
                            if (isTraceEnabled) {
                                logger.trace("removeAll {}", key);
                            }
                        }
                        try {
                            if (serverIsVersioned) {
                                if (isDebugEnabled) {
                                    logger.debug("associating version tag with {} version={}", key, versionTag);
                                }
                                // If we have received a version tag from a server, add it to the event
                                tagHolder.setVersionTag(versionTag);
                                tagHolder.setFromServer(true);
                            } else if (retryVersions != null) {
                                VersionTag versionTag1 = retryVersions.get(offset);
                                if (versionTag1 != null) {
                                    // If this is a retried event, and we have a version tag for the retry,
                                    // add it to the event.
                                    tagHolder.setVersionTag(versionTag1);
                                }
                            }
                            basicEntryRemoveAll(key, removeAllOp, offset, tagHolder);
                            // now we must check again since the cache may have closed during
                            // distribution causing this process to not receive and queue the
                            // event for clients
                            stopper.checkCancelInProgress(null);
                            succeeded.addKeyAndVersion(key, tagHolder.getVersionTag());
                        } catch (Exception ex) {
                            partialKeys.saveFailedKey(key, ex);
                        }
                        offset++;
                    }
                }
            };
            syncBulkOp(task, eventId);
            if (partialKeys.hasFailure()) {
                // Bug 51725: Now succeeded contains an order key list, may be missing the version tags.
                // Save reference of succeeded into partialKeys. The succeeded may be modified by
                // postRemoveAll() to fill in the version tags.
                partialKeys.setSucceededKeysAndVersions(succeeded);
                logger.info(LocalizedMessage.create(LocalizedStrings.Region_RemoveAll_Applied_PartialKeys_0_1, new Object[] { getFullPath(), partialKeys }));
                if (isDebugEnabled) {
                    logger.debug(partialKeys.detailString());
                }
                if (runtimeException == null) {
                    // if received exception from server first, ignore local exception
                    if (removeAllOp.isBridgeOperation()) {
                        if (partialKeys.getFailure() instanceof CancelException) {
                            runtimeException = (RuntimeException) partialKeys.getFailure();
                        } else if (partialKeys.getFailure() instanceof LowMemoryException) {
                            // fix for #43589
                            throw partialKeys.getFailure();
                        } else {
                            runtimeException = new PutAllPartialResultException(partialKeys);
                            if (isDebugEnabled) {
                                logger.debug("basicRemoveAll: {}", partialKeys.detailString());
                            }
                        }
                    } else {
                        throw partialKeys.getFailure();
                    }
                }
            }
        } catch (LowMemoryException lme) {
            throw lme;
        } catch (RuntimeException ex) {
            runtimeException = ex;
        } catch (Exception ex) {
            runtimeException = new RuntimeException(ex);
        } finally {
            removeAllOp.getBaseEvent().release();
            removeAllOp.freeOffHeapResources();
        }
        getDataView().postRemoveAll(removeAllOp, succeeded, this);
    } finally {
        unlockRVVForBulkOp();
    }
    if (runtimeException != null) {
        throw runtimeException;
    }
    return succeeded;
}
Also used : VersionedObjectList(org.apache.geode.internal.cache.tier.sockets.VersionedObjectList) PutAllPartialResult(org.apache.geode.internal.cache.PutAllPartialResultException.PutAllPartialResult) Endpoint(org.apache.geode.cache.client.internal.Endpoint) TimeoutException(org.apache.geode.cache.TimeoutException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) InternalGemFireException(org.apache.geode.InternalGemFireException) ConflictingPersistentDataException(org.apache.geode.cache.persistence.ConflictingPersistentDataException) CacheRuntimeException(org.apache.geode.cache.CacheRuntimeException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) EntryDestroyedException(org.apache.geode.cache.EntryDestroyedException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) ExecutionException(java.util.concurrent.ExecutionException) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) EntryExistsException(org.apache.geode.cache.EntryExistsException) PartitionedRegionStorageException(org.apache.geode.cache.PartitionedRegionStorageException) StatisticsDisabledException(org.apache.geode.cache.StatisticsDisabledException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) FailedSynchronizationException(org.apache.geode.cache.FailedSynchronizationException) NoSuchElementException(java.util.NoSuchElementException) QueryException(org.apache.geode.cache.query.QueryException) RedundancyAlreadyMetException(org.apache.geode.internal.cache.partitioned.RedundancyAlreadyMetException) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) LowMemoryException(org.apache.geode.cache.LowMemoryException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) SystemException(javax.transaction.SystemException) SubscriptionNotEnabledException(org.apache.geode.cache.client.SubscriptionNotEnabledException) RegionExistsException(org.apache.geode.cache.RegionExistsException) RegionReinitializedException(org.apache.geode.cache.RegionReinitializedException) CancelException(org.apache.geode.CancelException) DiskAccessException(org.apache.geode.cache.DiskAccessException) CacheWriterException(org.apache.geode.cache.CacheWriterException) IndexMaintenanceException(org.apache.geode.cache.query.IndexMaintenanceException) TransactionException(org.apache.geode.cache.TransactionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) RollbackException(javax.transaction.RollbackException) ConcurrentCacheModificationException(org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException) MultiIndexCreationException(org.apache.geode.cache.query.MultiIndexCreationException) DeltaSerializationException(org.apache.geode.DeltaSerializationException) LRUEntry(org.apache.geode.internal.cache.lru.LRUEntry) CacheRuntimeException(org.apache.geode.cache.CacheRuntimeException) TransactionException(org.apache.geode.cache.TransactionException) Iterator(java.util.Iterator) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) StoredObject(org.apache.geode.internal.offheap.StoredObject) CancelException(org.apache.geode.CancelException) Map(java.util.Map) IndexMap(org.apache.geode.internal.cache.persistence.query.IndexMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashMap(java.util.HashMap) LowMemoryException(org.apache.geode.cache.LowMemoryException)

Example 9 with ServerOperationException

use of org.apache.geode.cache.client.ServerOperationException in project geode by apache.

the class MemoryThresholdsDUnitTest method testFunctionExecutionRejection.

@Test
public void testFunctionExecutionRejection() throws Exception {
    final Host host = Host.getHost(0);
    final VM server1 = host.getVM(0);
    final VM server2 = host.getVM(1);
    final VM client = host.getVM(2);
    final String regionName = "FuncRej";
    ServerPorts ports1 = startCacheServer(server1, 80f, 90f, regionName, false, /* createPR */
    false, /* notifyBySubscription */
    0);
    ServerPorts ports2 = startCacheServer(server2, 80f, 90f, regionName, false, /* createPR */
    false, /* notifyBySubscription */
    0);
    startClient(client, server1, ports1.getPort(), regionName);
    registerTestMemoryThresholdListener(server1);
    registerTestMemoryThresholdListener(server2);
    final RejectFunction function = new RejectFunction();
    final RejectFunction function2 = new RejectFunction("noRejFunc", false);
    Invoke.invokeInEveryVM(new SerializableCallable("register function") {

        public Object call() throws Exception {
            FunctionService.registerFunction(function);
            FunctionService.registerFunction(function2);
            return null;
        }
    });
    client.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Pool p = PoolManager.find("pool1");
            assertTrue(p != null);
            FunctionService.onServers(p).execute(function);
            FunctionService.onServers(p).execute(function2);
            return null;
        }
    });
    final DistributedMember s1 = (DistributedMember) server1.invoke(getDistributedMember);
    server2.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            FunctionService.onMembers().execute(function);
            FunctionService.onMember(s1).execute(function);
            FunctionService.onMembers().execute(function2);
            FunctionService.onMember(s1).execute(function2);
            return null;
        }
    });
    setUsageAboveCriticalThreshold(server1);
    verifyListenerValue(server2, MemoryState.CRITICAL, 1, true);
    server1.invoke(addExpectedFunctionException);
    server2.invoke(addExpectedFunctionException);
    client.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Pool p = PoolManager.find("pool1");
            assertTrue(p != null);
            try {
                FunctionService.onServers(p).execute(function);
                fail("expected LowMemoryExcception was not thrown");
            } catch (ServerOperationException e) {
                if (!(e.getCause().getMessage().matches(".*low.*memory.*"))) {
                    Assert.fail("unexpected exception", e);
                }
            // expected
            }
            FunctionService.onServers(p).execute(function2);
            return null;
        }
    });
    server2.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            try {
                FunctionService.onMembers().execute(function);
                fail("expected LowMemoryExcception was not thrown");
            } catch (LowMemoryException e) {
            // expected
            }
            try {
                FunctionService.onMember(s1).execute(function);
                fail("expected LowMemoryExcception was not thrown");
            } catch (LowMemoryException e) {
            // expected
            }
            FunctionService.onMembers().execute(function2);
            FunctionService.onMember(s1).execute(function2);
            return null;
        }
    });
    server1.invoke(removeExpectedFunctionException);
    server2.invoke(removeExpectedFunctionException);
}
Also used : VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) Host(org.apache.geode.test.dunit.Host) Pool(org.apache.geode.cache.client.Pool) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) LowMemoryException(org.apache.geode.cache.LowMemoryException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) CacheException(org.apache.geode.cache.CacheException) LowMemoryException(org.apache.geode.cache.LowMemoryException) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 10 with ServerOperationException

use of org.apache.geode.cache.client.ServerOperationException in project geode by apache.

the class Bug36829DUnitTest method registerKey.

private static void registerKey(String key) throws Exception {
    // Get the region
    Region region = CacheServerTestUtil.getCache().getRegion(REGION_NAME);
    assertNotNull(region);
    try {
        region.registerInterest(key, InterestResultPolicy.NONE);
        fail("expected ServerOperationException");
    } catch (ServerOperationException expected) {
    }
}
Also used : Region(org.apache.geode.cache.Region) ServerOperationException(org.apache.geode.cache.client.ServerOperationException)

Aggregations

ServerOperationException (org.apache.geode.cache.client.ServerOperationException)27 ServerConnectivityException (org.apache.geode.cache.client.ServerConnectivityException)11 Region (org.apache.geode.cache.Region)10 CacheException (org.apache.geode.cache.CacheException)9 Host (org.apache.geode.test.dunit.Host)9 VM (org.apache.geode.test.dunit.VM)9 Test (org.junit.Test)7 IOException (java.io.IOException)6 List (java.util.List)6 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)6 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)6 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)6 Iterator (java.util.Iterator)5 ExecutionException (java.util.concurrent.ExecutionException)5 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)5 InternalGemFireException (org.apache.geode.InternalGemFireException)5 ServerLocation (org.apache.geode.distributed.internal.ServerLocation)5 VersionedObjectList (org.apache.geode.internal.cache.tier.sockets.VersionedObjectList)5 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)5 ArrayList (java.util.ArrayList)4