use of org.apache.geode.internal.cache.tier.sockets.Message in project geode by apache.
the class CommitCommandTest method testWriteNullResponse.
/**
* 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);
}
use of org.apache.geode.internal.cache.tier.sockets.Message in project geode by apache.
the class Destroy65 method writeReply.
protected void writeReply(Message origMsg, ServerConnection servConn, boolean entryNotFound, VersionTag tag) throws IOException {
Message replyMsg = servConn.getReplyMessage();
servConn.getCache().getCancelCriterion().checkCancelInProgress(null);
replyMsg.setMessageType(MessageType.REPLY);
replyMsg.setNumberOfParts(2);
replyMsg.setTransactionId(origMsg.getTransactionId());
replyMsg.addBytesPart(okBytes());
replyMsg.addIntPart(entryNotFound ? 1 : 0);
replyMsg.send(servConn);
if (logger.isTraceEnabled()) {
logger.trace("{}: rpl tx: {} parts={}", servConn.getName(), origMsg.getTransactionId(), replyMsg.getNumberOfParts());
}
}
use of org.apache.geode.internal.cache.tier.sockets.Message in project geode by apache.
the class Destroy70 method writeReplyWithRefreshMetadata.
@Override
protected void writeReplyWithRefreshMetadata(Message origMsg, ServerConnection servConn, PartitionedRegion pr, boolean entryNotFoundForRemove, byte nwHop, VersionTag versionTag) throws IOException {
Message replyMsg = servConn.getReplyMessage();
servConn.getCache().getCancelCriterion().checkCancelInProgress(null);
replyMsg.setMessageType(MessageType.REPLY);
int flags = 0;
int numParts = 3;
if (versionTag != null) {
flags |= DestroyOp.HAS_VERSION_TAG;
numParts++;
}
flags |= DestroyOp.HAS_ENTRY_NOT_FOUND_PART;
// if (logger.isDebugEnabled()) {
// logger.fine("writing response with metadata and " + numParts + " parts");
// }
replyMsg.setNumberOfParts(numParts);
replyMsg.setTransactionId(origMsg.getTransactionId());
replyMsg.addIntPart(flags);
if (versionTag != null) {
replyMsg.addObjPart(versionTag);
}
replyMsg.addBytesPart(new byte[] { pr.getMetadataVersion(), nwHop });
replyMsg.addIntPart(entryNotFoundForRemove ? 1 : 0);
pr.getPrStats().incPRMetaDataSentCount();
replyMsg.send(servConn);
if (logger.isTraceEnabled()) {
logger.trace("{}: rpl with REFRESH_METADATA tx: {}", servConn.getName(), origMsg.getTransactionId());
}
}
use of org.apache.geode.internal.cache.tier.sockets.Message in project geode by apache.
the class Destroy70 method writeReply.
@Override
protected void writeReply(Message origMsg, ServerConnection servConn, boolean entryNotFound, VersionTag versionTag) throws IOException {
if (logger.isDebugEnabled()) {
logger.debug("Destroy70.writeReply(entryNotFound={}, tag={})", entryNotFound, versionTag);
}
Message replyMsg = servConn.getReplyMessage();
servConn.getCache().getCancelCriterion().checkCancelInProgress(null);
replyMsg.setMessageType(MessageType.REPLY);
int flags = 0;
int numParts = 3;
if (versionTag != null) {
flags |= DestroyOp.HAS_VERSION_TAG;
numParts++;
}
flags |= DestroyOp.HAS_ENTRY_NOT_FOUND_PART;
// if (logger.isDebugEnabled()) {
// logger.fine("writing response with 1-byte metadata and " + numParts + " parts");
// }
replyMsg.setNumberOfParts(numParts);
replyMsg.setTransactionId(origMsg.getTransactionId());
replyMsg.addIntPart(flags);
if (versionTag != null) {
// if (logger.isDebugEnabled()) {
// logger.fine("wrote version tag in response: " + versionTag);
// }
replyMsg.addObjPart(versionTag);
// } else {
// if (logger.isDebugEnabled()) {
// logger.fine("response has no version tag");
// }
}
// make old single-hop code happy by puting byte[]{0} here
replyMsg.addBytesPart(okBytes());
replyMsg.addIntPart(entryNotFound ? 1 : 0);
replyMsg.send(servConn);
if (logger.isTraceEnabled()) {
logger.trace("{}: rpl tx: {} parts={}", servConn.getName(), origMsg.getTransactionId(), replyMsg.getNumberOfParts());
}
}
use of org.apache.geode.internal.cache.tier.sockets.Message in project geode by apache.
the class GatewayReceiverCommand method writeFatalException.
private static void writeFatalException(Message origMsg, Throwable exception, ServerConnection servConn, int batchId) throws IOException {
Message errorMsg = servConn.getErrorResponseMessage();
errorMsg.setMessageType(MessageType.EXCEPTION);
errorMsg.setNumberOfParts(2);
errorMsg.setTransactionId(origMsg.getTransactionId());
// they can deserialize.
if ((servConn.getClientVersion() == null || servConn.getClientVersion().compareTo(Version.GFE_80) < 0) && exception instanceof PdxRegistryMismatchException) {
PdxConfigurationException newException = new PdxConfigurationException(exception.getMessage());
newException.setStackTrace(exception.getStackTrace());
exception = newException;
}
errorMsg.addObjPart(exception);
// errorMsg.addStringPart(be.toString());
errorMsg.send(servConn);
logger.warn(LocalizedMessage.create(LocalizedStrings.ProcessBatch_0_WROTE_BATCH_EXCEPTION, servConn.getName()), exception);
}
Aggregations