Search in sources :

Example 1 with UnknownColumnException

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

the class ConnectionTest method testRecoverableCorruptedMessageDelivery.

@Test
public void testRecoverableCorruptedMessageDelivery() throws Throwable {
    test((inbound, outbound, endpoint) -> {
        int version = outbound.settings().acceptVersions.max;
        if (version < VERSION_40)
            return;
        AtomicInteger counter = new AtomicInteger();
        unsafeSetSerializer(Verb._TEST_1, () -> new IVersionedSerializer<Object>() {

            public void serialize(Object o, DataOutputPlus out, int version) throws IOException {
                out.writeInt((Integer) o);
            }

            public Object deserialize(DataInputPlus in, int version) throws IOException {
                if (counter.getAndIncrement() == 3)
                    throw new UnknownColumnException("");
                return in.readInt();
            }

            public long serializedSize(Object o, int version) {
                return Integer.BYTES;
            }
        });
        // Connect
        connect(outbound);
        CountDownLatch latch = new CountDownLatch(4);
        unsafeSetHandler(Verb._TEST_1, () -> message -> latch.countDown());
        for (int i = 0; i < 5; i++) outbound.enqueue(Message.out(Verb._TEST_1, 0xffffffff));
        latch.await(10, SECONDS);
        Assert.assertEquals(0, latch.getCount());
        Assert.assertEquals(6, counter.get());
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) UnknownColumnException(org.apache.cassandra.exceptions.UnknownColumnException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DataInputPlus(org.apache.cassandra.io.util.DataInputPlus) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) DataOutputPlus(org.apache.cassandra.io.util.DataOutputPlus) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 UnknownColumnException (org.apache.cassandra.exceptions.UnknownColumnException)1 DataInputPlus (org.apache.cassandra.io.util.DataInputPlus)1 DataOutputPlus (org.apache.cassandra.io.util.DataOutputPlus)1 Test (org.junit.Test)1