Package com.netflix.zeno.fastblob

Examples of com.netflix.zeno.fastblob.FastBlobStateEngine


public class FastBlobStateEngineReserializationTest {

    @Test
    public void canReserializeDeserializedData() throws Exception {
        FastBlobStateEngine stateEngine = typeAStateEngine();

        stateEngine.add("TypeA", new TypeA(1, 2));
        stateEngine.add("TypeA", new TypeA(3, 4));

        stateEngine.prepareForWrite();

        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        FastBlobWriter writer = new FastBlobWriter(stateEngine);
        writer.writeSnapshot(baos);

        FastBlobStateEngine deserializeEngine = typeAStateEngine();

        FastBlobReader reader = new FastBlobReader(deserializeEngine);

        reader.readSnapshot(new ByteArrayInputStream(baos.toByteArray()));

        deserializeEngine.fillSerializationStatesFromDeserializedData();

        deserializeEngine.prepareForWrite();

        ByteArrayOutputStream reserializedStream = new ByteArrayOutputStream();

        FastBlobWriter rewriter = new FastBlobWriter(deserializeEngine);
View Full Code Here


        System.out.println(Arrays.toString(reserializedStream.toByteArray()));

    }

    private FastBlobStateEngine typeAStateEngine() {
        return new FastBlobStateEngine(new SerializerFactory() {
            @Override
            public NFTypeSerializer<?>[] createSerializers() {
                // TODO Auto-generated method stub
                return new NFTypeSerializer<?>[] { new TypeASerializer() };
            }
View Full Code Here

        super.setUp();
    }

    @Test
    public void serializesAndDeserializesDeltas() throws Exception {
        serializationState = new FastBlobStateEngine(serializersFactory);

        cache("TypeA", new TypeA(1, 2));
        cache("TypeA", new TypeA(3, 4));

        serializeAndDeserializeSnapshot();
View Full Code Here

    @Test
    public void performDiff() throws IOException {

        /// load two state engines with data states
        FastBlobStateEngine fromStateEngine = getStateEngine();
        FastBlobStateEngine toStateEngine = getAnotherStateEngine();

        /// get a diff "instruction".  This describes how to match up objects
        /// between two FastBlobStateEngines.
        DiffInstruction instruction = getDiffInstruction();
       
View Full Code Here

    /*
     * Round trip the objects in a FastBlobStateEngine, so they appear in the type deserialization state.
     */
    private FastBlobStateEngine getDeserializedStateEngineWithObjects(A... objects) throws IOException {
        FastBlobStateEngine stateEngine = new FastBlobStateEngine(new ExampleSerializerFactory());

        for(A object : objects) {
            stateEngine.add("A", object);
        }

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream dataOutputStream = new DataOutputStream(baos);

        stateEngine.prepareForWrite();

        FastBlobWriter writer = new FastBlobWriter(stateEngine);
        writer.writeSnapshot(dataOutputStream);

        FastBlobReader reader = new FastBlobReader(stateEngine);
View Full Code Here

        writer.writeSnapshot(baos);
        brokenDeltaChainSnapshot2 = baos.toByteArray();
   }

    private FastBlobStateEngine newStateEngine() {
        return new FastBlobStateEngine(new SerializerFactory() {
            public NFTypeSerializer<?>[] createSerializers() {
                return new NFTypeSerializer<?>[] { new TypeFSerializer() };
            }
        });
    }
View Full Code Here

    @Test
    public void basicSerializationCycle() {
        /// First we create a state engine, we need to tell it about our data model by
        /// passing it a serializer factory which creates our top-level serializers.
        stateEngine = new FastBlobStateEngine(new ExampleSerializerFactory());

        /// For this example, we're just storing the serialized data in memory.
        byte snapshot[] = createSnapshot();
        byte delta[] = createDelta();

        /// Now we can pretend to be the client, and deserialize the data into a separate state engine.
        FastBlobStateEngine clientStateEngine = deserializeLatestData(snapshot, delta);

        /// We can grab the data for any class.  Here, we grab the values for class A.
        FastBlobTypeDeserializationState<A> aState = clientStateEngine.getTypeDeserializationState("A");

        /// the following will loop through all values after loading the snapshot
        /// and subsequently applying the delta.  It will print out "1" followed by "3".
        System.out.println("All As: ");
        for(A deserializedA : aState){
            System.out.println(deserializedA.getIntValue());
        }

        /// As another example, we can grab the values for class B.
        FastBlobTypeDeserializationState<B> bState = clientStateEngine.getTypeDeserializationState("B");

        /// Even though we didn't directly add the Bs, they were added because we added objects which
        /// referenced them.  Here, we iterate over all of the Bs after applying the delta.
        /// This will print out "1", "2", "3", "4", "6"
        System.out.println("All Bs: ");
View Full Code Here

    }

    public FastBlobStateEngine deserializeLatestData(byte snapshot[], byte delta[]) {
        /// now we are on the client.  We need to create a state engine, and again
        /// tell it about our data model.
        FastBlobStateEngine stateEngine = new FastBlobStateEngine(new ExampleSerializerFactory());

        /// we need to create a FastBlobReader, which is responsible for reading
        /// serialized blobs.
        FastBlobReader reader = new FastBlobReader(stateEngine);
View Full Code Here

    private FastBlobSerializationRecord rec;
    private FastBlobSchema schema;

    @Before
    public void setUp() {
        stateEngine = new FastBlobStateEngine(new SerializerFactory() {
            public NFTypeSerializer<?>[] createSerializers() {
                return new NFTypeSerializer<?>[] { new TestSchemaSerializer() };
            }
        });
View Full Code Here

    public void basicSerializationCycle() {

        /// First we create a state engine, we need to tell it about our data model by
        /// passing it a serializer factory which creates our top-level serializers.
        /// Here, we're also telling it that we will be creating two separate images.
        stateEngine = new FastBlobStateEngine(new ExampleSerializerFactory(), 2);

        /// For this example, we're just storing the serialized data in memory.
        createSnapshot();
        createDelta();

        /// Now we can pretend to be the client, and deserialize the data into a separate state engine.
        /// TODO: Try changing these to be image1Snapshot and image1Delta to observe the results.
        FastBlobStateEngine clientStateEngine = deserializeLatestData(image1Snapshot, image1Delta);

        System.out.println("StateEngine 1:");
        showValuesForStateEngine(clientStateEngine);

        clientStateEngine = deserializeLatestData(image2Snapshot, image2Delta);
View Full Code Here

TOP

Related Classes of com.netflix.zeno.fastblob.FastBlobStateEngine

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.