You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2022/03/01 21:06:20 UTC

[GitHub] [beam] jrmccluskey commented on a change in pull request #16979: [BEAM-13911] Add basic tests to Go direct runner.

jrmccluskey commented on a change in pull request #16979:
URL: https://github.com/apache/beam/pull/16979#discussion_r817133592



##########
File path: sdks/go/pkg/beam/runners/direct/direct_test.go
##########
@@ -0,0 +1,459 @@
+// 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 direct
+
+import (
+	"context"
+	"flag"
+	"fmt"
+	"os"
+	"reflect"
+	"sort"
+	"testing"
+
+	"github.com/apache/beam/sdks/v2/go/pkg/beam"
+	"github.com/apache/beam/sdks/v2/go/pkg/beam/core/metrics"
+	"github.com/google/go-cmp/cmp"
+)
+
+func executeWithT(ctx context.Context, t *testing.T, p *beam.Pipeline) (beam.PipelineResult, error) {
+	fmt.Println("startingTest - ", t.Name())
+	return Execute(ctx, p)
+}
+
+func init() {
+	beam.RegisterFunction(dofn1)
+	beam.RegisterFunction(dofn1x2)
+	beam.RegisterFunction(dofn1x5)
+	beam.RegisterFunction(dofn2x1)
+	beam.RegisterFunction(dofn3x1)
+	beam.RegisterFunction(dofn2x2KV)
+	beam.RegisterFunction(dofn2)
+	beam.RegisterFunction(dofnKV)
+	beam.RegisterFunction(dofnKV2)
+	beam.RegisterFunction(dofnGBK)
+	beam.RegisterFunction(dofnGBK2)
+	beam.RegisterType(reflect.TypeOf((*int64Check)(nil)))
+	beam.RegisterType(reflect.TypeOf((*stringCheck)(nil)))
+
+	beam.RegisterType(reflect.TypeOf((*testRow)(nil)))
+	beam.RegisterFunction(dofnKV3)
+	beam.RegisterFunction(dofnGBK3)
+
+	beam.RegisterFunction(dofn1Counter)
+	beam.RegisterFunction(dofnSink)
+}
+
+func dofn1(imp []byte, emit func(int64)) {
+	emit(1)
+	emit(2)
+	emit(3)
+}
+
+func dofn1x2(imp []byte, emitA func(int64), emitB func(int64)) {
+	emitA(1)
+	emitA(2)
+	emitA(3)
+	emitB(4)
+	emitB(5)
+	emitB(6)
+}
+
+func dofn1x5(imp []byte, emitA, emitB, emitC, emitD, emitE func(int64)) {
+	emitA(1)
+	emitB(2)
+	emitC(3)
+	emitD(4)
+	emitE(5)
+	emitA(6)
+	emitB(7)
+	emitC(8)
+	emitD(9)
+	emitE(10)
+}
+
+func dofn2x1(imp []byte, iter func(*int64) bool, emit func(int64)) {
+	var v, sum int64
+	for iter(&v) {
+		sum += v
+	}
+	emit(sum)
+}
+
+func dofn3x1(sum int64, iter1, iter2 func(*int64) bool, emit func(int64)) {
+	var v int64
+	for iter1(&v) {
+		sum += v
+	}
+	for iter2(&v) {
+		sum += v
+	}
+	emit(sum)
+}
+
+func dofn2x2KV(imp []byte, iter func(*string, *int64) bool, emitK func(string), emitV func(int64)) {
+	var k string
+	var v, sum int64
+	for iter(&k, &v) {
+		sum += v
+		emitK(k)
+	}
+	emitV(sum)
+}
+
+// int64Check validates that within a single bundle,
+// we received the expected int64 values.
+// Returns ints, but they are unused, because we haven't
+// handled ParDo0's yet.
+type int64Check struct {
+	Name string
+	Want []int
+	got  []int
+}
+
+func (fn *int64Check) ProcessElement(v int64, _ func(int64)) {
+	fn.got = append(fn.got, int(v))
+}
+
+func (fn *int64Check) FinishBundle(_ func(int64)) error {
+	sort.Ints(fn.got)
+	sort.Ints(fn.Want)
+	if d := cmp.Diff(fn.Want, fn.got); d != "" {
+		return fmt.Errorf("int64Check[%v] (-want, +got): %v", fn.Name, d)
+	}
+	return nil
+}
+
+// int64Check validates that within a single bundle,

