use of org.apache.cassandra.io.util.DataInputBuffer in project cassandra by apache.
the class HintTest method testSerializer.
@Test
public void testSerializer() throws IOException {
long now = FBUtilities.timestampMicros();
Mutation mutation = createMutation("testSerializer", now);
Hint hint = Hint.create(mutation, now / 1000);
// serialize
int serializedSize = (int) Hint.serializer.serializedSize(hint, MessagingService.current_version);
DataOutputBuffer dob = new DataOutputBuffer();
Hint.serializer.serialize(hint, dob, MessagingService.current_version);
assertEquals(serializedSize, dob.getLength());
// deserialize
DataInputPlus di = new DataInputBuffer(dob.buffer(), true);
Hint deserializedHint = Hint.serializer.deserialize(di, MessagingService.current_version);
// compare before/after
assertHintsEqual(hint, deserializedHint);
}
use of org.apache.cassandra.io.util.DataInputBuffer in project cassandra by apache.
the class StreamingTombstoneHistogramBuilderTest method testNumericTypes.
@Test
public void testNumericTypes() throws Exception {
StreamingTombstoneHistogramBuilder builder = new StreamingTombstoneHistogramBuilder(5, 0, 1);
builder.update(2);
builder.update(2);
builder.update(2);
// To check that value overflow is handled correctly
builder.update(2, Integer.MAX_VALUE);
TombstoneHistogram hist = builder.build();
Map<Integer, Integer> asMap = asMap(hist);
assertEquals(1, asMap.size());
assertEquals(Integer.MAX_VALUE, asMap.get(2).intValue());
// Make sure it's working with Serde
DataOutputBuffer out = new DataOutputBuffer();
TombstoneHistogram.serializer.serialize(hist, out);
byte[] bytes = out.toByteArray();
TombstoneHistogram deserialized = TombstoneHistogram.serializer.deserialize(new DataInputBuffer(bytes));
asMap = asMap(deserialized);
assertEquals(1, deserialized.size());
assertEquals(Integer.MAX_VALUE, asMap.get(2).intValue());
}
use of org.apache.cassandra.io.util.DataInputBuffer in project cassandra by apache.
the class MerkleTreeTest method testSerialization.
@Test
public void testSerialization() throws Exception {
Range<Token> full = new Range<>(tok(-1), tok(-1));
// populate and validate the tree
mt.maxsize(256);
mt.init();
for (TreeRange range : mt.rangeIterator()) range.addAll(new HIterator(range.right));
byte[] initialhash = mt.hash(full);
DataOutputBuffer out = new DataOutputBuffer();
mt.serialize(out, MessagingService.current_version);
byte[] serialized = out.toByteArray();
MerkleTree restoredOnHeap = MerkleTree.deserialize(new DataInputBuffer(serialized), false, MessagingService.current_version);
MerkleTree restoredOffHeap = MerkleTree.deserialize(new DataInputBuffer(serialized), true, MessagingService.current_version);
MerkleTree movedOffHeap = mt.moveOffHeap();
assertHashEquals(initialhash, restoredOnHeap.hash(full));
assertHashEquals(initialhash, restoredOffHeap.hash(full));
assertHashEquals(initialhash, movedOffHeap.hash(full));
assertEquals(mt, restoredOnHeap);
assertEquals(mt, restoredOffHeap);
assertEquals(mt, movedOffHeap);
assertEquals(restoredOnHeap, restoredOffHeap);
assertEquals(restoredOnHeap, movedOffHeap);
assertEquals(restoredOffHeap, movedOffHeap);
}
use of org.apache.cassandra.io.util.DataInputBuffer in project cassandra by apache.
the class JMXToolTest method serde.
private void serde(JMXTool.Dump.Format serializer, JMXTool.Diff.Format deserializer, DataOutputBuffer buffer, Map<String, JMXTool.Info> map) throws IOException {
buffer.clear();
serializer.dump(buffer, map);
Map<String, JMXTool.Info> read = deserializer.load(new DataInputBuffer(buffer.buffer(), false));
Assertions.assertThat(read).as("property deserialize(serialize(value)) == value failed").isEqualTo(map);
}
use of org.apache.cassandra.io.util.DataInputBuffer in project cassandra by apache.
the class SerializationUtils method cycleSerialization.
public static <T> T cycleSerialization(T src, IVersionedSerializer<T> serializer, int version) {
int expectedSize = (int) serializer.serializedSize(src, version);
try (DataOutputBuffer out = new DataOutputBuffer(expectedSize)) {
serializer.serialize(src, out, version);
Assert.assertEquals(expectedSize, out.buffer().limit());
try (DataInputBuffer in = new DataInputBuffer(out.buffer(), false)) {
return serializer.deserialize(in, version);
}
} catch (IOException e) {
throw new AssertionError(e);
}
}
Aggregations