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

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

                Author: ASF GitHub Bot
            Created on: 03/Mar/22 20:21
            Start Date: 03/Mar/22 20:21
    Worklog Time Spent: 10m 
      Work Description: youngoli commented on a change in pull request #16908:
URL: https://github.com/apache/beam/pull/16908#discussion_r819033619



##########
File path: sdks/go/test/integration/expansions_test.go
##########
@@ -0,0 +1,169 @@
+// 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 integration
+
+import (
+       "fmt"
+       "testing"
+
+       "github.com/apache/beam/sdks/v2/go/test/integration/internal/jars"
+       "github.com/google/go-cmp/cmp"
+)
+
+type testProcess struct {
+       killed bool
+       jar    string
+}
+
+func (p *testProcess) Kill() error {
+       p.killed = true
+       return nil
+}
+
+func failRun(_, _ string, _ ...string) (jars.Process, error) {
+       return nil, fmt.Errorf("unexpectedly running a jar, failing")
+}
+
+func succeedRun(_, jar string, _ ...string) (jars.Process, error) {
+       return &testProcess{jar: jar}, nil
+}
+
+// TestExpansionServices_GetAddr_Addresses tests calling GetAddr on provided 
addresses.
+func TestExpansionServices_GetAddr_Addresses(t *testing.T) {
+       addrsMap := map[string]string{
+               "label1": "testAddr1",
+               "label2": "testAddr2",
+               "label3": "testAddr3",
+       }
+       jarsMap := map[string]string{
+               "label2": "jarFilepath2",
+       }
+       es := &ExpansionServices{
+               addrs: addrsMap,
+               jars:  jarsMap,
+               procs: make([]jars.Process, 0),
+               run:   failRun,
+       }
+
+       // Ensure we get the same map we put in, and that addresses take 
priority over jars if
+       // both are given for the same label.
+       for label, wantAddr := range addrsMap {
+               gotAddr, err := es.GetAddr(label)
+               if err != nil {
+                       t.Errorf("unexpected error when getting address for 
\"%v\": %v", label, err)
+                       continue
+               }
+               if gotAddr != wantAddr {
+                       t.Errorf("incorrect address for \"%v\", want %v, got 
%v", label, wantAddr, gotAddr)
+               }
+       }
+       // Check that nonexistent labels fail.
+       if _, err := es.GetAddr("nonexistent_label"); err == nil {
+               t.Errorf("did not receive error when calling GetAddr with 
nonexistent label")
+       }
+}
+
+// TestExpansionServices_GetAddr_Jars tests calling GetAddr on provided jars.
+func TestExpansionServices_GetAddr_Jars(t *testing.T) {
+       addrsMap := map[string]string{}
+       jarsMap := map[string]string{
+               "label1": "jarFilepath1",
+               "label2": "jarFilepath2",
+               "label3": "jarFilepath3",
+       }
+       es := &ExpansionServices{
+               addrs: addrsMap,
+               jars:  jarsMap,
+               procs: make([]jars.Process, 0),
+               run:   succeedRun,
+       }
+
+       // Call GetAddr on each jar twice, checking that the addresses remain 
consistent.
+       gotMap := make(map[string]string)
+       for label := range jarsMap {
+               gotAddr, err := es.GetAddr(label)
+               if err != nil {
+                       t.Errorf("unexpected error when getting address for 
\"%v\": %v", label, err)
+                       continue
+               }
+               gotMap[label] = gotAddr
+       }
+       for label, gotAddr := range gotMap {
+               secondAddr, err := es.GetAddr(label)
+               if err != nil {
+                       t.Errorf("unexpected error when getting address for 
\"%v\": %v", label, err)
+                       continue
+               }
+               if secondAddr != gotAddr {
+                       t.Errorf("getAddr returned different address when 
called twice for \"%v\", "+
+                               "attempt 1: %v, attempt 2: %v", label, gotAddr, 
secondAddr)
+               }
+       }
+       // Check that all jars were run.
+       gotJars := make([]string, 0)
+       for _, proc := range es.procs {
+               testProc := proc.(*testProcess)
+               gotJars = append(gotJars, testProc.jar)
+       }
+       wantJars := make([]string, 0)
+       for _, jar := range jarsMap {
+               wantJars = append(wantJars, jar)
+       }
+       if diff := cmp.Diff(wantJars, gotJars); diff != "" {

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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 736293)
    Time Spent: 1h 20m  (was: 1h 10m)

> Add expansion service startup to Go integration test flags.
> -----------------------------------------------------------
>
>                 Key: BEAM-13857
>                 URL: https://issues.apache.org/jira/browse/BEAM-13857
>             Project: Beam
>          Issue Type: Bug
>          Components: sdk-go
>            Reporter: Ritesh Ghorse
>            Assignee: Daniel Oliveira
>            Priority: P2
>          Time Spent: 1h 20m
>  Remaining Estimate: 0h
>
> Currently a separate debezium io expansion address flag needs to be passed to 
> the runner when running cross-language debezium IO pipelines from Go SDK. 
> Find a way to do this in a better way so that we could have it started along 
> with java io expansion service while spinning up the test without bulking 
> :sdks:java:io:expansion-service.
> In particular, needing to add a flag per expansion service jar to our 
> integration tests will eventually become quite cluttered, so we may wish to 
> settle on some kind of KV map flag approach instead to reduce copypasta code 
> overhead.
> Edit: Decided on going with the KV map flag approach within the Go SDK 
> instead of in a bash script, and moving expansion service startup into the 
> codebase as well.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to