protected static void checkForInterrupt(ServerConnection serverConnection, Exception e) throws InterruptedException, InterruptedIOException { serverConnection.getCachedRegionHelper().checkCancelInProgress(e); if (e instanceof InterruptedException) { throw (InterruptedException) e; } if (e instanceof InterruptedIOException) { throw (InterruptedIOException) e; } }
private static void handleInterruptedIOException(ServerConnection serverConnection, Exception e) { CachedRegionHelper crHelper = serverConnection.getCachedRegionHelper(); if (!crHelper.isShutdown() && serverConnection.isOpen()) { if (!SUPPRESS_IO_EXCEPTION_LOGGING) { if (logger.isDebugEnabled()) logger.debug("Aborted message due to interrupt: {}", e.getMessage(), e); } } serverConnection.setFlagProcessMessagesAsFalse(); serverConnection.setClientDisconnectedException(e); }
private void handleRegionNull(ServerConnection servConn, String regionName, int batchId) { InternalCache cache = servConn.getCachedRegionHelper().getCacheForGatewayCommand(); if (cache != null && cache.isCacheAtShutdownAll()) { throw cache.getCacheClosedException("Shutdown occurred during message processing"); } else { String reason = String.format("Region %s was not found during batch create request %s", new Object[] {regionName, Integer.valueOf(batchId)}); throw new RegionDestroyedException(reason, regionName); } }
public boolean isOkayToSendResult() { return (sc.getAcceptor().isRunning() && !ids.isDisconnecting() && !sc.getCachedRegionHelper().getCache().isClosed() && !alreadySendException.get()); }
private static void handleShutdownException(Message msg, ServerConnection serverConnection, Exception e) { CachedRegionHelper crHelper = serverConnection.getCachedRegionHelper(); boolean potentialModification = serverConnection.getPotentialModification(); if (!crHelper.isShutdown()) { if (potentialModification) { int transId = msg != null ? msg.getTransactionId() : Integer.MIN_VALUE; logger.warn(String.format( "%s: Unexpected ShutdownException during operation on region: %s key: %s messageId: %s", new Object[] {serverConnection.getName(), serverConnection.getModRegion(), serverConnection.getModKey(), transId}), e); } else { logger.warn(String.format("%s: Unexpected ShutdownException: ", serverConnection.getName()), e); } } serverConnection.setFlagProcessMessagesAsFalse(); serverConnection.setClientDisconnectedException(e); }
@Before public void setUp() throws Exception { this.keySet = new KeySet(); MockitoAnnotations.initMocks(this); when(this.authzRequest.keySetAuthorize(eq(REGION_NAME))) .thenReturn(this.keySetOperationContext); when(this.cache.getRegion(isA(String.class))).thenReturn(this.region); when(this.cache.getCancelCriterion()).thenReturn(mock(CancelCriterion.class)); when(this.message.getPart(eq(0))).thenReturn(this.regionNamePart); when(this.regionNamePart.getString()).thenReturn(REGION_NAME); when(this.serverConnection.getCache()).thenReturn(this.cache); when(this.serverConnection.getCacheServerStats()).thenReturn(mock(CacheServerStats.class)); when(this.serverConnection.getAuthzRequest()).thenReturn(this.authzRequest); when(this.serverConnection.getCachedRegionHelper()).thenReturn(mock(CachedRegionHelper.class)); when(this.serverConnection.getChunkedResponseMessage()).thenReturn(this.chunkedResponseMessage); }
@Before public void setUp() throws Exception { this.getAll = new GetAll(); MockitoAnnotations.initMocks(this); when(this.authzRequest.getAuthorize(any(), any(), any())) .thenReturn(mock(GetOperationContext.class)); when(this.cache.getRegion(isA(String.class))).thenReturn(mock(LocalRegion.class)); when(this.cache.getCancelCriterion()).thenReturn(mock(CancelCriterion.class)); when(this.keyPart.getObject()).thenReturn(KEYS); when(this.message.getPart(eq(0))).thenReturn(this.regionNamePart); when(this.message.getPart(eq(1))).thenReturn(this.keyPart); when(this.regionNamePart.getString()).thenReturn(REGION_NAME); when(this.serverConnection.getCache()).thenReturn(this.cache); when(this.serverConnection.getCacheServerStats()).thenReturn(mock(CacheServerStats.class)); when(this.serverConnection.getAuthzRequest()).thenReturn(this.authzRequest); when(this.serverConnection.getCachedRegionHelper()).thenReturn(mock(CachedRegionHelper.class)); when(this.serverConnection.getChunkedResponseMessage()).thenReturn(this.chunkedResponseMessage); }
private static void handleIOException(Message msg, ServerConnection serverConnection, Exception e) { CachedRegionHelper crHelper = serverConnection.getCachedRegionHelper(); boolean potentialModification = serverConnection.getPotentialModification(); if (!crHelper.isShutdown() && serverConnection.isOpen()) { if (!SUPPRESS_IO_EXCEPTION_LOGGING) { if (potentialModification) { int transId = msg != null ? msg.getTransactionId() : Integer.MIN_VALUE; logger.warn(String.format( "%s: Unexpected IOException during operation for region: %s key: %s messId: %s", new Object[] {serverConnection.getName(), serverConnection.getModRegion(), serverConnection.getModKey(), transId}), e); } else { logger.warn(String.format("%s: Unexpected IOException: ", serverConnection.getName()), e); } } } serverConnection.setFlagProcessMessagesAsFalse(); serverConnection.setClientDisconnectedException(e); }
@Before public void setUp() throws Exception { this.getAll651 = new GetAll651(); MockitoAnnotations.initMocks(this); when(this.authzRequest.getAuthorize(any(), any(), any())) .thenReturn(mock(GetOperationContext.class)); when(this.cache.getRegion(isA(String.class))).thenReturn(mock(LocalRegion.class)); when(this.cache.getCancelCriterion()).thenReturn(mock(CancelCriterion.class)); when(this.keyPart.getObject()).thenReturn(KEYS); when(this.message.getPart(eq(0))).thenReturn(this.regionNamePart); when(this.message.getPart(eq(1))).thenReturn(this.keyPart); when(this.regionNamePart.getString()).thenReturn(REGION_NAME); when(this.serverConnection.getCache()).thenReturn(this.cache); when(this.serverConnection.getCacheServerStats()).thenReturn(mock(CacheServerStats.class)); when(this.serverConnection.getAuthzRequest()).thenReturn(this.authzRequest); when(this.serverConnection.getCachedRegionHelper()).thenReturn(mock(CachedRegionHelper.class)); when(this.serverConnection.getChunkedResponseMessage()).thenReturn(this.chunkedResponseMessage); }
@Before public void setUp() throws Exception { this.getAll70 = new GetAll70(); MockitoAnnotations.initMocks(this); when(this.authzRequest.getAuthorize(any(), any(), any())) .thenReturn(mock(GetOperationContext.class)); when(this.cache.getRegion(isA(String.class))).thenReturn(this.region); when(this.cache.getCancelCriterion()).thenReturn(mock(CancelCriterion.class)); when(this.keyPart.getObject()).thenReturn(KEYS); when(this.message.getPart(eq(0))).thenReturn(this.regionNamePart); when(this.message.getPart(eq(1))).thenReturn(this.keyPart); when(this.message.getPart(eq(2))).thenReturn(this.requestSerializableValuesPart); when(this.region.getAttributes()).thenReturn(this.regionAttributes); when(this.regionAttributes.getConcurrencyChecksEnabled()).thenReturn(true); when(this.regionNamePart.getString()).thenReturn(REGION_NAME); when(this.requestSerializableValuesPart.getInt()).thenReturn(0); when(this.serverConnection.getCache()).thenReturn(this.cache); when(this.serverConnection.getCacheServerStats()).thenReturn(mock(CacheServerStats.class)); when(this.serverConnection.getAuthzRequest()).thenReturn(this.authzRequest); when(this.serverConnection.getCachedRegionHelper()).thenReturn(mock(CachedRegionHelper.class)); when(this.serverConnection.getChunkedResponseMessage()).thenReturn(this.chunkedResponseMessage); }
@Before public void setUp() throws Exception { this.destroyRegion = new DestroyRegion(); MockitoAnnotations.initMocks(this); when(this.authzRequest.destroyRegionAuthorize(eq(REGION_NAME), eq(CALLBACK_ARG))) .thenReturn(mock(RegionDestroyOperationContext.class)); when(this.cache.getRegion(isA(String.class))).thenReturn(this.region); when(this.cache.getCancelCriterion()).thenReturn(mock(CancelCriterion.class)); when(this.callbackArgPart.getObject()).thenReturn(CALLBACK_ARG); when(this.eventPart.getSerializedForm()).thenReturn(EVENT); when(this.message.getNumberOfParts()).thenReturn(3); when(this.message.getPart(eq(0))).thenReturn(this.regionNamePart); when(this.message.getPart(eq(1))).thenReturn(this.eventPart); when(this.message.getPart(eq(2))).thenReturn(this.callbackArgPart); when(this.regionNamePart.getString()).thenReturn(REGION_NAME); when(this.serverConnection.getCache()).thenReturn(this.cache); when(this.serverConnection.getCacheServerStats()).thenReturn(this.cacheServerStats); when(this.serverConnection.getAuthzRequest()).thenReturn(this.authzRequest); when(this.serverConnection.getCachedRegionHelper()).thenReturn(mock(CachedRegionHelper.class)); when(this.serverConnection.getErrorResponseMessage()).thenReturn(this.errorResponseMessage); when(this.serverConnection.getReplyMessage()).thenReturn(this.responseMessage); when(this.serverConnection.getClientVersion()).thenReturn(Version.CURRENT); }
@Before public void setUp() throws Exception { this.get70 = new Get70(); MockitoAnnotations.initMocks(this); when(this.authzRequest.getAuthorize(any(), any(), any())).thenReturn(this.getOperationContext); when(this.cache.getRegion(isA(String.class))).thenReturn(this.region); when(this.cache.getCancelCriterion()).thenReturn(mock(CancelCriterion.class)); when(this.getOperationContext.getCallbackArg()).thenReturn(CALLBACK_ARG); when(this.keyPart.getStringOrObject()).thenReturn(KEY); when(this.message.getNumberOfParts()).thenReturn(3); when(this.message.getPart(eq(0))).thenReturn(this.regionNamePart); when(this.message.getPart(eq(1))).thenReturn(this.keyPart); when(this.message.getPart(eq(2))).thenReturn(this.valuePart); when(this.regionNamePart.getString()).thenReturn(REGION_NAME); when(this.serverConnection.getCache()).thenReturn(this.cache); when(this.serverConnection.getCacheServerStats()).thenReturn(this.cacheServerStats); when(this.serverConnection.getAuthzRequest()).thenReturn(this.authzRequest); when(this.serverConnection.getResponseMessage()).thenReturn(this.responseMessage); when(this.serverConnection.getCachedRegionHelper()).thenReturn(mock(CachedRegionHelper.class)); when(this.serverConnection.getErrorResponseMessage()).thenReturn(this.errorResponseMessage); when(this.serverConnection.getClientVersion()).thenReturn(Version.CURRENT); when(this.valuePart.getObject()).thenReturn(CALLBACK_ARG); }
@Override public void cmdExecute(final Message clientMessage, final ServerConnection serverConnection, final SecurityService securityService, long start) throws IOException { final boolean isDebugEnabled = logger.isDebugEnabled(); if (isDebugEnabled) { logger.debug("{}: rcv tx: {} from {} rcvTime: {}", serverConnection.getName(), clientMessage.getTransactionId(), serverConnection.getSocketString(), (DistributionStats.getStatTime() - start)); } ClientHealthMonitor chm = ClientHealthMonitor.getInstance(); if (chm != null) chm.receivedPing(serverConnection.getProxyID()); CachedRegionHelper crHelper = serverConnection.getCachedRegionHelper(); writeReply(clientMessage, serverConnection); serverConnection.setAsTrue(RESPONDED); if (isDebugEnabled) { logger.debug("{}: Sent ping reply to {}", serverConnection.getName(), serverConnection.getSocketString()); } }
@Before public void setUp() throws Exception { this.registerInterest = new RegisterInterest(); MockitoAnnotations.initMocks(this); when(this.authzRequest.registerInterestAuthorize(eq(REGION_NAME), eq(KEY), anyInt(), any())) .thenReturn(mock(RegisterInterestOperationContext.class)); when(this.cache.getRegion(isA(String.class))).thenReturn(mock(LocalRegion.class)); when(this.cache.getCancelCriterion()).thenReturn(mock(CancelCriterion.class)); when(this.durablePart.getObject()).thenReturn(DURABLE); when(this.interestTypePart.getInt()).thenReturn(0); when(this.keyPart.getStringOrObject()).thenReturn(KEY); when(this.message.getNumberOfParts()).thenReturn(6); when(this.message.getPart(eq(0))).thenReturn(this.regionNamePart); when(this.message.getPart(eq(1))).thenReturn(this.interestTypePart); when(this.message.getPart(eq(2))).thenReturn(mock(Part.class)); when(this.message.getPart(eq(3))).thenReturn(this.durablePart); when(this.message.getPart(eq(4))).thenReturn(this.keyPart); when(this.message.getPart(eq(5))).thenReturn(this.notifyPart); when(this.notifyPart.getObject()).thenReturn(DURABLE); when(this.regionNamePart.getString()).thenReturn(REGION_NAME); when(this.serverConnection.getCache()).thenReturn(this.cache); when(this.serverConnection.getAuthzRequest()).thenReturn(this.authzRequest); when(this.serverConnection.getCachedRegionHelper()).thenReturn(mock(CachedRegionHelper.class)); when(this.serverConnection.getChunkedResponseMessage()).thenReturn(this.chunkedResponseMessage); }
@Before public void setUp() throws Exception { this.request = new Request(); MockitoAnnotations.initMocks(this); when(this.authzRequest.getAuthorize(any(), any(), any())).thenReturn(this.getOperationContext); when(this.cache.getRegion(isA(String.class))).thenReturn(this.region); when(this.cache.getCancelCriterion()).thenReturn(mock(CancelCriterion.class)); when(this.getOperationContext.getCallbackArg()).thenReturn(CALLBACK_ARG); when(this.keyPart.getStringOrObject()).thenReturn(KEY); when(this.message.getNumberOfParts()).thenReturn(3); when(this.message.getPart(eq(0))).thenReturn(this.regionNamePart); when(this.message.getPart(eq(1))).thenReturn(this.keyPart); when(this.message.getPart(eq(2))).thenReturn(this.valuePart); when(this.regionNamePart.getString()).thenReturn(REGION_NAME); when(this.serverConnection.getCache()).thenReturn(this.cache); when(this.serverConnection.getCacheServerStats()).thenReturn(this.cacheServerStats); when(this.serverConnection.getAuthzRequest()).thenReturn(this.authzRequest); when(this.serverConnection.getResponseMessage()).thenReturn(this.responseMessage); when(this.serverConnection.getCachedRegionHelper()).thenReturn(mock(CachedRegionHelper.class)); when(this.serverConnection.getErrorResponseMessage()).thenReturn(this.errorResponseMessage); when(this.serverConnection.getClientVersion()).thenReturn(Version.CURRENT); when(this.valuePart.getObject()).thenReturn(CALLBACK_ARG); }
@Before public void setUp() throws Exception { this.invalidate = new Invalidate(); MockitoAnnotations.initMocks(this); when(this.authzRequest.invalidateAuthorize(any(), any(), any())) .thenReturn(mock(InvalidateOperationContext.class)); when(this.cache.getRegion(isA(String.class))).thenReturn(mock(LocalRegion.class)); when(this.cache.getCancelCriterion()).thenReturn(mock(CancelCriterion.class)); when(this.callbackArgPart.getObject()).thenReturn(CALLBACK_ARG); when(this.eventPart.getSerializedForm()).thenReturn(EVENT); when(this.keyPart.getStringOrObject()).thenReturn(KEY_STRING); when(this.message.getNumberOfParts()).thenReturn(4); when(this.message.getPart(eq(0))).thenReturn(this.regionNamePart); when(this.message.getPart(eq(1))).thenReturn(this.keyPart); when(this.message.getPart(eq(2))).thenReturn(this.eventPart); when(this.message.getPart(eq(3))).thenReturn(this.callbackArgPart); when(this.regionNamePart.getString()).thenReturn(REGION_NAME); when(this.serverConnection.getCache()).thenReturn(this.cache); when(this.serverConnection.getCacheServerStats()).thenReturn(mock(CacheServerStats.class)); when(this.serverConnection.getAuthzRequest()).thenReturn(this.authzRequest); when(this.serverConnection.getCachedRegionHelper()).thenReturn(mock(CachedRegionHelper.class)); when(this.serverConnection.getReplyMessage()).thenReturn(this.responseMessage); when(this.serverConnection.getErrorResponseMessage()).thenReturn(this.errorResponseMessage); when(this.serverConnection.getClientVersion()).thenReturn(Version.CURRENT); }
@Before public void setUp() throws Exception { this.destroy65 = new Destroy65(); MockitoAnnotations.initMocks(this); when(this.authzRequest.destroyAuthorize(eq(REGION_NAME), eq(KEY), eq(CALLBACK_ARG))) .thenReturn(this.destroyOperationContext); when(this.cache.getRegion(isA(String.class))).thenReturn(this.region); when(this.cache.getCancelCriterion()).thenReturn(mock(CancelCriterion.class)); when(this.callbackArgPart.getObject()).thenReturn(CALLBACK_ARG); when(this.eventPart.getSerializedForm()).thenReturn(EVENT); when(this.keyPart.getStringOrObject()).thenReturn(KEY); when(this.message.getNumberOfParts()).thenReturn(6); when(this.message.getPart(eq(0))).thenReturn(this.regionNamePart); when(this.message.getPart(eq(1))).thenReturn(this.keyPart); when(this.message.getPart(eq(3))).thenReturn(mock(Part.class)); when(this.message.getPart(eq(4))).thenReturn(this.eventPart); when(this.message.getPart(eq(5))).thenReturn(this.callbackArgPart); when(this.regionNamePart.getString()).thenReturn(REGION_NAME); when(this.serverConnection.getCache()).thenReturn(this.cache); when(this.serverConnection.getCacheServerStats()).thenReturn(this.cacheServerStats); when(this.serverConnection.getAuthzRequest()).thenReturn(this.authzRequest); when(this.serverConnection.getCachedRegionHelper()).thenReturn(mock(CachedRegionHelper.class)); when(this.serverConnection.getReplyMessage()).thenReturn(this.responseMessage); when(this.serverConnection.getErrorResponseMessage()).thenReturn(this.errorResponseMessage); when(this.serverConnection.getClientVersion()).thenReturn(Version.CURRENT); }
@Before public void setUp() throws Exception { this.removeAll = new RemoveAll(); MockitoAnnotations.initMocks(this); when(this.authzRequest.removeAllAuthorize(any(), any(), any())) .thenReturn(mock(RemoveAllOperationContext.class)); when(this.cache.getRegion(isA(String.class))).thenReturn(mock(PartitionedRegion.class)); when(this.cache.getCancelCriterion()).thenReturn(mock(CancelCriterion.class)); when(this.callbackArgPart.getObject()).thenReturn(CALLBACK_ARG); when(this.eventPart.getSerializedForm()).thenReturn(EVENT); when(this.flagsPart.getInt()).thenReturn(0); when(this.keyPart.getStringOrObject()).thenReturn(KEYS); when(this.message.getPart(eq(0))).thenReturn(this.regionNamePart); when(this.message.getPart(eq(1))).thenReturn(this.eventPart); when(this.message.getPart(eq(2))).thenReturn(this.flagsPart); when(this.message.getPart(eq(3))).thenReturn(this.callbackArgPart); when(this.message.getPart(eq(4))).thenReturn(this.numberofKeysPart); when(this.message.getPart(eq(5))).thenReturn(this.keyPart); when(this.message.getPart(eq(6))).thenReturn(this.timeoutPart); when(this.numberofKeysPart.getInt()).thenReturn(1); when(this.regionNamePart.getString()).thenReturn(REGION_NAME); when(this.serverConnection.getCache()).thenReturn(this.cache); when(this.serverConnection.getCacheServerStats()).thenReturn(mock(CacheServerStats.class)); when(this.serverConnection.getAuthzRequest()).thenReturn(this.authzRequest); when(this.serverConnection.getCachedRegionHelper()).thenReturn(mock(CachedRegionHelper.class)); when(this.serverConnection.getChunkedResponseMessage()).thenReturn(this.chunkedResponseMessage); when(this.timeoutPart.getInt()).thenReturn(5); }
@Test public void whenExceptionOccursThenLastResultReceivedMustNotBeSet() throws Exception { ServerToClientFunctionResultSender resultSender = getResultSender(); resultSender.ids = mock(InternalDistributedSystem.class); when(resultSender.ids.isDisconnecting()).thenReturn(false); Object object = mock(Object.class); resultSender.lastResultReceived = false; DistributedMember distributedMember = mock(DistributedMember.class); when(serverConnection.getPostAuthzRequest()) .thenThrow(new NotAuthorizedException("Should catch this exception")); CachedRegionHelper cachedRegionHelper = mock(CachedRegionHelper.class); when(serverConnection.getCachedRegionHelper()).thenReturn(cachedRegionHelper); InternalCache cache = mock(InternalCache.class); when(cachedRegionHelper.getCache()).thenReturn(cache); when(cache.isClosed()).thenReturn(false); expectedException.expect(NotAuthorizedException.class); resultSender.lastResult(object, distributedMember); assertFalse(resultSender.lastResultReceived); resultSender.lastResult(object); assertFalse(resultSender.lastResultReceived); }
private static void handleEOFException(Message msg, ServerConnection serverConnection, Exception eof) { CachedRegionHelper crHelper = serverConnection.getCachedRegionHelper(); CacheServerStats stats = serverConnection.getCacheServerStats(); boolean potentialModification = serverConnection.getPotentialModification(); if (!crHelper.isShutdown()) { if (potentialModification) { stats.incAbandonedWriteRequests(); } else { stats.incAbandonedReadRequests(); } if (!SUPPRESS_IO_EXCEPTION_LOGGING) { if (potentialModification) { int transId = msg != null ? msg.getTransactionId() : Integer.MIN_VALUE; logger.warn( "{}: EOFException during a write operation on region : {} key: {} messageId: {}", new Object[] {serverConnection.getName(), serverConnection.getModRegion(), serverConnection.getModKey(), transId}); } else { logger.debug("EOF exception", eof); logger.info("{}: connection disconnect detected by EOF.", serverConnection.getName()); } } } serverConnection.setFlagProcessMessagesAsFalse(); serverConnection.setClientDisconnectedException(eof); }