Search in sources :

Example 1 with FieldReferenceOffsetManager

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

the class TemplateProcessGeneratorTest method testGenerateLowLevelReaderCleanCompile.

@Test
public void testGenerateLowLevelReaderCleanCompile() {
    if ("arm".equals(System.getProperty("os.arch"))) {
        assertTrue(true);
    } else {
        try {
            FieldReferenceOffsetManager from = TemplateHandler.loadFrom("/template/smallExample.xml");
            MessageSchema schema = new MessageSchemaDynamic(from);
            String className = "LowLevelReader";
            StringBuilder target = new StringBuilder();
            TemplateProcessGeneratorLowLevelReader simple = new TemplateProcessGeneratorLowLevelReader(schema, target);
            simple.processSchema();
            // System.out.println(target);
            validateCleanCompile(className, target);
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
            fail();
        } catch (SAXException e) {
            e.printStackTrace();
            fail();
        } catch (IOException e) {
            e.printStackTrace();
            fail();
        }
    }
}
Also used : MessageSchema(com.ociweb.pronghorn.pipe.MessageSchema) TemplateProcessGeneratorLowLevelReader(com.ociweb.pronghorn.pipe.util.build.TemplateProcessGeneratorLowLevelReader) MessageSchemaDynamic(com.ociweb.pronghorn.pipe.MessageSchemaDynamic) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) FieldReferenceOffsetManager(com.ociweb.pronghorn.pipe.FieldReferenceOffsetManager) SAXException(org.xml.sax.SAXException) Test(org.junit.Test)

Example 2 with FieldReferenceOffsetManager

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

Example 3 with FieldReferenceOffsetManager

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

the class FROMValidation method checkSchema.

public static <S extends MessageSchema<S>> boolean checkSchema(String templateFile, Class<S> clazz) {
    StringBuilder target = new StringBuilder();
    buildConstructor(target, clazz);
    S schemaInstance = MessageSchema.findInstance(clazz);
    // ///////////////////////
    // ///////////////////////
    FieldReferenceOffsetManager expectedFrom = null;
    try {
        expectedFrom = TemplateHandler.loadFrom(templateFile);
    } catch (Exception e2) {
        e2.printStackTrace();
    }
    if (null == expectedFrom) {
        logger.error("Unable to find: {}", templateFile);
        return false;
    }
    // ///////////////////////
    // ///////////////////////
    boolean result = true;
    if (null != schemaInstance) {
        try {
            FieldReferenceOffsetManager encodedFrom = null;
            encodedFrom = MessageSchema.from(schemaInstance);
            if (null == encodedFrom || !expectedFrom.equals(encodedFrom)) {
                logger.error("Encoded source:" + expectedFrom);
                if (null != encodedFrom) {
                    logger.error("Template file:" + encodedFrom);
                }
                logger.error("//replacement source");
                result = false;
            }
            FieldReferenceOffsetManager.buildFROMConstructionSource(target, expectedFrom, "FROM", templateFile.substring(1 + templateFile.lastIndexOf('/')));
            // ////////////////
            if (!result) {
                forceCodeGen = true;
            }
            result &= testForMatchingLocators(clazz, expectedFrom, target);
        // ////////////////
        // ////////////////
        } catch (Exception e1) {
            e1.printStackTrace();
            result = false;
        }
    } else {
        result = false;
        try {
            logger.error("Encoded source: {}", expectedFrom);
            logger.error("//replacement source");
            FieldReferenceOffsetManager.buildFROMConstructionSource(target, expectedFrom, "FROM", templateFile.substring(1 + templateFile.lastIndexOf('/')));
            // ////////////////
            // ////////////////
            forceCodeGen = true;
            testForMatchingLocators(clazz, expectedFrom, target);
        // ////////////////
        // ////////////////
        } catch (Exception e1) {
            logger.error("unable to build FROM {} {}", e1.getClass().getSimpleName(), e1.getMessage());
        }
    }
    if (!result) {
        System.out.println(target);
    }
    return result;
}
Also used : FieldReferenceOffsetManager(com.ociweb.pronghorn.pipe.FieldReferenceOffsetManager) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 4 with FieldReferenceOffsetManager

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

the class TemplateProcessGeneratorLowLevelReader method processCallerPrep.

