This is an automated email from the ASF dual-hosted git repository.
tianxiaoliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-service-center.git
The following commit(s) were added to refs/heads/master by this push:
new 4345217 [feat] add account sync func and ut (#1195)
4345217 is described below
commit 4345217a232f83f9034d050277a966aaedab5147
Author: robotljw <[email protected]>
AuthorDate: Fri Dec 31 14:34:15 2021 +0800
[feat] add account sync func and ut (#1195)
---
datasource/common.go | 2 +
datasource/etcd/account.go | 52 ++++++++--
datasource/etcd/account_test.go | 127 +++++++++++++++++++++++
datasource/{common.go => etcd/task_util.go} | 38 +++----
datasource/{common.go => etcd/tombstone_util.go} | 37 +++----
datasource/manager.go | 1 +
go.mod | 7 +-
go.sum | 10 +-
test/test.go | 23 +++-
9 files changed, 239 insertions(+), 58 deletions(-)
diff --git a/datasource/common.go b/datasource/common.go
index 22b8b54..90d28cd 100644
--- a/datasource/common.go
+++ b/datasource/common.go
@@ -31,6 +31,8 @@ const (
RegistryDomainProject = "default/default"
RegistryAppID = "default"
Provider = "p"
+
+ ResourceAccount = "account"
)
// WrapErrResponse is temp func here to wait finish to refact the discosvc pkg
diff --git a/datasource/etcd/account.go b/datasource/etcd/account.go
index 529e7e5..d94352e 100644
--- a/datasource/etcd/account.go
+++ b/datasource/etcd/account.go
@@ -22,15 +22,18 @@ import (
"strconv"
"time"
+ rbacmodel "github.com/go-chassis/cari/rbac"
+ "github.com/go-chassis/cari/sync"
+ "github.com/go-chassis/foundation/stringutil"
+ "github.com/little-cui/etcdadpt"
+
+ "github.com/apache/servicecomb-service-center/datasource"
"github.com/apache/servicecomb-service-center/datasource/etcd/path"
"github.com/apache/servicecomb-service-center/datasource/rbac"
"github.com/apache/servicecomb-service-center/pkg/etcdsync"
"github.com/apache/servicecomb-service-center/pkg/log"
"github.com/apache/servicecomb-service-center/pkg/privacy"
"github.com/apache/servicecomb-service-center/pkg/util"
- rbacmodel "github.com/go-chassis/cari/rbac"
- "github.com/go-chassis/foundation/stringutil"
- "github.com/little-cui/etcdadpt"
)
func init() {
@@ -80,6 +83,14 @@ func (ds *RbacDAO) CreateAccount(ctx context.Context, a
*rbacmodel.Account) erro
log.Error("", err)
return err
}
+ if datasource.EnableSync {
+ op, err := GenTaskOpts("", "", sync.CreateAction,
datasource.ResourceAccount, a)
+ if err != nil {
+ log.Error("", err)
+ return err
+ }
+ opts = append(opts, op)
+ }
err = etcdadpt.Txn(ctx, opts)
if err != nil {
log.Error("can not save account info", err)
@@ -88,6 +99,7 @@ func (ds *RbacDAO) CreateAccount(ctx context.Context, a
*rbacmodel.Account) erro
log.Info("create new account: " + a.ID)
return nil
}
+
func GenAccountOpts(a *rbacmodel.Account, action etcdadpt.Action)
([]etcdadpt.OpOptions, error) {
opts := make([]etcdadpt.OpOptions, 0)
value, err := json.Marshal(a)
@@ -110,6 +122,7 @@ func GenAccountOpts(a *rbacmodel.Account, action
etcdadpt.Action) ([]etcdadpt.Op
return opts, nil
}
+
func (ds *RbacDAO) AccountExist(ctx context.Context, name string) (bool,
error) {
return etcdadpt.Exist(ctx, path.GenerateRBACAccountKey(name))
}
@@ -164,6 +177,7 @@ func (ds *RbacDAO) DeleteAccount(ctx context.Context, names
[]string) (bool, err
if len(names) == 0 {
return false, nil
}
+ var allOpts []etcdadpt.OpOptions
for _, name := range names {
a, err := ds.GetAccount(ctx, name)
if err != nil {
@@ -180,14 +194,29 @@ func (ds *RbacDAO) DeleteAccount(ctx context.Context,
names []string) (bool, err
continue //do not fail if some account is invalid
}
- err = etcdadpt.Txn(ctx, opts)
- if err != nil {
- log.Error(rbac.ErrDeleteAccountFailed.Error(), err)
- return false, err
+ if datasource.EnableSync {
+ taskOpt, err := GenTaskOpts("", "", sync.DeleteAction,
datasource.ResourceAccount, a)
+ if err != nil {
+ log.Error("", err)
+ return false, err
+ }
+ tombstoneOpt, err := GenTombstoneOpts("", "",
datasource.ResourceAccount, a.Name)
+ if err != nil {
+ log.Error("", err)
+ return false, err
+ }
+ opts = append(opts, tombstoneOpt, taskOpt)
}
+ allOpts = append(allOpts, opts...)
+ }
+ err := etcdadpt.Txn(ctx, allOpts)
+ if err != nil {
+ log.Error(rbac.ErrDeleteAccountFailed.Error(), err)
+ return false, err
}
return true, nil
}
+
func (ds *RbacDAO) UpdateAccount(ctx context.Context, name string, account
*rbacmodel.Account) error {
var (
opts []etcdadpt.OpOptions
@@ -218,7 +247,14 @@ func (ds *RbacDAO) UpdateAccount(ctx context.Context, name
string, account *rbac
}
opts = append(opts, opt)
}
-
+ if datasource.EnableSync {
+ op, err := GenTaskOpts("", "", sync.UpdateAction,
datasource.ResourceAccount, account)
+ if err != nil {
+ log.Error("", err)
+ return err
+ }
+ opts = append(opts, op)
+ }
err = etcdadpt.Txn(ctx, opts)
if err != nil {
log.Error("BatchCommit failed", err)
diff --git a/datasource/etcd/account_test.go b/datasource/etcd/account_test.go
new file mode 100644
index 0000000..58a36ae
--- /dev/null
+++ b/datasource/etcd/account_test.go
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the 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.
+ * The 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.
+ */
+
+package etcd_test
+
+import (
+ "context"
+ "testing"
+
+ rbacmodel "github.com/go-chassis/cari/rbac"
+ "github.com/stretchr/testify/assert"
+
+ "github.com/apache/servicecomb-service-center/datasource"
+ "github.com/apache/servicecomb-service-center/datasource/rbac"
+ "github.com/apache/servicecomb-service-center/eventbase/model"
+ "github.com/apache/servicecomb-service-center/eventbase/service/task"
+
"github.com/apache/servicecomb-service-center/eventbase/service/tombstone"
+ _ "github.com/apache/servicecomb-service-center/test"
+)
+
+func TestSyncAccount(t *testing.T) {
+
+ datasource.EnableSync = true
+
+ t.Run("create account", func(t *testing.T) {
+ t.Run("creating a account then delete it will create two tasks
and a tombstone should pass",
+ func(t *testing.T) {
+ a1 := rbacmodel.Account{
+ ID:
"sync-create-11111",
+ Name:
"sync-create-account1",
+ Password: "tnuocca-tset",
+ Roles: []string{"admin"},
+ TokenExpirationTime: "2020-12-30",
+ CurrentPassword: "tnuocca-tset1",
+ }
+ err :=
rbac.Instance().CreateAccount(context.Background(), &a1)
+ assert.NoError(t, err)
+ r, err :=
rbac.Instance().GetAccount(context.Background(), a1.Name)
+ assert.NoError(t, err)
+ assert.Equal(t, a1, *r)
+ _, err =
rbac.Instance().DeleteAccount(context.Background(), []string{a1.Name})
+ assert.NoError(t, err)
+ listTaskReq := model.ListTaskRequest{
+ Domain: "",
+ Project: "",
+ }
+ tasks, err := task.List(context.Background(),
&listTaskReq)
+ assert.NoError(t, err)
+ assert.Equal(t, 2, len(tasks))
+ task.Delete(context.Background(), tasks...)
+ tombstoneListReq := model.ListTombstoneRequest{
+ ResourceType:
datasource.ResourceAccount,
+ }
+ tombstones, err :=
tombstone.List(context.Background(), &tombstoneListReq)
+ assert.NoError(t, err)
+ assert.Equal(t, 1, len(tombstones))
+ err = tombstone.Delete(context.Background(),
tombstones...)
+ assert.NoError(t, err)
+ })
+ })
+
+ t.Run("update account", func(t *testing.T) {
+ t.Run("creating two accounts then update them,finally delete
them, will create six tasks and two tombstones should pass",
+ func(t *testing.T) {
+ a2 := rbacmodel.Account{
+ ID:
"sync-update-22222",
+ Name:
"sync-update-account2",
+ Password: "tnuocca-tset",
+ Roles: []string{"admin"},
+ TokenExpirationTime: "2020-12-30",
+ CurrentPassword: "tnuocca-tset",
+ }
+ a3 := rbacmodel.Account{
+ ID:
"sync-update-33333",
+ Name:
"sync-update-account3",
+ Password: "tnuocca-tset",
+ Roles: []string{"admin"},
+ TokenExpirationTime: "2020-12-30",
+ CurrentPassword: "tnuocca-tset",
+ }
+ err :=
rbac.Instance().CreateAccount(context.Background(), &a2)
+ assert.NoError(t, err)
+ err =
rbac.Instance().CreateAccount(context.Background(), &a3)
+ assert.NoError(t, err)
+ a2.Password = "new-password"
+ err =
rbac.Instance().UpdateAccount(context.Background(), a2.Name, &a2)
+ assert.NoError(t, err)
+ a3.Password = "new-password"
+ err =
rbac.Instance().UpdateAccount(context.Background(), a3.Name, &a3)
+ assert.NoError(t, err)
+ _, err =
rbac.Instance().DeleteAccount(context.Background(), []string{a2.Name, a3.Name})
+ assert.NoError(t, err)
+ listTaskReq := model.ListTaskRequest{
+ Domain: "",
+ Project: "",
+ }
+ tasks, err := task.List(context.Background(),
&listTaskReq)
+ assert.NoError(t, err)
+ assert.Equal(t, 6, len(tasks))
+ task.Delete(context.Background(), tasks...)
+ tombstoneListReq := model.ListTombstoneRequest{
+ ResourceType:
datasource.ResourceAccount,
+ }
+ tombstones, err :=
tombstone.List(context.Background(), &tombstoneListReq)
+ assert.NoError(t, err)
+ assert.Equal(t, 2, len(tombstones))
+ err = tombstone.Delete(context.Background(),
tombstones...)
+ assert.NoError(t, err)
+
+ })
+ })
+ datasource.EnableSync = false
+}
diff --git a/datasource/common.go b/datasource/etcd/task_util.go
similarity index 52%
copy from datasource/common.go
copy to datasource/etcd/task_util.go
index 22b8b54..232a841 100644
--- a/datasource/common.go
+++ b/datasource/etcd/task_util.go
@@ -15,33 +15,27 @@
* limitations under the License.
*/
-package datasource
+package etcd
import (
- pb "github.com/go-chassis/cari/discovery"
- "github.com/go-chassis/cari/pkg/errsvc"
-)
+ "encoding/json"
+
+ "github.com/go-chassis/cari/sync"
+ "github.com/little-cui/etcdadpt"
-const (
- SPLIT = "/"
- ServiceKeyPrefix = "/cse-sr/ms/files"
- InstanceKeyPrefix = "/cse-sr/inst/files"
- RegistryDomain = "default"
- RegistryProject = "default"
- RegistryDomainProject = "default/default"
- RegistryAppID = "default"
- Provider = "p"
+
"github.com/apache/servicecomb-service-center/eventbase/datasource/etcd/key"
)
-// WrapErrResponse is temp func here to wait finish to refact the discosvc pkg
-func WrapErrResponse(respErr error) (*pb.Response, error) {
- err, ok := respErr.(*errsvc.Error)
- if !ok {
- return pb.CreateResponse(pb.ErrInternal, err.Error()), err
+func GenTaskOpts(domain, project, action, resourceType string, resource
interface{}) (etcdadpt.OpOptions, error) {
+ task, err := sync.NewTask(domain, project, action, resourceType,
resource)
+ if err != nil {
+ return etcdadpt.OpOptions{}, err
}
- resp := pb.CreateResponseWithSCErr(err)
- if err.InternalError() {
- return resp, err
+ taskBytes, err := json.Marshal(task)
+ if err != nil {
+ return etcdadpt.OpOptions{}, err
}
- return resp, nil
+ taskOpPut := etcdadpt.OpPut(etcdadpt.WithStrKey(key.TaskKey(domain,
project,
+ task.ID, task.Timestamp)), etcdadpt.WithValue(taskBytes))
+ return taskOpPut, nil
}
diff --git a/datasource/common.go b/datasource/etcd/tombstone_util.go
similarity index 51%
copy from datasource/common.go
copy to datasource/etcd/tombstone_util.go
index 22b8b54..6a968c0 100644
--- a/datasource/common.go
+++ b/datasource/etcd/tombstone_util.go
@@ -15,33 +15,24 @@
* limitations under the License.
*/
-package datasource
+package etcd
import (
- pb "github.com/go-chassis/cari/discovery"
- "github.com/go-chassis/cari/pkg/errsvc"
-)
+ "encoding/json"
+
+ "github.com/go-chassis/cari/sync"
+ "github.com/little-cui/etcdadpt"
-const (
- SPLIT = "/"
- ServiceKeyPrefix = "/cse-sr/ms/files"
- InstanceKeyPrefix = "/cse-sr/inst/files"
- RegistryDomain = "default"
- RegistryProject = "default"
- RegistryDomainProject = "default/default"
- RegistryAppID = "default"
- Provider = "p"
+
"github.com/apache/servicecomb-service-center/eventbase/datasource/etcd/key"
)
-// WrapErrResponse is temp func here to wait finish to refact the discosvc pkg
-func WrapErrResponse(respErr error) (*pb.Response, error) {
- err, ok := respErr.(*errsvc.Error)
- if !ok {
- return pb.CreateResponse(pb.ErrInternal, err.Error()), err
- }
- resp := pb.CreateResponseWithSCErr(err)
- if err.InternalError() {
- return resp, err
+func GenTombstoneOpts(domain, project, resourceType, resourceID string)
(etcdadpt.OpOptions, error) {
+ tombstone := sync.NewTombstone(domain, project, resourceType,
resourceID)
+ tombstoneBytes, err := json.Marshal(tombstone)
+ if err != nil {
+ return etcdadpt.OpOptions{}, err
}
- return resp, nil
+ tombstoneOpPut :=
etcdadpt.OpPut(etcdadpt.WithStrKey(key.TombstoneKey(domain, project,
tombstone.ResourceType,
+ tombstone.ResourceID)), etcdadpt.WithValue(tombstoneBytes))
+ return tombstoneOpPut, nil
}
diff --git a/datasource/manager.go b/datasource/manager.go
index 0c78c71..46724da 100644
--- a/datasource/manager.go
+++ b/datasource/manager.go
@@ -31,6 +31,7 @@ type dataSourceEngine func(opts Options) (DataSource, error)
var (
plugins = make(map[string]dataSourceEngine)
dataSourceInst DataSource
+ EnableSync bool
)
// load plugins configuration into plugins
diff --git a/go.mod b/go.mod
index 8825492..bd620de 100644
--- a/go.mod
+++ b/go.mod
@@ -2,6 +2,7 @@ module github.com/apache/servicecomb-service-center
replace (
github.com/apache/servicecomb-service-center/api => ./api
+ github.com/apache/servicecomb-service-center/eventbase => ./eventbase
github.com/apache/thrift => github.com/apache/thrift
v0.0.0-20180125231006-3d556248a8b9
)
@@ -13,7 +14,7 @@ require (
github.com/deckarep/golang-set v1.7.1
github.com/elithrar/simple-scrypt v1.3.0
github.com/ghodss/yaml v1.0.0
- github.com/go-chassis/cari v0.5.1-0.20211208092532-78a52aa9d52e
+ github.com/go-chassis/cari v0.5.1-0.20211229072151-7fa40d0919c6
github.com/go-chassis/foundation v0.4.0
github.com/go-chassis/go-archaius v1.5.1
github.com/go-chassis/go-chassis-extension/protocol/grpc
v0.0.0-20210902082902-eb5df922afcd
@@ -59,6 +60,8 @@ require (
k8s.io/kube-openapi v0.0.0-20210527164424-3c818078ee3d
)
+require github.com/apache/servicecomb-service-center/eventbase
v0.0.0-00010101000000-000000000000
+
require (
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 //
indirect
@@ -93,6 +96,7 @@ require (
github.com/go-openapi/jsonreference v0.19.3 // indirect
github.com/go-openapi/swag v0.19.5 // indirect
github.com/go-stack/stack v1.8.0 // indirect
+ github.com/gofrs/uuid v4.0.0+incompatible // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.1 // indirect
@@ -169,6 +173,7 @@ require (
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/cheggaaa/pb.v1 v1.0.25 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
+ gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
diff --git a/go.sum b/go.sum
index e1f4c40..2c66fa5 100644
--- a/go.sum
+++ b/go.sum
@@ -179,11 +179,13 @@ github.com/go-chassis/cari
v0.0.0-20201210041921-7b6fbef2df11/go.mod h1:MgtsEI0A
github.com/go-chassis/cari v0.4.0/go.mod
h1:av/19fqwEP4eOC8unL/z67AAbFDwXUCko6SKa4Avrd8=
github.com/go-chassis/cari v0.5.0/go.mod
h1:av/19fqwEP4eOC8unL/z67AAbFDwXUCko6SKa4Avrd8=
github.com/go-chassis/cari v0.5.1-0.20210823023004-74041d1363c4/go.mod
h1:av/19fqwEP4eOC8unL/z67AAbFDwXUCko6SKa4Avrd8=
-github.com/go-chassis/cari v0.5.1-0.20211208092532-78a52aa9d52e
h1:6z88U255Sm/Ds10uT7ZqYomKLanDzTWxseDBITONFhk=
-github.com/go-chassis/cari v0.5.1-0.20211208092532-78a52aa9d52e/go.mod
h1:av/19fqwEP4eOC8unL/z67AAbFDwXUCko6SKa4Avrd8=
+github.com/go-chassis/cari v0.5.1-0.20211227133501-53aa20cf7a44/go.mod
h1:HG0Olv4sy/4e/3e9S0pofO0pzchaDjJ0hMweyFU7d5Q=
+github.com/go-chassis/cari v0.5.1-0.20211229072151-7fa40d0919c6
h1:7Ino94E57cnvKmyKVR0bDhZl/jcI+U2VMsHUD6qAvwg=
+github.com/go-chassis/cari v0.5.1-0.20211229072151-7fa40d0919c6/go.mod
h1:HG0Olv4sy/4e/3e9S0pofO0pzchaDjJ0hMweyFU7d5Q=
github.com/go-chassis/foundation v0.2.2-0.20201210043510-9f6d3de40234/go.mod
h1:2PjwqpVwYEVaAldl5A58a08viH8p27pNeYaiE3ZxOBA=
github.com/go-chassis/foundation v0.2.2/go.mod
h1:2PjwqpVwYEVaAldl5A58a08viH8p27pNeYaiE3ZxOBA=
github.com/go-chassis/foundation v0.3.0/go.mod
h1:2PjwqpVwYEVaAldl5A58a08viH8p27pNeYaiE3ZxOBA=
+github.com/go-chassis/foundation v0.3.1-0.20210806081520-3bd92d1ef787/go.mod
h1:6NsIUaHghTFRGfCBcZN011zl196F6OR5QvD9N+P4oWU=
github.com/go-chassis/foundation v0.4.0
h1:z0xETnSxF+vRXWjoIhOdzt6rywjZ4sB++utEl4YgWEY=
github.com/go-chassis/foundation v0.4.0/go.mod
h1:6NsIUaHghTFRGfCBcZN011zl196F6OR5QvD9N+P4oWU=
github.com/go-chassis/go-archaius v1.5.1
h1:1FrNyzzmD6o6BIjPF8uQ4Cc+u7qYIgQTpDk8uopBqfo=
@@ -258,6 +260,8 @@ github.com/gobuffalo/packr/v2 v2.0.9/go.mod
h1:emmyGweYTm6Kdper+iywB6YK5YzuKchGt
github.com/gobuffalo/packr/v2 v2.2.0/go.mod
h1:CaAwI0GPIAv+5wKLtv8Afwl+Cm78K/I/VCm/3ptBN+0=
github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754/go.mod
h1:HhnNqWY95UYwwW3uSASeV7vtgYkT2t16hJgV3AEPUpw=
github.com/godbus/dbus/v5 v5.0.4/go.mod
h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
+github.com/gofrs/uuid v4.0.0+incompatible
h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw=
+github.com/gofrs/uuid v4.0.0+incompatible/go.mod
h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gogo/protobuf v1.1.1/go.mod
h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.1/go.mod
h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d/go.mod
h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
@@ -433,6 +437,7 @@ github.com/labstack/gommon v0.3.0/go.mod
h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL
github.com/ledisdb/ledisdb v0.0.0-20200510135210-d35789ec47e6/go.mod
h1:n931TsDuKuq+uX4v1fulaMbA/7ZLLhjc85h7chZGBCQ=
github.com/leodido/go-urn v1.2.1/go.mod
h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
+github.com/little-cui/etcdadpt v0.2.1/go.mod
h1:727wftF2FS4vfkgFLmIvQue1XH+9u4lK2/hd6L7OAC8=
github.com/little-cui/etcdadpt v0.3.1
h1:lAPIffcOR6jROu/mWf+zHscV8urIu1qbsJvwvziLWDY=
github.com/little-cui/etcdadpt v0.3.1/go.mod
h1:HnRRpIrVEVNWobkiCvG2EHLWKKZ+L047EcI29ma2zA4=
github.com/magiconair/properties v1.8.1/go.mod
h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
@@ -972,6 +977,7 @@ gopkg.in/go-playground/validator.v8 v8.18.2/go.mod
h1:RX2a/7Ha8BgOhfk7j780h4/u/R
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
+gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22
h1:VpOs+IwYnYBaFnrNAeB8UUWtL3vEUnzSCL1nVjPhqrw=
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22/go.mod
h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA=
gopkg.in/natefinch/lumberjack.v2 v2.0.0
h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8=
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod
h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
diff --git a/test/test.go b/test/test.go
index d1c4c2f..4601c06 100644
--- a/test/test.go
+++ b/test/test.go
@@ -22,24 +22,30 @@ import (
"io"
"os"
"path/filepath"
+ "time"
+
+ "github.com/go-chassis/cari/db"
+ "github.com/go-chassis/go-archaius"
+ "github.com/little-cui/etcdadpt"
_ "github.com/apache/servicecomb-service-center/server/init"
+ _ "github.com/apache/servicecomb-service-center/eventbase/bootstrap"
_ "github.com/apache/servicecomb-service-center/server/bootstrap"
//grpc plugin
_ "github.com/go-chassis/go-chassis-extension/protocol/grpc/server"
"github.com/apache/servicecomb-service-center/datasource"
+ edatasource
"github.com/apache/servicecomb-service-center/eventbase/datasource"
"github.com/apache/servicecomb-service-center/pkg/util"
"github.com/apache/servicecomb-service-center/server/core"
"github.com/apache/servicecomb-service-center/server/metrics"
"github.com/apache/servicecomb-service-center/server/service/disco"
- "github.com/go-chassis/go-archaius"
- "github.com/little-cui/etcdadpt"
)
func init() {
var kind = "etcd"
+ var uri = "http://127.0.0.1:2379"
_ = archaius.Set("rbac.releaseLockAfter", "3s")
if IsETCD() {
_ = archaius.Set("registry.cache.mode", 0)
@@ -57,6 +63,19 @@ func init() {
_ = metrics.Init(metrics.Options{})
core.ServiceAPI = disco.AssembleResources()
+
+ if kind == "mongo" {
+ uri = "mongodb://127.0.0.1:27017"
+ }
+
+ err := edatasource.Init(db.Config{
+ Kind: kind,
+ URI: uri,
+ Timeout: 10 * time.Second,
+ })
+ if err != nil {
+ panic(err)
+ }
}
func createChassisConfig() {
b := []byte(`