[ 
https://issues.apache.org/jira/browse/BEAM-9642?focusedWorklogId=421820&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-421820
 ]

ASF GitHub Bot logged work on BEAM-9642:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 14/Apr/20 03:22
            Start Date: 14/Apr/20 03:22
    Worklog Time Spent: 10m 
      Work Description: youngoli commented on pull request #11327: [BEAM-9642] 
Add SDF execution units.
URL: https://github.com/apache/beam/pull/11327#discussion_r407843164
 
 

 ##########
 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) {
+                                       t.Errorf("ProcessElement(%v) has 
incorrect output: got: %v, want: %v",
+                                               test.in, got, test.want)
+                               }
+                               if err := node.FinishBundle(ctx); err != nil {
+                                       t.Fatalf("FinishBundle failed: %v", err)
+                               }
+                               if err := node.Down(ctx); err != nil {
+                                       t.Fatalf("Down failed: %v", err)
+                               }
+                       })
+               }
+       })
+
+       // Validate SplitAndSizeRestrictions matches its contract and properly
+       // invokes SDF methods SplitRestriction and RestrictionSize.
+       t.Run("SplitAndSizeRestrictions", func(t *testing.T) {
+               tests := []struct {
+                       name string
+                       fn   *graph.DoFn
+                       in   *FullValue
+                       want []*FullValue
+               }{
+                       {
+                               name: "SingleElem",
+                               fn:   dfn,
+                               in: &FullValue{
+                                       Elm: &FullValue{
+                                               Elm:       2,
+                                               Elm2:      nil,
+                                               Timestamp: testTimestamp,
+                                               Windows:   testWindows,
+                                       },
+                                       Elm2:      Restriction{5},
+                                       Timestamp: testTimestamp,
+                                       Windows:   testWindows,
+                               },
+                               want: []*FullValue{
+                                       {
+                                               Elm: &FullValue{
+                                                       Elm: &FullValue{
+                                                               Elm:       2,
+                                                               Elm2:      nil,
+                                                               Timestamp: 
testTimestamp,
+                                                               Windows:   
testWindows,
+                                                       },
+                                                       Elm2: Restriction{7},
+                                               },
+                                               Elm2:      9.0,
+                                               Timestamp: testTimestamp,
+                                               Windows:   testWindows,
+                                       },
+                                       {
+                                               Elm: &FullValue{
+                                                       Elm: &FullValue{
+                                                               Elm:       2,
+                                                               Elm2:      nil,
+                                                               Timestamp: 
testTimestamp,
+                                                               Windows:   
testWindows,
+                                                       },
+                                                       Elm2: Restriction{8},
+                                               },
+                                               Elm2:      10.0,
+                                               Timestamp: testTimestamp,
+                                               Windows:   testWindows,
+                                       },
+                               },
+                       },
+                       {
+                               name: "KvElem",
+                               fn:   kvdfn,
+                               in: &FullValue{
+                                       Elm: &FullValue{
+                                               Elm:       2,
+                                               Elm2:      5,
+                                               Timestamp: testTimestamp,
+                                               Windows:   testWindows,
+                                       },
+                                       Elm2:      Restriction{3},
+                                       Timestamp: testTimestamp,
+                                       Windows:   testWindows,
+                               },
+                               want: []*FullValue{
+                                       {
+                                               Elm: &FullValue{
+                                                       Elm: &FullValue{
+                                                               Elm:       2,
+                                                               Elm2:      5,
+                                                               Timestamp: 
testTimestamp,
+                                                               Windows:   
testWindows,
+                                                       },
+                                                       Elm2: Restriction{5},
+                                               },
+                                               Elm2:      12.0,
+                                               Timestamp: testTimestamp,
+                                               Windows:   testWindows,
+                                       },
+                                       {
+                                               Elm: &FullValue{
+                                                       Elm: &FullValue{
+                                                               Elm:       2,
+                                                               Elm2:      5,
+                                                               Timestamp: 
testTimestamp,
+                                                               Windows:   
testWindows,
+                                                       },
+                                                       Elm2: Restriction{8},
+                                               },
+                                               Elm2:      15.0,
+                                               Timestamp: testTimestamp,
+                                               Windows:   testWindows,
+                                       },
+                               },
+                       },
+               }
+               for _, test := range tests {
+                       test := test
+                       t.Run(test.name, func(t *testing.T) {
+                               ctx := context.Background()
+                               fake := &FakeNode{}
+                               node := SplitAndSizeRestrictions{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)
+                               }
+                               for i, got := range fake.Vals {
+                                       if !cmp.Equal(got, test.want[i]) {
+                                               t.Errorf("ProcessElement(%v) 
has incorrect output %v: got: %v, want: %v",
+                                                       test.in, i, got, 
test.want)
+                                       }
+                               }
+                               if err := node.FinishBundle(ctx); err != nil {
+                                       t.Fatalf("FinishBundle failed: %v", err)
+                               }
+                               if err := node.Down(ctx); err != nil {
+                                       t.Fatalf("Down failed: %v", err)
+                               }
+                       })
+               }
+       })
+
+       // Validate ProcessSizedElementsAndRestrictions matches its contract and
+       // properly invokes SDF methods CreateTracker and ProcessElement.
+       t.Run("ProcessSizedElementsAndRestrictions", func(t *testing.T) {
+               tests := []struct {
+                       name string
+                       fn   *graph.DoFn
+                       in   *FullValue
+                       want *FullValue
+               }{
+                       {
+                               name: "SingleElem",
+                               fn:   dfn,
+                               in: &FullValue{
+                                       Elm: &FullValue{
+                                               Elm: &FullValue{
+                                                       Elm:       3,
+                                                       Elm2:      nil,
+                                                       Timestamp: 
testTimestamp,
+                                                       Windows:   testWindows,
+                                               },
+                                               Elm2: Restriction{5},
+                                       },
+                                       Elm2:      8.0,
+                                       Timestamp: testTimestamp,
+                                       Windows:   testWindows,
+                               },
+                               want: &FullValue{
+                                       Elm:       8,
+                                       Elm2:      4,
+                                       Timestamp: testTimestamp,
+                                       Windows:   testWindows,
+                               },
+                       },
+                       {
+                               name: "KvElem",
+                               fn:   kvdfn,
+                               in: &FullValue{
+                                       Elm: &FullValue{
+                                               Elm: &FullValue{
+                                                       Elm:       3,
+                                                       Elm2:      10,
+                                                       Timestamp: 
testTimestamp,
+                                                       Windows:   testWindows,
+                                               },
+                                               Elm2: Restriction{5},
+                                       },
+                                       Elm2:      18.0,
+                                       Timestamp: testTimestamp,
+                                       Windows:   testWindows,
+                               },
+                               want: &FullValue{
+                                       Elm:       8,
+                                       Elm2:      12,
+                                       Timestamp: testTimestamp,
+                                       Windows:   testWindows,
+                               },
+                       },
+               }
+               for _, test := range tests {
+                       test := test
+                       t.Run(test.name, func(t *testing.T) {
+                               ctx := context.Background()
+                               fake := &FakeNode{}
+                               n := &ParDo{UID: 0, Fn: test.fn, Out: 
[]Node{fake}}
+                               node := 
ProcessSizedElementsAndRestrictions{PDo: n}
+
+                               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 {
 
 Review comment:
   Done.
 
----------------------------------------------------------------
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: 421820)
    Time Spent: 4h 20m  (was: 4h 10m)

> 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: 4h 20m
>  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)

Reply via email to