Search in sources :

Example 1 with RingOutputStream

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

the class RingStreamsTest method testRingToRingOutputStreamByte.

// TODO: RingStreams needs to be deleted and no longer used.
@Ignore
public void testRingToRingOutputStreamByte() {
    Pipe targetRing = new Pipe(new PipeConfig(RawDataSchema.instance, 1 << 10, 1 << 15));
    targetRing.initBuffers();
    targetRing.reset((1 << 10) - 3, 1 << 14);
    RingOutputStream ringOutputStream = new RingOutputStream(targetRing);
    int testBits = 8;
    int testSize = 1 << testBits;
    int testMask = testSize - 1;
    byte[] testData = new byte[testSize];
    int j = testSize;
    while (--j >= 0) {
        testData[j] = (byte) (j & 0xFF);
    }
    int testIdx = 0;
    int testTotal = testSize * 40;
    while (testIdx < testTotal) {
        int datLen = testIdx & testMask;
        assertEquals(0, Pipe.contentRemaining(targetRing));
        int i = 0;
        while (i < datLen) {
            ringOutputStream.write(testData[i++]);
        }
        ringOutputStream.close();
        // Now read the data off the target ring to confirm it matches
        ByteArrayOutputStream baost = new ByteArrayOutputStream();
        try {
            RingStreams.writeToOutputStream(targetRing, baost);
        } catch (Throwable e) {
            e.printStackTrace();
            fail();
        }
        byte[] byteArray = baost.toByteArray();
        // Arrays.equals(Arrays.copyOfRange(testData,0,datLen), byteArray));
        assertEquals("test:" + testIdx + " expected len:" + datLen + " data len:" + byteArray.length, datLen, byteArray.length);
        assertTrue(Arrays.toString(Arrays.copyOfRange(testData, 0, datLen)) + " vs " + Arrays.toString(byteArray), Arrays.equals(Arrays.copyOfRange(testData, 0, datLen), byteArray));
        testIdx++;
    }
}
Also used : PipeConfig(com.ociweb.pronghorn.pipe.PipeConfig) RingOutputStream(com.ociweb.pronghorn.pipe.stream.RingOutputStream) Pipe(com.ociweb.pronghorn.pipe.Pipe) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Ignore(org.junit.Ignore)

Example 2 with RingOutputStream

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

the class RingStreamsTest method testRingToRingOutputStream.

// TODO: RingStreams needs to be deleted and no longer used.
@Ignore
public void testRingToRingOutputStream() {
    Pipe testRing = new Pipe(new PipeConfig(RawDataSchema.instance, 1 << 5, 1 << 13));
    testRing.initBuffers();
    int blockSize = testRing.maxVarLen;
    Pipe targetRing = new Pipe(new PipeConfig(RawDataSchema.instance, 1 << 5, 1 << 13));
    targetRing.initBuffers();
    RingOutputStream ringOutputStream = new RingOutputStream(targetRing);
    int testBits = 11;
    int testSize = 1 << testBits;
    int testMask = testSize - 1;
    byte[] testData = new byte[testSize];
    int j = testSize;
    while (--j >= 0) {
        testData[j] = (byte) (j & 0xFF);
    }
    int testIdx = 0;
    int testTotal = testSize * 10;
    while (testIdx < testTotal) {
        int datLen = testIdx & testMask;
        assertEquals(0, Pipe.contentRemaining(testRing));
        assertEquals(0, Pipe.contentRemaining(targetRing));
        // Write data into the the ring buffer
        RingStreams.writeBytesToRing(testData, 0, datLen, testRing, blockSize);
        RingStreams.writeEOF(testRing);
        // Here we are reading from one ring and writing to another ring going through an OutputStream
        try {
            RingStreams.writeToOutputStream(testRing, ringOutputStream);
            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, datLen), baost.toByteArray()));
        testIdx++;
    }
}
Also used : PipeConfig(com.ociweb.pronghorn.pipe.PipeConfig) RingOutputStream(com.ociweb.pronghorn.pipe.stream.RingOutputStream) 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)2 PipeConfig (com.ociweb.pronghorn.pipe.PipeConfig)2 RingOutputStream (com.ociweb.pronghorn.pipe.stream.RingOutputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Ignore (org.junit.Ignore)2 IOException (java.io.IOException)1