Package com.netflix.zeno.fastblob.record

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


        TestSerializer testSerializer = new TestSerializer();
        testSerializer.setSerializationFramework(new FastBlobStateEngine(serializerFactory));
        FastBlobSerializationRecord rec = new FastBlobSerializationRecord(testSerializer.getFastBlobSchema());
        testSerializer.serialize(null, rec);

        ByteDataBuffer buf = new ByteDataBuffer();

        rec.writeDataTo(buf);

        FastBlobDeserializationRecord deserializeRec = new FastBlobDeserializationRecord(testSerializer.getFastBlobSchema(), buf.getUnderlyingArray());
        deserializeRec.position(0);

        Boolean deserialized = testSerializer.deserialize(deserializeRec);

        Assert.assertEquals(Boolean.TRUE, deserialized);
View Full Code Here


    public void testBytes() throws Exception {
        NFTypeSerializer<Object[]> testSerializer = framework.getSerializer(TestSerializerBytes.NAME);
        FastBlobSerializationRecord rec = new FastBlobSerializationRecord(testSerializer.getFastBlobSchema());
        testSerializer.serialize(new Object[]{bytes, bytes2}, rec);

        ByteDataBuffer buf = new ByteDataBuffer();

        rec.writeDataTo(buf);

        FastBlobDeserializationRecord deserializeRec = new FastBlobDeserializationRecord(testSerializer.getFastBlobSchema(), buf.getUnderlyingArray());
        deserializeRec.position(0);

        Object[] deserialized = testSerializer.deserialize(deserializeRec);

        Assert.assertArrayEquals(bytes, (byte[])deserialized[0]);
View Full Code Here

        this(262144);
    }

    public ByteArrayOrdinalMap(int bufferSize) {
        this.freeOrdinalTracker = new FreeOrdinalTracker();
        this.byteData = new ByteDataBuffer(bufferSize);
        this.pointersAndOrdinals = emptyKeyArray(256);
        this.sizeBeforeGrow = 179; /// 70% load factor
        this.size = 0;
    }
View Full Code Here

        for(int i=0;i<numThreads;i++) {
            final int threadNumber = i;
            executor.submit( new Runnable() {
                @Override
                public void run() {
                    final ByteDataBuffer mappedBuffer = new ByteDataBuffer();
                    final FastBlobDeserializationRecord rec = new FastBlobDeserializationRecord(destState.getSchema(), byteData.getUnderlyingArray());
                    final boolean imageMembershipsFlags[] = new boolean[imageMemberships.length];
                    final OrdinalRemapper remapper = new OrdinalRemapper(ordinalMapping);

                    for(int j = threadNumber;j < pointersAndOrdinals.length();j += numThreads) {
                        long pointerAndOrdinal = pointersAndOrdinals.get(j);
                        if(pointerAndOrdinal != EMPTY_BUCKET_VALUE) {
                            long pointer = pointerAndOrdinal & 0xFFFFFFFFFL;
                            int ordinal = (int)(pointerAndOrdinal >> 36);

                            for(int imageIndex=0;imageIndex<imageMemberships.length;imageIndex++) {
                                imageMembershipsFlags[imageIndex] = imageMemberships[imageIndex].get(ordinal);
                            }

                            int sizeOfData = VarInt.readVInt(byteData.getUnderlyingArray(), pointer);
                            pointer += VarInt.sizeOfVInt(sizeOfData);

                            rec.position(pointer);
                            remapper.remapOrdinals(rec, mappedBuffer);

                            int newOrdinal = destState.addData(mappedBuffer, FastBlobImageUtils.toLong(imageMembershipsFlags));
                            stateOrdinalMapping.setMappedOrdinal(ordinal, newOrdinal);

                            mappedBuffer.reset();
                        }
                    }
                }
            });
        }
View Full Code Here

        for(int i=0;i<keys.length;i++) {
            keys[i] = (VarInt.readVLong(is) << 36) | VarInt.readVLong(is);
        }

        ByteDataBuffer byteData = new ByteDataBuffer(262144);

        long byteDataSize = VarInt.readVLong(is);

        for(long i=0;i<byteDataSize;i++) {
            byteData.write((byte)is.read());
        }

        FreeOrdinalTracker freeOrdinalTracker = FreeOrdinalTracker.deserializeFrom(is);

        ByteArrayOrdinalMap deserializedMap = new ByteArrayOrdinalMap(keys, byteData, freeOrdinalTracker, hashedKeyArraySize);
