damondouglas commented on code in PR #29829:
URL: https://github.com/apache/beam/pull/29829#discussion_r1437866654


##########
sdks/go/test/integration/primitives/timers.go:
##########
@@ -0,0 +1,133 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package primitives
+
+import (
+       "context"
+       "strconv"
+
+       "github.com/apache/beam/sdks/v2/go/pkg/beam"
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/core/state"
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/core/timers"
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/register"
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/testing/passert"
+)
+
+// Based on 
https://github.com/apache/beam/blob/master/runners/flink/src/test/java/org/apache/beam/runners/flink/PortableTimersExecutionTest.java
+
+func init() {
+       register.DoFn2x0[[]byte, func(string, int)](&inputFn[string, int]{})
+       register.DoFn6x0[beam.Window, state.Provider, timers.Provider, string, 
int, func(kv[string, int])](&eventTimeFn{})
+       register.Emitter2[string, int]()
+       register.Emitter1[kv[string, int]]()
+}
+
+type kv[K, V any] struct {
+       Key   K
+       Value V
+}
+
+func kvfn[K, V any](k K, v V) kv[K, V] {
+       return kv[K, V]{k, v}
+}
+
+type inputFn[K, V any] struct {
+       Inputs []kv[K, V]
+}
+
+func (fn *inputFn[K, V]) ProcessElement(_ []byte, emit func(K, V)) {
+       for _, in := range fn.Inputs {
+               emit(in.Key, in.Value)
+       }
+}
+
+type eventTimeFn struct {
+       Callback timers.EventTime
+       MyKey    state.Value[string]
+
+       Offset      int
+       TimerOutput int
+}
+
+func (fn *eventTimeFn) ProcessElement(w beam.Window, sp state.Provider, tp 
timers.Provider, key string, value int, emit func(kv[string, int])) {
+       fn.Callback.Set(tp, w.MaxTimestamp().ToTime())
+       fn.MyKey.Write(sp, key)
+       emit(kvfn(key, value+fn.Offset))
+}
+
+func (fn *eventTimeFn) OnTimer(ctx context.Context, ts beam.EventTime, sp 
state.Provider, tp timers.Provider, key string, timer timers.Context, emit 
func(kv[string, int])) {
+       switch timer.Family {
+       case fn.Callback.Family:
+               switch timer.Tag {
+               case "":

Review Comment:
   When you say "So that'll be fixed shortly", do you mean in this PR or a 
future one? Otherwise, I'm ready to mark this PR as reviewed/ready.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to