use of io.openlineage.client.OpenLineage.NominalTimeRunFacet in project OpenLineage by OpenLineage.
the class OpenLineageTest method jsonSerialization.
@Test
public void jsonSerialization() throws JsonProcessingException {
ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC"));
URI producer = URI.create("producer");
OpenLineage ol = new OpenLineage(producer);
UUID runId = UUID.randomUUID();
RunFacets runFacets = ol.newRunFacetsBuilder().nominalTime(ol.newNominalTimeRunFacet(now, now)).build();
Run run = ol.newRun(runId, runFacets);
String name = "jobName";
String namespace = "namespace";
JobFacets jobFacets = ol.newJobFacetsBuilder().build();
Job job = ol.newJob(namespace, name, jobFacets);
List<InputDataset> inputs = Arrays.asList(ol.newInputDataset("ins", "input", null, null));
List<OutputDataset> outputs = Arrays.asList(ol.newOutputDataset("ons", "output", null, null));
RunEvent runStateUpdate = ol.newRunEvent(OpenLineage.RunEvent.EventType.START, now, run, job, inputs, outputs);
String json = mapper.writeValueAsString(runStateUpdate);
RunEvent read = mapper.readValue(json, RunEvent.class);
assertEquals(producer, read.getProducer());
assertEquals(runId, read.getRun().getRunId());
assertEquals(name, read.getJob().getName());
assertEquals(namespace, read.getJob().getNamespace());
assertEquals(runStateUpdate.getEventType(), read.getEventType());
assertEquals(runStateUpdate.getEventTime(), read.getEventTime());
assertEquals(1, runStateUpdate.getInputs().size());
NominalTimeRunFacet nominalTime = runStateUpdate.getRun().getFacets().getNominalTime();
assertEquals(now, nominalTime.getNominalStartTime());
assertEquals(now, nominalTime.getNominalEndTime());
InputDataset inputDataset = runStateUpdate.getInputs().get(0);
assertEquals("ins", inputDataset.getNamespace());
assertEquals("input", inputDataset.getName());
assertEquals(1, runStateUpdate.getOutputs().size());
OutputDataset outputDataset = runStateUpdate.getOutputs().get(0);
assertEquals("ons", outputDataset.getNamespace());
assertEquals("output", outputDataset.getName());
assertEquals(roundTrip(json), roundTrip(mapper.writeValueAsString(read)));
}
Aggregations