Search in sources :

Example 11 with DataFlowInfo

use of org.apache.inlong.sort.protocol.DataFlowInfo in project incubator-inlong by apache.

the class FieldMappingTransformerTest method testTransformWithDt.

@Test
public void testTransformWithDt() throws Exception {
    final FieldInfo fieldInfo = new FieldInfo("id", new LongFormatInfo());
    final FieldInfo dtFieldInfo = new BuiltInFieldInfo("dt", new TimestampFormatInfo(), BuiltInField.DATA_TIME);
    final SourceInfo sourceInfo = new TestingSourceInfo(new FieldInfo[] { fieldInfo, dtFieldInfo });
    final SinkInfo sinkInfo = new TestingSinkInfo(new FieldInfo[] { fieldInfo, dtFieldInfo });
    final long dataFlowId = 1L;
    final DataFlowInfo dataFlowInfo = new DataFlowInfo(dataFlowId, sourceInfo, sinkInfo);
    final FieldMappingTransformer transformer = new FieldMappingTransformer(new Configuration());
    transformer.addDataFlow(dataFlowInfo);
    // should be 3 fields (1 origin fields + time + attr)
    final Row sourceRow = new Row(1 + SOURCE_FIELD_SKIP_STEP);
    final long dt = System.currentTimeMillis();
    sourceRow.setField(0, dt);
    sourceRow.setField(1, "attr");
    sourceRow.setField(2, 9527L);
    final Record sourceRecord = new Record(dataFlowId, dt, sourceRow);
    final Record sinkRecord = transformer.transform(sourceRecord);
    assertEquals(dataFlowId, sinkRecord.getDataflowId());
    assertEquals(2, sinkRecord.getRow().getArity());
    assertEquals(9527L, sinkRecord.getRow().getField(0));
    assertEquals(new Timestamp(dt), sinkRecord.getRow().getField(1));
}
Also used : TestingSourceInfo(org.apache.inlong.sort.util.TestingUtils.TestingSourceInfo) SourceInfo(org.apache.inlong.sort.protocol.source.SourceInfo) TestingSourceInfo(org.apache.inlong.sort.util.TestingUtils.TestingSourceInfo) Configuration(org.apache.inlong.sort.configuration.Configuration) TimestampFormatInfo(org.apache.inlong.sort.formats.common.TimestampFormatInfo) SinkInfo(org.apache.inlong.sort.protocol.sink.SinkInfo) TestingSinkInfo(org.apache.inlong.sort.util.TestingUtils.TestingSinkInfo) Timestamp(java.sql.Timestamp) BuiltInFieldInfo(org.apache.inlong.sort.protocol.BuiltInFieldInfo) Record(org.apache.inlong.sort.flink.Record) LongFormatInfo(org.apache.inlong.sort.formats.common.LongFormatInfo) TestingSinkInfo(org.apache.inlong.sort.util.TestingUtils.TestingSinkInfo) Row(org.apache.flink.types.Row) FieldInfo(org.apache.inlong.sort.protocol.FieldInfo) BuiltInFieldInfo(org.apache.inlong.sort.protocol.BuiltInFieldInfo) DataFlowInfo(org.apache.inlong.sort.protocol.DataFlowInfo) Test(org.junit.Test)

Example 12 with DataFlowInfo

use of org.apache.inlong.sort.protocol.DataFlowInfo in project incubator-inlong by apache.

the class RecordTransformerTest method testTransformation.

