Search in sources :

Example 26 with DataOutputBuffer

use of org.apache.cassandra.io.util.DataOutputBuffer in project eiger by wlloyd.

the class CounterColumnTest method testSerializeDeserialize.

@Test
public void testSerializeDeserialize() throws IOException {
    Allocator allocator = HeapAllocator.instance;
    CounterContext.ContextState state = CounterContext.ContextState.allocate(4, 2, allocator);
    state.writeElement(NodeId.fromInt(1), 4L, 4L);
    state.writeElement(NodeId.fromInt(2), 4L, 4L, true);
    state.writeElement(NodeId.fromInt(3), 4L, 4L);
    state.writeElement(NodeId.fromInt(4), 4L, 4L, true);
    CounterColumn original = new CounterColumn(ByteBufferUtil.bytes("x"), state.context, 1L);
    DataOutputBuffer bufOut = new DataOutputBuffer();
    Column.serializer().serialize(original, bufOut);
    byte[] serialized = bufOut.getData();
    ByteArrayInputStream bufIn = new ByteArrayInputStream(serialized, 0, serialized.length);
    CounterColumn deserialized = (CounterColumn) Column.serializer().deserialize(new DataInputStream(bufIn));
    assert original.equals(deserialized);
    bufIn = new ByteArrayInputStream(serialized, 0, serialized.length);
    CounterColumn deserializedOnRemote = (CounterColumn) Column.serializer().deserialize(new DataInputStream(bufIn), IColumnSerializer.Flag.FROM_REMOTE);
    assert deserializedOnRemote.name().equals(original.name());
    assert deserializedOnRemote.total() == original.total();
    assert deserializedOnRemote.value().equals(cc.clearAllDelta(original.value()));
    assert deserializedOnRemote.timestamp() == deserialized.timestamp();
    assert deserializedOnRemote.timestampOfLastDelete() == deserialized.timestampOfLastDelete();
}
Also used : HeapAllocator(org.apache.cassandra.utils.HeapAllocator) Allocator(org.apache.cassandra.utils.Allocator) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputBuffer(org.apache.cassandra.io.util.DataOutputBuffer) DataInputStream(java.io.DataInputStream) ContextState(org.apache.cassandra.db.context.CounterContext.ContextState) CounterContext(org.apache.cassandra.db.context.CounterContext) Test(org.junit.Test)

Example 27 with DataOutputBuffer

use of org.apache.cassandra.io.util.DataOutputBuffer in project eiger by wlloyd.

the class LazilyCompactedRowTest method testOneRowManyColumns.

@Test
public void testOneRowManyColumns() throws IOException, ExecutionException, InterruptedException, NoSuchAlgorithmException {
    CompactionManager.instance.disableAutoCompaction();
    Table table = Table.open("Keyspace1");
    ColumnFamilyStore cfs = table.getColumnFamilyStore("Standard1");
    ByteBuffer key = ByteBuffer.wrap("k".getBytes());
    RowMutation rm = new RowMutation("Keyspace1", key);
    for (int i = 0; i < 1000; i++) rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes(i)), ByteBufferUtil.EMPTY_BYTE_BUFFER, 0);
    rm.apply();
    DataOutputBuffer out = new DataOutputBuffer();
    RowMutation.serializer().serialize(rm, out, MessagingService.version_);
    assert out.getLength() > DatabaseDescriptor.getColumnIndexSize();
    cfs.forceBlockingFlush();
    assertBytes(cfs, Integer.MAX_VALUE);
    assertDigest(cfs, Integer.MAX_VALUE);
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) DataOutputBuffer(org.apache.cassandra.io.util.DataOutputBuffer) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 28 with DataOutputBuffer

use of org.apache.cassandra.io.util.DataOutputBuffer in project eiger by wlloyd.

the class BloomFilterTest method testSerialize.

