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/12/23 02:11:42 UTC
[GitHub] [beam] ZhengLin-Li opened a new pull request, #24772: Increase unit testing coverage in the exec package
ZhengLin-Li opened a new pull request, #24772:
URL: https://github.com/apache/beam/pull/24772
Increase unit testing coverage in the exec package
addresses #21391
------------------------
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
- [x] Mention the appropriate issue in your description (for example: `addresses #123`), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment `fixes #<ISSUE NUMBER>` instead.
- [x] Update `CHANGES.md` with noteworthy changes.
- [x] If this contribution is large, please file an Apache [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
See the [Contributor Guide](https://beam.apache.org/contribute) for more tips on [how to make review process smoother](https://beam.apache.org/contribute/get-started-contributing/#make-the-reviewers-job-easier).
To check the build health, please visit [https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md](https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md)
GitHub Actions Tests Status (on master branch)
------------------------------------------------------------------------------------------------
[](https://github.com/apache/beam/actions?query=workflow%3A%22Build+python+source+distribution+and+wheels%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Python+Tests%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Java+Tests%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Go+tests%22+branch%3Amaster+event%3Aschedule)
See [CI.md](https://github.com/apache/beam/blob/master/CI.md) for more information about GitHub Actions CI.
--
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
[GitHub] [beam] github-actions[bot] commented on pull request #24772: Increase unit testing coverage in the exec package
Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #24772:
URL: https://github.com/apache/beam/pull/24772#issuecomment-1365943848
Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control
--
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
[GitHub] [beam] riteshghorse merged pull request #24772: [#21391]Increase unit testing coverage in the exec package
Posted by GitBox <gi...@apache.org>.
riteshghorse merged PR #24772:
URL: https://github.com/apache/beam/pull/24772
--
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
[GitHub] [beam] riteshghorse commented on a diff in pull request #24772: [#21391]Increase unit testing coverage in the exec package
Posted by GitBox <gi...@apache.org>.
riteshghorse commented on code in PR #24772:
URL: https://github.com/apache/beam/pull/24772#discussion_r1062146339
##########
sdks/go/pkg/beam/core/runtime/exec/translate_test.go:
##########
@@ -318,3 +320,197 @@ func makeWindowMappingFn(w *window.Fn) (*pipepb.FunctionSpec, error) {
}
return wFn, nil
}
+
+func TestInputIdToIndex(t *testing.T) {
+ tests := []struct {
+ in string
+ want int
+ }{
+ { // does not start with i
+ "90",
+ 0,
+ },
+ { // start with i
+ "i0",
+ 0,
+ },
+ {
+ "i1",
+ 1,
+ },
+ {
+ "i10",
+ 10,
+ },
+ }
+
+ for _, test := range tests {
+ got, err := inputIdToIndex(test.in)
+ if !strings.HasPrefix(test.in, "i") {
+ if err == nil {
+ t.Errorf("Should return err when string does not has a prefix of i, but didn't. inputIdToIndex(%v) = (%v, %v)", test.in, got, err)
+ }
+ } else {
+ if got != test.want {
+ t.Errorf("Can not correctly convert inputId to index. inputIdToIndex(%v) = (%v, %v), want %v", test.in, got, err, test.want)
+ }
+ }
+ }
+}
+
+func TestIndexToInputId(t *testing.T) {
+ tests := []struct {
+ in int
+ want string
+ }{
+ {
+ 1,
+ "i1",
+ },
+ {
+ 1000,
+ "i1000",
+ },
+ }
+
+ for _, test := range tests {
+ got := indexToInputId(test.in)
+ if got != test.want {
+ t.Errorf("Can not correctly convert index to inputId. indexToInputId(%v) = (%v), want %v", test.in, got, test.want)
+ }
+ }
+}
+
+func TestUnmarshalPort(t *testing.T) {
+ var port fnpb.RemoteGrpcPort
+
+ tests := []struct {
+ inputData []byte
+ outputPort Port
+ outputStr string
+ outputError error
+ }{
+ {
+ inputData: []byte{},
+ outputPort: Port{URL: port.GetApiServiceDescriptor().GetUrl()},
+ outputStr: fnpb.RemoteGrpcPort{}.CoderId,
+ outputError: nil,
+ },
+ }
+
+ for _, test := range tests {
+ port, str, err := unmarshalPort(test.inputData)
+ if err != nil && test.outputError == nil {
+ t.Errorf("There is an error where should not be. unmarshalPort(%v) = (%v, %v, %v), want (%v, %v, %v)", test.inputData, port, str, err, test.outputPort, test.outputStr, test.outputError)
+ } else if err != nil && err != test.outputError {
+ t.Errorf("There is an error that does not meet expectation. unmarshalPort(%v) = (%v, %v, %v), want (%v, %v, %v)", test.inputData, port, str, err, test.outputPort, test.outputStr, test.outputError)
+ } else if port != test.outputPort {
+ t.Errorf("The output port is not right. unmarshalPort(%v) = (%v, %v, %v), want (%v, %v, %v)", test.inputData, port, str, err, test.outputPort, test.outputStr, test.outputError)
+ } else if str != test.outputStr {
+ t.Errorf("The output string is not right. unmarshalPort(%v) = (%v, %v, %v), want (%v, %v, %v)", test.inputData, port, str, err, test.outputPort, test.outputStr, test.outputError)
+ }
+ }
+}
+
+func TestUnmarshalPlan(t *testing.T) {
+ transform := pipepb.PTransform{
+ Spec: &pipepb.FunctionSpec{
+ Urn: urnDataSource,
+ },
+ Outputs: map[string]string{},
+ }
+ tests := []struct {
+ name string
+ inputDesc *fnpb.ProcessBundleDescriptor
+ outputPlan *Plan
+ outputError error
+ }{
+ {
+ name: "test_no_root_units",
+ inputDesc: &fnpb.ProcessBundleDescriptor{
+ Id: "",
+ Transforms: map[string]*pipepb.PTransform{},
+ },
+ outputPlan: nil,
+ outputError: errors.Errorf("no root units"),
Review Comment:
yeah
--
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
[GitHub] [beam] ZhengLin-Li commented on a diff in pull request #24772: [#21391]Increase unit testing coverage in the exec package
Posted by GitBox <gi...@apache.org>.
ZhengLin-Li commented on code in PR #24772:
URL: https://github.com/apache/beam/pull/24772#discussion_r1062136898
##########
sdks/go/pkg/beam/core/runtime/exec/translate_test.go:
##########
@@ -318,3 +320,197 @@ func makeWindowMappingFn(w *window.Fn) (*pipepb.FunctionSpec, error) {
}
return wFn, nil
}
+
+func TestInputIdToIndex(t *testing.T) {
+ tests := []struct {
+ in string
+ want int
+ }{
+ { // does not start with i
+ "90",
+ 0,
+ },
+ { // start with i
+ "i0",
+ 0,
+ },
+ {
+ "i1",
+ 1,
+ },
+ {
+ "i10",
+ 10,
+ },
+ }
+
+ for _, test := range tests {
+ got, err := inputIdToIndex(test.in)
+ if !strings.HasPrefix(test.in, "i") {
+ if err == nil {
+ t.Errorf("Should return err when string does not has a prefix of i, but didn't. inputIdToIndex(%v) = (%v, %v)", test.in, got, err)
+ }
+ } else {
+ if got != test.want {
+ t.Errorf("Can not correctly convert inputId to index. inputIdToIndex(%v) = (%v, %v), want %v", test.in, got, err, test.want)
+ }
+ }
+ }
+}
+
+func TestIndexToInputId(t *testing.T) {
+ tests := []struct {
+ in int
+ want string
+ }{
+ {
+ 1,
+ "i1",
+ },
+ {
+ 1000,
+ "i1000",
+ },
+ }
+
+ for _, test := range tests {
+ got := indexToInputId(test.in)
+ if got != test.want {
+ t.Errorf("Can not correctly convert index to inputId. indexToInputId(%v) = (%v), want %v", test.in, got, test.want)
+ }
+ }
+}
+
+func TestUnmarshalPort(t *testing.T) {
+ var port fnpb.RemoteGrpcPort
+
+ tests := []struct {
+ inputData []byte
+ outputPort Port
+ outputStr string
+ outputError error
+ }{
+ {
+ inputData: []byte{},
+ outputPort: Port{URL: port.GetApiServiceDescriptor().GetUrl()},
+ outputStr: fnpb.RemoteGrpcPort{}.CoderId,
+ outputError: nil,
+ },
+ }
+
+ for _, test := range tests {
+ port, str, err := unmarshalPort(test.inputData)
+ if err != nil && test.outputError == nil {
+ t.Errorf("There is an error where should not be. unmarshalPort(%v) = (%v, %v, %v), want (%v, %v, %v)", test.inputData, port, str, err, test.outputPort, test.outputStr, test.outputError)
+ } else if err != nil && err != test.outputError {
+ t.Errorf("There is an error that does not meet expectation. unmarshalPort(%v) = (%v, %v, %v), want (%v, %v, %v)", test.inputData, port, str, err, test.outputPort, test.outputStr, test.outputError)
+ } else if port != test.outputPort {
+ t.Errorf("The output port is not right. unmarshalPort(%v) = (%v, %v, %v), want (%v, %v, %v)", test.inputData, port, str, err, test.outputPort, test.outputStr, test.outputError)
+ } else if str != test.outputStr {
+ t.Errorf("The output string is not right. unmarshalPort(%v) = (%v, %v, %v), want (%v, %v, %v)", test.inputData, port, str, err, test.outputPort, test.outputStr, test.outputError)
+ }
+ }
+}
+
+func TestUnmarshalPlan(t *testing.T) {
+ transform := pipepb.PTransform{
+ Spec: &pipepb.FunctionSpec{
+ Urn: urnDataSource,
+ },
+ Outputs: map[string]string{},
+ }
+ tests := []struct {
+ name string
+ inputDesc *fnpb.ProcessBundleDescriptor
+ outputPlan *Plan
+ outputError error
+ }{
+ {
+ name: "test_no_root_units",
+ inputDesc: &fnpb.ProcessBundleDescriptor{
+ Id: "",
+ Transforms: map[string]*pipepb.PTransform{},
+ },
+ outputPlan: nil,
+ outputError: errors.Errorf("no root units"),
Review Comment:
Should we use `errors.New(message string)` instead of `errors.errorf(format string, args ...any)` when we do not need to formant arguments in the output string?
--
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
[GitHub] [beam] github-actions[bot] commented on pull request #24772: Increase unit testing coverage in the exec package
Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #24772:
URL: https://github.com/apache/beam/pull/24772#issuecomment-1365925348
Assigning reviewers. If you would like to opt out of this review, comment `assign to next reviewer`:
R: @riteshghorse for label go.
Available commands:
- `stop reviewer notifications` - opt out of the automated review tooling
- `remind me after tests pass` - tag the comment author after tests pass
- `waiting on author` - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)
The PR bot will only process comments in the main thread (not review comments).
--
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
[GitHub] [beam] riteshghorse commented on pull request #24772: [#21391]Increase unit testing coverage in the exec package
Posted by GitBox <gi...@apache.org>.
riteshghorse commented on PR #24772:
URL: https://github.com/apache/beam/pull/24772#issuecomment-1371833861
Run Go PostCommit
--
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
[GitHub] [beam] codecov[bot] commented on pull request #24772: Increase unit testing coverage in the exec package
Posted by GitBox <gi...@apache.org>.
codecov[bot] commented on PR #24772:
URL: https://github.com/apache/beam/pull/24772#issuecomment-1363675058
# [Codecov](https://codecov.io/gh/apache/beam/pull/24772?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
> Merging [#24772](https://codecov.io/gh/apache/beam/pull/24772?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (b1e77e6) into [master](https://codecov.io/gh/apache/beam/commit/2b6d9dcb425a752e4f055accec6ed709eab2499c?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (2b6d9dc) will **increase** coverage by `0.00%`.
> The diff coverage is `n/a`.
```diff
@@ Coverage Diff @@
## master #24772 +/- ##
=======================================
Coverage 73.25% 73.26%
=======================================
Files 725 725
Lines 97444 97444
=======================================
+ Hits 71385 71393 +8
+ Misses 24709 24701 -8
Partials 1350 1350
```
| Flag | Coverage Δ | |
|---|---|---|
| go | `51.59% <ø> (+0.02%)` | :arrow_up: |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#carryforward-flags-in-the-pull-request-comment) to find out more.
| [Impacted Files](https://codecov.io/gh/apache/beam/pull/24772?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
|---|---|---|
| [sdks/go/pkg/beam/core/runtime/exec/translate.go](https://codecov.io/gh/apache/beam/pull/24772/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2Rrcy9nby9wa2cvYmVhbS9jb3JlL3J1bnRpbWUvZXhlYy90cmFuc2xhdGUuZ28=) | `17.96% <0.00%> (+0.76%)` | :arrow_up: |
| [sdks/go/pkg/beam/core/metrics/dumper.go](https://codecov.io/gh/apache/beam/pull/24772/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2Rrcy9nby9wa2cvYmVhbS9jb3JlL21ldHJpY3MvZHVtcGVyLmdv) | `53.96% <0.00%> (+4.76%)` | :arrow_up: |
:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
--
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
[GitHub] [beam] ZhengLin-Li commented on pull request #24772: Increase unit testing coverage in the exec package
Posted by GitBox <gi...@apache.org>.
ZhengLin-Li commented on PR #24772:
URL: https://github.com/apache/beam/pull/24772#issuecomment-1365943057
R: @riteshghorse
--
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
[GitHub] [beam] riteshghorse commented on a diff in pull request #24772: [#21391]Increase unit testing coverage in the exec package
Posted by GitBox <gi...@apache.org>.
riteshghorse commented on code in PR #24772:
URL: https://github.com/apache/beam/pull/24772#discussion_r1062123696
##########
sdks/go/pkg/beam/core/runtime/exec/translate_test.go:
##########
@@ -318,3 +320,197 @@ func makeWindowMappingFn(w *window.Fn) (*pipepb.FunctionSpec, error) {
}
return wFn, nil
}
+
+func TestInputIdToIndex(t *testing.T) {
+ tests := []struct {
+ in string
+ want int
+ }{
+ { // does not start with i
+ "90",
+ 0,
+ },
+ { // start with i
+ "i0",
+ 0,
+ },
+ {
+ "i1",
+ 1,
+ },
+ {
+ "i10",
+ 10,
+ },
+ }
+
+ for _, test := range tests {
+ got, err := inputIdToIndex(test.in)
+ if !strings.HasPrefix(test.in, "i") {
+ if err == nil {
+ t.Errorf("Should return err when string does not has a prefix of i, but didn't. inputIdToIndex(%v) = (%v, %v)", test.in, got, err)
+ }
+ } else {
+ if got != test.want {
+ t.Errorf("Can not correctly convert inputId to index. inputIdToIndex(%v) = (%v, %v), want %v", test.in, got, err, test.want)
+ }
+ }
+ }
+}
+
+func TestIndexToInputId(t *testing.T) {
+ tests := []struct {
+ in int
+ want string
+ }{
+ {
+ 1,
+ "i1",
+ },
+ {
+ 1000,
+ "i1000",
+ },
+ }
+
+ for _, test := range tests {
+ got := indexToInputId(test.in)
+ if got != test.want {
+ t.Errorf("Can not correctly convert index to inputId. indexToInputId(%v) = (%v), want %v", test.in, got, test.want)
+ }
+ }
+}
+
+func TestUnmarshalPort(t *testing.T) {
+ var port fnpb.RemoteGrpcPort
+
+ tests := []struct {
+ inputData []byte
+ outputPort Port
+ outputStr string
+ outputError error
+ }{
+ {
+ inputData: []byte{},
+ outputPort: Port{URL: port.GetApiServiceDescriptor().GetUrl()},
+ outputStr: fnpb.RemoteGrpcPort{}.CoderId,
+ outputError: nil,
+ },
+ }
+
+ for _, test := range tests {
+ port, str, err := unmarshalPort(test.inputData)
+ if err != nil && test.outputError == nil {
+ t.Errorf("There is an error where should not be. unmarshalPort(%v) = (%v, %v, %v), want (%v, %v, %v)", test.inputData, port, str, err, test.outputPort, test.outputStr, test.outputError)
+ } else if err != nil && err != test.outputError {
+ t.Errorf("There is an error that does not meet expectation. unmarshalPort(%v) = (%v, %v, %v), want (%v, %v, %v)", test.inputData, port, str, err, test.outputPort, test.outputStr, test.outputError)
+ } else if port != test.outputPort {
+ t.Errorf("The output port is not right. unmarshalPort(%v) = (%v, %v, %v), want (%v, %v, %v)", test.inputData, port, str, err, test.outputPort, test.outputStr, test.outputError)
+ } else if str != test.outputStr {
+ t.Errorf("The output string is not right. unmarshalPort(%v) = (%v, %v, %v), want (%v, %v, %v)", test.inputData, port, str, err, test.outputPort, test.outputStr, test.outputError)
+ }
+ }
+}
+
+func TestUnmarshalPlan(t *testing.T) {
+ transform := pipepb.PTransform{
+ Spec: &pipepb.FunctionSpec{
+ Urn: urnDataSource,
+ },
+ Outputs: map[string]string{},
+ }
+ tests := []struct {
+ name string
+ inputDesc *fnpb.ProcessBundleDescriptor
+ outputPlan *Plan
+ outputError error
+ }{
+ {
+ name: "test_no_root_units",
+ inputDesc: &fnpb.ProcessBundleDescriptor{
+ Id: "",
+ Transforms: map[string]*pipepb.PTransform{},
+ },
+ outputPlan: nil,
+ outputError: errors.Errorf("no root units"),
+ },
+ {
+ name: "test_zero_transform",
+ inputDesc: &fnpb.ProcessBundleDescriptor{
+ Id: "",
+ Transforms: map[string]*pipepb.PTransform{
+ "": {},
+ },
+ },
+ outputPlan: nil,
+ outputError: errors.Errorf("no root units"),
+ },
+ {
+ name: "test_transform_outputs_length_not_one",
+ inputDesc: &fnpb.ProcessBundleDescriptor{
+ Id: "",
+ Transforms: map[string]*pipepb.PTransform{
+ "": &transform,
+ },
+ },
+ outputPlan: nil,
+ outputError: errors.Errorf("expected one output from DataSource, got %v", transform.GetOutputs()),
+ },
+ }
+
+ for _, test := range tests {
+ t.Run(test.name, func(t *testing.T) {
+ plan, err := UnmarshalPlan(test.inputDesc)
+ if err != nil && test.outputError == nil {
+ t.Errorf("There is an error where should not be. UnmarshalPlan(%v) = (%v, %v), want (%v, %v)", test.inputDesc, plan, err, test.outputPlan, test.outputError)
+ } else if err != nil && !reflect.DeepEqual(err, test.outputError) {
+ t.Errorf("There is an error that does not meet expectation. UnmarshalPlan(%v) = (%v, %v), want (%v, %v)", test.inputDesc, plan, err, test.outputPlan, test.outputError)
+ } else if !reflect.DeepEqual(plan, test.outputPlan) {
+ t.Errorf("The output builder is not right. UnmarshalPlan(%v) = (%v, %v), want (%v, %v)", test.inputDesc, plan, err, test.outputPlan, test.outputError)
+ }
+ })
+ }
+}
+
+func TestNewBuilder(t *testing.T) {
+ descriptor := fnpb.ProcessBundleDescriptor{
+ Id: "",
+ Transforms: map[string]*pipepb.PTransform{},
+ }
+ tests := []struct {
+ name string
+ inputDesc *fnpb.ProcessBundleDescriptor
+ outputBuilder *builder
+ outputError error
+ }{
+ {
+ name: "test_1",
+ inputDesc: &descriptor,
+ outputBuilder: &builder{
+ desc: &descriptor,
+ coders: graphx.NewCoderUnmarshaller(descriptor.GetCoders()),
+ prev: make(map[string]int),
+ succ: make(map[string][]linkID),
+ windowing: make(map[string]*window.WindowingStrategy),
+ nodes: make(map[string]*PCollection),
+ links: make(map[linkID]Node),
+ units: nil,
+ idgen: &GenID{},
+ },
+ outputError: nil,
+ },
+ }
+
+ for _, test := range tests {
+ t.Run(test.name, func(t *testing.T) {
+ b, err := newBuilder(test.inputDesc)
+ if err != nil && test.outputError == nil {
+ t.Errorf("There is an error where should not be. newBuilder(%v) = (%v, %v), want (%v, %v)", test.inputDesc, b, err, test.outputBuilder, test.outputError)
+ } else if err != nil && err != test.outputError {
+ t.Errorf("There is an error that does not meet expectation. newBuilder(%v) = (%v, %v), want (%v, %v)", test.inputDesc, b, err, test.outputBuilder, test.outputError)
Review Comment:
```suggestion
t.Errorf("got an unexpected error: %v, want: %v", err, test.outputError)
```
##########
sdks/go/pkg/beam/core/runtime/exec/translate_test.go:
##########
@@ -318,3 +320,197 @@ func makeWindowMappingFn(w *window.Fn) (*pipepb.FunctionSpec, error) {
}
return wFn, nil
}
+
+func TestInputIdToIndex(t *testing.T) {
+ tests := []struct {
+ in string
+ want int
+ }{
+ { // does not start with i
+ "90",
+ 0,
+ },
+ { // start with i
+ "i0",
+ 0,
+ },
+ {
+ "i1",
+ 1,
+ },
+ {
+ "i10",
+ 10,
+ },
+ }
+
+ for _, test := range tests {
+ got, err := inputIdToIndex(test.in)
+ if !strings.HasPrefix(test.in, "i") {
+ if err == nil {
+ t.Errorf("Should return err when string does not has a prefix of i, but didn't. inputIdToIndex(%v) = (%v, %v)", test.in, got, err)
+ }
+ } else {
+ if got != test.want {
+ t.Errorf("Can not correctly convert inputId to index. inputIdToIndex(%v) = (%v, %v), want %v", test.in, got, err, test.want)
+ }
+ }
+ }
+}
+
+func TestIndexToInputId(t *testing.T) {
+ tests := []struct {
+ in int
+ want string
+ }{
+ {
+ 1,
+ "i1",
+ },
+ {
+ 1000,
+ "i1000",
+ },
+ }
+
+ for _, test := range tests {
+ got := indexToInputId(test.in)
+ if got != test.want {
+ t.Errorf("Can not correctly convert index to inputId. indexToInputId(%v) = (%v), want %v", test.in, got, test.want)
+ }
+ }
+}
+
+func TestUnmarshalPort(t *testing.T) {
+ var port fnpb.RemoteGrpcPort
+
+ tests := []struct {
+ inputData []byte
+ outputPort Port
+ outputStr string
+ outputError error
+ }{
+ {
+ inputData: []byte{},
+ outputPort: Port{URL: port.GetApiServiceDescriptor().GetUrl()},
+ outputStr: fnpb.RemoteGrpcPort{}.CoderId,
+ outputError: nil,
+ },
+ }
+
+ for _, test := range tests {
+ port, str, err := unmarshalPort(test.inputData)
+ if err != nil && test.outputError == nil {
+ t.Errorf("There is an error where should not be. unmarshalPort(%v) = (%v, %v, %v), want (%v, %v, %v)", test.inputData, port, str, err, test.outputPort, test.outputStr, test.outputError)
+ } else if err != nil && err != test.outputError {
+ t.Errorf("There is an error that does not meet expectation. unmarshalPort(%v) = (%v, %v, %v), want (%v, %v, %v)", test.inputData, port, str, err, test.outputPort, test.outputStr, test.outputError)
+ } else if port != test.outputPort {
+ t.Errorf("The output port is not right. unmarshalPort(%v) = (%v, %v, %v), want (%v, %v, %v)", test.inputData, port, str, err, test.outputPort, test.outputStr, test.outputError)
+ } else if str != test.outputStr {
+ t.Errorf("The output string is not right. unmarshalPort(%v) = (%v, %v, %v), want (%v, %v, %v)", test.inputData, port, str, err, test.outputPort, test.outputStr, test.outputError)
+ }
+ }
+}
+
+func TestUnmarshalPlan(t *testing.T) {
+ transform := pipepb.PTransform{
+ Spec: &pipepb.FunctionSpec{
+ Urn: urnDataSource,
+ },
+ Outputs: map[string]string{},
+ }
+ tests := []struct {
+ name string
+ inputDesc *fnpb.ProcessBundleDescriptor
+ outputPlan *Plan
+ outputError error
+ }{
+ {
+ name: "test_no_root_units",
+ inputDesc: &fnpb.ProcessBundleDescriptor{
+ Id: "",
+ Transforms: map[string]*pipepb.PTransform{},
+ },
+ outputPlan: nil,
+ outputError: errors.Errorf("no root units"),
Review Comment:
use `errors.New()` when format string is not used
##########
sdks/go/pkg/beam/core/runtime/exec/translate_test.go:
##########
@@ -318,3 +320,197 @@ func makeWindowMappingFn(w *window.Fn) (*pipepb.FunctionSpec, error) {
}
return wFn, nil
}
+
+func TestInputIdToIndex(t *testing.T) {
+ tests := []struct {
+ in string
+ want int
+ }{
+ { // does not start with i
+ "90",
+ 0,
+ },
+ { // start with i
+ "i0",
+ 0,
+ },
+ {
+ "i1",
+ 1,
+ },
+ {
+ "i10",
+ 10,
+ },
+ }
+
+ for _, test := range tests {
+ got, err := inputIdToIndex(test.in)
+ if !strings.HasPrefix(test.in, "i") {
+ if err == nil {
+ t.Errorf("Should return err when string does not has a prefix of i, but didn't. inputIdToIndex(%v) = (%v, %v)", test.in, got, err)
+ }
+ } else {
+ if got != test.want {
+ t.Errorf("Can not correctly convert inputId to index. inputIdToIndex(%v) = (%v, %v), want %v", test.in, got, err, test.want)
+ }
+ }
+ }
+}
+
+func TestIndexToInputId(t *testing.T) {
+ tests := []struct {
+ in int
+ want string
+ }{
+ {
+ 1,
+ "i1",
+ },
+ {
+ 1000,
+ "i1000",
+ },
+ }
+
+ for _, test := range tests {
+ got := indexToInputId(test.in)
+ if got != test.want {
+ t.Errorf("Can not correctly convert index to inputId. indexToInputId(%v) = (%v), want %v", test.in, got, test.want)
+ }
+ }
+}
+
+func TestUnmarshalPort(t *testing.T) {
+ var port fnpb.RemoteGrpcPort
+
+ tests := []struct {
+ inputData []byte
+ outputPort Port
+ outputStr string
+ outputError error
+ }{
+ {
+ inputData: []byte{},
+ outputPort: Port{URL: port.GetApiServiceDescriptor().GetUrl()},
+ outputStr: fnpb.RemoteGrpcPort{}.CoderId,
+ outputError: nil,
+ },
+ }
+
+ for _, test := range tests {
+ port, str, err := unmarshalPort(test.inputData)
+ if err != nil && test.outputError == nil {
+ t.Errorf("There is an error where should not be. unmarshalPort(%v) = (%v, %v, %v), want (%v, %v, %v)", test.inputData, port, str, err, test.outputPort, test.outputStr, test.outputError)
+ } else if err != nil && err != test.outputError {
+ t.Errorf("There is an error that does not meet expectation. unmarshalPort(%v) = (%v, %v, %v), want (%v, %v, %v)", test.inputData, port, str, err, test.outputPort, test.outputStr, test.outputError)
+ } else if port != test.outputPort {
+ t.Errorf("The output port is not right. unmarshalPort(%v) = (%v, %v, %v), want (%v, %v, %v)", test.inputData, port, str, err, test.outputPort, test.outputStr, test.outputError)
+ } else if str != test.outputStr {
+ t.Errorf("The output string is not right. unmarshalPort(%v) = (%v, %v, %v), want (%v, %v, %v)", test.inputData, port, str, err, test.outputPort, test.outputStr, test.outputError)
+ }
+ }
+}
+
+func TestUnmarshalPlan(t *testing.T) {
+ transform := pipepb.PTransform{
+ Spec: &pipepb.FunctionSpec{
+ Urn: urnDataSource,
+ },
+ Outputs: map[string]string{},
+ }
+ tests := []struct {
+ name string
+ inputDesc *fnpb.ProcessBundleDescriptor
+ outputPlan *Plan
+ outputError error
+ }{
+ {
+ name: "test_no_root_units",
+ inputDesc: &fnpb.ProcessBundleDescriptor{
+ Id: "",
+ Transforms: map[string]*pipepb.PTransform{},
+ },
+ outputPlan: nil,
+ outputError: errors.Errorf("no root units"),
+ },
+ {
+ name: "test_zero_transform",
+ inputDesc: &fnpb.ProcessBundleDescriptor{
+ Id: "",
+ Transforms: map[string]*pipepb.PTransform{
+ "": {},
+ },
+ },
+ outputPlan: nil,
+ outputError: errors.Errorf("no root units"),
Review Comment:
use `errors.New()` when format string is not used
##########
sdks/go/pkg/beam/core/runtime/exec/translate_test.go:
##########
@@ -318,3 +320,197 @@ func makeWindowMappingFn(w *window.Fn) (*pipepb.FunctionSpec, error) {
}
return wFn, nil
}
+
+func TestInputIdToIndex(t *testing.T) {
+ tests := []struct {
+ in string
+ want int
+ }{
+ { // does not start with i
+ "90",
+ 0,
+ },
+ { // start with i
+ "i0",
+ 0,
+ },
+ {
+ "i1",
+ 1,
+ },
+ {
+ "i10",
+ 10,
+ },
+ }
+
+ for _, test := range tests {
+ got, err := inputIdToIndex(test.in)
+ if !strings.HasPrefix(test.in, "i") {
+ if err == nil {
+ t.Errorf("Should return err when string does not has a prefix of i, but didn't. inputIdToIndex(%v) = (%v, %v)", test.in, got, err)
+ }
+ } else {
+ if got != test.want {
+ t.Errorf("Can not correctly convert inputId to index. inputIdToIndex(%v) = (%v, %v), want %v", test.in, got, err, test.want)
+ }
+ }
+ }
+}
+
+func TestIndexToInputId(t *testing.T) {
+ tests := []struct {
+ in int
+ want string
+ }{
+ {
+ 1,
+ "i1",
+ },
+ {
+ 1000,
+ "i1000",
+ },
+ }
+
+ for _, test := range tests {
+ got := indexToInputId(test.in)
+ if got != test.want {
+ t.Errorf("Can not correctly convert index to inputId. indexToInputId(%v) = (%v), want %v", test.in, got, test.want)
+ }
+ }
+}
+
+func TestUnmarshalPort(t *testing.T) {
+ var port fnpb.RemoteGrpcPort
+
+ tests := []struct {
+ inputData []byte
+ outputPort Port
+ outputStr string
+ outputError error
+ }{
+ {
+ inputData: []byte{},
+ outputPort: Port{URL: port.GetApiServiceDescriptor().GetUrl()},
+ outputStr: fnpb.RemoteGrpcPort{}.CoderId,
+ outputError: nil,
+ },
+ }
+
+ for _, test := range tests {
+ port, str, err := unmarshalPort(test.inputData)
+ if err != nil && test.outputError == nil {
+ t.Errorf("There is an error where should not be. unmarshalPort(%v) = (%v, %v, %v), want (%v, %v, %v)", test.inputData, port, str, err, test.outputPort, test.outputStr, test.outputError)
+ } else if err != nil && err != test.outputError {
+ t.Errorf("There is an error that does not meet expectation. unmarshalPort(%v) = (%v, %v, %v), want (%v, %v, %v)", test.inputData, port, str, err, test.outputPort, test.outputStr, test.outputError)
Review Comment:
consider changing this to "got an unexpected error: %v, want: %v".
similarly in other places where there are similar statements.
--
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