[ https://issues.apache.org/jira/browse/BEAM-9642?focusedWorklogId=419637&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-419637 ]
ASF GitHub Bot logged work on BEAM-9642: ---------------------------------------- Author: ASF GitHub Bot Created on: 09/Apr/20 18:49 Start Date: 09/Apr/20 18:49 Worklog Time Spent: 10m Work Description: lostluck commented on pull request #11327: [BEAM-9642] Add SDF execution units. URL: https://github.com/apache/beam/pull/11327#discussion_r406404105 ########## File path: sdks/go/pkg/beam/core/runtime/exec/sdf_test.go ########## @@ -0,0 +1,408 @@ +// 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 exec + +import ( + "context" + "github.com/apache/beam/sdks/go/pkg/beam/core/graph" + "github.com/apache/beam/sdks/go/pkg/beam/core/graph/window" + "github.com/apache/beam/sdks/go/pkg/beam/core/typex" + "github.com/google/go-cmp/cmp" + "testing" +) + +// testTimestamp is a constant used to check that timestamps are retained. +const testTimestamp = 15 + +// testWindow is a constant used to check that windows are retained +var testWindows = []typex.Window{window.IntervalWindow{Start: 10, End: 20}} + +// TestSdfNodes verifies that the various SDF nodes fulfill each of their +// described contracts, that they each successfully invoke any SDF methods +// needed, and that they preserve timestamps and windows correctly. +func TestSdfNodes(t *testing.T) { + // Setup. The DoFns created below are defined in sdf_invokers_test.go and + // have testable behavior to confirm that they got correctly invoked. + // Without knowing the expected behavior of these DoFns, the desired outputs + // in the unit tests below will not make much sense. + dfn, err := graph.NewDoFn(&Sdf{}, graph.NumMainInputs(graph.MainSingle)) + if err != nil { + t.Fatalf("invalid function: %v", err) + } + kvdfn, err := graph.NewDoFn(&KvSdf{}, graph.NumMainInputs(graph.MainKv)) + if err != nil { + t.Fatalf("invalid function: %v", err) + } + + // Validate PairWithRestriction matches its contract and properly invokes + // SDF method CreateInitialRestriction. + t.Run("PairWithRestriction", func(t *testing.T) { + tests := []struct { + name string + fn *graph.DoFn + in *FullValue + want *FullValue + }{ + { + name: "SingleElem", + fn: dfn, + in: &FullValue{ + Elm: 5, + Elm2: nil, + Timestamp: testTimestamp, + Windows: testWindows, + }, + want: &FullValue{ + Elm: &FullValue{ + Elm: 5, + Elm2: nil, + Timestamp: testTimestamp, + Windows: testWindows, + }, + Elm2: Restriction{5}, + Timestamp: testTimestamp, + Windows: testWindows, + }, + }, + { + name: "KvElem", + fn: kvdfn, + in: &FullValue{ + Elm: 5, + Elm2: 2, + Timestamp: testTimestamp, + Windows: testWindows, + }, + want: &FullValue{ + Elm: &FullValue{ + Elm: 5, + Elm2: 2, + Timestamp: testTimestamp, + Windows: testWindows, + }, + Elm2: Restriction{7}, + Timestamp: testTimestamp, + Windows: testWindows, + }, + }, + } + for _, test := range tests { + test := test + t.Run(test.name, func(t *testing.T) { + ctx := context.Background() + fake := &FakeNode{} + node := PairWithRestriction{UID: 0, Fn: test.fn, Out: []Node{fake}} + + if err := node.Up(ctx); err != nil { + t.Fatalf("Up failed: %v", err) + } + if err := node.StartBundle(ctx, "bundle_id", DataContext{}); err != nil { + t.Fatalf("StartBundle failed: %v", err) + } + + if err := node.ProcessElement(ctx, test.in); err != nil { + t.Fatalf("ProcessElement failed: %v", err) + } + got := fake.Vals[0] + if !cmp.Equal(got, test.want) { Review comment: I forgotwe had cmp probably configured in the gogradle.lock file. Nice. https://github.com/apache/beam/blob/master/sdks/go/gogradle.lock#L223 In a different PR we could probably update the comparison helpers in fullvalue_test.go to use cmp options and Transformers instead which would make things much clearer. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 419637) Time Spent: 3.5h (was: 3h 20m) > Add SDF execution-time runners > ------------------------------ > > Key: BEAM-9642 > URL: https://issues.apache.org/jira/browse/BEAM-9642 > Project: Beam > Issue Type: Sub-task > Components: sdk-go > Reporter: Daniel Oliveira > Assignee: Daniel Oliveira > Priority: Major > Time Spent: 3.5h > Remaining Estimate: 0h > > Adds execution-time SDF runner units to the exec package, and any unit tests > + helpers required. > This is needed to get the expanded SDF URNs to execute in the runner harness. -- This message was sent by Atlassian Jira (v8.3.4#803005)