/** * Test for GEODE-537 No NPE should be thrown from the * {@link CommitCommand#writeCommitResponse(org.apache.geode.internal.cache.TXCommitMessage, Message, ServerConnection)} * if the response message is null as it is the case when JTA transaction is rolled back with * TX_SYNCHRONIZATION AFTER_COMPLETION STATUS_ROLLEDBACK */ @Test public void testWriteNullResponse() throws Exception { InternalCache cache = mock(InternalCache.class); Message origMsg = mock(Message.class); ServerConnection servConn = mock(ServerConnection.class); when(servConn.getResponseMessage()).thenReturn(mock(Message.class)); when(servConn.getCache()).thenReturn(cache); when(cache.getCancelCriterion()).thenReturn(mock(CancelCriterion.class)); CommitCommand.writeCommitResponse(null, origMsg, servConn); }
@Before public void setUp() throws Exception { this.getClientPartitionAttributesCommand = new GetClientPartitionAttributesCommand(); MockitoAnnotations.initMocks(this); when(this.cache.getRegion(isA(String.class))).thenReturn(mock(PartitionedRegion.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.getResponseMessage()).thenReturn(this.responseMessage); }
@Before public void setUp() throws Exception { this.getClientPartitionAttributesCommand66 = new GetClientPartitionAttributesCommand66(); MockitoAnnotations.initMocks(this); when(this.cache.getRegion(isA(String.class))).thenReturn(mock(LocalRegion.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.getResponseMessage()).thenReturn(this.responseMessage); }
@Before public void setUp() throws Exception { this.containsKey66 = new ContainsKey66(); MockitoAnnotations.initMocks(this); when(this.region.containsKey(eq(REGION_NAME))).thenReturn(true); when(this.cache.getRegion(isA(String.class))).thenReturn(this.region); when(this.serverConnection.getCache()).thenReturn(this.cache); when(this.serverConnection.getCacheServerStats()).thenReturn(this.cacheServerStats); when(this.serverConnection.getErrorResponseMessage()).thenReturn(this.errorResponseMessage); when(this.serverConnection.getResponseMessage()).thenReturn(this.responseMessage); when(this.serverConnection.getAuthzRequest()).thenReturn(this.authzRequest); when(this.serverConnection.getClientVersion()).thenReturn(Version.CURRENT); when(this.regionNamePart.getString()).thenReturn(REGION_NAME); when(this.keyPart.getStringOrObject()).thenReturn(KEY); when(this.modePart.getInt()).thenReturn(0); 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.modePart); }
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); Region region = mock(LocalRegion.class); when(region.containsKey(isA(String.class))).thenReturn(true); InternalCache cache = mock(InternalCache.class); when(cache.getRegion(isA(String.class))).thenReturn(region); CacheServerStats cacheServerStats = mock(CacheServerStats.class); when(this.serverConnection.getCache()).thenReturn(cache); when(this.serverConnection.getCacheServerStats()).thenReturn(cacheServerStats); when(this.serverConnection.getResponseMessage()).thenReturn(this.replyMessage); when(this.serverConnection.getAuthzRequest()).thenReturn(this.authzRequest); when(this.serverConnection.getErrorResponseMessage()).thenReturn(this.errorResponseMessage); Part regionNamePart = mock(Part.class); when(regionNamePart.getString()).thenReturn(REGION_NAME); Part keyPart = mock(Part.class); when(keyPart.getStringOrObject()).thenReturn(KEY); when(this.message.getPart(eq(0))).thenReturn(regionNamePart); when(this.message.getPart(eq(1))).thenReturn(keyPart); }
private static void writeContainsKeyResponse(boolean containsKey, Message origMsg, ServerConnection servConn) throws IOException { Message responseMsg = servConn.getResponseMessage(); responseMsg.setMessageType(MessageType.RESPONSE); responseMsg.setNumberOfParts(1); responseMsg.setTransactionId(origMsg.getTransactionId()); responseMsg.addObjPart(containsKey ? Boolean.TRUE : Boolean.FALSE); responseMsg.send(servConn); }
private static void writeSizeResponse(Integer sizeCount, Message origMsg, ServerConnection servConn) throws IOException { Message responseMsg = servConn.getResponseMessage(); responseMsg.setMessageType(MessageType.RESPONSE); responseMsg.setNumberOfParts(1); responseMsg.setTransactionId(origMsg.getTransactionId()); responseMsg.addObjPart(sizeCount); responseMsg.send(servConn); }
private static void writeContainsKeyResponse(boolean containsKey, Message origMsg, ServerConnection servConn) throws IOException { Message responseMsg = servConn.getResponseMessage(); responseMsg.setMessageType(MessageType.RESPONSE); responseMsg.setNumberOfParts(1); responseMsg.setTransactionId(origMsg.getTransactionId()); responseMsg.addObjPart(containsKey ? Boolean.TRUE : Boolean.FALSE); responseMsg.send(servConn); }
@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); }
@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); }
private void writeReply(Message msg, ServerConnection servConn, int batchId, int numberOfEvents) throws IOException { Message replyMsg = servConn.getResponseMessage(); replyMsg.setMessageType(MessageType.REPLY); replyMsg.setTransactionId(msg.getTransactionId()); replyMsg.setNumberOfParts(2); replyMsg.addIntPart(batchId); replyMsg.addIntPart(numberOfEvents); replyMsg.setTransactionId(msg.getTransactionId()); replyMsg.send(servConn); servConn.setAsTrue(Command.RESPONDED); if (logger.isDebugEnabled()) { logger.debug("{}: rpl tx: {} batchId {} numberOfEvents: {}", servConn.getName(), msg.getTransactionId(), batchId, numberOfEvents); } }
protected static void writeResponseWithFunctionAttribute(byte[] data, Message origMsg, ServerConnection serverConnection) throws IOException { Message responseMsg = serverConnection.getResponseMessage(); responseMsg.setMessageType(MessageType.RESPONSE); responseMsg.setTransactionId(origMsg.getTransactionId()); responseMsg.setNumberOfParts(1); responseMsg.addBytesPart(data); serverConnection.getCache().getCancelCriterion().checkCancelInProgress(null); responseMsg.send(serverConnection); origMsg.clearParts(); }
protected static void writeCommitResponse(TXCommitMessage response, Message origMsg, ServerConnection servConn) throws IOException { Message responseMsg = servConn.getResponseMessage(); responseMsg.setMessageType(MessageType.RESPONSE); responseMsg.setTransactionId(origMsg.getTransactionId()); responseMsg.setNumberOfParts(1); if (response != null) { response.setClientVersion(servConn.getClientVersion()); } responseMsg.addObjPart(response, false); servConn.getCache().getCancelCriterion().checkCancelInProgress(null); if (logger.isDebugEnabled()) { logger.debug("TX: sending a nonNull response for transaction: {}", new TXId((InternalDistributedMember) servConn.getProxyID().getDistributedMember(), origMsg.getTransactionId())); } responseMsg.send(servConn); origMsg.clearParts(); }
@Override public void cmdExecute(final Message clientMessage, final ServerConnection serverConnection, final SecurityService securityService, long start) throws IOException, ClassNotFoundException { serverConnection.setAsTrue(REQUIRES_RESPONSE); if (logger.isDebugEnabled()) { logger.debug("{}: Received get pdx types from {}", serverConnection.getName(), serverConnection.getSocketString()); } Map<Integer, PdxType> types; try { InternalCache cache = serverConnection.getCache(); types = cache.getPdxRegistry().typeMap(); } catch (Exception e) { writeException(clientMessage, e, false, serverConnection); serverConnection.setAsTrue(RESPONDED); return; } Message responseMsg = serverConnection.getResponseMessage(); responseMsg.setMessageType(MessageType.RESPONSE); responseMsg.setNumberOfParts(1); responseMsg.setTransactionId(clientMessage.getTransactionId()); responseMsg.addObjPart(types); responseMsg.send(serverConnection); serverConnection.setAsTrue(RESPONDED); } }
@Override public void cmdExecute(final Message clientMessage, final ServerConnection serverConnection, final SecurityService securityService, long start) throws IOException, ClassNotFoundException { serverConnection.setAsTrue(REQUIRES_RESPONSE); if (logger.isDebugEnabled()) { logger.debug("{}: Received get pdx enums from {}", serverConnection.getName(), serverConnection.getSocketString()); } Map<Integer, EnumInfo> enums; try { InternalCache cache = serverConnection.getCache(); enums = cache.getPdxRegistry().enumMap(); } catch (Exception e) { writeException(clientMessage, e, false, serverConnection); serverConnection.setAsTrue(RESPONDED); return; } Message responseMsg = serverConnection.getResponseMessage(); responseMsg.setMessageType(MessageType.RESPONSE); responseMsg.setNumberOfParts(1); responseMsg.setTransactionId(clientMessage.getTransactionId()); responseMsg.addObjPart(enums); responseMsg.send(serverConnection); serverConnection.setAsTrue(RESPONDED); } }
Message responseMsg = serverConnection.getResponseMessage(); responseMsg.setMessageType(MessageType.RESPONSE); responseMsg.setNumberOfParts(1);
Message responseMsg = serverConnection.getResponseMessage(); responseMsg.setMessageType(MessageType.RESPONSE); responseMsg.setNumberOfParts(1);
Message responseMsg = serverConnection.getResponseMessage(); responseMsg.setMessageType(MessageType.RESPONSE); responseMsg.setNumberOfParts(1);
protected static void writeResponse(Object data, Object callbackArg, Message origMsg, boolean isObject, ServerConnection serverConnection) throws IOException { Message responseMsg = serverConnection.getResponseMessage(); responseMsg.setMessageType(MessageType.RESPONSE); responseMsg.setTransactionId(origMsg.getTransactionId()); if (callbackArg == null) { responseMsg.setNumberOfParts(1); } else { responseMsg.setNumberOfParts(2); } if (data instanceof byte[]) { responseMsg.addRawPart((byte[]) data, isObject); } else { Assert.assertTrue(isObject, "isObject should be true when value is not a byte[]"); responseMsg.addObjPart(data, false); } if (callbackArg != null) { responseMsg.addObjPart(callbackArg); } serverConnection.getCache().getCancelCriterion().checkCancelInProgress(null); responseMsg.send(serverConnection); origMsg.clearParts(); }
protected static void writeResponseWithRefreshMetadata(Object data, Object callbackArg, Message origMsg, boolean isObject, ServerConnection serverConnection, PartitionedRegion pr, byte nwHop) throws IOException { Message responseMsg = serverConnection.getResponseMessage(); responseMsg.setMessageType(MessageType.RESPONSE); responseMsg.setTransactionId(origMsg.getTransactionId()); if (callbackArg == null) { responseMsg.setNumberOfParts(2); } else { responseMsg.setNumberOfParts(3); } if (data instanceof byte[]) { responseMsg.addRawPart((byte[]) data, isObject); } else { Assert.assertTrue(isObject, "isObject should be true when value is not a byte[]"); responseMsg.addObjPart(data, false); } if (callbackArg != null) { responseMsg.addObjPart(callbackArg); } responseMsg.addBytesPart(new byte[] {pr.getMetadataVersion(), nwHop}); serverConnection.getCache().getCancelCriterion().checkCancelInProgress(null); responseMsg.send(serverConnection); origMsg.clearParts(); }