You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ha...@apache.org on 2021/06/01 06:10:26 UTC

[skywalking-banyandb] branch main updated (ab3537f -> d836f89)

This is an automated email from the ASF dual-hosted git repository.

hanahmily pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-banyandb.git.


 discard ab3537f  Introduce mock system
     new d836f89  Introduce mock system

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (ab3537f)
            \
             N -- N -- N   refs/heads/main (d836f89)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .licenserc.yaml                  |  1 +
 Makefile                         |  1 -
 api/fbs/v1/database_generated.go | 45 +++++++++++++--------
 api/fbs/v1/query_generated.go    | 87 ++++++++++++++++++++++++++++++++--------
 api/fbs/v1/rpc_generated.go      | 17 --------
 api/fbs/v1/trace_generated.go    | 24 ++++-------
 scripts/ci/install_fb.sh         |  2 +-
 7 files changed, 107 insertions(+), 70 deletions(-)

[skywalking-banyandb] 01/01: Introduce mock system

Posted by ha...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

hanahmily pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-banyandb.git

commit d836f895cb8d32042029807de48b8acaf5daf738
Author: Gao Hongtao <ha...@gmail.com>
AuthorDate: Tue Jun 1 10:43:49 2021 +0800

    Introduce mock system
    
    Signed-off-by: Gao Hongtao <ha...@gmail.com>
---
 .github/workflows/go.yml                   |  18 ++++-
 .gitignore                                 |   4 +
 .licenserc.yaml                            |   4 +
 Makefile                                   |   7 +-
 api/fbs/v1/database_generated.go           |  17 ----
 api/fbs/v1/query_generated.go              |  17 ----
 api/fbs/v1/rpc_generated.go                |  17 ----
 api/fbs/v1/trace_generated.go              |  17 ----
 banyand/kv/kv.go                           |   1 +
 banyand/storage/database_test.go           | 124 +++++++++++++++++------------
 banyand/storage/storage.go                 |   1 +
 go.mod                                     |   1 +
 go.sum                                     |   1 +
 scripts/build/lint.mk                      |   2 +
 scripts/build/test.mk                      |   7 +-
 scripts/ci/{instal_fb.sh => install_fb.sh} |   5 +-
 16 files changed, 114 insertions(+), 129 deletions(-)

diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml
index 0ecc247..9efc48b 100644
--- a/.github/workflows/go.yml
+++ b/.github/workflows/go.yml
@@ -39,6 +39,8 @@ jobs:
         uses: apache/skywalking-eyes@5c90c9698806040f50671a172a7cac17974ecebd
       - name: Update dependencies
         run: GOPROXY=https://proxy.golang.org go mod download
+      - name: Install flatc
+        run: bash scripts/ci/install_fb.sh
       - name: Lint
         run: make lint
       - name: Check
@@ -59,9 +61,23 @@ jobs:
         run: make build
       - name: Build release
         run: make release
+  test:
+    name: Test
+    runs-on: ubuntu-20.04
+    steps:
+      - name: Install Go
+        uses: actions/setup-go@v2
+        with:
+          go-version: 1.16
+      - name: Check out code into the Go module directory
+        uses: actions/checkout@v2
+      - name: Update dependencies
+        run: GOPROXY=https://proxy.golang.org go mod download
+      - name: Test
+        run: make test
   checks:
     name: build
     runs-on: ubuntu-20.04
-    needs: [check, build]
+    needs: [check, build, test]
     steps:
       - run: echo 'success'
diff --git a/.gitignore b/.gitignore
index 6434c34..0bb2865 100644
--- a/.gitignore
+++ b/.gitignore
@@ -41,3 +41,7 @@ build/release/
 .DS_Store
 .env
 .run
+
+# mock files
+*mock.go
+*mock_test.go
diff --git a/.licenserc.yaml b/.licenserc.yaml
index b545fed..49f0ed4 100644
--- a/.licenserc.yaml
+++ b/.licenserc.yaml
@@ -69,6 +69,10 @@ header: # `header` section is configurations for source codes license header.
     - '**/go.sum'
     - 'LICENSE'
     - 'NOTICE'
