Search in sources :

Example 6 with BlockedByteArray

use of org.apache.derby.impl.io.vfmem.BlockedByteArray in project derby by apache.

the class BlockedByteArrayTest method testLengthNoInitialBlocksWriteSingleByte.

public void testLengthNoInitialBlocksWriteSingleByte() {
    BlockedByteArray src = new BlockedByteArray();
    assertEquals(0, src.length());
    src.writeByte(0, (byte) 1);
    assertEquals(1, src.length());
    for (int i = 0; i < 66 * 1024; i++) {
        src.writeByte(1 + i, (byte) i);
        assertEquals(i + 2, src.length());
    }
}
Also used : BlockedByteArray(org.apache.derby.impl.io.vfmem.BlockedByteArray)

Example 7 with BlockedByteArray

use of org.apache.derby.impl.io.vfmem.BlockedByteArray in project derby by apache.

the class BlockedByteArrayTest method testCapacityGrowth.

/**
 * Performs a series of capacity changes.
 *
 * @throws IOException if something goes wrong
 */
public void testCapacityGrowth() throws IOException {
    BlockedByteArray src = createBlockedByteArray(0);
    // 1 MB
    src.setLength(1 * 1024 * 1024);
    // 10 MB
    src.setLength(10 * 1024 * 1024);
    // 5 MB
    src.setLength(5 * 1024 * 1024);
    // 7 MB
    src.setLength(7 * 1024 * 1024);
    assertEquals(7 * 1024 * 1024L, src.length());
    // 0 bytes
    src.setLength(0);
    assertEquals(0L, src.length());
    // 39 MB
    src.setLength(39 * 1024 * 1024);
    // 39 MB +1 B
    src.setLength(39 * 1024 * 1024 + 1);
    assertEquals(39 * 1024 * 1024 + 1L, src.length());
    // 39 MB
    src.setLength(39 * 1024 * 1024);
    assertEquals(39 * 1024 * 1024L, src.length());
    // 39 MB
    src.setLength(39 * 1024 * 1024);
    assertEquals(39 * 1024 * 1024L, src.length());
    // Invalid value - causes array to be truncated.
    src.setLength(-1);
    assertEquals(0L, src.length());
}
Also used : BlockedByteArray(org.apache.derby.impl.io.vfmem.BlockedByteArray)

Example 8 with BlockedByteArray

use of org.apache.derby.impl.io.vfmem.BlockedByteArray in project derby by apache.

the class BlockedByteArrayTest method testReadArray.

public void testReadArray() throws IOException {
    int size = 65 * 1024;
    BlockedByteArray src = createBlockedByteArray(size);
    byte[] buf = new byte[4 * 1024];
    int read = 0;
    while (read < size) {
        read += src.read(read, buf, 0, buf.length);
    }
    src = createBlockedByteArray(size);
    buf = new byte[2567];
    read = 0;
    while (read < size) {
        read += src.read(read, buf, 0, buf.length);
    }
    src = createBlockedByteArray(size);
    buf = new byte[16 * 1024];
    read = 0;
    while (read < size) {
        read += src.read(read, buf, 0, buf.length);
    }
}
Also used : BlockedByteArray(org.apache.derby.impl.io.vfmem.BlockedByteArray)

Aggregations

BlockedByteArray (org.apache.derby.impl.io.vfmem.BlockedByteArray)8 InputStream (java.io.InputStream)1 LoopingAlphabetStream (org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream)1