use of org.apache.cassandra.transport.messages.ErrorMessage in project cassandra by apache.
the class ProtocolErrorTest method testErrorMessageWithNullString.
@Test
public void testErrorMessageWithNullString() {
// test for CASSANDRA-11167
ErrorMessage msg = ErrorMessage.fromException(new ServerError((String) null));
assert msg.toString().endsWith("null") : msg.toString();
int size = ErrorMessage.codec.encodedSize(msg, ProtocolVersion.CURRENT);
ByteBuf buf = Unpooled.buffer(size);
ErrorMessage.codec.encode(msg, buf, ProtocolVersion.CURRENT);
ByteBuf expected = Unpooled.wrappedBuffer(new byte[] { // int error code
0x00, // int error code
0x00, // int error code
0x00, // int error code
0x00, // short message length
0x00, // short message length
0x00 });
Assert.assertEquals(expected, buf);
}
use of org.apache.cassandra.transport.messages.ErrorMessage in project cassandra by apache.
the class ErrorMessageTest method testV5CasWriteTimeoutSerDeser.
@Test
public void testV5CasWriteTimeoutSerDeser() {
int contentions = 1;
int receivedBlockFor = 3;
ConsistencyLevel consistencyLevel = ConsistencyLevel.SERIAL;
CasWriteTimeoutException ex = new CasWriteTimeoutException(WriteType.CAS, consistencyLevel, receivedBlockFor, receivedBlockFor, contentions);
ErrorMessage deserialized = encodeThenDecode(ErrorMessage.fromException(ex), ProtocolVersion.V5);
assertTrue(deserialized.error instanceof CasWriteTimeoutException);
CasWriteTimeoutException deserializedEx = (CasWriteTimeoutException) deserialized.error;
assertEquals(WriteType.CAS, deserializedEx.writeType);
assertEquals(contentions, deserializedEx.contentions);
assertEquals(consistencyLevel, deserializedEx.consistency);
assertEquals(receivedBlockFor, deserializedEx.received);
assertEquals(receivedBlockFor, deserializedEx.blockFor);
assertEquals(ex.getMessage(), deserializedEx.getMessage());
assertTrue(deserializedEx.getMessage().contains("CAS operation timed out - encountered contentions"));
}
use of org.apache.cassandra.transport.messages.ErrorMessage in project cassandra by apache.
the class ErrorMessageTest method testV5WriteFailureSerDeser.
@Test
public void testV5WriteFailureSerDeser() {
int receivedBlockFor = 3;
ConsistencyLevel consistencyLevel = ConsistencyLevel.ALL;
WriteType writeType = WriteType.SIMPLE;
WriteFailureException wfe = new WriteFailureException(consistencyLevel, receivedBlockFor, receivedBlockFor, writeType, failureReasonMap2);
ErrorMessage deserialized = encodeThenDecode(ErrorMessage.fromException(wfe), ProtocolVersion.V5);
WriteFailureException deserializedWfe = (WriteFailureException) deserialized.error;
assertEquals(failureReasonMap2, deserializedWfe.failureReasonByEndpoint);
assertEquals(receivedBlockFor, deserializedWfe.received);
assertEquals(receivedBlockFor, deserializedWfe.blockFor);
assertEquals(consistencyLevel, deserializedWfe.consistency);
assertEquals(writeType, deserializedWfe.writeType);
}
Aggregations