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

#87 view create and get content #88

Merged
merged 9 commits into from Feb 7, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Expand Up @@ -43,7 +43,7 @@ jobs:
- bash scripts/travis/goConstChecker.sh
- stage: GoLint Checker
script:
- go get -u golang.org/x/lint
- go get -u golang.org/x/lint/golint
- bash scripts/travis/goLintChecker.sh
- stage: GoCyclo Checker
script:
Expand All @@ -55,8 +55,8 @@ jobs:
- GO111MODULE=on go mod download
- GO111MODULE=on go mod vendor
- bash scripts/travis/start_deps.sh
- sleep 15
- cd $HOME/gopath/src/github.com/apache/servicecomb-kie
- go get github.com/mattn/goveralls
- go get golang.org/x/tools/cmd/cover
- sleep 30
- bash scripts/travis/unit_test.sh && $HOME/gopath/bin/goveralls -coverprofile=coverage.txt -service=travis-ci
8 changes: 4 additions & 4 deletions client/client.go
Expand Up @@ -53,7 +53,7 @@ type Client struct {
opts Config
cipher security.Cipher
c *httpclient.Requests
currentRevision string
CurrentRevision string
}

//Config is the config of client
Expand Down Expand Up @@ -133,9 +133,9 @@ func (c *Client) Get(ctx context.Context, opts ...GetOption) (*model.KVResponse,

var url string
if options.Key != "" {
url = fmt.Sprintf("%s/%s/%s/%s/%s?revision=%s", c.opts.Endpoint, version, options.Project, APIPathKV, options.Key, c.currentRevision)
url = fmt.Sprintf("%s/%s/%s/%s/%s?revision=%s", c.opts.Endpoint, version, options.Project, APIPathKV, options.Key, c.CurrentRevision)
} else {
url = fmt.Sprintf("%s/%s/%s/%s?revision=%s", c.opts.Endpoint, version, options.Project, APIPathKV, c.currentRevision)
url = fmt.Sprintf("%s/%s/%s/%s?revision=%s", c.opts.Endpoint, version, options.Project, APIPathKV, c.CurrentRevision)
}
if options.Wait != "" {
url = url + "&wait=" + options.Wait
Expand Down Expand Up @@ -176,7 +176,7 @@ func (c *Client) Get(ctx context.Context, opts ...GetOption) (*model.KVResponse,
openlogging.Error("unmarshal kv failed:" + err.Error())
return nil, err
}
c.currentRevision = resp.Header.Get(common.HeaderRevision)
c.CurrentRevision = resp.Header.Get(common.HeaderRevision)
return kvs, nil
}

Expand Down
25 changes: 13 additions & 12 deletions client/client_test.go
Expand Up @@ -37,17 +37,17 @@ func TestClient_Put(t *testing.T) {
Labels: map[string]string{"service": "client"},
Value: "timeout: 1s",
}
_, err := c.Put(context.TODO(), kv, WithProject("test"))
_, err := c.Put(context.TODO(), kv, WithProject("client_test"))
assert.NoError(t, err)

kvs, _ := c.Get(context.TODO(),
WithKey("app.properties"),
WithGetProject("test"),
WithGetProject("client_test"),
WithLabels(map[string]string{"service": "client"}))
assert.GreaterOrEqual(t, len(kvs.Data), 1)

_, err = c.Get(context.TODO(),
WithGetProject("test"),
WithGetProject("client_test"),
WithLabels(map[string]string{"service": "client"}))
assert.Equal(t, ErrNoChanges, err)

Expand All @@ -59,7 +59,7 @@ func TestClient_Put(t *testing.T) {
go func() {
kvs, err = c.Get(context.TODO(),
WithLabels(map[string]string{"service": "client"}),
WithGetProject("test"),
WithGetProject("client_test"),
WithWait("10s"))
assert.NoError(t, err)
assert.Equal(t, "timeout: 2s", kvs.Data[0].Value)
Expand All @@ -69,7 +69,7 @@ func TestClient_Put(t *testing.T) {
Labels: map[string]string{"service": "client"},
Value: "timeout: 2s",
}
_, err := c.Put(context.TODO(), kv, WithProject("test"))
_, err := c.Put(context.TODO(), kv, WithProject("client_test"))
assert.NoError(t, err)
})
t.Run("exact match", func(t *testing.T) {
Expand All @@ -78,10 +78,11 @@ func TestClient_Put(t *testing.T) {
Labels: map[string]string{"service": "client", "version": "1.0"},
Value: "timeout: 2s",
}
_, err := c.Put(context.TODO(), kv, WithProject("test"))
_, err := c.Put(context.TODO(), kv, WithProject("client_test"))
assert.NoError(t, err)
t.Log(c.CurrentRevision)
kvs, err = c.Get(context.TODO(),
WithGetProject("test"),
WithGetProject("client_test"),
WithLabels(map[string]string{"service": "client"}),
WithExact())
assert.NoError(t, err)
Expand All @@ -99,15 +100,15 @@ func TestClient_Delete(t *testing.T) {
kvBody.Value = "100s"
kvBody.ValueType = "text"
kvBody.Labels = make(map[string]string)
kvBody.Labels["env"] = "test"
kv, err := c.Put(context.TODO(), kvBody, WithProject("test"))
kvBody.Labels["env"] = "client_test"
kv, err := c.Put(context.TODO(), kvBody, WithProject("client_test"))
assert.NoError(t, err)
kvs, err := c.Get(context.TODO(),
WithKey("time"),
WithGetProject("test"),
WithLabels(map[string]string{"env": "test"}))
WithGetProject("client_test"),
WithLabels(map[string]string{"env": "client_test"}))
assert.NoError(t, err)
assert.NotNil(t, kvs)
err = c.Delete(context.TODO(), kv.ID, "", WithProject("test"))
err = c.Delete(context.TODO(), kv.ID, "", WithProject("client_test"))
assert.NoError(t, err)
}
23 changes: 22 additions & 1 deletion deployments/db.js
Expand Up @@ -67,11 +67,32 @@ db.createCollection( "label", {
}
} }
} );