Review comment:
       ```suggestion
   // stringCheck validates that within a single bundle,
   ```

##########
File path: sdks/go/pkg/beam/runners/direct/direct_test.go
##########
@@ -0,0 +1,459 @@
+// 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 direct
+
+import (
+	"context"
+	"flag"
+	"fmt"
+	"os"
+	"reflect"
+	"sort"
+	"testing"
+
+	"github.com/apache/beam/sdks/v2/go/pkg/beam"
+	"github.com/apache/beam/sdks/v2/go/pkg/beam/core/metrics"
+	"github.com/google/go-cmp/cmp"
+)
+
+func executeWithT(ctx context.Context, t *testing.T, p *beam.Pipeline) (beam.PipelineResult, error) {
+	fmt.Println("startingTest - ", t.Name())
+	return Execute(ctx, p)
+}
+
+func init() {
+	beam.RegisterFunction(dofn1)
+	beam.RegisterFunction(dofn1x2)
+	beam.RegisterFunction(dofn1x5)
+	beam.RegisterFunction(dofn2x1)
+	beam.RegisterFunction(dofn3x1)
+	beam.RegisterFunction(dofn2x2KV)
+	beam.RegisterFunction(dofn2)
+	beam.RegisterFunction(dofnKV)
+	beam.RegisterFunction(dofnKV2)
+	beam.RegisterFunction(dofnGBK)
+	beam.RegisterFunction(dofnGBK2)
+	beam.RegisterType(reflect.TypeOf((*int64Check)(nil)))
+	beam.RegisterType(reflect.TypeOf((*stringCheck)(nil)))
+
+	beam.RegisterType(reflect.TypeOf((*testRow)(nil)))
+	beam.RegisterFunction(dofnKV3)
+	beam.RegisterFunction(dofnGBK3)
+
+	beam.RegisterFunction(dofn1Counter)
+	beam.RegisterFunction(dofnSink)
+}
+
+func dofn1(imp []byte, emit func(int64)) {
+	emit(1)
+	emit(2)
+	emit(3)
+}
+
+func dofn1x2(imp []byte, emitA func(int64), emitB func(int64)) {
+	emitA(1)
+	emitA(2)
+	emitA(3)
+	emitB(4)
+	emitB(5)
+	emitB(6)
+}
+
+func dofn1x5(imp []byte, emitA, emitB, emitC, emitD, emitE func(int64)) {
+	emitA(1)
+	emitB(2)
+	emitC(3)
+	emitD(4)
+	emitE(5)
+	emitA(6)
+	emitB(7)
+	emitC(8)
+	emitD(9)
+	emitE(10)
+}
+
+func dofn2x1(imp []byte, iter func(*int64) bool, emit func(int64)) {
+	var v, sum int64
+	for iter(&v) {
+		sum += v
+	}
+	emit(sum)
+}
+
+func dofn3x1(sum int64, iter1, iter2 func(*int64) bool, emit func(int64)) {
+	var v int64
+	for iter1(&v) {
+		sum += v
+	}
+	for iter2(&v) {
+		sum += v
+	}
+	emit(sum)
+}
+
+func dofn2x2KV(imp []byte, iter func(*string, *int64) bool, emitK func(string), emitV func(int64)) {
+	var k string
+	var v, sum int64
+	for iter(&k, &v) {
+		sum += v
+		emitK(k)
+	}
+	emitV(sum)
+}
+
+// int64Check validates that within a single bundle,
+// we received the expected int64 values.
+// Returns ints, but they are unused, because we haven't
+// handled ParDo0's yet.
+type int64Check struct {
+	Name string
+	Want []int
+	got  []int
+}
+
+func (fn *int64Check) ProcessElement(v int64, _ func(int64)) {
+	fn.got = append(fn.got, int(v))
+}
+
+func (fn *int64Check) FinishBundle(_ func(int64)) error {
+	sort.Ints(fn.got)
+	sort.Ints(fn.Want)
+	if d := cmp.Diff(fn.Want, fn.got); d != "" {
+		return fmt.Errorf("int64Check[%v] (-want, +got): %v", fn.Name, d)
+	}
+	return nil
+}
+
+// int64Check validates that within a single bundle,
+// we received the expected int64 values.

