@Test public void testGoodConcreteTypes() throws Exception { analyzeProcessElementMethod( new AnonymousMethod() { private void method(DoFn<Integer, String>.ProcessContext c) {} }); }
@Test public void testReturnsProcessContinuation() throws Exception { DoFnSignature.ProcessElementMethod signature = analyzeProcessElementMethod( new AnonymousMethod() { private DoFn.ProcessContinuation method( DoFn<Integer, String>.ProcessContext context) { return null; } }); assertTrue(signature.hasReturnValue()); }
@Test public void testBadExtraProcessContextType() throws Exception { thrown.expect(IllegalArgumentException.class); thrown.expectMessage( "Integer is not a valid context parameter. " + "Should be one of [BoundedWindow, RestrictionTracker<?, ?>]"); analyzeProcessElementMethod( new AnonymousMethod() { private void method(DoFn<Integer, String>.ProcessContext c, Integer n) {} }); }
@Test public void testBadReturnType() throws Exception { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Must return void or ProcessContinuation"); analyzeProcessElementMethod( new AnonymousMethod() { private int method(DoFn<Integer, String>.ProcessContext context) { return 0; } }); }
@Test public void testSplittableProcessElementMustNotHaveOtherParams() throws Exception { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Illegal parameter"); thrown.expectMessage("BoundedWindow"); DoFnSignature.ProcessElementMethod signature = analyzeProcessElementMethod( new AnonymousMethod() { private void method( DoFn<Integer, String>.ProcessContext context, SomeRestrictionTracker tracker, BoundedWindow window) {} }); }
@Test public void testBadGenericsTwoArgs() throws Exception { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("DoFn<Integer, Integer>.ProcessContext"); thrown.expectMessage("must have type"); thrown.expectMessage("DoFn<Integer, String>.ProcessContext"); analyzeProcessElementMethod( new AnonymousMethod() { private void method(DoFn<Integer, Integer>.ProcessContext c) {} }); }
@Test public void testBadGenericWildCards() throws Exception { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("DoFn<Integer, ? super Integer>.ProcessContext"); thrown.expectMessage("must have type"); thrown.expectMessage("DoFn<Integer, String>.ProcessContext"); analyzeProcessElementMethod( new AnonymousMethod() { private void method(DoFn<Integer, ? super Integer>.ProcessContext c) {} }); }
@Test public void testHasRestrictionTracker() throws Exception { DoFnSignature.ProcessElementMethod signature = analyzeProcessElementMethod( new AnonymousMethod() { private void method( DoFn<Integer, String>.ProcessContext context, SomeRestrictionTracker tracker) {} }); assertTrue(signature.isSplittable()); assertTrue( signature .extraParameters() .stream() .anyMatch( Predicates.instanceOf(DoFnSignature.Parameter.RestrictionTrackerParameter.class) ::apply)); assertEquals(SomeRestrictionTracker.class, signature.trackerT().getRawType()); }