diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index 06197d503e..a1d16be807 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -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 @@ -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 \ No newline at end of file diff --git a/.gitignore b/.gitignore index ecfccf119f..00e15e868b 100644 --- a/.gitignore +++ b/.gitignore @@ -37,4 +37,7 @@ application.pid *.iml # git -*.orig \ No newline at end of file +*.orig + +# integrate test +integrate_test.sh \ No newline at end of file diff --git a/Makefile b/Makefile index 4021bff0d0..0c643f71cb 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/build/contrib/builder/image/integrate/Dockerfile b/build/contrib/builder/image/integrate/Dockerfile new file mode 100644 index 0000000000..190598bed1 --- /dev/null +++ b/build/contrib/builder/image/integrate/Dockerfile @@ -0,0 +1,4 @@ +FROM golang:1.16 +MAINTAINER lingfenglangshao@gmail.com + +RUN apt-get update && apt-get install -y redis-server \ No newline at end of file diff --git a/configs/integrate_config.json b/configs/integrate_config.json new file mode 100644 index 0000000000..e53eb0e0a0 --- /dev/null +++ b/configs/integrate_config.json @@ -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": "" + } + } + } + } + } + } + ] + } + ] + } + ] + } + ] +} diff --git a/go.mod b/go.mod index 74fb3d825e..4c45c9d484 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 67ea42e0da..d8ea3c7296 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/sdk/go-sdk/client/hello.go b/sdk/go-sdk/client/hello.go index 94a68ad77e..31960f8281 100644 --- a/sdk/go-sdk/client/hello.go +++ b/sdk/go-sdk/client/hello.go @@ -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 diff --git a/sdk/go-sdk/client/hello_test.go b/sdk/go-sdk/client/hello_test.go index feec8774c8..44b82a71da 100644 --- a/sdk/go-sdk/client/hello_test.go +++ b/sdk/go-sdk/client/hello_test.go @@ -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") diff --git a/test/runtime/integrate_test.sh b/test/runtime/integrate_test.sh new file mode 100644 index 0000000000..7bdfab1293 --- /dev/null +++ b/test/runtime/integrate_test.sh @@ -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/... + diff --git a/test/runtime/other_component_integrate_test.go b/test/runtime/other_component_integrate_test.go new file mode 100644 index 0000000000..88056cc308 --- /dev/null +++ b/test/runtime/other_component_integrate_test.go @@ -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 ======================= + +} diff --git a/test/runtime/redis_integrate_test.go b/test/runtime/redis_integrate_test.go new file mode 100644 index 0000000000..46d1cc0a42 --- /dev/null +++ b/test/runtime/redis_integrate_test.go @@ -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) + } +} diff --git a/test/integrate/wasm_test.go b/test/wasm/wasm_test.go similarity index 98% rename from test/integrate/wasm_test.go rename to test/wasm/wasm_test.go index b3ac924019..cbe038fc2c 100644 --- a/test/integrate/wasm_test.go +++ b/test/wasm/wasm_test.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package integrate +package wasm import ( "context" diff --git a/test/test.sh b/test/wasm/wasm_test.sh similarity index 94% rename from test/test.sh rename to test/wasm/wasm_test.sh index bc790379bb..2db3586e9f 100644 --- a/test/test.sh +++ b/test/wasm/wasm_test.sh @@ -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/...