Review comment:
       ```suggestion
   // we received the expected string values.
   ```

##########
File path: sdks/go/pkg/beam/runners/direct/direct_test.go
##########
@@ -0,0 +1,459 @@
+// 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 direct
+
+import (
+	"context"
+	"flag"
+	"fmt"
+	"os"
+	"reflect"
+	"sort"
+	"testing"
+
+	"github.com/apache/beam/sdks/v2/go/pkg/beam"
+	"github.com/apache/beam/sdks/v2/go/pkg/beam/core/metrics"
+	"github.com/google/go-cmp/cmp"
+)
+
+func executeWithT(ctx context.Context, t *testing.T, p *beam.Pipeline) (beam.PipelineResult, error) {
+	fmt.Println("startingTest - ", t.Name())
+	return Execute(ctx, p)
+}
+
+func init() {
+	beam.RegisterFunction(dofn1)
+	beam.RegisterFunction(dofn1x2)
+	beam.RegisterFunction(dofn1x5)
+	beam.RegisterFunction(dofn2x1)
+	beam.RegisterFunction(dofn3x1)
+	beam.RegisterFunction(dofn2x2KV)
+	beam.RegisterFunction(dofn2)
+	beam.RegisterFunction(dofnKV)
+	beam.RegisterFunction(dofnKV2)
+	beam.RegisterFunction(dofnGBK)
+	beam.RegisterFunction(dofnGBK2)
+	beam.RegisterType(reflect.TypeOf((*int64Check)(nil)))
+	beam.RegisterType(reflect.TypeOf((*stringCheck)(nil)))
+
+	beam.RegisterType(reflect.TypeOf((*testRow)(nil)))
+	beam.RegisterFunction(dofnKV3)
+	beam.RegisterFunction(dofnGBK3)
+
+	beam.RegisterFunction(dofn1Counter)
+	beam.RegisterFunction(dofnSink)
+}
+
+func dofn1(imp []byte, emit func(int64)) {
+	emit(1)
+	emit(2)
+	emit(3)
+}
+
+func dofn1x2(imp []byte, emitA func(int64), emitB func(int64)) {
+	emitA(1)
+	emitA(2)
+	emitA(3)
+	emitB(4)
+	emitB(5)
+	emitB(6)
+}
+
+func dofn1x5(imp []byte, emitA, emitB, emitC, emitD, emitE func(int64)) {
+	emitA(1)
+	emitB(2)
+	emitC(3)
+	emitD(4)
+	emitE(5)
+	emitA(6)
+	emitB(7)
+	emitC(8)
+	emitD(9)
+	emitE(10)
+}
+
+func dofn2x1(imp []byte, iter func(*int64) bool, emit func(int64)) {
+	var v, sum int64
+	for iter(&v) {
+		sum += v
+	}
+	emit(sum)
+}
+
+func dofn3x1(sum int64, iter1, iter2 func(*int64) bool, emit func(int64)) {
+	var v int64
+	for iter1(&v) {
+		sum += v
+	}
+	for iter2(&v) {
+		sum += v
+	}
+	emit(sum)
+}
+
+func dofn2x2KV(imp []byte, iter func(*string, *int64) bool, emitK func(string), emitV func(int64)) {
+	var k string
+	var v, sum int64
+	for iter(&k, &v) {
+		sum += v
+		emitK(k)
+	}
+	emitV(sum)
+}
+
+// int64Check validates that within a single bundle,
+// we received the expected int64 values.
+// Returns ints, but they are unused, because we haven't
+// handled ParDo0's yet.
+type int64Check struct {
+	Name string
+	Want []int
+	got  []int
+}
+
+func (fn *int64Check) ProcessElement(v int64, _ func(int64)) {
+	fn.got = append(fn.got, int(v))
+}
+
+func (fn *int64Check) FinishBundle(_ func(int64)) error {
+	sort.Ints(fn.got)
+	sort.Ints(fn.Want)
+	if d := cmp.Diff(fn.Want, fn.got); d != "" {
+		return fmt.Errorf("int64Check[%v] (-want, +got): %v", fn.Name, d)
+	}
+	return nil
+}
+
+// int64Check validates that within a single bundle,
+// we received the expected int64 values.
+// Returns ints, but they are unused, because we haven't

Review comment:
       ```suggestion
   // Returns strings, but they are unused, because we haven't
   ```




-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org