Search in sources :

Example 1 with StateParameter

use of org.apache.beam.sdk.transforms.reflect.DoFnSignature.Parameter.StateParameter in project beam by apache.

the class DoFnSignaturesTest method testDeclAndUsageOfStateInSuperclass.

@Test
public void testDeclAndUsageOfStateInSuperclass() throws Exception {
    class DoFnOverridingAbstractStateUse extends DoFnDeclaringStateAndAbstractUse {

        @Override
        public void processWithState(ProcessContext c, ValueState<String> state) {
        }
    }
    DoFnSignature sig = DoFnSignatures.getSignature(new DoFnOverridingAbstractStateUse().getClass());
    assertThat(sig.stateDeclarations().size(), equalTo(1));
    assertThat(sig.processElement().extraParameters().size(), equalTo(2));
    DoFnSignature.StateDeclaration decl = sig.stateDeclarations().get(DoFnOverridingAbstractStateUse.STATE_ID);
    StateParameter stateParam = (StateParameter) sig.processElement().extraParameters().get(1);
    assertThat(decl.field(), equalTo(DoFnDeclaringStateAndAbstractUse.class.getDeclaredField("myStateSpec")));
    // The method we pull out is the superclass method; this is what allows validation to remain
    // simple. The later invokeDynamic instruction causes it to invoke the actual implementation.
    assertThat(stateParam.referent(), equalTo(decl));
}
Also used : ValueState(org.apache.beam.sdk.state.ValueState) StateParameter(org.apache.beam.sdk.transforms.reflect.DoFnSignature.Parameter.StateParameter) Test(org.junit.Test)

Aggregations

ValueState (org.apache.beam.sdk.state.ValueState)1 StateParameter (org.apache.beam.sdk.transforms.reflect.DoFnSignature.Parameter.StateParameter)1 Test (org.junit.Test)1