@Override
protected void processCallerPrep() throws IOException {
    FieldReferenceOffsetManager from = MessageSchema.from(schema);
    helperMethods(from);
    bodyTarget.append("\n");
    bodyTarget.append("@Override\n");
    bodyTarget.append("public void run() {\n");
    // if (!Pipe.hasContentToRead(input)) {
    // return;
    // }
    appendStaticCall(bodyTarget.append(tab).append("if (!"), pipeClass, "hasContentToRead").append(pipeVarName).append(")) {\n");
    bodyTarget.append(tab).append(tab).append("return;\n");
    bodyTarget.append(tab).append("}\n");
    bodyTarget.append(tab).append("int ").append(cursorVarName).append(";\n");
    if (hasSimpleMessagesOnly) {
        appendStaticCall(bodyTarget.append("if ("), pipeClass, "hasContentToRead").append(pipeVarName).append(")");
        additionalLoopLogic(bodyTarget);
        bodyTarget.append("){\n");
        appendStaticCall(bodyTarget.append(cursorVarName).append(" = "), pipeClass, "takeMsgIdx").append(pipeVarName).append(");\n");
    } else {
        // if (LowLevelStateManager.isStartNewMessage(navState)) {
        bodyTarget.append(tab).append("if (").append(stageMgrClassName).append(".isStartNewMessage(").append(stageMgrVarName).append(")) {\n");
        // cursor = Pipe.takeMsgIdx(input);
        appendStaticCall(bodyTarget.append(tab).append(tab).append(cursorVarName).append(" = "), pipeClass, "takeMsgIdx").append(pipeVarName).append(");\n");
        // } else {
        bodyTarget.append(tab).append("} else {\n");
        // cursor = LowLevelStateManager.activeCursor(navState);
        bodyTarget.append(tab).append(tab).append(cursorVarName).append(" = ").append(stageMgrClassName).append(".activeCursor(").append(stageMgrVarName).append(");\n");
        // }
        bodyTarget.append(tab).append("}\n");
    }
    // switch(cursor)) {
    bodyTarget.append(tab).append("switch(").append(cursorVarName).append(") {\n");
}
Also used : FieldReferenceOffsetManager(com.ociweb.pronghorn.pipe.FieldReferenceOffsetManager)

Example 5 with FieldReferenceOffsetManager

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

the class TemplateProcessGeneratorLowLevelReader method appendMessageIdentifier.

private void appendMessageIdentifier(int cursor, MessageSchema schema) throws IOException {
    FieldReferenceOffsetManager from = MessageSchema.from(schema);
    bodyTarget.append("/*");
    appendInternalMethodName(cursor);
    bodyTarget.append("*/");
    if (schema instanceof MessageSchemaDynamic || null == from.fieldNameScript[cursor]) {
        bodyTarget.append(Integer.toString(cursor));
    } else {
        bodyTarget.append(schema.getClass().getSimpleName()).append(".");
        bodyTarget.append(FieldReferenceOffsetManager.buildMsgConstName(from, cursor));
    }
}
Also used : MessageSchemaDynamic(com.ociweb.pronghorn.pipe.MessageSchemaDynamic) FieldReferenceOffsetManager(com.ociweb.pronghorn.pipe.FieldReferenceOffsetManager)

Aggregations

FieldReferenceOffsetManager (com.ociweb.pronghorn.pipe.FieldReferenceOffsetManager)19 MessageSchemaDynamic (com.ociweb.pronghorn.pipe.MessageSchemaDynamic)5 IOException (java.io.IOException)4 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)4 SAXException (org.xml.sax.SAXException)4 Test (org.junit.Test)3 MessageSchema (com.ociweb.pronghorn.pipe.MessageSchema)2 Pipe (com.ociweb.pronghorn.pipe.Pipe)1 PipeConfig (com.ociweb.pronghorn.pipe.PipeConfig)1 TemplateProcessGeneratorLowLevelReader (com.ociweb.pronghorn.pipe.util.build.TemplateProcessGeneratorLowLevelReader)1 TemplateProcessGeneratorLowLevelWriter (com.ociweb.pronghorn.pipe.util.build.TemplateProcessGeneratorLowLevelWriter)1