Search in sources :

Example 11 with PipeConfig

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

the class PipeSingleTemplateTest method simpleBytesWriteRead.

@Test
public void simpleBytesWriteRead() {
    // this ring is 2^7 eg 128
    byte primaryRingSizeInBits = 7;
    byte byteRingSizeInBits = 16;
    Pipe ring = new Pipe(new PipeConfig(RawDataSchema.instance, 1 << primaryRingSizeInBits, 1 << byteRingSizeInBits));
    ring.initBuffers();
    int messageSize = FROM.fragDataSize[FRAG_LOC];
    int varDataMax = (ring.blobMask / (ring.slabMask >> 1)) / messageSize;
    int testSize = (1 << primaryRingSizeInBits) / messageSize;
    populateRingBufferWithBytes(ring, varDataMax, testSize);
    // now read the data back
    int BYTE_LOC = FieldReferenceOffsetManager.lookupFieldLocator("ByteArray", FRAG_LOC, FROM);
    byte[] target = new byte[varDataMax];
    int k = testSize;
    while (PipeReader.tryReadFragment(ring)) {
        if (PipeReader.isNewMessage(ring)) {
            assertEquals(0, PipeReader.getMsgIdx(ring));
            int expectedLength = (varDataMax * (--k)) / testSize;
            // read bytes as normal code would do
            int actualLength = PipeReader.readBytes(ring, BYTE_LOC, target, 0);
            assertEquals(expectedLength, actualLength);
        }
    }
}
Also used : PipeConfig(com.ociweb.pronghorn.pipe.PipeConfig) Pipe(com.ociweb.pronghorn.pipe.Pipe) Test(org.junit.Test)

Example 12 with PipeConfig

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

the class PipeSingleTemplateASCIITest method simpleBytesWriteReadThreaded.

@Test
public void simpleBytesWriteReadThreaded() {
    // this ring is 2^7 eg 128
    final byte primaryRingSizeInBits = 7;
    final byte byteRingSizeInBits = 16;
    final Pipe<RawDataSchema> ring = new Pipe<RawDataSchema>(new PipeConfig(RawDataSchema.instance, 1 << primaryRingSizeInBits, 1 << byteRingSizeInBits));
    ring.initBuffers();
    final int messageSize = RawDataSchema.FROM.fragDataSize[RawDataSchema.MSG_CHUNKEDSTREAM_1];
    final int varDataMax = (ring.blobMask / (ring.slabMask >> 1)) / messageSize;
    final int testSize = (1 << primaryRingSizeInBits) / messageSize;
    Thread t = new Thread(new Runnable() {

        @Override
        public void run() {
            populateRingBufferWithASCII(ring, varDataMax, testSize);
        }
    });
    t.start();
    // now read the data back
    StringBuilder target = new StringBuilder();
    char[] target2 = new char[varDataMax];
    int k = testSize;
    while (k > 1) {
        // System.err.println("content "+ring.contentRemaining(ring));
        if (PipeReader.tryReadFragment(ring)) {
            // this method releases old messages as needed and moves pointer up to the next fragment
            // count down all the expected messages so we stop this test at the right time
            k--;
            target.setLength(0);
            // would use this method rarely to determine if fragment starts new message
            assertTrue(PipeReader.isNewMessage(ring));
            // when we only have 1 message type this would not normally be called
            assertEquals(0, PipeReader.getMsgIdx(ring));
            int expectedLength = (varDataMax * k) / testSize;
            String testString = buildTestString(expectedLength);
            if (0 == (k & 2)) {
                int actualLength = ((StringBuilder) PipeReader.readASCII(ring, RawDataSchema.MSG_CHUNKEDSTREAM_1_FIELD_BYTEARRAY_2, target)).length();
                assertEquals(expectedLength, actualLength);
                assertEquals(testString, target.toString());
            } else {
                int actualLength = PipeReader.readASCII(ring, RawDataSchema.MSG_CHUNKEDSTREAM_1_FIELD_BYTEARRAY_2, target2, 0);
                assertEquals(expectedLength, actualLength);
                assertTrue(testString + " vs " + new String(target2, 0, actualLength), Arrays.equals(testString.toCharArray(), Arrays.copyOfRange(target2, 0, actualLength)));
            }
        } else {
            // unable to read so at this point
            // we can do other work and try again soon
            Thread.yield();
        }
    }
}
Also used : PipeConfig(com.ociweb.pronghorn.pipe.PipeConfig) Pipe(com.ociweb.pronghorn.pipe.Pipe) Test(org.junit.Test)

