|
33 | 33 | import org.apache.beam.sdk.schemas.SchemaTranslation; |
34 | 34 | import org.apache.beam.sdk.schemas.logicaltypes.MicrosInstant; |
35 | 35 | import org.apache.beam.sdk.testing.PAssert; |
| 36 | +import org.apache.beam.sdk.testing.TestPipeline; |
36 | 37 | import org.apache.beam.sdk.testing.UsesPythonExpansionService; |
37 | 38 | import org.apache.beam.sdk.testing.ValidatesRunner; |
38 | 39 | import org.apache.beam.sdk.transforms.Create; |
|
43 | 44 | import org.apache.beam.sdk.values.Row; |
44 | 45 | import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableList; |
45 | 46 | import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableMap; |
| 47 | +import org.junit.Rule; |
46 | 48 | import org.junit.Test; |
47 | 49 | import org.junit.experimental.categories.Category; |
48 | 50 | import org.junit.runner.RunWith; |
49 | 51 | import org.junit.runners.JUnit4; |
50 | 52 |
|
51 | 53 | @RunWith(JUnit4.class) |
52 | 54 | public class PythonExternalTransformTest implements Serializable { |
| 55 | + @Rule public transient TestPipeline testPipeline = TestPipeline.create(); |
53 | 56 |
|
54 | 57 | @Test |
55 | 58 | @Category({ValidatesRunner.class, UsesPythonExpansionService.class}) |
56 | 59 | public void trivialPythonTransform() { |
57 | | - Pipeline p = Pipeline.create(); |
58 | 60 | PCollection<String> output = |
59 | | - p.apply(Create.of(KV.of("A", "x"), KV.of("A", "y"), KV.of("B", "z"))) |
| 61 | + testPipeline |
| 62 | + .apply(Create.of(KV.of("A", "x"), KV.of("A", "y"), KV.of("B", "z"))) |
60 | 63 | .apply( |
61 | 64 | PythonExternalTransform |
62 | 65 | .<PCollection<KV<String, String>>, PCollection<KV<String, Iterable<String>>>> |
63 | 66 | from("apache_beam.GroupByKey")) |
64 | 67 | .apply(Keys.create()); |
65 | 68 | PAssert.that(output).containsInAnyOrder("A", "B"); |
66 | | - // TODO: Run this on a multi-language supporting runner. |
| 69 | + testPipeline.run(); |
67 | 70 | } |
68 | 71 |
|
69 | 72 | @Test |
70 | 73 | @Category({ValidatesRunner.class, UsesPythonExpansionService.class}) |
71 | 74 | public void pythonTransformWithDependencies() { |
72 | | - Pipeline p = Pipeline.create(); |
73 | 75 | PCollection<String> output = |
74 | | - p.apply(Create.of("elephant", "mouse", "sheep")) |
| 76 | + testPipeline |
| 77 | + .apply(Create.of("elephant", "mouse", "sheep")) |
75 | 78 | .apply( |
76 | 79 | PythonExternalTransform.<PCollection<String>, PCollection<String>>from( |
77 | 80 | "apache_beam.Map") |
78 | 81 | .withArgs(PythonCallableSource.of("import inflection\ninflection.pluralize")) |
79 | 82 | .withExtraPackages(ImmutableList.of("inflection")) |
80 | 83 | .withOutputCoder(StringUtf8Coder.of())); |
81 | 84 | PAssert.that(output).containsInAnyOrder("elephants", "mice", "sheep"); |
82 | | - // TODO: Run this on a multi-language supporting runner. |
| 85 | + testPipeline.run(); |
83 | 86 | } |
84 | 87 |
|
85 | 88 | @Test |
|
0 commit comments