Search in sources :

Example 6 with ErrorMessage

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);
}
Also used : ErrorMessage(org.apache.cassandra.transport.messages.ErrorMessage) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 7 with ErrorMessage

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"));
}
Also used : ConsistencyLevel(org.apache.cassandra.db.ConsistencyLevel) ErrorMessage(org.apache.cassandra.transport.messages.ErrorMessage) CasWriteTimeoutException(org.apache.cassandra.exceptions.CasWriteTimeoutException) Test(org.junit.Test)

Example 8 with ErrorMessage

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);
}
Also used : ConsistencyLevel(org.apache.cassandra.db.ConsistencyLevel) WriteFailureException(org.apache.cassandra.exceptions.WriteFailureException) WriteType(org.apache.cassandra.db.WriteType) ErrorMessage(org.apache.cassandra.transport.messages.ErrorMessage) Test(org.junit.Test)

Aggregations

ErrorMessage (org.apache.cassandra.transport.messages.ErrorMessage)8 Test (org.junit.Test)7 ConsistencyLevel (org.apache.cassandra.db.ConsistencyLevel)6 CasWriteTimeoutException (org.apache.cassandra.exceptions.CasWriteTimeoutException)3 ByteBuf (io.netty.buffer.ByteBuf)2 CasWriteUnknownResultException (org.apache.cassandra.exceptions.CasWriteUnknownResultException)2 WriteTimeoutException (org.apache.cassandra.exceptions.WriteTimeoutException)2 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 ChannelPromise (io.netty.channel.ChannelPromise)1 VoidChannelPromise (io.netty.channel.VoidChannelPromise)1 ByteToMessageDecoder (io.netty.handler.codec.ByteToMessageDecoder)1 Attribute (io.netty.util.Attribute)1 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 QueryProcessor (org.apache.cassandra.cql3.QueryProcessor)1 WriteType (org.apache.cassandra.db.WriteType)1