use of com.ociweb.pronghorn.pipe.Pipe in project PronghornPipes by oci-pronghorn.
the class RingStreamsTest method testWriteToOutputStream.
// TODO: RingStreams needs to be deleted and no longer used.
@Ignore
public void testWriteToOutputStream() {
Pipe testRing = new Pipe(new PipeConfig(RawDataSchema.instance, 1 << 4, 1 << 13));
testRing.initBuffers();
StringBuilder builder = new StringBuilder();
while (builder.length() < 4096) {
testOneMessage(testRing, builder.toString());
builder.append((char) ('A' + (builder.length() & 0x7)));
}
}
use of com.ociweb.pronghorn.pipe.Pipe 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.Pipe 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++;
}
}
use of com.ociweb.pronghorn.pipe.Pipe in project PronghornPipes by oci-pronghorn.
the class GenerativeTest method buildPopulatedRing.
public Pipe buildPopulatedRing(FieldReferenceOffsetManager from, PipeConfig rbConfig, int commonSeed, int iterations) {
int i;
Pipe ring2 = new Pipe(rbConfig);
ring2.initBuffers();
StreamingWriteVisitorGenerator swvg2 = new StreamingWriteVisitorGenerator(from, new Random(commonSeed), varLength, varLength);
StreamingVisitorWriter svw2 = new StreamingVisitorWriter(ring2, swvg2);
svw2.startup();
i = iterations;
while (--i > 0) {
svw2.run();
}
return ring2;
}
use of com.ociweb.pronghorn.pipe.Pipe in project PronghornPipes by oci-pronghorn.
the class GenerativeTest method mostImporantCoverageTest.
@Test
public void mostImporantCoverageTest() {
StringBuilder schema = new StringBuilder();
generateCoveringTestSchema(schema);
FieldReferenceOffsetManager from = loadFrom(schema.toString());
PipeConfig rbConfig = new PipeConfig(new MessageSchemaDynamic(from), messages, varLength);
int commonSeed = 300;
int iterations = 2;
Pipe ring1 = buildPopulatedRing(from, rbConfig, commonSeed, iterations);
Pipe ring2 = buildPopulatedRing(from, rbConfig, commonSeed, iterations);
// confirm that both rings contain the exact same thing
assertTrue(Arrays.equals(Pipe.primaryBuffer(ring1), Pipe.primaryBuffer(ring2)));
assertTrue(Arrays.equals(Pipe.byteBuffer(ring1), Pipe.byteBuffer(ring2)));
// ////////////////////////
// now starts the real test, we need to read/write these values, and check them against the original
// ///////////////////////
// while try read from token look up the right read type.
// reads all the messsages until the ring is empty
Pipe ring1byReadWrite = new Pipe(rbConfig);
Pipe ring1byCopy = new Pipe(rbConfig);
ring1byReadWrite.initBuffers();
// first and only messsage;
int messageIdx = 0;
while (PipeReader.tryReadFragment(ring1) && PipeWriter.tryWriteFragment(ring1byReadWrite, messageIdx)) {
int msgId = PipeReader.getMsgIdx(ring1);
int scriptSize = from.fragScriptSize[msgId];
int s = 0;
int fieldId = 1000;
while (++s < scriptSize) {
int idx = msgId + s;
fieldId++;
long fromFieldId = from.fieldIdScript[idx];
if (0 != fromFieldId && fromFieldId != fieldId) {
fail("Did not find expected field id " + fieldId + " != " + fromFieldId);
}
// this is a slow linear search repeated for each message, TODO: B, replace this with an array of pre-build values
int fieldLOC = 0 == fromFieldId ? 0 : FieldReferenceOffsetManager.lookupFieldLocator(fromFieldId, msgId, from);
int token = from.tokens[idx];
int type = TokenBuilder.extractType(token);
switch(type) {
case TypeMask.IntegerUnsigned:
case TypeMask.IntegerUnsignedOptional:
case TypeMask.IntegerSigned:
case TypeMask.IntegerSignedOptional:
int intValue = PipeReader.readInt(ring1, fieldLOC);
float floatValue = PipeReader.readIntBitsToFloat(ring1, fieldLOC);
int expectedInt = Float.floatToRawIntBits(floatValue);
if (intValue != expectedInt) {
fail();
}
PipeWriter.writeInt(ring1byReadWrite, fieldLOC, intValue);
break;
case TypeMask.LongUnsigned:
case TypeMask.LongUnsignedOptional:
case TypeMask.LongSigned:
case TypeMask.LongSignedOptional:
long longValue = PipeReader.readLong(ring1, fieldLOC);
double doubleValue = PipeReader.readLongBitsToDouble(ring1, fieldLOC);
long expectedLong = Double.doubleToRawLongBits(doubleValue);
if (longValue != expectedLong) {
fail();
}
break;
case TypeMask.TextASCII:
case TypeMask.TextASCIIOptional:
PipeReader.readASCII(ring1, fieldLOC, new StringBuilder());
break;
case TypeMask.TextUTF8:
case TypeMask.TextUTF8Optional:
// RingReader.readUTF8(ring1, fieldLOC, new StringBuilder());
break;
case TypeMask.Decimal:
case TypeMask.DecimalOptional:
PipeReader.readDecimalExponent(ring1, fieldLOC);
PipeReader.readDecimalMantissa(ring1, fieldLOC);
break;
case TypeMask.ByteVector:
case TypeMask.ByteVectorOptional:
// RingReader.readBytes(ring1, fieldLOC, ByteBuffer.allocate(70));
break;
}
if (TypeMask.Decimal == type || TypeMask.DecimalOptional == type) {
// extra slot for the long
s++;
}
}
}
// once per message.
PipeReader.releaseReadLock(ring1);
System.err.println(ring1);
// load schema and generate test data
// generate test data off generated template files
// test read and write of all data
// use visitor API
// use high level RingReader/RingWalker
}
Aggregations