Search in sources :

Example 26 with TimerSpec

use of org.apache.beam.sdk.state.TimerSpec in project beam by apache.

the class DoFnSignaturesTest method testSimpleTimerIdNamedDoFn.

@Test
public void testSimpleTimerIdNamedDoFn() throws Exception {
    class DoFnForTestSimpleTimerIdNamedDoFn extends DoFn<KV<String, Integer>, Long> {

        @TimerId("foo")
        private final TimerSpec bizzle = TimerSpecs.timer(TimeDomain.EVENT_TIME);

        @ProcessElement
        public void foo(ProcessContext context) {
        }

        @OnTimer("foo")
        public void onFoo() {
        }
    }
    // Test classes at the bottom of the file
    DoFnSignature sig = DoFnSignatures.signatureForDoFn(new DoFnForTestSimpleTimerIdNamedDoFn());
    final String timerDeclarationId = TimerDeclaration.PREFIX + "foo";
    assertThat(sig.timerDeclarations().size(), equalTo(1));
    DoFnSignature.TimerDeclaration decl = sig.timerDeclarations().get(timerDeclarationId);
    assertThat(decl.id(), equalTo(timerDeclarationId));
    assertThat(decl.field(), equalTo(DoFnForTestSimpleTimerIdNamedDoFn.class.getDeclaredField("bizzle")));
}
Also used : DoFn(org.apache.beam.sdk.transforms.DoFn) FakeDoFn(org.apache.beam.sdk.transforms.reflect.DoFnSignaturesTestUtils.FakeDoFn) Matchers.containsString(org.hamcrest.Matchers.containsString) TimerDeclaration(org.apache.beam.sdk.transforms.reflect.DoFnSignature.TimerDeclaration) TimerSpec(org.apache.beam.sdk.state.TimerSpec) Test(org.junit.Test)

Aggregations

TimerSpec (org.apache.beam.sdk.state.TimerSpec)26 Test (org.junit.Test)25 Timer (org.apache.beam.sdk.state.Timer)19 KV (org.apache.beam.sdk.values.KV)18 Matchers.containsString (org.hamcrest.Matchers.containsString)17 DoFn (org.apache.beam.sdk.transforms.DoFn)13 StringUtils.byteArrayToJsonString (org.apache.beam.sdk.util.StringUtils.byteArrayToJsonString)12 Instant (org.joda.time.Instant)12 OnTimer (org.apache.beam.sdk.transforms.DoFn.OnTimer)11 BoundedWindow (org.apache.beam.sdk.transforms.windowing.BoundedWindow)11 Category (org.junit.experimental.categories.Category)11 StateSpec (org.apache.beam.sdk.state.StateSpec)7 ValueState (org.apache.beam.sdk.state.ValueState)6 IntervalWindow (org.apache.beam.sdk.transforms.windowing.IntervalWindow)6 Pipeline (org.apache.beam.sdk.Pipeline)5 FakeDoFn (org.apache.beam.sdk.transforms.reflect.DoFnSignaturesTestUtils.FakeDoFn)5 ArrayList (java.util.ArrayList)4 Coder (org.apache.beam.sdk.coders.Coder)4 KvCoder (org.apache.beam.sdk.coders.KvCoder)4 StringUtf8Coder (org.apache.beam.sdk.coders.StringUtf8Coder)4