|
18 | 18 | package org.apache.beam.runners.dataflow;
|
19 | 19 |
|
20 | 20 | import static org.apache.beam.runners.dataflow.DataflowRunner.getContainerImageForJob;
|
21 |
| -import static org.hamcrest.Matchers.allOf; |
22 | 21 | import static org.hamcrest.Matchers.both;
|
23 |
| -import static org.hamcrest.Matchers.containsInAnyOrder; |
24 | 22 | import static org.hamcrest.Matchers.containsString;
|
25 | 23 | import static org.hamcrest.Matchers.equalTo;
|
26 |
| -import static org.hamcrest.Matchers.greaterThan; |
27 | 24 | import static org.hamcrest.Matchers.hasItem;
|
28 | 25 | import static org.hamcrest.Matchers.is;
|
| 26 | +import static org.hamcrest.Matchers.not; |
29 | 27 | import static org.hamcrest.Matchers.startsWith;
|
30 | 28 | import static org.junit.Assert.assertEquals;
|
31 | 29 | import static org.junit.Assert.assertFalse;
|
|
52 | 50 | import java.io.File;
|
53 | 51 | import java.io.FileNotFoundException;
|
54 | 52 | import java.io.IOException;
|
55 |
| -import java.io.Reader; |
56 | 53 | import java.net.URL;
|
57 | 54 | import java.net.URLClassLoader;
|
58 |
| -import java.nio.CharBuffer; |
59 | 55 | import java.nio.channels.FileChannel;
|
60 | 56 | import java.nio.channels.SeekableByteChannel;
|
61 | 57 | import java.nio.file.Files;
|
62 | 58 | import java.nio.file.StandardOpenOption;
|
63 | 59 | import java.util.ArrayList;
|
64 | 60 | import java.util.Arrays;
|
65 |
| -import java.util.Collection; |
66 | 61 | import java.util.Collections;
|
67 | 62 | import java.util.LinkedList;
|
68 | 63 | import java.util.List;
|
|
71 | 66 | import org.apache.beam.runners.dataflow.DataflowRunner.StreamingShardedWriteFactory;
|
72 | 67 | import org.apache.beam.runners.dataflow.options.DataflowPipelineDebugOptions;
|
73 | 68 | import org.apache.beam.runners.dataflow.options.DataflowPipelineOptions;
|
74 |
| -import org.apache.beam.runners.dataflow.options.DataflowPipelineWorkerPoolOptions; |
75 | 69 | import org.apache.beam.sdk.Pipeline;
|
76 | 70 | import org.apache.beam.sdk.Pipeline.PipelineVisitor;
|
77 | 71 | import org.apache.beam.sdk.coders.BigEndianIntegerCoder;
|
78 | 72 | import org.apache.beam.sdk.coders.Coder;
|
| 73 | +import org.apache.beam.sdk.coders.VoidCoder; |
79 | 74 | import org.apache.beam.sdk.extensions.gcp.auth.NoopCredentialFactory;
|
80 | 75 | import org.apache.beam.sdk.extensions.gcp.auth.TestCredential;
|
| 76 | +import org.apache.beam.sdk.io.FileBasedSink; |
81 | 77 | import org.apache.beam.sdk.io.FileSystems;
|
82 | 78 | import org.apache.beam.sdk.io.TextIO;
|
83 |
| -import org.apache.beam.sdk.io.Write; |
| 79 | +import org.apache.beam.sdk.io.WriteFiles; |
84 | 80 | import org.apache.beam.sdk.options.PipelineOptions;
|
85 | 81 | import org.apache.beam.sdk.options.PipelineOptions.CheckEnabled;
|
86 | 82 | import org.apache.beam.sdk.options.PipelineOptionsFactory;
|
87 | 83 | import org.apache.beam.sdk.options.ValueProvider;
|
88 | 84 | import org.apache.beam.sdk.options.ValueProvider.StaticValueProvider;
|
| 85 | +import org.apache.beam.sdk.runners.AppliedPTransform; |
89 | 86 | import org.apache.beam.sdk.runners.TransformHierarchy;
|
90 | 87 | import org.apache.beam.sdk.runners.TransformHierarchy.Node;
|
91 | 88 | import org.apache.beam.sdk.testing.ExpectedLogs;
|
92 | 89 | import org.apache.beam.sdk.testing.TestPipeline;
|
93 |
| -import org.apache.beam.sdk.transforms.AppliedPTransform; |
94 | 90 | import org.apache.beam.sdk.transforms.Create;
|
95 | 91 | import org.apache.beam.sdk.transforms.PTransform;
|
96 | 92 | import org.apache.beam.sdk.util.GcsUtil;
|
|
101 | 97 | import org.apache.beam.sdk.values.PDone;
|
102 | 98 | import org.apache.beam.sdk.values.PValue;
|
103 | 99 | import org.apache.beam.sdk.values.TimestampedValue;
|
| 100 | +import org.apache.beam.sdk.values.TupleTag; |
104 | 101 | import org.apache.beam.sdk.values.WindowingStrategy;
|
105 | 102 | import org.hamcrest.Description;
|
106 | 103 | import org.hamcrest.Matchers;
|
@@ -1130,59 +1127,31 @@ public void testWorkerHarnessContainerImage() {
|
1130 | 1127 | assertThat(getContainerImageForJob(options), equalTo("gcr.io/java/foo"));
|
1131 | 1128 | }
|
1132 | 1129 |
|
1133 |
| - static class SimpleFilenamePolicy extends FilenamePolicy { |
1134 |
| - String baseLocation; |
1135 |
| - |
1136 |
| - SimpleFilenamePolicy(String baseLocation) { |
1137 |
| - this.baseLocation = baseLocation; |
1138 |
| - } |
1139 |
| - |
1140 |
| - @Override |
1141 |
| - public String windowedFilename(WindowedContext c) { |
1142 |
| - return baseLocation + "-shard-" + c.getShardNumber(); |
1143 |
| - } |
1144 |
| - |
1145 |
| - @Override |
1146 |
| - public String unwindowedFilename(Context c) { |
1147 |
| - throw new UnsupportedOperationException("Unsupported"); |
1148 |
| - } |
1149 |
| - |
1150 |
| - @Override |
1151 |
| - public ValueProvider<String> getBaseOutputFilenameProvider() { |
1152 |
| - return StaticValueProvider.of(baseLocation); |
1153 |
| - } |
1154 |
| - }; |
1155 |
| - |
1156 |
| - PipelineOptions getOptions() { |
1157 |
| - PipelineOptions options = TestPipeline.testingPipelineOptions(); |
1158 |
| - options.setRunner(DataflowRunner.class); |
1159 |
| - options.as(DataflowPipelineOptions.class).setStreaming(true); |
1160 |
| - options.as(DataflowPipelineWorkerPoolOptions.class).setMaxNumWorkers(10); |
1161 |
| - return options; |
1162 |
| - } |
1163 |
| - @Rule public final transient TestPipeline p = TestPipeline.fromOptions(getOptions()); |
1164 |
| - |
1165 | 1130 | @Test
|
1166 | 1131 | public void testStreamingWriteWithNoShardingReturnsNewTransform() {
|
1167 | 1132 | TestPipeline p = TestPipeline.create();
|
1168 | 1133 | StreamingShardedWriteFactory<Object> factory = new StreamingShardedWriteFactory(p.getOptions());
|
1169 |
| - Write<Object> original = Write.to(new TestSink()); |
| 1134 | + WriteFiles<Object> original = WriteFiles.to(new TestSink(tmpFolder.toString())); |
1170 | 1135 | PCollection<Object> objs = (PCollection) p.apply(Create.empty(VoidCoder.of()));
|
1171 |
| - AppliedPTransform<PCollection<Object>, PDone, Write<Object>> originalApplication = |
| 1136 | + AppliedPTransform<PCollection<Object>, PDone, WriteFiles<Object>> originalApplication = |
1172 | 1137 | AppliedPTransform.of(
|
1173 |
| - "write", objs.expand(), Collections.<TupleTag<?>, PValue>emptyMap(), original, p); |
| 1138 | + "writefiles", objs.expand(), Collections.<TupleTag<?>, PValue>emptyMap(), original, p); |
1174 | 1139 |
|
1175 | 1140 | assertThat(
|
1176 | 1141 | factory.getReplacementTransform(originalApplication).getTransform(),
|
1177 | 1142 | not(equalTo((Object) original)));
|
1178 | 1143 | }
|
1179 | 1144 |
|
1180 |
| - private static class TestSink extends Sink<Object> { |
| 1145 | + private static class TestSink extends FileBasedSink<Object> { |
1181 | 1146 | @Override
|
1182 | 1147 | public void validate(PipelineOptions options) {}
|
1183 | 1148 |
|
| 1149 | + TestSink(String tmpFolder) { |
| 1150 | + super(StaticValueProvider.of(FileSystems.matchNewResource(tmpFolder, true)), |
| 1151 | + null); |
| 1152 | + } |
1184 | 1153 | @Override
|
1185 |
| - public WriteOperation<Object, ?> createWriteOperation(PipelineOptions options) { |
| 1154 | + public FileBasedWriteOperation<Object> createWriteOperation() { |
1186 | 1155 | throw new IllegalArgumentException("Should not be used");
|
1187 | 1156 | }
|
1188 | 1157 | }
|
|
0 commit comments