Example 13 with PipeConfig

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

the class JSONParserTest method buildPopulatedPipe.

private Pipe buildPopulatedPipe(String json) {
    Pipe pipe = new Pipe(new PipeConfig(RawDataSchema.instance));
    pipe.initBuffers();
    int size = Pipe.addMsgIdx(pipe, 0);
    DataOutputBlobWriter output = pipe.outputStream(pipe);
    output.openField();
    output.append(json);
    output.closeLowLevelField();
    Pipe.confirmLowLevelWrite(pipe, size);
    Pipe.publishWrites(pipe);
    return pipe;
}
Also used : PipeConfig(com.ociweb.pronghorn.pipe.PipeConfig) DataOutputBlobWriter(com.ociweb.pronghorn.pipe.DataOutputBlobWriter) Pipe(com.ociweb.pronghorn.pipe.Pipe)

Example 14 with PipeConfig

use of com.ociweb.pronghorn.pipe.PipeConfig in project GreenLightning by oci-pronghorn.

the class ReactiveOperators method createPipes.

private Pipe[] createPipes(BuilderImpl builder, int i, int matches, Object listener, Grouper g) {
    if (i < interfaces.size()) {
        final PipeConfig config = g.config(builder.schemaMapper(schemas.get(i)));
        final boolean isInUse = null != config;
        final boolean doesMatch = interfaces.get(i).isInstance(listener) && isInUse;
        Pipe[] result = createPipes(builder, i + 1, doesMatch ? 1 + matches : matches, listener, g);
        if (doesMatch) {
            // logger.info("Does Match! {}", listener);
            result[matches] = new Pipe(config.grow2x());
        }
        return result;
    } else {
        return new Pipe[matches];
    }
}
Also used : PipeConfig(com.ociweb.pronghorn.pipe.PipeConfig) Pipe(com.ociweb.pronghorn.pipe.Pipe)

Example 15 with PipeConfig

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

the class PipeSingleTemplateDecimalTest method simpleWriteRead.

@Test
public void simpleWriteRead() {
    byte primaryRingSizeInBits = 9;
    byte byteRingSizeInBits = 17;
    Pipe ring = new Pipe(new PipeConfig(new MessageSchemaDynamic(FROM), 1 << primaryRingSizeInBits, 1 << byteRingSizeInBits));
    ring.initBuffers();
    String emptyToString = ring.toString();
    assertTrue(emptyToString, emptyToString.contains("slabHeadPos 0"));
    assertTrue(emptyToString, emptyToString.contains("slabTailPos 0"));
    assertTrue(emptyToString, emptyToString.contains("RingId"));
    int messageSize = FROM.fragDataSize[FRAG_LOC];
    int varDataMax = (ring.blobMask / (ring.slabMask >> 1)) / messageSize;
    // reduce by one so we have room for the ending EOM value
    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) {
            break;
        }
        readTestValue(ring, varDataMax, testSize, FIELD_LOC, k, messageIdx);
    }
}
Also used : PipeConfig(com.ociweb.pronghorn.pipe.PipeConfig) Pipe(com.ociweb.pronghorn.pipe.Pipe) Test(org.junit.Test)

Aggregations

Pipe (com.ociweb.pronghorn.pipe.Pipe)19 PipeConfig (com.ociweb.pronghorn.pipe.PipeConfig)19 Test (org.junit.Test)10 Ignore (org.junit.Ignore)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 IOException (java.io.IOException)5 RingInputStream (com.ociweb.pronghorn.pipe.stream.RingInputStream)3 RingOutputStream (com.ociweb.pronghorn.pipe.stream.RingOutputStream)2 DataOutputBlobWriter (com.ociweb.pronghorn.pipe.DataOutputBlobWriter)1 FieldReferenceOffsetManager (com.ociweb.pronghorn.pipe.FieldReferenceOffsetManager)1 MessageSchemaDynamic (com.ociweb.pronghorn.pipe.MessageSchemaDynamic)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1