Search in sources :

Example 1 with FixedSizeFrameTupleAppender

use of org.apache.hyracks.storage.am.lsm.invertedindex.ondisk.FixedSizeFrameTupleAppender in project asterixdb by apache.

the class FixedSizeFrameTupleTest method singleFieldTest.

/**
     * This test verifies the correct behavior of the FixedSizeFrameTuple class.
     * Frames containing FixedSizeFrameTuple's require neither tuple slots nor
     * field slots. The tests inserts generated data into a frame until the
     * frame is full, and then verifies the frame's contents.
     *
     */
@Test
public void singleFieldTest() throws Exception {
    ByteBuffer buffer = ByteBuffer.allocate(FRAME_SIZE);
    ITypeTraits[] fields = new ITypeTraits[1];
    fields[0] = IntegerPointable.TYPE_TRAITS;
    FixedSizeFrameTupleAppender ftapp = new FixedSizeFrameTupleAppender(FRAME_SIZE, fields);
    FixedSizeFrameTupleAccessor ftacc = new FixedSizeFrameTupleAccessor(FRAME_SIZE, fields);
    boolean frameHasSpace = true;
    ArrayList<Integer> check = new ArrayList<Integer>();
    ftapp.reset(buffer, true);
    while (frameHasSpace) {
        int val = rnd.nextInt();
        frameHasSpace = ftapp.append(val);
        if (frameHasSpace) {
            check.add(val);
            ftapp.incrementTupleCount(1);
        }
    }
    ftacc.reset(buffer);
    for (int i = 0; i < ftacc.getTupleCount(); i++) {
        int val = IntegerPointable.getInteger(ftacc.getBuffer().array(), ftacc.getTupleStartOffset(i));
        Assert.assertEquals(check.get(i).intValue(), val);
    }
}
Also used : ITypeTraits(org.apache.hyracks.api.dataflow.value.ITypeTraits) ArrayList(java.util.ArrayList) FixedSizeFrameTupleAccessor(org.apache.hyracks.storage.am.lsm.invertedindex.ondisk.FixedSizeFrameTupleAccessor) ByteBuffer(java.nio.ByteBuffer) FixedSizeFrameTupleAppender(org.apache.hyracks.storage.am.lsm.invertedindex.ondisk.FixedSizeFrameTupleAppender) Test(org.junit.Test)

Aggregations

ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 ITypeTraits (org.apache.hyracks.api.dataflow.value.ITypeTraits)1 FixedSizeFrameTupleAccessor (org.apache.hyracks.storage.am.lsm.invertedindex.ondisk.FixedSizeFrameTupleAccessor)1 FixedSizeFrameTupleAppender (org.apache.hyracks.storage.am.lsm.invertedindex.ondisk.FixedSizeFrameTupleAppender)1 Test (org.junit.Test)1