@Test(expected = IllegalArgumentException.class) @Category(NeedsRunner.class) public void testIgnoreNullableFail() throws Exception { // ignoring nullable is opposite of weakening Schema inputSchema = pipeline.getSchemaRegistry().getSchema(Nullable2.class); Schema outputSchema = pipeline.getSchemaRegistry().getSchema(Nullable1.class); Cast.widening(outputSchema).verifyCompatibility(inputSchema); }
@Test(expected = IllegalArgumentException.class) @Category(NeedsRunner.class) public void testWeakedNullableFail() throws Exception { Schema inputSchema = pipeline.getSchemaRegistry().getSchema(Nullable1.class); Schema outputSchema = pipeline.getSchemaRegistry().getSchema(Nullable2.class); Cast.widening(outputSchema).verifyCompatibility(inputSchema); }
@Test(expected = IllegalArgumentException.class) @Category(NeedsRunner.class) public void testTypeNarrowFail() throws Exception { // narrowing is the opposite of widening Schema inputSchema = pipeline.getSchemaRegistry().getSchema(TypeWiden2.class); Schema outputSchema = pipeline.getSchemaRegistry().getSchema(TypeWiden1.class); Cast.narrowing(outputSchema).verifyCompatibility(inputSchema); }
@Test(expected = IllegalArgumentException.class) @Category(NeedsRunner.class) public void testComplexCastFail() throws Exception { Schema inputSchema = pipeline.getSchemaRegistry().getSchema(All1.class); Schema outputSchema = pipeline.getSchemaRegistry().getSchema(All2.class); Cast.widening(outputSchema).verifyCompatibility(inputSchema); }
@Test public void testCreateRegisteredSchema() { p.getSchemaRegistry() .registerSchemaForClass( String.class, STRING_SCHEMA, s -> Row.withSchema(STRING_SCHEMA).addValue(s).build(), r -> r.getString("field")); PCollection<String> out = p.apply(Create.of("a", "b", "c", "d")); assertThat(out.getCoder(), instanceOf(SchemaCoder.class)); }
@Test @Category(NeedsRunner.class) public void testTypeWiden() throws Exception { Schema outputSchema = pipeline.getSchemaRegistry().getSchema(TypeWiden2.class); PCollection<TypeWiden2> pojos = pipeline .apply(Create.of(new TypeWiden1())) .apply(Cast.widening(outputSchema)) .apply(Convert.to(TypeWiden2.class)); PAssert.that(pojos).containsInAnyOrder(new TypeWiden2()); pipeline.run(); }
@Test @Category(NeedsRunner.class) public void testWeakedNullable() throws Exception { Schema outputSchema = pipeline.getSchemaRegistry().getSchema(Nullable2.class); PCollection<Nullable2> pojos = pipeline .apply(Create.of(new Nullable1())) .apply(Cast.narrowing(outputSchema)) .apply(Convert.to(Nullable2.class)); PAssert.that(pojos).containsInAnyOrder(new Nullable2()); pipeline.run(); }
@Test @Category(NeedsRunner.class) public void testComplexCast() throws Exception { Schema outputSchema = pipeline.getSchemaRegistry().getSchema(All2.class); PCollection<All2> pojos = pipeline .apply(Create.of(new All1())) .apply(Cast.narrowing(outputSchema)) .apply(Convert.to(All2.class)); PAssert.that(pojos).containsInAnyOrder(new All2()); pipeline.run(); }
@Test @Category(NeedsRunner.class) public void testTypeNarrow() throws Exception { // narrowing is the opposite of widening Schema outputSchema = pipeline.getSchemaRegistry().getSchema(TypeWiden1.class); PCollection<TypeWiden1> pojos = pipeline .apply(Create.of(new TypeWiden2())) .apply(Cast.narrowing(outputSchema)) .apply(Convert.to(TypeWiden1.class)); PAssert.that(pojos).containsInAnyOrder(new TypeWiden1()); pipeline.run(); }
@Test @Category(NeedsRunner.class) public void testProjection() throws Exception { Schema outputSchema = pipeline.getSchemaRegistry().getSchema(Projection2.class); PCollection<Projection2> pojos = pipeline .apply(Create.of(new Projection1())) .apply(Cast.widening(outputSchema)) .apply(Convert.to(Projection2.class)); PAssert.that(pojos).containsInAnyOrder(new Projection2()); pipeline.run(); }
@Test @Category(NeedsRunner.class) public void testIgnoreNullable() throws Exception { // ignoring nullable is opposite of weakening Schema outputSchema = pipeline.getSchemaRegistry().getSchema(Nullable1.class); PCollection<Nullable1> pojos = pipeline .apply(Create.of(new Nullable2())) .apply(Cast.narrowing(outputSchema)) .apply(Convert.to(Nullable1.class)); PAssert.that(pojos).containsInAnyOrder(new Nullable1()); pipeline.run(); }
.getSchemaRegistry() .registerSchemaForClass( MyPojo.class,