public static BloomFilter testSerialize(BloomFilter f) throws IOException {
    f.add(ByteBufferUtil.bytes("a"));
    DataOutputBuffer out = new DataOutputBuffer();
    f.serializer().serialize(f, out);
    ByteArrayInputStream in = new ByteArrayInputStream(out.getData(), 0, out.getLength());
    BloomFilter f2 = f.serializer().deserialize(new DataInputStream(in));
    assert f2.isPresent(ByteBufferUtil.bytes("a"));
    assert !f2.isPresent(ByteBufferUtil.bytes("b"));
    return f2;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputBuffer(org.apache.cassandra.io.util.DataOutputBuffer) DataInputStream(java.io.DataInputStream)

Example 29 with DataOutputBuffer

use of org.apache.cassandra.io.util.DataOutputBuffer in project cassandra by apache.

the class StorageProxy method sendMessagesToNonlocalDC.

private static void sendMessagesToNonlocalDC(MessageOut<? extends IMutation> message, Collection<InetAddress> targets, AbstractWriteResponseHandler<IMutation> handler) {
    Iterator<InetAddress> iter = targets.iterator();
    InetAddress target = iter.next();
    // Add the other destinations of the same message as a FORWARD_HEADER entry
    try (DataOutputBuffer out = new DataOutputBuffer()) {
        out.writeInt(targets.size() - 1);
        while (iter.hasNext()) {
            InetAddress destination = iter.next();
            CompactEndpointSerializationHelper.serialize(destination, out);
            int id = MessagingService.instance().addCallback(handler, message, destination, message.getTimeout(), handler.consistencyLevel, true);
            out.writeInt(id);
            logger.trace("Adding FWD message to {}@{}", id, destination);
        }
        message = message.withParameter(Mutation.FORWARD_TO, out.getData());
        // send the combined message + forward headers
        int id = MessagingService.instance().sendRR(message, target, handler, true);
        logger.trace("Sending message to {}@{}", id, target);
    } catch (IOException e) {
        // DataOutputBuffer is in-memory, doesn't throw IOException
        throw new AssertionError(e);
    }
}
Also used : DataOutputBuffer(org.apache.cassandra.io.util.DataOutputBuffer) IOException(java.io.IOException) InetAddress(java.net.InetAddress) Hint(org.apache.cassandra.hints.Hint)

Example 30 with DataOutputBuffer

use of org.apache.cassandra.io.util.DataOutputBuffer in project cassandra by apache.

the class PagingState method serialize.

public ByteBuffer serialize(ProtocolVersion protocolVersion) {
    assert rowMark == null || protocolVersion == rowMark.protocolVersion;
    try (DataOutputBuffer out = new DataOutputBufferFixed(serializedSize(protocolVersion))) {
        ByteBuffer pk = partitionKey == null ? ByteBufferUtil.EMPTY_BYTE_BUFFER : partitionKey;
        ByteBuffer mark = rowMark == null ? ByteBufferUtil.EMPTY_BYTE_BUFFER : rowMark.mark;
        if (protocolVersion.isSmallerOrEqualTo(ProtocolVersion.V3)) {
            ByteBufferUtil.writeWithShortLength(pk, out);
            ByteBufferUtil.writeWithShortLength(mark, out);
            out.writeInt(remaining);
            out.writeInt(remainingInPartition);
        } else {
            ByteBufferUtil.writeWithVIntLength(pk, out);
            ByteBufferUtil.writeWithVIntLength(mark, out);
            out.writeUnsignedVInt(remaining);
            out.writeUnsignedVInt(remainingInPartition);
        }
        return out.buffer();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : DataOutputBuffer(org.apache.cassandra.io.util.DataOutputBuffer) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) DataOutputBufferFixed(org.apache.cassandra.io.util.DataOutputBufferFixed)

Aggregations

DataOutputBuffer (org.apache.cassandra.io.util.DataOutputBuffer)68 Test (org.junit.Test)25 DataInputBuffer (org.apache.cassandra.io.util.DataInputBuffer)17 IOException (java.io.IOException)16 ByteBuffer (java.nio.ByteBuffer)15 ByteArrayInputStream (java.io.ByteArrayInputStream)10 DataInputStream (java.io.DataInputStream)10 DataInputPlus (org.apache.cassandra.io.util.DataInputPlus)8 File (java.io.File)6 CRC32 (java.util.zip.CRC32)5 InetAddress (java.net.InetAddress)3 ArrayList (java.util.ArrayList)3 DataOutputBufferFixed (org.apache.cassandra.io.util.DataOutputBufferFixed)3 SequentialWriter (org.apache.cassandra.io.util.SequentialWriter)3 Message (org.apache.cassandra.net.Message)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 DataOutputStream (java.io.DataOutputStream)2 Map (java.util.Map)2 UUID (java.util.UUID)2 Mutation (org.apache.cassandra.db.Mutation)2