Skip to content
Merged
Show file tree
Hide file tree
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 @@ -62,10 +62,10 @@ public class CloningBundleFactoryTest {

@Test
public void rootBundleSucceedsIgnoresCoder() {
WindowedValue<Record> one = WindowedValues.valueInGlobalWindow(new Record());
WindowedValue<Record> two = WindowedValues.valueInGlobalWindow(new Record());
CommittedBundle<Record> root =
factory.<Record>createRootBundle().add(one).add(two).commit(Instant.now());
WindowedValue<TestRecord> one = WindowedValues.valueInGlobalWindow(new TestRecord());
WindowedValue<TestRecord> two = WindowedValues.valueInGlobalWindow(new TestRecord());
CommittedBundle<TestRecord> root =
factory.<TestRecord>createRootBundle().add(one).add(two).commit(Instant.now());

assertThat(root.getElements(), containsInAnyOrder(one, two));
}
Expand Down Expand Up @@ -122,71 +122,71 @@ public void keyedBundleWorkingCoderSucceedsClonesOutput() {

@Test
public void bundleEncodeFailsAddFails() {
PCollection<Record> pc = p.apply(Create.empty(new RecordNoEncodeCoder()));
UncommittedBundle<Record> bundle = factory.createBundle(pc);
PCollection<TestRecord> pc = p.apply(Create.empty(new TestRecordNoEncodeCoder()));
UncommittedBundle<TestRecord> bundle = factory.createBundle(pc);

thrown.expect(UserCodeException.class);
thrown.expectCause(isA(CoderException.class));
thrown.expectMessage("Encode not allowed");
bundle.add(WindowedValues.valueInGlobalWindow(new Record()));
bundle.add(WindowedValues.valueInGlobalWindow(new TestRecord()));
}

@Test
public void bundleDecodeFailsAddFails() {
PCollection<Record> pc = p.apply(Create.empty(new RecordNoDecodeCoder()));
UncommittedBundle<Record> bundle = factory.createBundle(pc);
PCollection<TestRecord> pc = p.apply(Create.empty(new TestRecordNoDecodeCoder()));
UncommittedBundle<TestRecord> bundle = factory.createBundle(pc);

thrown.expect(UserCodeException.class);
thrown.expectCause(isA(CoderException.class));
thrown.expectMessage("Decode not allowed");
bundle.add(WindowedValues.valueInGlobalWindow(new Record()));
bundle.add(WindowedValues.valueInGlobalWindow(new TestRecord()));
}

@Test
public void keyedBundleEncodeFailsAddFails() {
PCollection<Record> pc = p.apply(Create.empty(new RecordNoEncodeCoder()));
UncommittedBundle<Record> bundle =
PCollection<TestRecord> pc = p.apply(Create.empty(new TestRecordNoEncodeCoder()));
UncommittedBundle<TestRecord> bundle =
factory.createKeyedBundle(StructuralKey.of("foo", StringUtf8Coder.of()), pc);

thrown.expect(UserCodeException.class);
thrown.expectCause(isA(CoderException.class));
thrown.expectMessage("Encode not allowed");
bundle.add(WindowedValues.valueInGlobalWindow(new Record()));
bundle.add(WindowedValues.valueInGlobalWindow(new TestRecord()));
}

@Test
public void keyedBundleDecodeFailsAddFails() {
PCollection<Record> pc = p.apply(Create.empty(new RecordNoDecodeCoder()));
UncommittedBundle<Record> bundle =
PCollection<TestRecord> pc = p.apply(Create.empty(new TestRecordNoDecodeCoder()));
UncommittedBundle<TestRecord> bundle =
factory.createKeyedBundle(StructuralKey.of("foo", StringUtf8Coder.of()), pc);

thrown.expect(UserCodeException.class);
thrown.expectCause(isA(CoderException.class));
thrown.expectMessage("Decode not allowed");
bundle.add(WindowedValues.valueInGlobalWindow(new Record()));
bundle.add(WindowedValues.valueInGlobalWindow(new TestRecord()));
}

static class Record {}
static class TestRecord {}

static class RecordNoEncodeCoder extends AtomicCoder<Record> {
static class TestRecordNoEncodeCoder extends AtomicCoder<TestRecord> {

@Override
public void encode(Record value, OutputStream outStream) throws IOException {
public void encode(TestRecord value, OutputStream outStream) throws IOException {
throw new CoderException("Encode not allowed");
}

@Override
public Record decode(InputStream inStream) throws IOException {
public TestRecord decode(InputStream inStream) throws IOException {
return null;
}
}

static class RecordNoDecodeCoder extends AtomicCoder<Record> {
static class TestRecordNoDecodeCoder extends AtomicCoder<TestRecord> {
@Override
public void encode(Record value, OutputStream outStream) throws IOException {}
public void encode(TestRecord value, OutputStream outStream) throws IOException {}

@Override
public Record decode(InputStream inStream) throws IOException {
public TestRecord decode(InputStream inStream) throws IOException {
throw new CoderException("Decode not allowed");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ public static Iterable<Coder<?>> data() {
IntervalWindow.getCoder()))
.add(ByteArrayCoder.of())
.add(VarLongCoder.of())
.add(SerializableCoder.of(Record.class))
.add(SerializableCoder.of(TestRecord.class))
.add(AvroCoder.generic(avroSchema))
.add(AvroCoder.specific(AvroGeneratedUser.class))
.add(AvroCoder.reflect(Record.class))
.add(AvroCoder.reflect(TestRecord.class))
.add(CollectionCoder.of(VarLongCoder.of()))
.add(ListCoder.of(VarLongCoder.of()))
.add(SetCoder.of(VarLongCoder.of()))
Expand Down Expand Up @@ -254,7 +254,7 @@ private static void checkPipelineProtoCoderIds(
}
}

private static class Record implements Serializable {}
private static class TestRecord implements Serializable {}

private static org.apache.avro.Schema avroSchema =
new org.apache.avro.Schema.Parser()
Expand Down Expand Up @@ -286,13 +286,14 @@ public int hashCode() {
}

/** A non-custom coder with no registered translator. */
private static class ArbitraryCoder extends StructuredCoder<Record> {
private static class ArbitraryCoder extends StructuredCoder<TestRecord> {
@Override
public void encode(Record value, OutputStream outStream) throws CoderException, IOException {}
public void encode(TestRecord value, OutputStream outStream)
throws CoderException, IOException {}

@Override
public Record decode(InputStream inStream) throws CoderException, IOException {
return new Record();
public TestRecord decode(InputStream inStream) throws CoderException, IOException {
return new TestRecord();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,17 @@ public void testCreateEmptyIterableWithCoder() {
p.run();
}

static class Record implements Serializable {}
static class TestRecord implements Serializable {}

static class Record2 extends Record {}
static class TestRecord2 extends TestRecord {}

private static class RecordCoder extends AtomicCoder<Record> {
private static class TestRecordCoder extends AtomicCoder<TestRecord> {
@Override
public void encode(Record value, OutputStream outStream) throws CoderException, IOException {}
public void encode(TestRecord value, OutputStream outStream)
throws CoderException, IOException {}

@Override
public Record decode(InputStream inStream) throws CoderException, IOException {
public TestRecord decode(InputStream inStream) throws CoderException, IOException {
return null;
}
}
Expand All @@ -154,7 +155,7 @@ public void testPolymorphicType() throws Exception {
thrown.expectMessage(Matchers.containsString("Unable to infer a coder"));

// Create won't infer a default coder in this case.
p.apply(Create.of(new Record(), new Record2()));
p.apply(Create.of(new TestRecord(), new TestRecord2()));

p.run();
}
Expand Down Expand Up @@ -309,11 +310,11 @@ public void testCreateTimestampedPolymorphicType() throws Exception {
thrown.expectMessage(Matchers.containsString("Unable to infer a coder"));

// Create won't infer a default coder in this case.
PCollection<Record> c =
PCollection<TestRecord> c =
p.apply(
Create.timestamped(
TimestampedValue.of(new Record(), new Instant(0)),
TimestampedValue.of(new Record2(), new Instant(0))));
TimestampedValue.of(new TestRecord(), new Instant(0)),
TimestampedValue.of(new TestRecord2(), new Instant(0))));

p.run();

Expand All @@ -322,24 +323,24 @@ public void testCreateTimestampedPolymorphicType() throws Exception {

@Test
public void testCreateTimestampedDefaultOutputCoderUsingCoder() throws Exception {
Coder<Record> coder = new RecordCoder();
Create.TimestampedValues<Record> values =
Coder<TestRecord> coder = new TestRecordCoder();
Create.TimestampedValues<TestRecord> values =
Create.timestamped(
TimestampedValue.of(new Record(), new Instant(0)),
TimestampedValue.of(new Record2(), new Instant(0)))
TimestampedValue.of(new TestRecord(), new Instant(0)),
TimestampedValue.of(new TestRecord2(), new Instant(0)))
.withCoder(coder);
assertThat(p.apply(values).getCoder(), equalTo(coder));
}

@Test
public void testCreateTimestampedDefaultOutputCoderUsingTypeDescriptor() throws Exception {
Coder<Record> coder = new RecordCoder();
p.getCoderRegistry().registerCoderForClass(Record.class, coder);
Create.TimestampedValues<Record> values =
Coder<TestRecord> coder = new TestRecordCoder();
p.getCoderRegistry().registerCoderForClass(TestRecord.class, coder);
Create.TimestampedValues<TestRecord> values =
Create.timestamped(
TimestampedValue.of(new Record(), new Instant(0)),
TimestampedValue.of(new Record2(), new Instant(0)))
.withType(new TypeDescriptor<Record>() {});
TimestampedValue.of(new TestRecord(), new Instant(0)),
TimestampedValue.of(new TestRecord2(), new Instant(0)))
.withType(new TypeDescriptor<TestRecord>() {});
assertThat(p.apply(values).getCoder(), equalTo(coder));
}

Expand Down Expand Up @@ -460,26 +461,28 @@ public void testCreateGetName() {

@Test
public void testCreateDefaultOutputCoderUsingInference() throws Exception {
Coder<Record> coder = new RecordCoder();
p.getCoderRegistry().registerCoderForClass(Record.class, coder);
Coder<TestRecord> coder = new TestRecordCoder();
p.getCoderRegistry().registerCoderForClass(TestRecord.class, coder);
assertThat(
p.apply(Create.of(new Record(), new Record(), new Record())).getCoder(), equalTo(coder));
p.apply(Create.of(new TestRecord(), new TestRecord(), new TestRecord())).getCoder(),
equalTo(coder));
}

@Test
public void testCreateDefaultOutputCoderUsingCoder() throws Exception {
Coder<Record> coder = new RecordCoder();
Coder<TestRecord> coder = new TestRecordCoder();
assertThat(
p.apply(Create.of(new Record(), new Record2()).withCoder(coder)).getCoder(),
p.apply(Create.of(new TestRecord(), new TestRecord2()).withCoder(coder)).getCoder(),
equalTo(coder));
}

@Test
public void testCreateDefaultOutputCoderUsingTypeDescriptor() throws Exception {
Coder<Record> coder = new RecordCoder();
p.getCoderRegistry().registerCoderForClass(Record.class, coder);
Create.Values<Record> values =
Create.of(new Record(), new Record2()).withType(new TypeDescriptor<Record>() {});
Coder<TestRecord> coder = new TestRecordCoder();
p.getCoderRegistry().registerCoderForClass(TestRecord.class, coder);
Create.Values<TestRecord> values =
Create.of(new TestRecord(), new TestRecord2())
.withType(new TypeDescriptor<TestRecord>() {});
assertThat(p.apply(values).getCoder(), equalTo(coder));
}

Expand Down
Loading