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

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

                Author: ASF GitHub Bot
            Created on: 30/Mar/20 18:17
            Start Date: 30/Mar/20 18:17
    Worklog Time Spent: 10m 
      Work Description: lostluck commented on pull request #11257: [BEAM-3301] 
Create runtime invokers for SDF methods.
URL: https://github.com/apache/beam/pull/11257#discussion_r400397429
 
 

 ##########
 File path: sdks/go/pkg/beam/core/runtime/exec/sdf_invokers_test.go
 ##########
 @@ -0,0 +1,262 @@
+// 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 (
+       "github.com/apache/beam/sdks/go/pkg/beam/core/graph"
+       "github.com/google/go-cmp/cmp"
+       "testing"
+)
+
+func init() {
+}
+
+// TestInvokes runs tests on each SDF method invoker, using the SDFs defined
+// in this file. Tests both single-element and KV element cases.
+func TestInvokes(t *testing.T) {
+       // Setup.
+       dfn, err := graph.NewDoFn(&Sdf{}, graph.NumMainInputs(graph.MainSingle))
+       if err != nil {
+               t.Fatalf("invalid function: %v", err)
+       }
+       sdf := (*graph.SplittableDoFn)(dfn)
+
+       dfn, err = graph.NewDoFn(&KvSdf{}, graph.NumMainInputs(graph.MainKv))
+       if err != nil {
+               t.Fatalf("invalid function: %v", err)
+       }
+       kvsdf := (*graph.SplittableDoFn)(dfn)
+
+       // Tests.
+       t.Run("invokeCreateInitialRestriction", func(t *testing.T) {
+               tests := []struct {
+                       name string
+                       sdf  *graph.SplittableDoFn
+                       elms *FullValue
+                       want Restriction
+               }{
+                       {"SingleElem", sdf, &FullValue{Elm: 5}, Restriction{5}},
+                       {"KvElem", kvsdf, &FullValue{Elm: 5, Elm2: 2}, 
Restriction{7}},
+               }
+               for _, test := range tests {
+                       test := test
+                       fn := test.sdf.CreateInitialRestrictionFn()
+                       t.Run(test.name, func(t *testing.T) {
+                               got, err := invokeCreateInitialRestriction(fn, 
test.elms)
+                               if err != nil {
+                                       
t.Fatalf("invokeCreateInitialRestriction failed: %v", err)
+                               }
+                               if !cmp.Equal(got, test.want) {
+                                       
t.Errorf("invokeCreateInitialRestriction(%v) has incorrect output: got: %v, 
want: %v", test.elms, got, test.want)
+                               }
+                       })
+               }
+       })
+
+       t.Run("invokeSplitRestriction", func(t *testing.T) {
+               tests := []struct {
+                       name string
+                       sdf  *graph.SplittableDoFn
+                       elms *FullValue
+                       rest Restriction
+                       want []interface{}
+               }{
+                       {
+                               "SingleElem",
+                               sdf,
+                               &FullValue{Elm: 5},
+                               Restriction{3},
+                               []interface{}{Restriction{8}, Restriction{9}},
+                       }, {
+                               "KvElem",
+                               kvsdf,
+                               &FullValue{Elm: 5, Elm2: 2},
+                               Restriction{3},
+                               []interface{}{Restriction{8}, Restriction{5}},
+                       },
+               }
+               for _, test := range tests {
+                       test := test
+                       fn := test.sdf.SplitRestrictionFn()
+                       t.Run(test.name, func(t *testing.T) {
+                               got, err := invokeSplitRestriction(fn, 
test.elms, test.rest)
+                               if err != nil {
+                                       t.Fatalf("invokeSplitRestriction 
failed: %v", err)
+                               }
+                               if !cmp.Equal(got, test.want) {
+                                       t.Errorf("invokeSplitRestriction(%v, 
%v) has incorrect output: got: %v, want: %v",
+                                               test.elms, test.rest, got, 
test.want)
+                               }
+                       })
+               }
+       })
+
+       t.Run("invokeRestrictionSize", func(t *testing.T) {
+               tests := []struct {
+                       name string
+                       sdf  *graph.SplittableDoFn
+                       elms *FullValue
+                       rest Restriction
+                       want float64
+               }{
+                       {
+                               "SingleElem",
+                               sdf,
+                               &FullValue{Elm: 5},
+                               Restriction{3},
+                               8,
+                       }, {
+                               "KvElem",
+                               kvsdf,
+                               &FullValue{Elm: 5, Elm2: 2},
+                               Restriction{3},
+                               10,
+                       },
+               }
+               for _, test := range tests {
+                       test := test
+                       fn := test.sdf.RestrictionSizeFn()
+                       t.Run(test.name, func(t *testing.T) {
+                               got, err := invokeRestrictionSize(fn, 
test.elms, test.rest)
+                               if err != nil {
+                                       t.Fatalf("invokeRestrictionSize failed: 
%v", err)
+                               }
+                               if !cmp.Equal(got, test.want) {
+                                       t.Errorf("invokeRestrictionSize(%v, %v) 
has incorrect output: got: %v, want: %v",
+                                               test.elms, test.rest, got, 
test.want)
+                               }
+                       })
+               }
+       })
+
+       t.Run("invokeCreateTracker", func(t *testing.T) {
+               tests := []struct {
+                       name string
+                       sdf  *graph.SplittableDoFn
+                       rest Restriction
+                       want *RTracker
+               }{
+                       {
+                               "SingleElem",
+                               sdf,
+                               Restriction{3},
+                               &RTracker{
+                                       Restriction{3},
+                                       1,
+                               },
+                       }, {
+                               "KvElem",
+                               kvsdf,
+                               Restriction{5},
+                               &RTracker{
+                                       Restriction{5},
+                                       2,
+                               },
+                       },
+               }
+               for _, test := range tests {
+                       test := test
+                       fn := test.sdf.CreateTrackerFn()
+                       t.Run(test.name, func(t *testing.T) {
+                               got, err := invokeCreateTracker(fn, test.rest)
+                               if err != nil {
+                                       t.Fatalf("invokeCreateTracker failed: 
%v", err)
+                               }
+                               if !cmp.Equal(got, test.want) {
+                                       t.Errorf("invokeCreateTracker(%v) has 
incorrect output: got: %v, want: %v",
+                                               test.rest, got, test.want)
+                               }
+                       })
+               }
+       })
+}
+
+type Restriction struct {
+       Val int
+}
+
+// RTracker's methods can all be no-ops, we just need it to implement 
sdf.RTracker.
+type RTracker struct {
+       Rest Restriction
+       Val  int
+}
+
+func (rt *RTracker) TryClaim(interface{}) bool                      { return 
false }
+func (rt *RTracker) GetError() error                                { return 
nil }
+func (rt *RTracker) TrySplit(fraction float64) (interface{}, error) { return 
nil, nil }
+func (rt *RTracker) GetProgress() float64                           { return 0 
}
+func (rt *RTracker) IsDone() bool                                   { return 
false }
+
+// In order to test that these methods get called properly, each one has an
+// implementation that lets us confirm that each argument was passed properly.
+
+type Sdf struct {
+}
+
+// Creates a restriction with the given value.
+func (fn *Sdf) CreateInitialRestriction(i int) Restriction {
+       return Restriction{i}
+}
+
+// Outputs two restrictions, the first containing the sum of i and rest.Val, 
the
 
 Review comment:
   While this type and methods are only for test purposes, please adhere to the 
Go documentation idiom of having the method name in full to start the comment.
 
----------------------------------------------------------------
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: 412496)
    Time Spent: 11h 50m  (was: 11h 40m)

> Go SplittableDoFn support
> -------------------------
>
>                 Key: BEAM-3301
>                 URL: https://issues.apache.org/jira/browse/BEAM-3301
>             Project: Beam
>          Issue Type: Improvement
>          Components: sdk-go
>            Reporter: Henning Rohde
>            Assignee: Daniel Oliveira
>            Priority: Major
>          Time Spent: 11h 50m
>  Remaining Estimate: 0h
>
> SDFs will be the only way to add streaming and liquid sharded IO for Go.
> Design doc: https://s.apache.org/splittable-do-fn



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to