Search in sources :

Example 1 with PluginSerializer

use of com.cinchapi.concourse.server.plugin.io.PluginSerializer in project concourse by cinchapi.

the class LazyTrackingTObjectResultDatasetTest method testSerializationRepro.

@Test
public void testSerializationRepro() {
    String json = FileOps.read(Resources.getAbsolutePath("/data.json"));
    List<Multimap<String, Object>> objects = Convert.anyJsonToJava(json);
    for (Multimap<String, Object> object : objects) {
        long entity = Time.now();
        for (Entry<String, Collection<Object>> entry : object.asMap().entrySet()) {
            String attribute = entry.getKey();
            for (Object value : entry.getValue()) {
                dataset.insert(entity, attribute, Convert.javaToThrift(value));
            }
        }
    }
    PluginSerializer serializer = new PluginSerializer();
    ByteBuffer bytes = serializer.serialize(dataset);
    ComplexTObject complex = ComplexTObject.fromJavaObject(bytes);
    ByteBuffer bytes2 = complex.getJavaObject();
    Object obj = serializer.deserialize(bytes2);
    Assert.assertEquals(dataset, obj);
}
Also used : Multimap(com.google.common.collect.Multimap) ComplexTObject(com.cinchapi.concourse.thrift.ComplexTObject) Collection(java.util.Collection) ComplexTObject(com.cinchapi.concourse.thrift.ComplexTObject) TObject(com.cinchapi.concourse.thrift.TObject) PluginSerializer(com.cinchapi.concourse.server.plugin.io.PluginSerializer) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 2 with PluginSerializer

use of com.cinchapi.concourse.server.plugin.io.PluginSerializer in project concourse by cinchapi.

the class ObjectResultDatasetTest method testSerialization.

@Test
public void testSerialization() {
    ObjectResultDataset dataset = new ObjectResultDataset(new TObjectResultDataset());
    dataset.insert(1L, "name", "Jeff Nelson");
    PluginSerializer serializer = new PluginSerializer();
    ByteBuffer bytes = serializer.serialize(dataset);
    ComplexTObject complex = ComplexTObject.fromJavaObject(bytes);
    ByteBuffer bytes2 = complex.getJavaObject();
    Object obj = serializer.deserialize(bytes2);
    Assert.assertEquals(dataset, obj);
}
Also used : ComplexTObject(com.cinchapi.concourse.thrift.ComplexTObject) ComplexTObject(com.cinchapi.concourse.thrift.ComplexTObject) PluginSerializer(com.cinchapi.concourse.server.plugin.io.PluginSerializer) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 3 with PluginSerializer

use of com.cinchapi.concourse.server.plugin.io.PluginSerializer in project concourse by cinchapi.

the class LazyTrackingTObjectResultDatasetTest method testSerialization.

@Test
public void testSerialization() {
    dataset.insert(1L, "name", Convert.javaToThrift("Jeff Nelson"));
    PluginSerializer serializer = new PluginSerializer();
    ByteBuffer bytes = serializer.serialize(dataset);
    ComplexTObject complex = ComplexTObject.fromJavaObject(bytes);
    ByteBuffer bytes2 = complex.getJavaObject();
    Object obj = serializer.deserialize(bytes2);
    Assert.assertEquals(dataset, obj);
}
Also used : ComplexTObject(com.cinchapi.concourse.thrift.ComplexTObject) ComplexTObject(com.cinchapi.concourse.thrift.ComplexTObject) TObject(com.cinchapi.concourse.thrift.TObject) PluginSerializer(com.cinchapi.concourse.server.plugin.io.PluginSerializer) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 4 with PluginSerializer

use of com.cinchapi.concourse.server.plugin.io.PluginSerializer in project concourse by cinchapi.

the class LazyTrackingTObjectResultDatasetTest method testTrackingEnabledWhenDeserialized.

@Test
public void testTrackingEnabledWhenDeserialized() {
    dataset.put(1L, ImmutableMap.of("foo", ImmutableSet.of(Convert.javaToThrift(1), Convert.javaToThrift(2), Convert.javaToThrift(3))));
    dataset.put(2L, ImmutableMap.of("foo", ImmutableSet.of(Convert.javaToThrift(1), Convert.javaToThrift(2), Convert.javaToThrift(3))));
    dataset.put(3L, ImmutableMap.of("foo", ImmutableSet.of(Convert.javaToThrift(1), Convert.javaToThrift(2), Convert.javaToThrift(3))));
    PluginSerializer serializer = new PluginSerializer();
    ByteBuffer bytes = serializer.serialize(dataset);
    Dataset<Long, String, TObject> dataset2 = serializer.deserialize(bytes);
    Assert.assertNull(Reflection.get("tracking", dataset));
    Assert.assertNotNull(Reflection.get("tracking", dataset2));
}
Also used : ComplexTObject(com.cinchapi.concourse.thrift.ComplexTObject) TObject(com.cinchapi.concourse.thrift.TObject) PluginSerializer(com.cinchapi.concourse.server.plugin.io.PluginSerializer) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 5 with PluginSerializer

use of com.cinchapi.concourse.server.plugin.io.PluginSerializer in project concourse by cinchapi.

the class LazyTrackingTObjectResultDatasetTest method testInvertRepro.

@Test
public void testInvertRepro() {
    String json = FileOps.read(Resources.getAbsolutePath("/data.json"));
    List<Multimap<String, Object>> objects = Convert.anyJsonToJava(json);
    for (Multimap<String, Object> object : objects) {
        long entity = Time.now();
        dataset.put(entity, object.asMap().entrySet().stream().collect(Collectors.toMap(Entry::getKey, e -> e.getValue().stream().map(Convert::javaToThrift).collect(Collectors.toSet()))));
    }
    PluginSerializer serializer = new PluginSerializer();
    ByteBuffer bytes = serializer.serialize(dataset);
    ComplexTObject complex = ComplexTObject.fromJavaObject(bytes);
    ByteBuffer bytes2 = complex.getJavaObject();
    dataset = serializer.deserialize(bytes2);
    ObjectResultDataset dataset2 = new ObjectResultDataset(dataset);
    Assert.assertEquals(dataset.toString(), dataset2.toString());
}
Also used : Multimap(com.google.common.collect.Multimap) Entry(java.util.Map.Entry) Convert(com.cinchapi.concourse.util.Convert) ComplexTObject(com.cinchapi.concourse.thrift.ComplexTObject) ComplexTObject(com.cinchapi.concourse.thrift.ComplexTObject) TObject(com.cinchapi.concourse.thrift.TObject) PluginSerializer(com.cinchapi.concourse.server.plugin.io.PluginSerializer) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

PluginSerializer (com.cinchapi.concourse.server.plugin.io.PluginSerializer)5 ComplexTObject (com.cinchapi.concourse.thrift.ComplexTObject)5 ByteBuffer (java.nio.ByteBuffer)5 Test (org.junit.Test)5 TObject (com.cinchapi.concourse.thrift.TObject)4 Multimap (com.google.common.collect.Multimap)2 Convert (com.cinchapi.concourse.util.Convert)1 Collection (java.util.Collection)1 Entry (java.util.Map.Entry)1