use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project providence by morimekta.
the class ITRunner method runJackson.
private void runJackson(FormatStatistics statistics) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream(16 * 1024 * 1024);
long totalTime = 0;
PM instance = null;
for (PM pvd : pvdList) {
long start = System.nanoTime();
MAPPER.writerFor(pvd.getClass()).writeValue(baos, pvd);
baos.write('\n');
long end = System.nanoTime();
long time = end - start;
totalTime += time;
statistics.JwriteStat.addValue(time);
instance = pvd;
}
statistics.JtotalWriteStat.addValue(totalTime);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ObjectReader reader = MAPPER.readerFor(instance.getClass());
totalTime = 0;
Iterator<PM> iterator = pvdList.iterator();
while (bais.available() > 0) {
String tmp = IOUtils.readString(bais, '\n');
ByteArrayInputStream tb = new ByteArrayInputStream(tmp.getBytes(UTF_8));
long start = System.nanoTime();
PM pvd = reader.readValue(tb);
long end = System.nanoTime();
long time = end - start;
totalTime += time;
statistics.JreadStat.addValue(time);
if (!iterator.hasNext()) {
throw new AssertionError("More read than written objects!");
}
PM next = iterator.next();
if (!pvd.equals(next)) {
throw new AssertionError("Read value not equal written");
}
}
if (iterator.hasNext()) {
throw new AssertionError("More written than read objects!");
}
statistics.JtotalReadStat.addValue(totalTime);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project LogHub by fbacchella.
the class TestEventProcessing method check.
public static void check(String pipeLineTest, String configFile) {
try {
Properties props = Configuration.parse(configFile);
TestEventProcessing.setAppender();
props.pipelines.stream().forEach(i -> i.configure(props));
Thread t = new EventsProcessor(props.mainQueue, props.outputQueues, props.namedPipeLine, props.maxSteps, props.repository);
t.setName("ProcessingThread");
t.setDaemon(true);
t.start();
ObjectMapper mapper = new ObjectMapper(factory);
ObjectReader reader = mapper.reader().forType(Map.class);
MappingIterator<Map<String, Object>> i = reader.readValues(new InputStreamReader(System.in, "UTF-8"));
while (i.hasNext()) {
Map<String, Object> eventMap = i.next();
Date eventDate = null;
if (eventMap.containsKey(Event.TIMESTAMPKEY) && eventMap.get(Event.TIMESTAMPKEY) instanceof String) {
TemporalAccessor ta = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:m:ss.SSSxx").parse((CharSequence) eventMap.remove(Event.TIMESTAMPKEY));
OffsetDateTime now;
// Try to resolve the time zone first
ZoneId zi = ta.query(TemporalQueries.zone());
ZoneOffset zo = ta.query(TemporalQueries.offset());
if (zo != null) {
now = OffsetDateTime.now(zo);
} else if (zi != null) {
now = OffsetDateTime.now(zi);
} else {
now = OffsetDateTime.now(ZoneId.systemDefault());
}
eventDate = Date.from(now.toInstant());
}
Event ev = Event.emptyTestEvent(ConnectionContext.EMPTY);
ev.putAll(eventMap);
if (eventDate != null) {
ev.setTimestamp(eventDate);
}
ev.inject(props.namedPipeLine.get(pipeLineTest), props.mainQueue);
}
Thread.currentThread().join();
// Thread.sleep(Long.MAX_VALUE);
} catch (IOException e) {
e.printStackTrace();
} catch (ConfigException e) {
System.out.format("Error in %s: %s\n", e.getLocation(), e.getMessage());
System.exit(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project flink by apache.
the class LookupKeySerdeTest method testLookupKey.
@Test
public void testLookupKey() throws IOException {
TableConfig tableConfig = TableConfig.getDefault();
ModuleManager moduleManager = new ModuleManager();
CatalogManager catalogManager = CatalogManager.newBuilder().classLoader(Thread.currentThread().getContextClassLoader()).config(tableConfig.getConfiguration()).defaultCatalog("default_catalog", new GenericInMemoryCatalog("default_db")).build();
FlinkContext flinkContext = new FlinkContextImpl(false, tableConfig, moduleManager, new FunctionCatalog(tableConfig, catalogManager, moduleManager), catalogManager, null);
SerdeContext serdeCtx = new SerdeContext(null, flinkContext, Thread.currentThread().getContextClassLoader(), FlinkTypeFactory.INSTANCE(), FlinkSqlOperatorTable.instance());
ObjectReader objectReader = JsonSerdeUtil.createObjectReader(serdeCtx);
ObjectWriter objectWriter = JsonSerdeUtil.createObjectWriter(serdeCtx);
LookupJoinUtil.LookupKey[] lookupKeys = new LookupJoinUtil.LookupKey[] { new LookupJoinUtil.ConstantLookupKey(new BigIntType(), new RexBuilder(FlinkTypeFactory.INSTANCE()).makeLiteral("a")), new LookupJoinUtil.FieldRefLookupKey(3) };
for (LookupJoinUtil.LookupKey lookupKey : lookupKeys) {
LookupJoinUtil.LookupKey result = objectReader.readValue(objectWriter.writeValueAsString(lookupKey), LookupJoinUtil.LookupKey.class);
assertEquals(lookupKey, result);
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project flink by apache.
the class LogicalWindowSerdeTest method testLogicalWindowSerde.
@Test
public void testLogicalWindowSerde() throws IOException {
SerdeContext serdeCtx = new SerdeContext(null, new FlinkContextImpl(false, TableConfig.getDefault(), new ModuleManager(), null, CatalogManagerMocks.createEmptyCatalogManager(), null), Thread.currentThread().getContextClassLoader(), FlinkTypeFactory.INSTANCE(), FlinkSqlOperatorTable.instance());
ObjectReader objectReader = JsonSerdeUtil.createObjectReader(serdeCtx);
ObjectWriter objectWriter = JsonSerdeUtil.createObjectWriter(serdeCtx);
assertEquals(objectReader.readValue(objectWriter.writeValueAsString(window), LogicalWindow.class), window);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project Fast-Android-Networking by amitshekhariitbhu.
the class JacksonParserFactory method responseBodyParser.
@Override
public Parser<ResponseBody, ?> responseBodyParser(Type type) {
JavaType javaType = mapper.getTypeFactory().constructType(type);
ObjectReader reader = mapper.readerFor(javaType);
return new JacksonResponseBodyParser<>(reader);
}
Aggregations