You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by sa...@apache.org on 2022/06/15 11:07:53 UTC
[cassandra] branch cassandra-4.0 updated: Ensure test messages are actually corrupted when expected
This is an automated email from the ASF dual-hosted git repository.
samt pushed a commit to branch cassandra-4.0
in repository https://gitbox.apache.org/repos/asf/cassandra.git
The following commit(s) were added to refs/heads/cassandra-4.0 by this push:
new 28690e0ebc Ensure test messages are actually corrupted when expected
28690e0ebc is described below
commit 28690e0ebc6c4df6e2e36c04c93c52f45abda9c9
Author: Sam Tunnicliffe <sa...@apache.org>
AuthorDate: Mon Jun 13 20:00:15 2022 +0100
Ensure test messages are actually corrupted when expected
Patch by Sam Tunnicliffe; reviewed by Brandon Williams for CASSANDRA-17630
---
.../org/apache/cassandra/transport/CQLConnectionTest.java | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/test/unit/org/apache/cassandra/transport/CQLConnectionTest.java b/test/unit/org/apache/cassandra/transport/CQLConnectionTest.java
index 96f28a2488..fef25fb3e2 100644
--- a/test/unit/org/apache/cassandra/transport/CQLConnectionTest.java
+++ b/test/unit/org/apache/cassandra/transport/CQLConnectionTest.java
@@ -147,7 +147,7 @@ public class CQLConnectionTest
// Before closing, the server should send an ErrorMessage to inform the
// client of the corrupt message.
Function<ByteBuf, ByteBuf> corruptor = msg -> {
- msg.setByte(msg.readableBytes() / 2, 0xffff);
+ flipBit(msg, msg.readableBytes() / 2);
return msg;
};
IntFunction<Envelope> envelopeProvider = i -> randomEnvelope(i, Message.Type.OPTIONS);
@@ -195,7 +195,7 @@ public class CQLConnectionTest
{
int frameBoundary = MAX_FRAMED_PAYLOAD_SIZE - seenBytes;
corruptedByte = msg.readerIndex() + frameBoundary + 100;
- msg.setByte(corruptedByte, 0xffff);
+ flipBit(msg, corruptedByte);
}
else
{
@@ -543,6 +543,11 @@ public class CQLConnectionTest
};
}
+ private void flipBit(ByteBuf buf, int index)
+ {
+ buf.setByte(index, buf.getByte(index) ^ (1 << 4));
+ }
+
private static class MutableEnvelope extends Envelope
{
public MutableEnvelope(Envelope source)
@@ -603,6 +608,9 @@ public class CQLConnectionTest
Message.Request request = new OptionsMessage();
request.setSource(source);
request.setStreamId(source.header.streamId);
+ Connection connection = channel.attr(Connection.attributeKey).get();
+ request.attach(connection);
+
return request;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org