Search in sources :

Example 1 with Pipe

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

the class ReactiveManagerPipeConsumer method applyReactiveOperators.

private static void applyReactiveOperators(ReactiveListenerStage r, Pipe[] localInputs, Object localObj, ReactiveOperator[] localOperators, int count) {
    int hasMoreWork;
    do {
        hasMoreWork = 0;
        int i = count;
        while (--i >= 0) {
            Pipe localPipe = localInputs[i];
            if (Pipe.contentRemaining(localPipe) > 0) {
                localOperators[i].apply(i, localObj, localPipe, r);
                if (Pipe.contentRemaining(localPipe) > 0) {
                    hasMoreWork++;
                }
            }
        }
    } while (--hasMoreWork >= 0);
}
Also used : Pipe(com.ociweb.pronghorn.pipe.Pipe)

Example 2 with Pipe

use of com.ociweb.pronghorn.pipe.Pipe 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);
    }
}
Also used : PipeConfig(com.ociweb.pronghorn.pipe.PipeConfig) Pipe(com.ociweb.pronghorn.pipe.Pipe) Test(org.junit.Test)

Example 3 with Pipe

use of com.ociweb.pronghorn.pipe.Pipe 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)));
                        }
                    }
                }
            }
        }
    }
}
Also used : PipeConfig(com.ociweb.pronghorn.pipe.PipeConfig) Pipe(com.ociweb.pronghorn.pipe.Pipe) Test(org.junit.Test)

Example 4 with Pipe

use of com.ociweb.pronghorn.pipe.Pipe 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++;
    }
}
Also used : PipeConfig(com.ociweb.pronghorn.pipe.PipeConfig) ByteArrayInputStream(java.io.ByteArrayInputStream) Pipe(com.ociweb.pronghorn.pipe.Pipe) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Ignore(org.junit.Ignore)

Example 5 with Pipe

use of com.ociweb.pronghorn.pipe.Pipe 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++;
    }
}
Also used : PipeConfig(com.ociweb.pronghorn.pipe.PipeConfig) RingInputStream(com.ociweb.pronghorn.pipe.stream.RingInputStream) Pipe(com.ociweb.pronghorn.pipe.Pipe) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Ignore(org.junit.Ignore)

Aggregations

Pipe (com.ociweb.pronghorn.pipe.Pipe)42 PipeConfig (com.ociweb.pronghorn.pipe.PipeConfig)19 Test (org.junit.Test)18 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 Ignore (org.junit.Ignore)7 MessageSchemaDynamic (com.ociweb.pronghorn.pipe.MessageSchemaDynamic)5 IOException (java.io.IOException)5 StreamingVisitorReader (com.ociweb.pronghorn.pipe.stream.StreamingVisitorReader)4 StreamingVisitorWriter (com.ociweb.pronghorn.pipe.stream.StreamingVisitorWriter)4 StreamingWriteVisitorGenerator (com.ociweb.pronghorn.pipe.stream.StreamingWriteVisitorGenerator)4 Random (java.util.Random)4 RingInputStream (com.ociweb.pronghorn.pipe.stream.RingInputStream)3 JSONVisitor (com.ociweb.pronghorn.util.parse.JSONVisitor)3 JSONVisitorCapture (com.ociweb.pronghorn.util.parse.JSONVisitorCapture)3 NetPayloadSchema (com.ociweb.pronghorn.network.schema.NetPayloadSchema)2 DataOutputBlobWriter (com.ociweb.pronghorn.pipe.DataOutputBlobWriter)2 RawDataSchema (com.ociweb.pronghorn.pipe.RawDataSchema)2 RingOutputStream (com.ociweb.pronghorn.pipe.stream.RingOutputStream)2 StreamingReadVisitor (com.ociweb.pronghorn.pipe.stream.StreamingReadVisitor)2 StreamingReadVisitorMatcher (com.ociweb.pronghorn.pipe.stream.StreamingReadVisitorMatcher)2