Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Redis Component in integrate test #412

Merged
merged 4 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ jobs:
- name: Post Coverage
run: bash <(curl -s https://codecov.io/bash)

integrate:
name: integrate
wasm-integrate:
name: wasm-integrate
runs-on: ubuntu-latest
needs: build
steps:
- name: Set up Go
uses: actions/setup-go@v2
Expand All @@ -84,3 +85,19 @@ jobs:

- name: Run Integrate tests.
run: make wasm-integrate-ci

runtime-integrate:
name: runtime-integrate
runs-on: ubuntu-latest
needs: build
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.14.13

- name: Check out code
uses: actions/checkout@v2

- name: Run Integrate tests.
run: make runtime-integrate-ci
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,7 @@ application.pid
*.iml

# git
*.orig
*.orig

# integrate test
integrate_test.sh
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ image: build-local

wasm-integrate-ci:
docker build --rm -t ${BUILD_IMAGE} build/contrib/builder/image/faas
docker run --rm -v $(shell pwd):/go/src/${PROJECT_NAME} -v $(shell pwd)/test/test.sh:/go/src/${PROJECT_NAME}/test.sh -w /go/src/${PROJECT_NAME} ${BUILD_IMAGE} sh ./test.sh
docker run --rm -v $(shell pwd):/go/src/${PROJECT_NAME} -v $(shell pwd)/test/wasm/wasm_test.sh:/go/src/${PROJECT_NAME}/wasm_test.sh -w /go/src/${PROJECT_NAME} ${BUILD_IMAGE} sh ./wasm_test.sh

runtime-integrate-ci:
docker build --rm -t ${BUILD_IMAGE} build/contrib/builder/image/integrate
docker run --rm -v $(shell pwd):/go/src/${PROJECT_NAME} -v $(shell pwd)/test/runtime/integrate_test.sh:/go/src/${PROJECT_NAME}/integrate_test.sh -w /go/src/${PROJECT_NAME} ${BUILD_IMAGE} sh ./integrate_test.sh

coverage:
sh ${SCRIPT_DIR}/report.sh
Expand Down
4 changes: 4 additions & 0 deletions build/contrib/builder/image/integrate/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM golang:1.16
MAINTAINER lingfenglangshao@gmail.com

RUN apt-get update && apt-get install -y redis-server
58 changes: 58 additions & 0 deletions configs/integrate_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"servers": [
{
"default_log_path": "stdout",
"default_log_level": "INFO",
"listeners": [
{
"name": "grpc",
"address": "0.0.0.0:34904",
"bind_port": true,
"filter_chains": [
{
"filters": [
{
"type": "grpc",
"config": {
"server_name": "runtime",
"grpc_config": {
"hellos": {
"helloworld": {
"hello": "welcome layotto"
}
},
"state": {
"redis": {
"metadata": {
"redisHost": "localhost:6379",
"redisPassword": ""
}
}
},
"lock": {
"redis": {
"metadata": {
"redisHost": "localhost:6379",
"redisPassword": ""
}
}
},
"sequencer": {
"redis": {
"metadata": {
"redisHost": "127.0.0.1:6379",
"redisPassword": ""
}
}
}
}
}
}
]
}
]
}
]
}
]
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ require (
google.golang.org/protobuf v1.27.1
mosn.io/api v0.0.0-20211217011300-b851d129be01
mosn.io/layotto/components v0.0.0-20220119065745-4f03f6779399
mosn.io/layotto/sdk/go-sdk v0.0.0-20220311052659-a386713c7c13
mosn.io/layotto/spec v0.0.0-20220119065745-4f03f6779399
mosn.io/mosn v0.25.1-0.20211217125944-69b50c40af81
mosn.io/pkg v0.0.0-20211217101631-d914102d1baf
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2104,6 +2104,8 @@ launchpad.net/xmlpath v0.0.0-20130614043138-000000000004/go.mod h1:vqyExLOM3qBx7
mosn.io/api v0.0.0-20210204052134-5b9a826795fd/go.mod h1:TBv4bz2f2RbpgdohbVAFRFVOoN8YyEUiLH3jAh752Qc=
mosn.io/api v0.0.0-20211217011300-b851d129be01 h1:65nAZDE6BidyDprKL8OAY4O9BIzWSgVzisAM087tAZI=
mosn.io/api v0.0.0-20211217011300-b851d129be01/go.mod h1:TBv4bz2f2RbpgdohbVAFRFVOoN8YyEUiLH3jAh752Qc=
mosn.io/layotto/sdk/go-sdk v0.0.0-20220311052659-a386713c7c13 h1:fc6ZJwISIjkhmbxemb4YK2wZYWaqYiXwrvGCgC6YqBg=
mosn.io/layotto/sdk/go-sdk v0.0.0-20220311052659-a386713c7c13/go.mod h1:mMrIBDCM2kTSCFC5a7rog00FPxCVCSh5Qtq81X4f9f8=
mosn.io/mosn v0.25.1-0.20211217125944-69b50c40af81 h1:fzaxZAsG0JC3PBTQ6M8aNoCA4pKXVAhsV8HTI1aB9Hw=
mosn.io/mosn v0.25.1-0.20211217125944-69b50c40af81/go.mod h1:JwLkls6oMaap0+P1uZ1d1ccdLPigdK8xH8gDSm3SEq4=
mosn.io/pkg v0.0.0-20211217101631-d914102d1baf h1:PaYMeKbmtMnhnzzQyKQifxAtkKrCv5uti8Tr00WvX+Y=
Expand Down
4 changes: 3 additions & 1 deletion sdk/go-sdk/client/hello.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ type SayHelloResp struct {
}

func (c *GRPCClient) SayHello(ctx context.Context, in *SayHelloRequest) (*SayHelloResp, error) {
req := &runtimev1pb.SayHelloRequest{ServiceName: in.ServiceName}
req := &runtimev1pb.SayHelloRequest{
ServiceName: in.ServiceName,
}
resp, err := c.protoClient.SayHello(ctx, req)
if err != nil {
return nil, err
Expand Down
4 changes: 3 additions & 1 deletion sdk/go-sdk/client/hello_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import (
)

func TestSayHello(t *testing.T) {
item := &SayHelloRequest{"helloworld"}
item := &SayHelloRequest{
ServiceName: "helloworld",
}
resp, err := testClient.SayHello(context.Background(), item)
assert.Nil(t, err)
assert.Equal(t, resp.Hello, "world")
Expand Down
22 changes: 22 additions & 0 deletions test/runtime/integrate_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# Copyright 2021 Layotto Authors
#
# Licensed 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.
#

go build ./cmd/layotto
nohup redis-server &
nohup ./layotto start -c ./configs/integrate_config.json &
go get mosn.io/layotto/sdk/go-sdk/client
go test -p 1 -v ./test/runtime/...

29 changes: 29 additions & 0 deletions test/runtime/other_component_integrate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2021 Layotto Authors
*
* Licensed 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 runtime

import (
"testing"
)

func TestAllApiWithOtherComponents(t *testing.T) {

//======================= Other Component Start =======================
// TODO
//======================= Other Component End =======================

}
156 changes: 156 additions & 0 deletions test/runtime/redis_integrate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/*
* Copyright 2021 Layotto Authors
*
* Licensed 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 runtime

import (
"context"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"mosn.io/layotto/sdk/go-sdk/client"
runtimev1pb "mosn.io/layotto/spec/proto/runtime/v1"
"sync"
"testing"
)

var componentName = "redis"

func TestHelloApi(t *testing.T) {
cli, err := client.NewClientWithAddress("127.0.0.1:34904")
if err != nil {
t.Fatal(err)
}
defer cli.Close()

ctx := context.Background()

helloReq := &client.SayHelloRequest{
ServiceName: "helloworld",
}
helloResp, err := cli.SayHello(ctx, helloReq)
assert.Nil(t, err)
assert.Equal(t, "welcome layotto", helloResp.Hello)
}

func TestStateApi(t *testing.T) {
cli, err := client.NewClientWithAddress("127.0.0.1:34904")
if err != nil {
t.Fatal(err)
}
defer cli.Close()

ctx := context.Background()

stateKey := "MyKey"
stateValue := []byte("Hello Layotto!")
err = cli.SaveState(ctx, componentName, stateKey, stateValue)
assert.Nil(t, err)

stateResp, err := cli.GetState(ctx, componentName, stateKey)
assert.Nil(t, err)
assert.Equal(t, stateValue, stateResp.Value)
}

func TestLockApi(t *testing.T) {
cli, err := client.NewClientWithAddress("127.0.0.1:34904")
if err != nil {
t.Fatal(err)
}
defer cli.Close()

ctx := context.Background()

owner1 := uuid.New().String()
owner2 := uuid.New().String()
resourceId := "MyLock"

// 1. client1 tryLock
resp, err := cli.TryLock(ctx, &runtimev1pb.TryLockRequest{
StoreName: componentName,
ResourceId: resourceId,
LockOwner: owner1,
Expire: 100000,
})
assert.Nil(t, err)
assert.True(t, resp.Success)

var wg sync.WaitGroup
wg.Add(1)
// 2. client2 tryLock
go func() {
resp, err := cli.TryLock(ctx, &runtimev1pb.TryLockRequest{
StoreName: componentName,
ResourceId: resourceId,
LockOwner: owner2,
Expire: 1000,
})
assert.Nil(t, err)
assert.False(t, resp.Success)
wg.Done()
}()
wg.Wait()
// 3. client1 unlock
unlockResp, err := cli.Unlock(ctx, &runtimev1pb.UnlockRequest{
StoreName: componentName,
ResourceId: resourceId,
LockOwner: owner1,
})
assert.Nil(t, err)
assert.Equal(t, runtimev1pb.UnlockResponse_SUCCESS, unlockResp.Status)

// 4. client2 get lock
wg.Add(1)
go func() {
resp, err := cli.TryLock(ctx, &runtimev1pb.TryLockRequest{
StoreName: componentName,
ResourceId: resourceId,
LockOwner: owner2,
Expire: 10,
})
assert.Nil(t, err)
assert.True(t, true, resp.Success)
// 5. client2 unlock
unlockResp, err := cli.Unlock(ctx, &runtimev1pb.UnlockRequest{
StoreName: componentName,
ResourceId: resourceId,
LockOwner: owner2,
})
assert.Nil(t, err)
assert.Equal(t, runtimev1pb.UnlockResponse_SUCCESS, unlockResp.Status)
wg.Done()
}()
wg.Wait()
}

func TestSequencerApi(t *testing.T) {
cli, err := client.NewClientWithAddress("127.0.0.1:34904")
if err != nil {
t.Fatal(err)
}
defer cli.Close()

ctx := context.Background()
sequencerKey := "MyKey"

for i := 1; i < 10; i++ {
resp, err := cli.GetNextId(ctx, &runtimev1pb.GetNextIdRequest{
StoreName: componentName,
Key: sequencerKey,
})
assert.Nil(t, err)
assert.Equal(t, int64(i), resp.NextId)
}
}
2 changes: 1 addition & 1 deletion test/integrate/wasm_test.go → test/wasm/wasm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package integrate
package wasm

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion test/test.sh → test/wasm/wasm_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
go build -tags wasmer ./cmd/layotto
nohup ./layotto start -c ./demo/faas/config.json &
nohup redis-server &
go test -p 1 -v ./test/integrate/...
go test -p 1 -v ./test/wasm/...