Search in sources :

Example 1 with RingInputStream

use of com.ociweb.pronghorn.pipe.stream.RingInputStream in project PronghornPipes by oci-pronghorn.

the class RingStreamsTest method testRingToRingInputStreamBytes.

// TODO: RingStreams needs to be deleted and no longer used.
@Ignore
public void testRingToRingInputStreamBytes() {
    Pipe testRing = new Pipe(new PipeConfig(RawDataSchema.instance, 1 << 4, 1 << 12));
    testRing.initBuffers();
    int blockSize = testRing.maxVarLen;
    RingInputStream ringInputStream = new RingInputStream(testRing);
    int testSize = 2048;
    byte[] testData = new byte[testSize];
    int testIdx = 0;
    while (testIdx < testSize) {
        assertEquals(0, Pipe.contentRemaining(testRing));
        int j = 10;
        while (--j >= 0) {
            // Write data into the the ring buffer
            RingStreams.writeBytesToRing(testData, 0, testIdx, testRing, blockSize);
            RingStreams.writeEOF(testRing);
            ByteArrayOutputStream baost = new ByteArrayOutputStream();
            int value;
            try {
                while ((value = ringInputStream.read()) >= 0) {
                    baost.write(value);
                }
                ringInputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
                fail();
            }
            assertTrue("expectedLen:" + testIdx + " found:" + baost.size(), Arrays.equals(Arrays.copyOfRange(testData, 0, testIdx), baost.toByteArray()));
        }
        testData[testIdx] = (byte) (testIdx & 0xFF);
        testIdx++;
    }
}
Also used : PipeConfig(com.ociweb.pronghorn.pipe.PipeConfig) RingInputStream(com.ociweb.pronghorn.pipe.stream.RingInputStream) Pipe(com.ociweb.pronghorn.pipe.Pipe) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Ignore(org.junit.Ignore)

Example 2 with RingInputStream

use of com.ociweb.pronghorn.pipe.stream.RingInputStream in project PronghornPipes by oci-pronghorn.

the class RingStreamsTest method testRingToRingInputStreamToggleMethods.

// TODO: RingStreams needs to be deleted and no longer used.
@Ignore
public void testRingToRingInputStreamToggleMethods() {
    Pipe testRing = new Pipe(new PipeConfig(RawDataSchema.instance, 1 << 4, 1 << 12));
    testRing.initBuffers();
    int blockSize = testRing.maxVarLen;
    RingInputStream ringInputStream = new RingInputStream(testRing);
    int testSize = 2048;
    byte[] testData = new byte[testSize];
    int testIdx = 0;
    while (testIdx < testSize) {
        assertEquals(0, Pipe.contentRemaining(testRing));
        int j = 10;
        while (--j >= 0) {
            // Write data into the the ring buffer
            RingStreams.writeBytesToRing(testData, 0, testIdx, testRing, blockSize);
            RingStreams.writeEOF(testRing);
            ByteArrayOutputStream baost = new ByteArrayOutputStream();
            int value;
            try {
                int buf = 7;
                byte[] tempBuf = new byte[buf];
                // must span these to calls.
                while ((value = ringInputStream.read(tempBuf)) >= 0) {
                    // using array read
                    baost.write(tempBuf, 0, value);
                    if ((value = ringInputStream.read()) >= 0) {
                        // using single byte read
                        baost.write(value);
                    } else {
                        break;
                    }
                }
                ringInputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
                fail();
            }
            assertTrue("len:" + testIdx + " vs " + baost.toByteArray().length, Arrays.equals(Arrays.copyOfRange(testData, 0, testIdx), baost.toByteArray()));
        }
        testData[testIdx] = (byte) (testIdx & 0xFF);
        testIdx++;
    }
}
Also used : PipeConfig(com.ociweb.pronghorn.pipe.PipeConfig) RingInputStream(com.ociweb.pronghorn.pipe.stream.RingInputStream) Pipe(com.ociweb.pronghorn.pipe.Pipe) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Ignore(org.junit.Ignore)

Example 3 with RingInputStream

use of com.ociweb.pronghorn.pipe.stream.RingInputStream in project PronghornPipes by oci-pronghorn.

the class RingStreamsTest method testRingToRingInputStream.

// TODO: RingStreams needs to be deleted and no longer used.
@Ignore
public void testRingToRingInputStream() {
    Pipe testRing = new Pipe(new PipeConfig(RawDataSchema.instance, 1 << 5, 1 << 13));
    testRing.initBuffers();
    int blockSize = testRing.maxVarLen;
    RingInputStream ringInputStream = new RingInputStream(testRing);
    Pipe targetRing = new Pipe(new PipeConfig(RawDataSchema.instance, 1 << 5, 1 << 13));
    targetRing.initBuffers();
    int testSize = 3000;
    byte[] testData = new byte[testSize];
    int testIdx = 0;
    while (testIdx < testSize) {
        assertEquals(0, Pipe.contentRemaining(targetRing));
        // Write data into the the ring buffer
        RingStreams.writeBytesToRing(testData, 0, testIdx, testRing, blockSize);
        RingStreams.writeEOF(testRing);
        // Here we are reading from one ring and writing to another ring going through an InputStream
        try {
            RingStreams.readFromInputStream(ringInputStream, targetRing);
            RingStreams.writeEOF(targetRing);
        } catch (IOException e) {
            e.printStackTrace();
            fail();
        }
        // Now read the data off the target ring to confirm it matches
        ByteArrayOutputStream baost = new ByteArrayOutputStream();
        try {
            RingStreams.writeToOutputStream(targetRing, baost);
        } catch (IOException e) {
            e.printStackTrace();
            fail();
        }
        assertTrue("len:" + testIdx, Arrays.equals(Arrays.copyOfRange(testData, 0, testIdx), baost.toByteArray()));
        testData[testIdx] = (byte) (testIdx & 0xFF);
        testIdx++;
    }
}
Also used : PipeConfig(com.ociweb.pronghorn.pipe.PipeConfig) RingInputStream(com.ociweb.pronghorn.pipe.stream.RingInputStream) Pipe(com.ociweb.pronghorn.pipe.Pipe) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Ignore(org.junit.Ignore)

Aggregations

Pipe (com.ociweb.pronghorn.pipe.Pipe)3 PipeConfig (com.ociweb.pronghorn.pipe.PipeConfig)3 RingInputStream (com.ociweb.pronghorn.pipe.stream.RingInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)3 Ignore (org.junit.Ignore)3