+    - '**/build/**'
+    - '**/*_mock.go'
+    - '**/*_mock_test.go'
+    - '**/*_generated.go'
 
   comment: on-failure # on what condition license-eye will comment on the pull request, `on-failure`, `always`, `never`.
 
diff --git a/Makefile b/Makefile
index 490aeb1..f85313c 100644
--- a/Makefile
+++ b/Makefile
@@ -28,8 +28,9 @@ clean: TARGET=clean test-clean
 clean: default  ## Clean artifacts in all projects
 
 generate: ## Generate API codes
+	go install github.com/golang/mock/mockgen@v1.5.0
+	go generate ./...
 	$(MAKE) -C api/fbs generate
-	$(MAKE) license-fix
 	$(MAKE) format
 
 build: TARGET=all
@@ -81,7 +82,7 @@ EXPECTED_GO_VERSION_PREFIX := "go version go$(CONFIGURED_GO_VERSION)"
 GO_VERSION := $(shell go version)
 
 ## Check that the status is consistent with CI.
-check: clean
+check: clean generate
 # case statement because /bin/sh cannot do prefix comparison, awk is awkward and assuming /bin/bash is brittle
 	@case "$(GO_VERSION)" in $(EXPECTED_GO_VERSION_PREFIX)* ) ;; * ) \
 		echo "Expected 'go version' to start with $(EXPECTED_GO_VERSION_PREFIX), but it didn't: $(GO_VERSION)"; \
@@ -98,7 +99,7 @@ check: clean
 		exit 1; \
 	fi
 	
-pre-push: lint license-check check ## Check source files before pushing to the remote repo
+pre-push: generate lint license-check check ## Check source files before pushing to the remote repo
 
 ##@ License targets
 
diff --git a/api/fbs/v1/database_generated.go b/api/fbs/v1/database_generated.go
index ffb9cb0..0021dc6 100644
--- a/api/fbs/v1/database_generated.go
+++ b/api/fbs/v1/database_generated.go
@@ -1,20 +1,3 @@
-//
-// Licensed to 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. Apache Software Foundation (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.
 // Code generated by the FlatBuffers compiler. DO NOT EDIT.
 
 package v1
diff --git a/api/fbs/v1/query_generated.go b/api/fbs/v1/query_generated.go
index 6990dd0..4114fcb 100644
--- a/api/fbs/v1/query_generated.go
+++ b/api/fbs/v1/query_generated.go
@@ -1,20 +1,3 @@
-//
-// Licensed to 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. Apache Software Foundation (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.
 // Code generated by the FlatBuffers compiler. DO NOT EDIT.
 
 package v1
diff --git a/api/fbs/v1/rpc_generated.go b/api/fbs/v1/rpc_generated.go
index e138cd3..1531d39 100644
--- a/api/fbs/v1/rpc_generated.go
+++ b/api/fbs/v1/rpc_generated.go
@@ -1,20 +1,3 @@
-//
-// Licensed to 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. Apache Software Foundation (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.
 // Code generated by the FlatBuffers compiler. DO NOT EDIT.
 
 package v1
diff --git a/api/fbs/v1/trace_generated.go b/api/fbs/v1/trace_generated.go
index b2beef5..df3dd7a 100644
--- a/api/fbs/v1/trace_generated.go
+++ b/api/fbs/v1/trace_generated.go
@@ -1,20 +1,3 @@
-//
-// Licensed to 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. Apache Software Foundation (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.
 // Code generated by the FlatBuffers compiler. DO NOT EDIT.
 
 package v1
diff --git a/banyand/kv/kv.go b/banyand/kv/kv.go
index 80efdb4..22dbc76 100644
--- a/banyand/kv/kv.go
+++ b/banyand/kv/kv.go
@@ -15,6 +15,7 @@
 // specific language governing permissions and limitations
 // under the License.
 