View Full Code Here

        Assert.assertEquals(null, deserialized[1]);
    }

    private FastBlobDeserializationRecord serializeDeserialize(NFTypeSerializer<String[]> testSerializer, FastBlobSerializationRecord rec) throws IOException {

        ByteDataBuffer buf = new ByteDataBuffer();

        rec.writeDataTo(buf);

        FastBlobDeserializationRecord deserializeRec = new FastBlobDeserializationRecord(testSerializer.getFastBlobSchema(), buf.getUnderlyingArray());

        deserializeRec.position(0);

        return deserializeRec;
    }
View Full Code Here

public class ByteDataBufferTest {

    @Test
    public void recordsData() {
        ByteDataBuffer buf = new ByteDataBuffer(256);

        for(int i=0;i<1000;i++) {
            buf.write((byte)i);
        }

        for(int i=0;i<1000;i++) {
            assertEquals((byte)i, buf.get(i));
        }
    }
View Full Code Here

        }
    }

    @Test
    public void canBeReset() {
        ByteDataBuffer buf = new ByteDataBuffer(256);

        for(int i=0;i<1000;i++) {
            buf.write((byte)10);
        }

        buf.reset();

        for(int i=0;i<1000;i++) {
            buf.write((byte)i);
        }

        for(int i=0;i<1000;i++) {
            assertEquals((byte)i, buf.get(i));
        }
    }
View Full Code Here

    @Test
    public void compacts() {
        ByteArrayOrdinalMap map = new ByteArrayOrdinalMap();

        ByteDataBuffer buf = new ByteDataBuffer();

        /// add 1000 entries
        for(int i=0;i<1000;i++) {
            VarInt.writeVInt(buf, 10000 + i);
            map.getOrAssignOrdinal(buf);
            buf.reset();
        }


        /// mark half of the entries used
        ThreadSafeBitSet bitSet = new ThreadSafeBitSet(10);
        for(int i=0;i<1000;i+=2) {
            bitSet.set(i);
        }

        /// compact away the unused entries
        map.compact(bitSet);

        /// ensure that the used entries are still available
        for(int i=0;i<1000;i+=2) {
            VarInt.writeVInt(buf, 10000 + i);
            Assert.assertEquals(i, map.getOrAssignOrdinal(buf));
            buf.reset();
        }


        /// track the ordinals which are assigned to new values
        Set<Integer> newlyAssignedOrdinals = new HashSet<Integer>();
        for(int i=1;i<1000;i+=2) {
            VarInt.writeVInt(buf, 50230532 + i);
            int newOrdinal = map.getOrAssignOrdinal(buf);
            newlyAssignedOrdinals.add(newOrdinal);
            buf.reset();
        }

        /// those ordinals should be the recycled ones after the compact.
        for(int i=1;i<1000;i+=2) {
            Assert.assertTrue(newlyAssignedOrdinals.contains(i));
View Full Code Here

    @Test
    public void clientSideHeapSafeUsageTest() {
        ByteArrayOrdinalMap map = new ByteArrayOrdinalMap();

        ByteDataBuffer buf = new ByteDataBuffer();

        for(int i=0;i<1000;i++) {
            VarInt.writeVInt(buf, 10000 + i);
            map.put(buf, i + 50);
            buf.reset();
        }

        for(int i=0;i<1000;i++) {
            VarInt.writeVInt(buf, 10000 + i);
            Assert.assertEquals(i + 50, map.get(buf));
            buf.reset();
        }

        for(int i=0;i<1000;i++) {
            VarInt.writeVInt(buf, 20000 + i);
            Assert.assertEquals(-1, map.get(buf));
            buf.reset();
        }

        map.clear();

        Assert.assertEquals(0, map.getDataSize());

        for(int i=0;i<5000;i++) {
            VarInt.writeVInt(buf, 20000 + i);
            Assert.assertEquals(-1, map.get(buf));
            buf.reset();
        }

        for(int i=0;i<5000;i++) {
            VarInt.writeVInt(buf, 20000 + i);
            map.put(buf, i + 50);
            buf.reset();
        }

    }
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.