Search in sources :

Example 1 with ByteArrayUtil

use of com.apple.foundationdb.tuple.ByteArrayUtil in project fdb-record-layer by FoundationDB.

the class BunchedTupleSerializerTest method serializeKey.

@Test
public void serializeKey() {
    List<Tuple> sortedTuples = TEST_TUPLES.stream().sorted().collect(Collectors.toList());
    List<Tuple> sortedKeys = TEST_TUPLES.stream().map(serializer::serializeKey).sorted(ByteArrayUtil::compareUnsigned).map(serializer::deserializeKey).collect(Collectors.toList());
    assertEquals(sortedTuples, sortedKeys);
    // Add a subspace and make sure unpacking by length works.
    Subspace subspace = new Subspace(Tuple.from("fake", "subspace"));
    List<Tuple> prefixedTuples = TEST_TUPLES.stream().map(serializer::serializeKey).map(b -> ByteArrayUtil.join(subspace.getKey(), b)).map(data -> serializer.deserializeKey(data, subspace.getKey().length)).collect(Collectors.toList());
    assertEquals(TEST_TUPLES, prefixedTuples);
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ByteArrayUtil(com.apple.foundationdb.tuple.ByteArrayUtil) Arrays(java.util.Arrays) Collectors(java.util.stream.Collectors) Subspace(com.apple.foundationdb.subspace.Subspace) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) Tuple(com.apple.foundationdb.tuple.Tuple) AbstractMap(java.util.AbstractMap) List(java.util.List) Map(java.util.Map) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Collections(java.util.Collections) Subspace(com.apple.foundationdb.subspace.Subspace) Tuple(com.apple.foundationdb.tuple.Tuple) ByteArrayUtil(com.apple.foundationdb.tuple.ByteArrayUtil) Test(org.junit.jupiter.api.Test)

Aggregations

Subspace (com.apple.foundationdb.subspace.Subspace)1 ByteArrayUtil (com.apple.foundationdb.tuple.ByteArrayUtil)1 Tuple (com.apple.foundationdb.tuple.Tuple)1 AbstractMap (java.util.AbstractMap)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Assertions.assertArrayEquals (org.junit.jupiter.api.Assertions.assertArrayEquals)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)1 Test (org.junit.jupiter.api.Test)1