use of org.apache.beam.sdk.transforms.reflect.DoFnSignatures.FnAnalysisContext in project beam by apache.
the class DoFnSignaturesSplittableDoFnTest method testSplittableProcessElementMustNotHaveUnsupportedParams.
@Test
// used via reflection
@SuppressWarnings("unused")
public void testSplittableProcessElementMustNotHaveUnsupportedParams() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Illegal parameter");
thrown.expectMessage("ValueState");
DoFn<Integer, String> doFn = new DoFn<Integer, String>() {
@StateId("my-state-id")
public final StateSpec<ValueState<String>> myStateSpec = StateSpecs.value(StringUtf8Coder.of());
@ProcessElement
public void method(DoFn<Integer, String>.ProcessContext context, SomeRestrictionTracker tracker, @StateId("my-state-id") ValueState<String> myState) {
}
};
Method processElementMethod = null;
for (Method method : doFn.getClass().getDeclaredMethods()) {
if ("method".equals(method.getName())) {
processElementMethod = method;
}
}
checkState(processElementMethod != null);
FnAnalysisContext context = FnAnalysisContext.create();
context.addStateDeclaration(DoFnSignature.StateDeclaration.create("my-state-id", doFn.getClass().getField("myStateSpec"), new TypeDescriptor<ValueState<String>>() {
}));
DoFnSignatures.analyzeProcessElementMethod(errors(), new TypeDescriptor<DoFn<Integer, String>>() {
}, processElementMethod, TypeDescriptor.of(Integer.class), TypeDescriptor.of(String.class), context);
}
Aggregations