@Test
public void testTransformation() throws Exception {
    final int bufferSize = 1024;
    final RecordTransformer transformer = new RecordTransformer(bufferSize);
    final FieldInfo field1 = new FieldInfo("field1", new LongFormatInfo());
    final FieldInfo field2 = new FieldInfo("field2", new StringFormatInfo());
    final TestingSinkInfo sinkInfo = new TestingSinkInfo(new FieldInfo[] { field1, field2 });
    final DataFlowInfo dataFlowInfo = new DataFlowInfo(1L, new EmptySourceInfo(), sinkInfo);
    transformer.addDataFlow(dataFlowInfo);
    final Row row = new Row(2);
    row.setField(0, 1024L);
    row.setField(1, "9527");
    final Record record = new Record(1L, System.currentTimeMillis(), row);
    final Record transformed = transformer.toRecord(transformer.toSerializedRecord(record));
    assertEquals(record, transformed);
    // check the buffers
    assertEquals(0, transformer.getDataInputDeserializer().available());
    assertEquals(0, transformer.getDataOutputSerializer().length());
    assertEquals(bufferSize, transformer.getDataOutputSerializer().getSharedBuffer().length);
    transformer.removeDataFlow(dataFlowInfo);
    assertEquals(0, transformer.getRowSerializers().size());
}
Also used : SerializedRecord(org.apache.inlong.sort.flink.SerializedRecord) Record(org.apache.inlong.sort.flink.Record) LongFormatInfo(org.apache.inlong.sort.formats.common.LongFormatInfo) TestingSinkInfo(org.apache.inlong.sort.util.TestingUtils.TestingSinkInfo) Row(org.apache.flink.types.Row) EmptySourceInfo(org.apache.inlong.sort.util.TestingUtils.EmptySourceInfo) StringFormatInfo(org.apache.inlong.sort.formats.common.StringFormatInfo) FieldInfo(org.apache.inlong.sort.protocol.FieldInfo) DataFlowInfo(org.apache.inlong.sort.protocol.DataFlowInfo) Test(org.junit.Test)

Example 13 with DataFlowInfo

use of org.apache.inlong.sort.protocol.DataFlowInfo in project incubator-inlong by apache.

the class RecordTransformerTest method testRecordAndSerializerFieldNotMatch.

@Test
public void testRecordAndSerializerFieldNotMatch() throws Exception {
    final int bufferSize = 1024;
    final RecordTransformer transformer = new RecordTransformer(bufferSize);
    final FieldInfo field1 = new FieldInfo("field1", new LongFormatInfo());
    final FieldInfo field2 = new FieldInfo("field2", new StringFormatInfo());
    final TestingSinkInfo sinkInfo = new TestingSinkInfo(new FieldInfo[] { field1, field2 });
    final DataFlowInfo dataFlowInfo = new DataFlowInfo(1L, new EmptySourceInfo(), sinkInfo);
    transformer.addDataFlow(dataFlowInfo);
    final Row row = new Row(2);
    row.setField(0, 1024L);
    row.setField(1, 2048);
    final Record record = new Record(1L, System.currentTimeMillis(), row);
    try {
        transformer.toSerializedRecord(record);
        Assert.fail();
    } catch (Exception expected) {
    }
    final FieldInfo newField1 = new FieldInfo("field1", new LongFormatInfo());
    final FieldInfo newField2 = new FieldInfo("field2", new IntFormatInfo());
    final TestingSinkInfo newSinkInfo = new TestingSinkInfo(new FieldInfo[] { newField1, newField2 });
    final DataFlowInfo newDataFlowInfo = new DataFlowInfo(1L, new EmptySourceInfo(), newSinkInfo);
    transformer.updateDataFlow(newDataFlowInfo);
    SerializedRecord serializedRecord = transformer.toSerializedRecord(record);
    transformer.updateDataFlow(dataFlowInfo);
    try {
        transformer.toRecord(serializedRecord);
        Assert.fail();
    } catch (Exception expected) {
    }
}
Also used : SerializedRecord(org.apache.inlong.sort.flink.SerializedRecord) IntFormatInfo(org.apache.inlong.sort.formats.common.IntFormatInfo) SerializedRecord(org.apache.inlong.sort.flink.SerializedRecord) Record(org.apache.inlong.sort.flink.Record) LongFormatInfo(org.apache.inlong.sort.formats.common.LongFormatInfo) TestingSinkInfo(org.apache.inlong.sort.util.TestingUtils.TestingSinkInfo) Row(org.apache.flink.types.Row) EmptySourceInfo(org.apache.inlong.sort.util.TestingUtils.EmptySourceInfo) StringFormatInfo(org.apache.inlong.sort.formats.common.StringFormatInfo) FieldInfo(org.apache.inlong.sort.protocol.FieldInfo) DataFlowInfo(org.apache.inlong.sort.protocol.DataFlowInfo) Test(org.junit.Test)

