use of com.ociweb.pronghorn.pipe.PipeConfig in project PronghornPipes by oci-pronghorn.
the class PipeSingleTemplateFloatTest method simpleWriteRead.
@Test
public void simpleWriteRead() {
byte primaryRingSizeInBits = 9;
byte byteRingSizeInBits = 18;
Pipe ring = new Pipe(new PipeConfig(new MessageSchemaDynamic(FROM), 1 << primaryRingSizeInBits, 1 << byteRingSizeInBits));
ring.initBuffers();
int messageSize = FROM.fragDataSize[FRAG_LOC];
int varDataMax = (ring.blobMask / (ring.slabMask >> 1)) / messageSize;
// room for EOF
int testSize = ((1 << primaryRingSizeInBits) / messageSize) - 1;
writeTestValue(ring, varDataMax, testSize);
// now read the data back
int FIELD_LOC = FieldReferenceOffsetManager.lookupFieldLocator(SINGLE_MESSAGE_NAMES[0], FRAG_LOC, FROM);
int k = testSize;
while (PipeReader.tryReadFragment(ring)) {
--k;
assertTrue(PipeReader.isNewMessage(ring));
int messageIdx = PipeReader.getMsgIdx(ring);
if (messageIdx < 0) {
return;
}
testReadValue(ring, varDataMax, testSize, FIELD_LOC, k, messageIdx);
}
}
use of com.ociweb.pronghorn.pipe.PipeConfig in project PronghornPipes by oci-pronghorn.
the class PipeSingleTemplateUTF8Test method simpleBytesWriteRead.
@Test
public void simpleBytesWriteRead() {
Pipe<RawDataSchema> ring = new Pipe<RawDataSchema>(new PipeConfig(RawDataSchema.instance, 1 << primaryRingSizeInBits, 1 << byteRingSizeInBits));
ring.initBuffers();
// fewer chars for UTF8
int varDataMax = ring.maxVarLen / 5;
int testSize = (1 << byteRingSizeInBits) / ring.maxVarLen;
populateRingBufferWithUTF8(ring, varDataMax, testSize);
StringBuilder target = new StringBuilder();
// HACK
char[] target2 = new char[varDataMax << 1];
int k = testSize;
while (PipeReader.tryReadFragment(ring)) {
if (PipeReader.isNewMessage(ring)) {
target.setLength(0);
assertEquals(0, PipeReader.getMsgIdx(ring));
int expectedCharLength = (varDataMax * (--k)) / testSize;
String testString = buildTestString(expectedCharLength);
assert (testString.length() == expectedCharLength);
if (0 == (k & 1)) {
int actualLength = ((StringBuilder) PipeReader.readUTF8(ring, RawDataSchema.MSG_CHUNKEDSTREAM_1_FIELD_BYTEARRAY_2, target)).length();
assertEquals(expectedCharLength, actualLength);
assertEquals(testString, target.toString());
} else {
int actualLength = PipeReader.readUTF8(ring, RawDataSchema.MSG_CHUNKEDSTREAM_1_FIELD_BYTEARRAY_2, target2, 0);
assertEquals(expectedCharLength, actualLength);
int j = expectedCharLength;
while (--j >= 0) {
int expectedChar = (int) testString.charAt(j);
int computedChar = (int) target2[j];
if (expectedChar != computedChar) {
// special case, these are utf-16 reserved chars and the utf-8 encoder will turn them into 63
if (computedChar == 63 && (0xD800 == (0xF800 & expectedChar))) {
// not an error
} else {
fail("exp:" + testString + " vs \nfnd:" + new String(Arrays.copyOfRange(target2, 0, expectedCharLength)));
}
}
}
}
}
}
}
use of com.ociweb.pronghorn.pipe.PipeConfig in project PronghornPipes by oci-pronghorn.
the class RingStreamsTest method testReadFromInputStream.
// TODO: RingStreams needs to be deleted and no longer used.
@Ignore
public void testReadFromInputStream() {
int testBits = 14;
// data block must not fill full buffer
int testSize = (1 << testBits) >> 2;
int lenMask = (1 << (testBits - 2)) - 1;
Pipe testRing = new Pipe(new PipeConfig(RawDataSchema.instance, 1 << 6, 1 << 17));
testRing.initBuffers();
byte[] testData = new byte[testSize];
int j = testSize;
while (--j >= 0) {
testData[j] = (byte) (0xFF & j);
}
int testIdx = 0;
int cycleBits = 4;
int testStop = testSize << cycleBits;
while (testIdx < testStop) {
final int expectedLength = testIdx & lenMask;
ByteArrayInputStream inputStream = new ByteArrayInputStream(Arrays.copyOfRange(testData, 0, expectedLength));
try {
RingStreams.readFromInputStream(inputStream, testRing);
RingStreams.writeEOF(testRing);
ByteArrayOutputStream baost = new ByteArrayOutputStream();
try {
RingStreams.writeToOutputStream(testRing, baost);
} catch (IOException e) {
e.printStackTrace();
fail();
}
assertEquals(0, Pipe.contentRemaining(testRing));
assertTrue("len:" + expectedLength + " vs " + baost.toByteArray().length, Arrays.equals(Arrays.copyOfRange(testData, 0, expectedLength), baost.toByteArray()));
} catch (IOException e) {
e.printStackTrace();
fail();
}
testIdx++;
}
}
use of com.ociweb.pronghorn.pipe.PipeConfig 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.PipeConfig 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)));
}
}
Aggregations