Search in sources :

Example 1 with FnAnalysisContext

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);
}
Also used : DoFnSignaturesTestUtils.analyzeProcessElementMethod(org.apache.beam.sdk.transforms.reflect.DoFnSignaturesTestUtils.analyzeProcessElementMethod) AnonymousMethod(org.apache.beam.sdk.transforms.reflect.DoFnSignaturesTestUtils.AnonymousMethod) Method(java.lang.reflect.Method) StateSpec(org.apache.beam.sdk.state.StateSpec) DoFn(org.apache.beam.sdk.transforms.DoFn) FakeDoFn(org.apache.beam.sdk.transforms.reflect.DoFnSignaturesTestUtils.FakeDoFn) ValueState(org.apache.beam.sdk.state.ValueState) FnAnalysisContext(org.apache.beam.sdk.transforms.reflect.DoFnSignatures.FnAnalysisContext) TypeDescriptor(org.apache.beam.sdk.values.TypeDescriptor) Test(org.junit.Test)

Aggregations

Method (java.lang.reflect.Method)1 StateSpec (org.apache.beam.sdk.state.StateSpec)1 ValueState (org.apache.beam.sdk.state.ValueState)1 DoFn (org.apache.beam.sdk.transforms.DoFn)1 FnAnalysisContext (org.apache.beam.sdk.transforms.reflect.DoFnSignatures.FnAnalysisContext)1 AnonymousMethod (org.apache.beam.sdk.transforms.reflect.DoFnSignaturesTestUtils.AnonymousMethod)1 FakeDoFn (org.apache.beam.sdk.transforms.reflect.DoFnSignaturesTestUtils.FakeDoFn)1 DoFnSignaturesTestUtils.analyzeProcessElementMethod (org.apache.beam.sdk.transforms.reflect.DoFnSignaturesTestUtils.analyzeProcessElementMethod)1 TypeDescriptor (org.apache.beam.sdk.values.TypeDescriptor)1 Test (org.junit.Test)1