Example 14 with DataFlowInfo

use of org.apache.inlong.sort.protocol.DataFlowInfo in project incubator-inlong by apache.

the class MetaManagerTest method testAddAndUpdateAndRemoveDataFlow.

@Test(timeout = 30000)
public void testAddAndUpdateAndRemoveDataFlow() throws Exception {
    final Configuration config = new Configuration();
    config.setString(Constants.CLUSTER_ID, cluster);
    config.setString(Constants.ZOOKEEPER_QUORUM, ZOOKEEPER.getConnectString());
    config.setString(Constants.ZOOKEEPER_ROOT, zkRoot);
    final MetaManager metaManager = MetaManager.getInstance(config);
    final TestDataFlowInfoListener testDataFlowInfoListener = new TestDataFlowInfoListener();
    metaManager.registerDataFlowInfoListener(testDataFlowInfoListener);
    // add dataFlow
    ZkTools.addDataFlowToCluster(cluster, 1, ZOOKEEPER.getConnectString(), zkRoot);
    ZkTools.updateDataFlowInfo(prepareDataFlowInfo(1), cluster, 1, ZOOKEEPER.getConnectString(), zkRoot);
    // update dataFlow
    ZkTools.updateDataFlowInfo(prepareDataFlowInfo(1), cluster, 1, ZOOKEEPER.getConnectString(), zkRoot);
    // remove dataFlow
    ZkTools.removeDataFlowFromCluster(cluster, 1, ZOOKEEPER.getConnectString(), zkRoot);
    while (true) {
        List<Object> operations = testDataFlowInfoListener.getOperations();
        if (operations.size() == 1) {
            assertTrue(operations.get(0) instanceof DataFlowInfo);
            assertEquals(1, ((DataFlowInfo) operations.get(0)).getId());
        } else if (operations.size() == 2) {
            assertTrue(operations.get(1) instanceof DataFlowInfo);
            assertEquals(1, ((DataFlowInfo) operations.get(0)).getId());
            break;
        } else if (operations.size() == 3) {
            assertTrue(operations.get(2) instanceof DataFlowInfo);
            assertEquals(1, ((DataFlowInfo) operations.get(0)).getId());
            break;
        } else {
            Thread.sleep(100);
        }
    }
}
Also used : Configuration(org.apache.inlong.sort.configuration.Configuration) DataFlowInfo(org.apache.inlong.sort.protocol.DataFlowInfo) Test(org.junit.Test)

Example 15 with DataFlowInfo

use of org.apache.inlong.sort.protocol.DataFlowInfo in project incubator-inlong by apache.

the class MultiTenancyInLongMsgMixedDeserializerTest method testDeserialize.

