Search in sources :

Example 1 with Builder

use of org.apache.beam.sdk.transforms.display.DisplayData.Builder in project beam by apache.

the class ParDoTest method testWithOutputTagsDisplayData.

@Test
public void testWithOutputTagsDisplayData() {
    DoFn<String, String> fn = new DoFn<String, String>() {

        @ProcessElement
        public void proccessElement(ProcessContext c) {
        }

        @Override
        public void populateDisplayData(Builder builder) {
            builder.add(DisplayData.item("fnMetadata", "foobar"));
        }
    };
    ParDo.MultiOutput<String, String> parDo = ParDo.of(fn).withOutputTags(new TupleTag<String>(), TupleTagList.empty());
    DisplayData displayData = DisplayData.from(parDo);
    assertThat(displayData, includesDisplayDataFor("fn", fn));
    assertThat(displayData, hasDisplayItem("fn", fn.getClass()));
}
Also used : Builder(org.apache.beam.sdk.transforms.display.DisplayData.Builder) UsesStatefulParDo(org.apache.beam.sdk.testing.UsesStatefulParDo) UsesTimersInParDo(org.apache.beam.sdk.testing.UsesTimersInParDo) StringUtils.byteArrayToJsonString(org.apache.beam.sdk.util.StringUtils.byteArrayToJsonString) Matchers.containsString(org.hamcrest.Matchers.containsString) DisplayData(org.apache.beam.sdk.transforms.display.DisplayData) Test(org.junit.Test)

Example 2 with Builder

use of org.apache.beam.sdk.transforms.display.DisplayData.Builder in project beam by apache.

the class ParDoTest method testDoFnWithContextDisplayData.

@Test
public void testDoFnWithContextDisplayData() {
    DoFn<String, String> fn = new DoFn<String, String>() {

        @ProcessElement
        public void proccessElement(ProcessContext c) {
        }

        @Override
        public void populateDisplayData(Builder builder) {
            builder.add(DisplayData.item("fnMetadata", "foobar"));
        }
    };
    SingleOutput<String, String> parDo = ParDo.of(fn);
    DisplayData displayData = DisplayData.from(parDo);
    assertThat(displayData, includesDisplayDataFor("fn", fn));
    assertThat(displayData, hasDisplayItem("fn", fn.getClass()));
}
Also used : Builder(org.apache.beam.sdk.transforms.display.DisplayData.Builder) StringUtils.byteArrayToJsonString(org.apache.beam.sdk.util.StringUtils.byteArrayToJsonString) Matchers.containsString(org.hamcrest.Matchers.containsString) DisplayData(org.apache.beam.sdk.transforms.display.DisplayData) Test(org.junit.Test)

Example 3 with Builder

use of org.apache.beam.sdk.transforms.display.DisplayData.Builder in project beam by apache.

the class ParDoTest method testDoFnDisplayData.

@Test
public void testDoFnDisplayData() {
    DoFn<String, String> fn = new DoFn<String, String>() {

        @ProcessElement
        public void processElement(ProcessContext c) {
        }

        @Override
        public void populateDisplayData(Builder builder) {
            builder.add(DisplayData.item("doFnMetadata", "bar"));
        }
    };
    SingleOutput<String, String> parDo = ParDo.of(fn);
    DisplayData displayData = DisplayData.from(parDo);
    assertThat(displayData, hasDisplayItem(allOf(hasKey("fn"), hasType(DisplayData.Type.JAVA_CLASS), DisplayDataMatchers.hasValue(fn.getClass().getName()))));
    assertThat(displayData, includesDisplayDataFor("fn", fn));
}
Also used : Builder(org.apache.beam.sdk.transforms.display.DisplayData.Builder) StringUtils.byteArrayToJsonString(org.apache.beam.sdk.util.StringUtils.byteArrayToJsonString) Matchers.containsString(org.hamcrest.Matchers.containsString) DisplayData(org.apache.beam.sdk.transforms.display.DisplayData) Test(org.junit.Test)

Aggregations

DisplayData (org.apache.beam.sdk.transforms.display.DisplayData)3 Builder (org.apache.beam.sdk.transforms.display.DisplayData.Builder)3 StringUtils.byteArrayToJsonString (org.apache.beam.sdk.util.StringUtils.byteArrayToJsonString)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 Test (org.junit.Test)3 UsesStatefulParDo (org.apache.beam.sdk.testing.UsesStatefulParDo)1 UsesTimersInParDo (org.apache.beam.sdk.testing.UsesTimersInParDo)1