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++;
}
}
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++;
}
}
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++;
}
}
Aggregations