@Test
public void testDeserialize() throws Exception {
    final MultiTenancyInLongMsgMixedDeserializer deserializer = new MultiTenancyInLongMsgMixedDeserializer();
    final FieldInfo stringField = new FieldInfo("not_important", new StringFormatInfo());
    final FieldInfo longField = new FieldInfo("id", new LongFormatInfo());
    final TubeSourceInfo tubeSourceInfo = new TubeSourceInfo("topic", "address", null, new InLongMsgCsvDeserializationInfo("tid", '|', false), new FieldInfo[] { stringField, longField });
    final EmptySinkInfo sinkInfo = new EmptySinkInfo();
    final DataFlowInfo dataFlowInfo = new DataFlowInfo(1L, tubeSourceInfo, sinkInfo);
    deserializer.addDataFlow(dataFlowInfo);
    final InLongMsg inLongMsg = InLongMsg.newInLongMsg();
    final String attrs = "m=0&" + InLongMsgUtils.INLONGMSG_ATTR_STREAM_ID + "=tid&t=20210513";
    final String body1 = "tianqiwan|29";
    inLongMsg.addMsg(attrs, body1.getBytes());
    final TestingCollector<Record> collector = new TestingCollector<>();
    deserializer.deserialize(new InLongMsgMixedSerializedRecord("topic", 0, inLongMsg.buildArray()), collector);
    assertEquals(1, collector.results.size());
    assertEquals(1L, collector.results.get(0).getDataflowId());
    assertEquals(4, collector.results.get(0).getRow().getArity());
    final long time = new SimpleDateFormat("yyyyMMdd").parse("20210513").getTime();
    assertEquals(new Timestamp(time), collector.results.get(0).getRow().getField(0));
    final Map<String, String> attributes = new HashMap<>();
    attributes.put("m", "0");
    attributes.put(InLongMsgUtils.INLONGMSG_ATTR_STREAM_ID, "tid");
    attributes.put("t", "20210513");
    assertEquals(attributes, collector.results.get(0).getRow().getField(1));
    assertEquals("tianqiwan", collector.results.get(0).getRow().getField(2));
    assertEquals(29L, collector.results.get(0).getRow().getField(3));
}
Also used : EmptySinkInfo(org.apache.inlong.sort.util.TestingUtils.EmptySinkInfo) HashMap(java.util.HashMap) InLongMsg(org.apache.inlong.common.msg.InLongMsg) Timestamp(java.sql.Timestamp) TestingCollector(org.apache.inlong.sort.util.TestingUtils.TestingCollector) InLongMsgMixedSerializedRecord(org.apache.inlong.sort.flink.InLongMsgMixedSerializedRecord) Record(org.apache.inlong.sort.flink.Record) InLongMsgMixedSerializedRecord(org.apache.inlong.sort.flink.InLongMsgMixedSerializedRecord) LongFormatInfo(org.apache.inlong.sort.formats.common.LongFormatInfo) InLongMsgCsvDeserializationInfo(org.apache.inlong.sort.protocol.deserialization.InLongMsgCsvDeserializationInfo) TubeSourceInfo(org.apache.inlong.sort.protocol.source.TubeSourceInfo) StringFormatInfo(org.apache.inlong.sort.formats.common.StringFormatInfo) SimpleDateFormat(java.text.SimpleDateFormat) FieldInfo(org.apache.inlong.sort.protocol.FieldInfo) DataFlowInfo(org.apache.inlong.sort.protocol.DataFlowInfo) Test(org.junit.Test)

Aggregations

DataFlowInfo (org.apache.inlong.sort.protocol.DataFlowInfo)18 Test (org.junit.Test)11 FieldInfo (org.apache.inlong.sort.protocol.FieldInfo)10 Row (org.apache.flink.types.Row)8 Record (org.apache.inlong.sort.flink.Record)8 LongFormatInfo (org.apache.inlong.sort.formats.common.LongFormatInfo)8 TestingSinkInfo (org.apache.inlong.sort.util.TestingUtils.TestingSinkInfo)7 StringFormatInfo (org.apache.inlong.sort.formats.common.StringFormatInfo)6 EmptySourceInfo (org.apache.inlong.sort.util.TestingUtils.EmptySourceInfo)6 Configuration (org.apache.inlong.sort.configuration.Configuration)5 SerializedRecord (org.apache.inlong.sort.flink.SerializedRecord)5 HashMap (java.util.HashMap)3 RowSerializer (org.apache.flink.api.java.typeutils.runtime.RowSerializer)3 WorkflowListenerException (org.apache.inlong.manager.common.exceptions.WorkflowListenerException)3 SinkInfo (org.apache.inlong.sort.protocol.sink.SinkInfo)3 SourceInfo (org.apache.inlong.sort.protocol.source.SourceInfo)3 Timestamp (java.sql.Timestamp)2 InlongGroupInfo (org.apache.inlong.manager.common.pojo.group.InlongGroupInfo)2 SinkResponse (org.apache.inlong.manager.common.pojo.sink.SinkResponse)2 GroupResourceProcessForm (org.apache.inlong.manager.common.pojo.workflow.form.GroupResourceProcessForm)2