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/02/25 21:44:05 UTC

[GitHub] [beam] riteshghorse commented on a change in pull request #16952: [BEAM-14001] Update coder.go unit tests

riteshghorse commented on a change in pull request #16952:
URL: https://github.com/apache/beam/pull/16952#discussion_r815174258



##########
File path: sdks/go/pkg/beam/core/runtime/exec/coder_test.go
##########
@@ -116,4 +132,106 @@ func compareFV(t *testing.T, got *FullValue, want *FullValue) {
 		t.Errorf("got %v [type: %s], want %v [type %s]",
 			got, reflect.TypeOf(got), wantFv, reflect.TypeOf(wantFv))
 	}
+
+	// Check if the desired FV has windowing information
+	if want.Windows != nil {
+		if gotLen, wantLen := len(got.Windows), len(want.Windows); gotLen != wantLen {
+			t.Fatalf("got %d windows in FV, want %v", gotLen, wantLen)
+		}
+		for i := range want.Windows {
+			if gotWin, wantWin := got.Windows[i], want.Windows[i]; !wantWin.Equals(gotWin) {
+				t.Errorf("got window %v at position %d, want %v", gotWin, i, wantWin)
+			}
+		}
+	}
+}
+
+func TestIterableCoder(t *testing.T) {
+	cod := coder.NewI(coder.NewVarInt())
+	wantVals := []int64{8, 24, 72}
+	val := &FullValue{Elm: wantVals}
+
+	var buf bytes.Buffer
+	enc := MakeElementEncoder(cod)
+	if err := enc.Encode(val, &buf); err != nil {
+		t.Fatalf("Couldn't encode value: %v", err)
+	}
+
+	dec := MakeElementDecoder(cod)
+	result, err := dec.Decode(&buf)
+	if err != nil {
+		t.Fatalf("Couldn't decode value: %v", err)
+	}
+
+	gotVals, ok := result.Elm.([]int64)
+	if !ok {
+		t.Fatalf("got output element %v, want []int64", result.Elm)
+	}
+
+	if got, want := len(gotVals), len(wantVals); got != want {
+		t.Errorf("got %d elements in iterable, want %d", got, want)
+	}
+
+	for i := range gotVals {
+		if got, want := gotVals[i], wantVals[i]; got != want {
+			t.Errorf("got %d at position %d, want %d", got, i, want)
+		}
+	}
+}
+
+// TODO(BEAM-10660): Update once proper timer support is added
+func TestTimerCoder(t *testing.T) {
+	var buf bytes.Buffer
+	tCoder := coder.NewT(coder.NewVarInt(), coder.NewGlobalWindow())
+	wantVal := &FullValue{Elm: int64(13)}
+
+	enc := MakeElementEncoder(tCoder)
+	if err := enc.Encode(wantVal, &buf); err != nil {
+		t.Fatalf("Couldn't encode value: %v", err)
+	}
+
+	dec := MakeElementDecoder(tCoder)
+	result, err := dec.Decode(&buf)
+	if err != nil {
+		t.Fatalf("Couldn't decode value: %v", err)
+	}
+
+	compareFV(t, result, wantVal)
+}
+
+type namedTypeForTest struct {
+	A, B int64
+	C    string
+}
+
+func TestRowCoder(t *testing.T) {

Review comment:
       It looks correct to me




-- 
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