Search in sources :

Example 1 with WriteFailureException

use of org.apache.cassandra.exceptions.WriteFailureException in project cassandra by apache.

the class ErrorMessageTest method testRequestFailureExceptionMakesCopy.

/**
     * Make sure that the map passed in to create a Read/WriteFailureException is copied
     * so later modifications to the map passed in don't affect the map in the exception.
     *
     * This is to prevent potential issues in serialization if the map created in
     * ReadCallback/AbstractWriteResponseHandler is modified due to a delayed failure
     * response after the exception is created.
     */
@Test
public void testRequestFailureExceptionMakesCopy() throws UnknownHostException {
    Map<InetAddress, RequestFailureReason> modifiableFailureReasons = new HashMap<>(failureReasonMap1);
    ReadFailureException rfe = new ReadFailureException(ConsistencyLevel.ALL, 3, 3, false, modifiableFailureReasons);
    WriteFailureException wfe = new WriteFailureException(ConsistencyLevel.ALL, 3, 3, WriteType.SIMPLE, modifiableFailureReasons);
    modifiableFailureReasons.put(InetAddress.getByName("127.0.0.4"), RequestFailureReason.UNKNOWN);
    assertEquals(failureReasonMap1, rfe.failureReasonByEndpoint);
    assertEquals(failureReasonMap1, wfe.failureReasonByEndpoint);
}
Also used : WriteFailureException(org.apache.cassandra.exceptions.WriteFailureException) RequestFailureReason(org.apache.cassandra.exceptions.RequestFailureReason) ReadFailureException(org.apache.cassandra.exceptions.ReadFailureException) HashMap(java.util.HashMap) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 2 with WriteFailureException

use of org.apache.cassandra.exceptions.WriteFailureException 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 = serializeAndGetDeserializedErrorMessage(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

WriteFailureException (org.apache.cassandra.exceptions.WriteFailureException)2 Test (org.junit.Test)2 InetAddress (java.net.InetAddress)1 HashMap (java.util.HashMap)1 ConsistencyLevel (org.apache.cassandra.db.ConsistencyLevel)1 WriteType (org.apache.cassandra.db.WriteType)1 ReadFailureException (org.apache.cassandra.exceptions.ReadFailureException)1 RequestFailureReason (org.apache.cassandra.exceptions.RequestFailureReason)1 ErrorMessage (org.apache.cassandra.transport.messages.ErrorMessage)1