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();
}
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);
}
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;
}
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);
}
}
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);
}
}
Aggregations