Search in sources :

Example 6 with DataInputStreamPlus

use of org.apache.cassandra.io.util.DataInputPlus.DataInputStreamPlus in project cassandra by apache.

the class SerializationsTest method testGossipDigestRead.

@Test
public void testGossipDigestRead() throws IOException {
    if (EXECUTE_WRITES)
        testGossipDigestWrite();
    int count = 0;
    DataInputStreamPlus in = getInput("gms.Gossip.bin");
    while (count < Statics.Digests.size()) assert GossipDigestAck2.serializer.deserialize(in, getVersion()) != null;
    assert GossipDigestAck.serializer.deserialize(in, getVersion()) != null;
    assert GossipDigestAck2.serializer.deserialize(in, getVersion()) != null;
    assert GossipDigestSyn.serializer.deserialize(in, getVersion()) != null;
    in.close();
}
Also used : DataInputStreamPlus(org.apache.cassandra.io.util.DataInputPlus.DataInputStreamPlus) Test(org.junit.Test)

Example 7 with DataInputStreamPlus

use of org.apache.cassandra.io.util.DataInputPlus.DataInputStreamPlus in project cassandra by apache.

the class SerializationsTest method testSyncRequestRead.

@Test
public void testSyncRequestRead() throws IOException {
    if (EXECUTE_WRITES)
        testSyncRequestWrite();
    InetAddress local = InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 });
    InetAddress src = InetAddress.getByAddress(new byte[] { 127, 0, 0, 2 });
    InetAddress dest = InetAddress.getByAddress(new byte[] { 127, 0, 0, 3 });
    try (DataInputStreamPlus in = getInput("service.SyncRequest.bin")) {
        RepairMessage message = RepairMessage.serializer.deserialize(in, getVersion());
        assert message.messageType == RepairMessage.Type.SYNC_REQUEST;
        assert DESC.equals(message.desc);
        assert local.equals(((SyncRequest) message).initiator);
        assert src.equals(((SyncRequest) message).src);
        assert dest.equals(((SyncRequest) message).dst);
        assert ((SyncRequest) message).ranges.size() == 1 && ((SyncRequest) message).ranges.contains(FULL_RANGE);
        assert MessageIn.read(in, getVersion(), -1) != null;
    }
}
Also used : DataInputStreamPlus(org.apache.cassandra.io.util.DataInputPlus.DataInputStreamPlus) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 8 with DataInputStreamPlus

use of org.apache.cassandra.io.util.DataInputPlus.DataInputStreamPlus in project cassandra by apache.

the class SerializationsTest method testValidationCompleteRead.

@Test
public void testValidationCompleteRead() throws IOException {
    if (EXECUTE_WRITES)
        testValidationCompleteWrite();
    try (DataInputStreamPlus in = getInput("service.ValidationComplete.bin")) {
        // empty validation
        RepairMessage message = RepairMessage.serializer.deserialize(in, getVersion());
        assert message.messageType == RepairMessage.Type.VALIDATION_COMPLETE;
        assert DESC.equals(message.desc);
        assert ((ValidationComplete) message).success();
        assert ((ValidationComplete) message).trees != null;
        // validation with a tree
        message = RepairMessage.serializer.deserialize(in, getVersion());
        assert message.messageType == RepairMessage.Type.VALIDATION_COMPLETE;
        assert DESC.equals(message.desc);
        assert ((ValidationComplete) message).success();
        assert ((ValidationComplete) message).trees != null;
        // failed validation
        message = RepairMessage.serializer.deserialize(in, getVersion());
        assert message.messageType == RepairMessage.Type.VALIDATION_COMPLETE;
        assert DESC.equals(message.desc);
        assert !((ValidationComplete) message).success();
        assert ((ValidationComplete) message).trees == null;
        // MessageOuts
        for (int i = 0; i < 3; i++) assert MessageIn.read(in, getVersion(), -1) != null;
    }
}
Also used : DataInputStreamPlus(org.apache.cassandra.io.util.DataInputPlus.DataInputStreamPlus) Test(org.junit.Test)

