Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BEAM-22] Use an explicit coder in XmlSourceTest #112

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static org.junit.Assert.assertTrue;

import com.google.cloud.dataflow.sdk.Pipeline;
import com.google.cloud.dataflow.sdk.coders.AvroCoder;
import com.google.cloud.dataflow.sdk.io.Source.Reader;
import com.google.cloud.dataflow.sdk.options.PipelineOptions;
import com.google.cloud.dataflow.sdk.options.PipelineOptionsFactory;
Expand All @@ -36,6 +37,7 @@
import com.google.cloud.dataflow.sdk.values.PCollection;
import com.google.common.collect.ImmutableList;

import org.apache.avro.reflect.ReflectData;
import org.hamcrest.Matchers;
import org.junit.Ignore;
import org.junit.Rule;
Expand All @@ -55,6 +57,7 @@
import java.util.List;
import java.util.Random;

import javax.annotation.Nullable;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;

Expand Down Expand Up @@ -156,12 +159,12 @@ public class XmlSourceTest {
@XmlRootElement
static class Train {
public static final int TRAIN_NUMBER_UNDEFINED = -1;
public String name = null;
public String color = null;
@Nullable public String name = null;
@Nullable public String color = null;
public int number = TRAIN_NUMBER_UNDEFINED;

@XmlAttribute(name = "size")
public String size = null;
@Nullable public String size = null;

public Train() {}

Expand Down Expand Up @@ -576,7 +579,11 @@ public void testReadXMLSmallDataflow() throws IOException {
.withRecordClass(Train.class)
.withMinBundleSize(1024);

PCollection<Train> output = p.apply(Read.from(source).named("ReadFileData"));
// The default JAXB Coder is not suitable as part of a composite coder.
AvroCoder<Train> intermediateCoder =
AvroCoder.of(Train.class, ReflectData.AllowNull.get().getSchema(Train.class));
PCollection<Train> output =
p.apply(Read.from(source).named("ReadFileData")).setCoder(intermediateCoder);

List<Train> expectedResults =
ImmutableList.of(new Train("Thomas", 1, "blue", null), new Train("Henry", 3, "green", null),
Expand Down Expand Up @@ -665,7 +672,9 @@ public void testReadXMLLargeDataflow() throws IOException {
.withRecordElement("train")
.withRecordClass(Train.class)
.withMinBundleSize(1024);
PCollection<Train> output = p.apply(Read.from(source).named("ReadFileData"));
AvroCoder<Train> intermediateCoder = AvroCoder.of(Train.class);
PCollection<Train> output =
p.apply(Read.from(source).named("ReadFileData")).setCoder(intermediateCoder);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please update to the happy apply syntax (aka, drop 'named').


DataflowAssert.that(output).containsInAnyOrder(trains);
p.run();
Expand Down Expand Up @@ -812,7 +821,9 @@ public void testReadXMLFilePattern() throws IOException {
.withRecordElement("train")
.withRecordClass(Train.class)
.withMinBundleSize(1024);
PCollection<Train> output = p.apply(Read.from(source).named("ReadFileData"));
AvroCoder<Train> intermediateCoder = AvroCoder.of(Train.class);
PCollection<Train> output =
p.apply(Read.from(source).named("ReadFileData")).setCoder(intermediateCoder);

List<Train> expectedResults = new ArrayList<>();
expectedResults.addAll(trains1);
Expand Down