Package com.netflix.zeno.fastblob.record

Examples of com.netflix.zeno.fastblob.record.ByteDataBuffer


        for(int i=0;i<numThreads;i++) {
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    Random rand = new Random();
                    ByteDataBuffer buf = new ByteDataBuffer();

                    for(int i=0;i<numIterationsPerThread;i++) {
                        int value = rand.nextInt(numUniqueValues);

                        VarInt.writeVInt(buf, value);

                        Integer ordinal = Integer.valueOf(map.getOrAssignOrdinal(buf));

                        Integer beatMe = controlMap.putIfAbsent(value, ordinal);

                        if(beatMe != null) {
                            Assert.assertEquals(ordinal, beatMe);
                        }

                        buf.reset();
                    }

                }
            });

        }

        shutdown(executor);

        /// serialize then deserialize the map
        /*ByteArrayOutputStream os = new ByteArrayOutputStream();
        map.serializeTo(os);
        ByteArrayOrdinalMap deserializedMap = ByteArrayOrdinalMap.deserializeFrom(new ByteArrayInputStream(os.toByteArray()));*/

        ByteDataBuffer buf = new ByteDataBuffer();

        for(Map.Entry<Integer, Integer> entry : controlMap.entrySet()) {
            Integer value = entry.getKey();
            Integer expected = entry.getValue();

            buf.reset();
            VarInt.writeVLong(buf, value.longValue());

            int actual = map.getOrAssignOrdinal(buf);

            Assert.assertEquals(actual, expected.intValue());
View Full Code Here


    private final ByteDataBuffer scratch;
    private final OrdinalMapping ordinalMapping;

    public OrdinalRemapper(OrdinalMapping ordinalMapping) {
        this.ordinalMapping = ordinalMapping;
        this.scratch = new ByteDataBuffer();
    }
View Full Code Here

        assertData(destState, new byte[] { 6, 7, 8, 9 }, false, true);
        f.delete();
    }

    private void addData(FastBlobTypeSerializationState<Integer> srcState, byte data[], boolean... images) {
        ByteDataBuffer buf = createBuffer(data);
        srcState.addData(buf, FastBlobImageUtils.toLong(images));
    }
View Full Code Here

        Assert.assertEquals(images[0], destState.getImageMembershipBitSet(0).get(ordinal));
        Assert.assertEquals(images[1], destState.getImageMembershipBitSet(1).get(ordinal));
    }

    private ByteDataBuffer createBuffer(byte[] data) {
        ByteDataBuffer buf = new ByteDataBuffer();
        for(int i=0;i<data.length;i++)
            buf.write(data[i]);
        return buf;
    }
View Full Code Here

        NFTypeSerializer<PojoWithAllTypes> serializer = stateEngine.getSerializer("TestType");

        serializer.serialize(testType, rec);

        ByteDataBuffer buf = new ByteDataBuffer();

        rec.writeDataTo(buf);

        FastBlobDeserializationRecord deserializationRecord = new FastBlobDeserializationRecord(schema, buf.getUnderlyingArray());
        deserializationRecord.position(0);

        PojoWithAllTypes deserialized = serializer.deserialize(deserializationRecord);

        Assert.assertTrue(deserialized.boolField);
View Full Code Here

    @Test
    public void retainsByteSequences() {
        ByteSequenceRetainer retainer = new ByteSequenceRetainer();

        ByteDataBuffer buf = new ByteDataBuffer();
        buf.write((byte)1);
        buf.write((byte)2);
        buf.write((byte)3);

        retainer.addByteSequence(10, buf.getUnderlyingArray(), 0, 3);

        ByteDataBuffer retrieved = new ByteDataBuffer();

        int retrievedLength = retainer.retrieveSequence(10, retrieved);

        Assert.assertEquals(3, retrievedLength);
        Assert.assertEquals(1, retrieved.get(0));
        Assert.assertEquals(2, retrieved.get(1));
        Assert.assertEquals(3, retrieved.get(2));
    }
View Full Code Here

    private int size;
    private int sizeBeforeGrow;

    public ByteSequenceRetainer() {
        this.buf = new ByteDataBuffer(262144);
        this.keys = new long[256];
        Arrays.fill(keys, EMPTY_BUCKET_VALUE);
        this.size = 0;
        this.sizeBeforeGrow = 179;
    }
View Full Code Here

    }


    @Test
    public void cachingElementsResultsInDeduplication() {
        ByteDataBuffer d1Buf = new ByteDataBuffer();
        ByteDataBuffer d2Buf = new ByteDataBuffer();

        flatBlobFramework.serialize("TypeD", d1, d1Buf);
        flatBlobFramework.serialize("TypeD", d2, d2Buf);

        TypeD deserializedD1 = flatBlobFramework.deserialize("TypeD", d1Buf.getUnderlyingArray(), true);
        TypeD deserializedD2 = flatBlobFramework.deserialize("TypeD", d2Buf.getUnderlyingArray(), true);

        Assert.assertSame(deserializedD1.getTypeA(), deserializedD2.getTypeA());
    }
View Full Code Here

        Assert.assertSame(deserializedD1.getTypeA(), deserializedD2.getTypeA());
    }

    @Test
    public void uncachedElementsAreNotDeduplicated() {
        ByteDataBuffer d1Buf = new ByteDataBuffer();
        ByteDataBuffer d2Buf = new ByteDataBuffer();

        flatBlobFramework.serialize("TypeD", d1, d1Buf);
        flatBlobFramework.serialize("TypeD", d2, d2Buf);

        TypeD deserializedD1 = flatBlobFramework.deserialize("TypeD", d1Buf.getUnderlyingArray(), false);
        TypeD deserializedD2 = flatBlobFramework.deserialize("TypeD", d2Buf.getUnderlyingArray(), false);

        Assert.assertNotSame(deserializedD1.getTypeA(), deserializedD2.getTypeA());
    }
View Full Code Here

    @Test
    public void evictionOfCachedElementsWillResultInNewObjects() {
        FlatBlobEvictor evictor = new FlatBlobEvictor(typeDSerializerFactory, flatBlobFramework);

        ByteDataBuffer d1Buf = new ByteDataBuffer();
        ByteDataBuffer d2Buf = new ByteDataBuffer();

        flatBlobFramework.serialize("TypeD", d1, d1Buf);
        flatBlobFramework.serialize("TypeD", d2, d2Buf);

        TypeD deserializedD1 = flatBlobFramework.deserialize("TypeD", d1Buf.getUnderlyingArray(), true);

        evictor.evict("TypeD", deserializedD1);

        TypeD deserializedD2 = flatBlobFramework.deserialize("TypeD", d2Buf.getUnderlyingArray(), true);

        Assert.assertNotSame(deserializedD1.getTypeA(), deserializedD2.getTypeA());
    }
View Full Code Here

TOP

Related Classes of com.netflix.zeno.fastblob.record.ByteDataBuffer

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.