Search in sources :

Example 1 with TestingCollector

use of org.apache.inlong.sort.util.TestingUtils.TestingCollector 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

Timestamp (java.sql.Timestamp)1 SimpleDateFormat (java.text.SimpleDateFormat)1 HashMap (java.util.HashMap)1 InLongMsg (org.apache.inlong.common.msg.InLongMsg)1 InLongMsgMixedSerializedRecord (org.apache.inlong.sort.flink.InLongMsgMixedSerializedRecord)1 Record (org.apache.inlong.sort.flink.Record)1 LongFormatInfo (org.apache.inlong.sort.formats.common.LongFormatInfo)1 StringFormatInfo (org.apache.inlong.sort.formats.common.StringFormatInfo)1 DataFlowInfo (org.apache.inlong.sort.protocol.DataFlowInfo)1 FieldInfo (org.apache.inlong.sort.protocol.FieldInfo)1 InLongMsgCsvDeserializationInfo (org.apache.inlong.sort.protocol.deserialization.InLongMsgCsvDeserializationInfo)1 TubeSourceInfo (org.apache.inlong.sort.protocol.source.TubeSourceInfo)1 EmptySinkInfo (org.apache.inlong.sort.util.TestingUtils.EmptySinkInfo)1 TestingCollector (org.apache.inlong.sort.util.TestingUtils.TestingCollector)1 Test (org.junit.Test)1