Example 9 with DataInputStreamPlus

use of org.apache.cassandra.io.util.DataInputPlus.DataInputStreamPlus in project cassandra by apache.

the class SerializationsTest method testEstimatedHistogramRead.

@Test
public void testEstimatedHistogramRead() throws IOException {
    if (EXECUTE_WRITES)
        testEstimatedHistogramWrite();
    try (DataInputStreamPlus in = getInput("utils.EstimatedHistogram.bin")) {
        Assert.assertNotNull(EstimatedHistogram.serializer.deserialize(in));
        Assert.assertNotNull(EstimatedHistogram.serializer.deserialize(in));
        Assert.assertNotNull(EstimatedHistogram.serializer.deserialize(in));
    }
}
Also used : DataInputStreamPlus(org.apache.cassandra.io.util.DataInputPlus.DataInputStreamPlus) Test(org.junit.Test)

Example 10 with DataInputStreamPlus

use of org.apache.cassandra.io.util.DataInputPlus.DataInputStreamPlus in project cassandra by apache.

the class IncomingStreamingConnection method run.

@Override
// Not closing constructed DataInputPlus's as the stream needs to remain open.
@SuppressWarnings("resource")
public void run() {
    try {
        // we can't do anything with a wrong-version stream connection, so drop it.
        if (version != StreamMessage.CURRENT_VERSION)
            throw new IOException(String.format("Received stream using protocol version %d (my version %d). Terminating connection", version, StreamMessage.CURRENT_VERSION));
        DataInputPlus input = new DataInputStreamPlus(socket.getInputStream());
        StreamInitMessage init = StreamInitMessage.serializer.deserialize(input, version);
        //Set SO_TIMEOUT on follower side
        if (!init.isForOutgoing)
            socket.setSoTimeout(DatabaseDescriptor.getStreamingSocketTimeout());
        // The initiator makes two connections, one for incoming and one for outgoing.
        // The receiving side distinguish two connections by looking at StreamInitMessage#isForOutgoing.
        // Note: we cannot use the same socket for incoming and outgoing streams because we want to
        // parallelize said streams and the socket is blocking, so we might deadlock.
        StreamResultFuture.initReceivingSide(init.sessionIndex, init.planId, init.description, init.from, this, init.isForOutgoing, version, init.keepSSTableLevel, init.isIncremental, init.pendingRepair);
    } catch (Throwable t) {
        logger.error("Error while reading from socket from {}.", socket.getRemoteSocketAddress(), t);
        close();
    }
}
Also used : DataInputStreamPlus(org.apache.cassandra.io.util.DataInputPlus.DataInputStreamPlus) DataInputPlus(org.apache.cassandra.io.util.DataInputPlus) StreamInitMessage(org.apache.cassandra.streaming.messages.StreamInitMessage) IOException(java.io.IOException)

Aggregations

DataInputStreamPlus (org.apache.cassandra.io.util.DataInputPlus.DataInputStreamPlus)10 Test (org.junit.Test)6 InetAddress (java.net.InetAddress)2 DataInputPlus (org.apache.cassandra.io.util.DataInputPlus)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 ReadableByteChannel (java.nio.channels.ReadableByteChannel)1 Future (java.util.concurrent.Future)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1 Checksum (java.util.zip.Checksum)1 LZ4BlockInputStream (net.jpountz.lz4.LZ4BlockInputStream)1 LZ4FastDecompressor (net.jpountz.lz4.LZ4FastDecompressor)1 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)1 CorruptFileException (org.apache.cassandra.io.util.CorruptFileException)1 DataOutputStreamPlus (org.apache.cassandra.io.util.DataOutputStreamPlus)1 NIODataInputStream (org.apache.cassandra.io.util.NIODataInputStream)1 WrappedDataOutputStreamPlus (org.apache.cassandra.io.util.WrappedDataOutputStreamPlus)1 NodePair (org.apache.cassandra.repair.NodePair)1