Skip to content

Commit 4be0eff

Browse files
mrzzyZhu Zhanyan
andauthored
Expand Go and Java SDK Test Coverage (feast-dev#720)
* Added TestGetOnlineFeatures() client_test to test client.GetOnlineFeatures() * Added unit test for Java SDK's FeastClient * Make Python SDK's client.get_online_features() unit test more comprehensive * Remove code added to debug the Python SDK tests * Change repo referenced in go.mod to mrzzy fork to test modules retrieval * Fix python sdk lint * Revert "Change repo referenced in go.mod to mrzzy fork to test modules retrieval" This reverts commit 13008ccef6b6cbee6299029589b5e9e864eee7ae. * Optmisation: Init stripFields map to expected size in client.GetOnlineFeatures() * Make the name of the client test case more descriptive * Add missing mock files * Fix rebase markers in project root go mod * Fix compilation issue cause by downgrade to java 8 * Revert row count in python SDK client test to 300 Co-authored-by: Zhu Zhanyan <zhu.zhanyan@gojek.com>
1 parent 83d9cfa commit 4be0eff

11 files changed

Lines changed: 435 additions & 38 deletions

File tree

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ require (
2525
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
2626
golang.org/x/net v0.0.0-20200513185701-a91f0712d120
2727
golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9 // indirect
28-
golang.org/x/tools v0.0.0-20200528185414-6be401e3f76e // indirect
28+
golang.org/x/tools v0.0.0-20200521211927-2b542361a4fc // indirect
29+
google.golang.org/genproto v0.0.0-20200515170657-fc4c6c6a6587 // indirect
2930
google.golang.org/grpc v1.29.1
3031
google.golang.org/protobuf v1.24.0 // indirect
3132
gopkg.in/russross/blackfriday.v2 v2.0.0 // indirect

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,10 @@ golang.org/x/tools v0.0.0-20200504022951-6b6965ac5dd1 h1:C8rdnd6KieI73Z2Av0sS0t4
462462
golang.org/x/tools v0.0.0-20200504022951-6b6965ac5dd1/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
463463
golang.org/x/tools v0.0.0-20200515220128-d3bf790afa53 h1:vmsb6v0zUdmUlXfwKaYrHPPRCV0lHq/IwNIf0ASGjyQ=
464464
golang.org/x/tools v0.0.0-20200515220128-d3bf790afa53/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
465-
golang.org/x/tools v0.0.0-20200528185414-6be401e3f76e h1:jTL1CJ2kmavapMVdBKy6oVrhBHByRCMfykS45+lEFQk=
466-
golang.org/x/tools v0.0.0-20200528185414-6be401e3f76e/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
465+
golang.org/x/tools v0.0.0-20200519205726-57a9e4404bf7 h1:nm4zDh9WvH4jiuUpMY5RUsvOwrtTVVAsUaCdLW71hfY=
466+
golang.org/x/tools v0.0.0-20200519205726-57a9e4404bf7/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
467+
golang.org/x/tools v0.0.0-20200521211927-2b542361a4fc h1:6m2YO+AmBApbUOmhsghW+IfRyZOY4My4UYvQQrEpHfY=
468+
golang.org/x/tools v0.0.0-20200521211927-2b542361a4fc/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
467469
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
468470
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
469471
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

sdk/go/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (fc *GrpcClient) GetOnlineFeatures(ctx context.Context, req *OnlineFeatures
6161

6262
// strip projects from to projects
6363
for _, fieldValue := range resp.GetFieldValues() {
64-
stripFields := make(map[string]*types.Value)
64+
stripFields := make(map[string]*types.Value, len(fieldValue.Fields))
6565
for refStr, value := range fieldValue.Fields {
6666
_, isEntity := entityRefs[refStr]
6767
if !isEntity { // is feature ref

sdk/go/client_test.go

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package feast
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
"github.com/feast-dev/feast/sdk/go/mocks"
8+
"github.com/feast-dev/feast/sdk/go/protos/feast/serving"
9+
"github.com/feast-dev/feast/sdk/go/protos/feast/types"
10+
"github.com/golang/mock/gomock"
11+
"github.com/google/go-cmp/cmp"
12+
"github.com/opentracing/opentracing-go"
13+
)
14+
15+
func TestGetOnlineFeatures(t *testing.T) {
16+
tt := []struct {
17+
name string
18+
req OnlineFeaturesRequest
19+
recieve OnlineFeaturesResponse
20+
want OnlineFeaturesResponse
21+
wantErr bool
22+
err error
23+
}{
24+
{
25+
name: "Valid client Get Online Features call",
26+
req: OnlineFeaturesRequest{
27+
Features: []string{
28+
"driver:rating",
29+
"rating",
30+
},
31+
Entities: []Row{
32+
{"driver_id": Int64Val(1)},
33+
},
34+
Project: "driver_project",
35+
},
36+
// check GetOnlineFeatures() should strip projects returned from serving
37+
recieve: OnlineFeaturesResponse{
38+
RawResponse: &serving.GetOnlineFeaturesResponse{
39+
FieldValues: []*serving.GetOnlineFeaturesResponse_FieldValues{
40+
{
41+
Fields: map[string]*types.Value{
42+
"driver_project/driver:rating": Int64Val(1),
43+
"driver_project/rating": Int64Val(1),
44+
},
45+
},
46+
},
47+
},
48+
},
49+
want: OnlineFeaturesResponse{
50+
RawResponse: &serving.GetOnlineFeaturesResponse{
51+
FieldValues: []*serving.GetOnlineFeaturesResponse_FieldValues{
52+
{
53+
Fields: map[string]*types.Value{
54+
"driver:rating": Int64Val(1),
55+
"rating": Int64Val(1),
56+
},
57+
},
58+
},
59+
},
60+
},
61+
},
62+
}
63+
64+
for _, tc := range tt {
65+
t.Run(tc.name, func(t *testing.T) {
66+
// mock feast grpc client get online feature requestss
67+
ctrl := gomock.NewController(t)
68+
defer ctrl.Finish()
69+
cli := mock_serving.NewMockServingServiceClient(ctrl)
70+
ctx := context.Background()
71+
_, traceCtx := opentracing.StartSpanFromContext(ctx, "get_online_features")
72+
rawRequest, _ := tc.req.buildRequest()
73+
resp := tc.recieve.RawResponse
74+
cli.EXPECT().GetOnlineFeatures(traceCtx, rawRequest).Return(resp, nil).Times(1)
75+
76+
client := &GrpcClient{
77+
cli: cli,
78+
}
79+
got, err := client.GetOnlineFeatures(ctx, &tc.req)
80+
81+
if err != nil && !tc.wantErr {
82+
t.Errorf("error = %v, wantErr %v", err, tc.wantErr)
83+
return
84+
}
85+
if tc.wantErr && err.Error() != tc.err.Error() {
86+
t.Errorf("error = %v, expected err = %v", err, tc.err)
87+
return
88+
}
89+
// TODO: compare directly once OnlineFeaturesResponse no longer embeds a rawResponse.
90+
if !cmp.Equal(got.RawResponse.String(), tc.want.RawResponse.String()) {
91+
t.Errorf("got: \n%v\nwant:\n%v", got.RawResponse.String(), tc.want.RawResponse.String())
92+
}
93+
})
94+
}
95+
}

sdk/go/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/feast-dev/feast/sdk/go
33
go 1.13
44

55
require (
6+
github.com/golang/mock v1.4.3
67
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0
78
github.com/google/go-cmp v0.4.0
89
github.com/opentracing/opentracing-go v1.1.0

sdk/go/go.sum

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekf
1212
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
1313
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6 h1:ZgQEtGgCBiWRM39fZuwSd1LwSqqSW0hOdXCYYDX0R3I=
1414
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
15+
github.com/golang/mock v1.1.1 h1:G5FRp8JnTd7RQH5kemVNlMeyXQAztQ3mOWV95KxsXH8=
1516
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
17+
github.com/golang/mock v1.4.3 h1:GV+pQPG/EUUbkh47niozDcADz6go/dUwhVzdUQHIVRw=
18+
github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
1619
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
1720
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
1821
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
@@ -63,6 +66,7 @@ golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5h
6366
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
6467
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd h1:r7DufRZuZbWB7j439YfAzP8RPDa9unLkpwQKUYbIMPI=
6568
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
69+
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
6670
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
6771
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
6872
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
@@ -71,6 +75,8 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
7175
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
7276
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
7377
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
78+
golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
79+
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135 h1:5Beo0mZN8dRzgrMMkDp0jc8YXQKx9DiJ2k1dkvGsn5A=
7480
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
7581
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
7682
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
@@ -100,3 +106,5 @@ gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
100106
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
101107
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
102108
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
109+
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
110+
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=

sdk/go/mocks/serving_mock.go

Lines changed: 116 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/java/pom.xml

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<properties>
1919
<!-- TODO: Standardize other modules on JUnit 5 and move this to parent -->
2020
<junit.version>5.5.2</junit.version>
21+
<mockito.version>2.28.2</mockito.version>
2122
</properties>
2223

2324
<dependencies>
@@ -40,6 +41,10 @@
4041
<groupId>io.grpc</groupId>
4142
<artifactId>grpc-stub</artifactId>
4243
</dependency>
44+
<dependency>
45+
<groupId>io.grpc</groupId>
46+
<artifactId>grpc-testing</artifactId>
47+
</dependency>
4348
<dependency>
4449
<groupId>com.google.protobuf</groupId>
4550
<artifactId>protobuf-java-util</artifactId>
@@ -55,7 +60,7 @@
5560
<artifactId>slf4j-api</artifactId>
5661
</dependency>
5762

58-
<!-- JUnit 5 -->
63+
<!-- Testing: JUnit 5 & Mockito -->
5964
<dependency>
6065
<groupId>org.junit.jupiter</groupId>
6166
<artifactId>junit-jupiter-engine</artifactId>
@@ -80,7 +85,24 @@
8085
<version>3.6</version>
8186
<scope>compile</scope>
8287
</dependency>
83-
88+
<dependency>
89+
<groupId>org.mockito</groupId>
90+
<artifactId>mockito-core</artifactId>
91+
<version>${mockito.version}</version>
92+
<scope>test</scope>
93+
</dependency>
94+
<dependency>
95+
<groupId>org.mockito</groupId>
96+
<artifactId>mockito-inline</artifactId>
97+
<version>${mockito.version}</version>
98+
<scope>test</scope>
99+
</dependency>
100+
<dependency>
101+
<groupId>org.junit.vintage</groupId>
102+
<artifactId>junit-vintage-engine</artifactId>
103+
<version>${junit.version}</version>
104+
<scope>test</scope>
105+
</dependency>
84106
</dependencies>
85107

86108
<build>

0 commit comments

Comments
 (0)