db.createCollection( "view", {
validator: { $jsonSchema: {
bsonType: "object",
required: [ "id","domain","project","display","criteria" ],
properties: {
id: {
bsonType: "string",
},
domain: {
bsonType: "string"
},
project: {
bsonType: "string"
},
criteria: {
bsonType: "string"
}
}
} }
} );
//index
db.kv.createIndex({"id": 1}, { unique: true } );
db.kv.createIndex({key: 1, label_id: 1,domain:1,project:1},{ unique: true });
db.label.createIndex({"id": 1}, { unique: true } );
db.label.createIndex({format: 1,domain:1,project:1},{ unique: true });
db.view.createIndex({"id": 1}, { unique: true } );
db.view.createIndex({display:1,domain:1,project:1},{ unique: true });
//db config
db.setProfilingLevel(1, {slowms: 80, sampleRate: 1} );
2 changes: 1 addition & 1 deletion examples/dev/docker-compose.yaml
Expand Up @@ -17,7 +17,7 @@
version: '3.1'
services:
mongo:
image: mongo
image: mongo:4.0
restart: always
ports:
- 27017:27017
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Expand Up @@ -8,15 +8,13 @@ require (
github.com/go-chassis/go-chassis v1.8.2-0.20191227102336-e3ac2ea137b1
github.com/go-chassis/paas-lager v1.1.1
github.com/go-mesh/openlogging v1.0.1
github.com/golang/snappy v0.0.1 // indirect
github.com/hashicorp/mdns v1.0.1 // indirect
github.com/hashicorp/serf v0.8.5
github.com/satori/go.uuid v1.2.0
github.com/stretchr/testify v1.4.0
github.com/urfave/cli v1.20.0
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c // indirect
github.com/xdg/stringprep v1.0.0 // indirect
go.mongodb.org/mongo-driver v1.2.1
go.mongodb.org/mongo-driver v1.3.0
gopkg.in/yaml.v2 v2.2.4
)

Expand Down