+//go:generate mockgen -destination=./kv_mock.go -package=kv . Hook
 package kv
 
 import (
diff --git a/banyand/storage/database_test.go b/banyand/storage/database_test.go
index a873420..d772173 100644
--- a/banyand/storage/database_test.go
+++ b/banyand/storage/database_test.go
@@ -27,6 +27,7 @@ import (
 	"time"
 
 	"github.com/dgraph-io/badger/v3/y"
+	"github.com/golang/mock/gomock"
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
 
@@ -47,13 +48,19 @@ func TestDB_Create_Directory(t *testing.T) {
 }
 
 func TestDB_Store(t *testing.T) {
-	p := new(mockPlugin)
+	ctrl := gomock.NewController(t)
+	defer ctrl.Finish()
+	var ap AccessPoint
+	p := mockPlugin(ctrl, func(get GetAccessPoint) {
+		ap = get()
+	})
+
 	tempDir, db := setUp(t, p)
 	defer func() {
 		db.GracefulStop()
 		removeDir(tempDir)
 	}()
-	ap := p.ApFunc()
+
 	s := ap.Store("normal")
 	assert.NoError(t, s.Put([]byte("key1"), []byte{12}))
 	val, err := s.Get([]byte("key1"))
@@ -77,7 +84,68 @@ func TestDB_Store(t *testing.T) {
 	assert.Equal(t, [][]byte{{33}}, vals)
 }
 
-func setUp(t *testing.T, p *mockPlugin) (tempDir string, db Database) {
+func mockPlugin(ctrl *gomock.Controller, f func(get GetAccessPoint)) Plugin {
+	p := NewMockPlugin(ctrl)
+	p.
+		EXPECT().
+		ID().
+		Return("foo").
+		AnyTimes()
+	p.
+		EXPECT().
+		Init().
+		Return([]KVSpec{
+			{
+				Name: "normal",
+				Type: KVTypeNormal,
+			},
+			{
+				Name:       "auto-gen",
+				Type:       KVTypeNormal,
+				AutoGenKey: true,
+			},
+			{
+				Name:           "time-series",
+				Type:           KVTypeTimeSeries,
+				TimeSeriesHook: mockHook(ctrl),
+			},
+		}).
+		AnyTimes()
+	p.
+		EXPECT().
+		Start(gomock.Any()).
+		Do(f).
+		AnyTimes()
+	return p
+}
+
+func mockHook(ctrl *gomock.Controller) kv.Hook {
+	h := kv.NewMockHook(ctrl)
+	h.
+		EXPECT().
+		Reduce(gomock.Any(), gomock.Any()).
+		DoAndReturn(func(left bytes.Buffer, right y.ValueStruct) bytes.Buffer {
+			return left
+		}).
+		AnyTimes()
+	h.
+		EXPECT().
+		Extract(gomock.Any(), gomock.Any()).
+		DoAndReturn(func(raw []byte, ts uint64) ([]byte, error) {
+			return raw, nil
+		}).
+		AnyTimes()
+	h.
+		EXPECT().
+		Split(gomock.Any()).
+		DoAndReturn(func(raw []byte) ([][]byte, error) {
+			return [][]byte{raw}, nil
+		}).
+		AnyTimes()
+	return h
+}
+
+func setUp(t *testing.T, p Plugin) (tempDir string, db Database) {
 	require.NoError(t, logger.Init(logger.Logging{
 		Env:   "dev",
 		Level: "debug",
@@ -113,53 +181,3 @@ func removeDir(dir string) {
 		fmt.Printf("Error while removing dir: %v\n", err)
 	}
 }
-
-var _ Plugin = (*mockPlugin)(nil)
-
-type mockPlugin struct {
-	ApFunc GetAccessPoint
-}
-
-func (m *mockPlugin) ID() string {
-	return "foo"
-}
-
-func (m *mockPlugin) Init() []KVSpec {
-	return []KVSpec{
-		{
-			Name: "normal",
-			Type: KVTypeNormal,
-		},
-		{
-			Name:       "auto-gen",
-			Type:       KVTypeNormal,
-			AutoGenKey: true,
-		},
-		{
-			Name:           "time-series",
-			Type:           KVTypeTimeSeries,
-			TimeSeriesHook: &mockHook{},
-		},
-	}
-}
-
-func (m *mockPlugin) Start(point GetAccessPoint) {
-	m.ApFunc = point
-}
-
-var _ kv.Hook = (*mockHook)(nil)
-
-type mockHook struct {
-}
-
-func (m *mockHook) Reduce(left bytes.Buffer, right y.ValueStruct) bytes.Buffer {
-	return left
-}
-
-func (m *mockHook) Extract(raw []byte, ts uint64) ([]byte, error) {
-	return raw, nil
-}
-
-func (m *mockHook) Split(raw []byte) ([][]byte, error) {
-	return [][]byte{raw}, nil
-}
diff --git a/banyand/storage/storage.go b/banyand/storage/storage.go
index dfad909..15bffc0 100644
--- a/banyand/storage/storage.go
+++ b/banyand/storage/storage.go
@@ -15,6 +15,7 @@
 // specific language governing permissions and limitations
 // under the License.
 
+//go:generate mockgen -destination=./storage_mock.go -package=storage . Plugin
 package storage
 
 import (
diff --git a/go.mod b/go.mod
index 4c7e9c0..6c472d5 100644
--- a/go.mod
+++ b/go.mod
@@ -4,6 +4,7 @@ go 1.16
 
 require (
 	github.com/dgraph-io/badger/v3 v3.2011.1
+	github.com/golang/mock v1.3.1
 	github.com/google/flatbuffers v1.12.0
 	github.com/oklog/run v1.1.0
 	github.com/spf13/cobra v1.1.3
diff --git a/go.sum b/go.sum
index 9a41ac4..5fbfbd8 100644
--- a/go.sum
+++ b/go.sum
@@ -82,6 +82,7 @@ github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6 h1:ZgQEtGgCBiWRM
 github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
 github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
 github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
+github.com/golang/mock v1.3.1 h1:qGJ6qTW+x6xX/my+8YUVl4WNpX9B7+/l2tRsHGZ7f2s=
 github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y=
 github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
 github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
diff --git a/scripts/build/lint.mk b/scripts/build/lint.mk
index 509e5b8..dad733d 100644
--- a/scripts/build/lint.mk
+++ b/scripts/build/lint.mk
@@ -32,4 +32,6 @@ $(LINTER):
 
 .PHONY: lint
 lint: $(LINTER) ## Run all the linters
+	go install github.com/golang/mock/mockgen@v1.5.0
+	go generate $(TEST_PKG_LIST) 
 	$(LINTER) --verbose run $(LINT_OPTS) --config $(root_dir)/golangci.yml
diff --git a/scripts/build/test.mk b/scripts/build/test.mk
index e28ad28..87d39e2 100644
--- a/scripts/build/test.mk
+++ b/scripts/build/test.mk
@@ -31,7 +31,9 @@ TEST_COVERAGE_EXTRA_OPTS ?=
 ##@ Test targets
 
 .PHONY: test
-test: ## Run all the unit tests
+test: $(MOCKGEN) ## Run all the unit tests
+	go install github.com/golang/mock/mockgen@v1.5.0
+	go generate $(TEST_PKG_LIST) 
 	go test $(TEST_OPTS) $(TEST_EXTRA_OPTS) -tags "$(TEST_TAGS)" $(TEST_PKG_LIST)
 
 .PHONY: test-race
@@ -47,4 +49,5 @@ test-coverage: ## Run all the unit tests with coverage analysis on
 
 .PHONY: test-clean
 test-clean::  ## Clean all test artifacts
-	rm -rf $(TEST_COVERAGE_DIR)
\ No newline at end of file
+	rm -rf $(TEST_COVERAGE_DIR)
+	
\ No newline at end of file
diff --git a/scripts/ci/instal_fb.sh b/scripts/ci/install_fb.sh
similarity index 92%
rename from scripts/ci/instal_fb.sh
rename to scripts/ci/install_fb.sh
index ece6be6..319787e 100644
--- a/scripts/ci/instal_fb.sh
+++ b/scripts/ci/install_fb.sh
@@ -19,7 +19,7 @@
 
 set -e
 
-FB_VERSION=${FB_VERSION:=v1.12.0}
+FB_VERSION=${FB_VERSION:=v2.0.0}
 
 for CMD in curl cmake g++ make; do
   command -v $CMD > /dev/null || \
@@ -39,7 +39,8 @@ cd flatbuffers-${FB_VERSION#v}
 cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release
 make
 ./flattests
-cp flatc /usr/local/bin/flatc
+sudo cp flatc /usr/local/bin/flatc
+sudo chmod +x /usr/local/bin/flatc
 
 ## Cleanup Temp Build Directory
 popd