You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by ti...@apache.org on 2020/02/28 06:49:10 UTC
[servicecomb-kie] branch master updated: fix the issue #99 that the
key parameters in path does not effect (#100)
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-kie.git
The following commit(s) were added to refs/heads/master by this push:
new 2a8362c fix the issue #99 that the key parameters in path does not effect (#100)
2a8362c is described below
commit 2a8362c1739920fba1bb2cc6a54a041952647ce7
Author: zhulijian <zh...@huawei.com>
AuthorDate: Fri Feb 28 14:49:01 2020 +0800
fix the issue #99 that the key parameters in path does not effect (#100)
* update URLPatterns of KVResource about parameters of get kv api
Signed-off-by: zhulijian <zh...@huawei.com>
* fix the issue that the key parameters in path does not effect
Signed-off-by: zhulijian <zh...@huawei.com>
* ut
Signed-off-by: zhulijian <zh...@huawei.com>
---
scripts/travis/start_deps.sh | 3 ++-
scripts/travis/unit_test.sh | 1 +
server/resource/v1/kv_resource.go | 18 +++++++++---------
server/resource/v1/kv_resource_test.go | 33 +++++++++++++++++++++++++++++----
4 files changed, 41 insertions(+), 14 deletions(-)
diff --git a/scripts/travis/start_deps.sh b/scripts/travis/start_deps.sh
index e1d7d3f..2d6b251 100755
--- a/scripts/travis/start_deps.sh
+++ b/scripts/travis/start_deps.sh
@@ -17,4 +17,5 @@
cd build
bash build_docker.sh
-sudo docker-compose -f $GOPATH/src/github.com/apache/servicecomb-kie/deployments/docker/docker-compose.yaml up -d
\ No newline at end of file
+sudo docker-compose -f $GOPATH/src/github.com/apache/servicecomb-kie/deployments/docker/docker-compose.yaml down
+sudo docker-compose -f $GOPATH/src/github.com/apache/servicecomb-kie/deployments/docker/docker-compose.yaml up -d
diff --git a/scripts/travis/unit_test.sh b/scripts/travis/unit_test.sh
index 7568afd..bad6b02 100755
--- a/scripts/travis/unit_test.sh
+++ b/scripts/travis/unit_test.sh
@@ -18,6 +18,7 @@ set -e
# Make the Coverage File
echo "mode: atomic" > coverage.txt
+go clean -testcache
#Start the Test
for d in $(go list ./... | grep -v vendor | grep -v third_party | grep -v examples); do
echo $d
diff --git a/server/resource/v1/kv_resource.go b/server/resource/v1/kv_resource.go
index 5db4912..765ca7e 100644
--- a/server/resource/v1/kv_resource.go
+++ b/server/resource/v1/kv_resource.go
@@ -118,7 +118,7 @@ func (r *KVResource) GetByKey(rctx *restful.Context) {
WriteErrResponse(rctx, http.StatusBadRequest, err.Error(), common.ContentTypeText)
return
}
- returnData(rctx, domain, project, labels, pageNum, pageSize, status, insID)
+ returnData(rctx, domain, project, key, labels, pageNum, pageSize, status, insID)
}
//List response kv list
@@ -149,10 +149,10 @@ func (r *KVResource) List(rctx *restful.Context) {
WriteErrResponse(rctx, http.StatusBadRequest, err.Error(), common.ContentTypeText)
return
}
- returnData(rctx, domain, project, labels, pageNum, pageSize, status, sessionID)
+ returnData(rctx, domain, project, "", labels, pageNum, pageSize, status, sessionID)
}
-func returnData(rctx *restful.Context, domain interface{}, project string, labels map[string]string, pageNum, pageSize int64, status, sessionID string) {
+func returnData(rctx *restful.Context, domain interface{}, project, key string, labels map[string]string, pageNum, pageSize int64, status, sessionID string) {
revStr := rctx.ReadQueryParameter(common.QueryParamRev)
wait := rctx.ReadQueryParameter(common.QueryParamWait)
if sessionID != "" {
@@ -160,7 +160,7 @@ func returnData(rctx *restful.Context, domain interface{}, project string, label
}
if revStr == "" {
if wait == "" {
- queryAndResponse(rctx, domain, project, "", labels, pageNum, pageSize, status)
+ queryAndResponse(rctx, domain, project, key, labels, pageNum, pageSize, status)
return
}
changed, err := eventHappened(rctx, wait, &pubsub.Topic{
@@ -174,7 +174,7 @@ func returnData(rctx *restful.Context, domain interface{}, project string, label
return
}
if changed {
- queryAndResponse(rctx, domain, project, "", labels, pageNum, pageSize, status)
+ queryAndResponse(rctx, domain, project, key, labels, pageNum, pageSize, status)
return
}
rctx.WriteHeader(http.StatusNotModified)
@@ -189,7 +189,7 @@ func returnData(rctx *restful.Context, domain interface{}, project string, label
return
}
if revised {
- queryAndResponse(rctx, domain, project, "", labels, pageNum, pageSize, status)
+ queryAndResponse(rctx, domain, project, key, labels, pageNum, pageSize, status)
return
} else if wait != "" {
changed, err := eventHappened(rctx, wait, &pubsub.Topic{
@@ -203,7 +203,7 @@ func returnData(rctx *restful.Context, domain interface{}, project string, label
return
}
if changed {
- queryAndResponse(rctx, domain, project, "", labels, pageNum, pageSize, status)
+ queryAndResponse(rctx, domain, project, key, labels, pageNum, pageSize, status)
return
}
rctx.WriteHeader(http.StatusNotModified)
@@ -363,7 +363,7 @@ func (r *KVResource) URLPatterns() []restful.Route {
ResourceFunc: r.GetByKey,
FuncDesc: "get key values by key and labels",
Parameters: []*restful.Parameters{
- DocPathProject, DocPathKey, DocQueryLabelParameters, DocQueryMatch, DocQueryRev,
+ DocPathProject, DocPathKey, DocQueryLabelParameters, DocQueryWait, DocQueryMatch, DocQueryRev,
},
Returns: []*restful.Returns{
{
@@ -399,7 +399,7 @@ func (r *KVResource) URLPatterns() []restful.Route {
ResourceFunc: r.List,
FuncDesc: "list key values by labels and key",
Parameters: []*restful.Parameters{
- DocPathProject, DocQueryLabelParameters, DocQueryWait, DocQueryMatch,
+ DocPathProject, DocQueryLabelParameters, DocQueryWait, DocQueryMatch, DocQueryRev,
},
Returns: []*restful.Returns{
{
diff --git a/server/resource/v1/kv_resource_test.go b/server/resource/v1/kv_resource_test.go
index 93dea44..84315ce 100644
--- a/server/resource/v1/kv_resource_test.go
+++ b/server/resource/v1/kv_resource_test.go
@@ -91,6 +91,31 @@ func TestKVResource_Put(t *testing.T) {
assert.Equal(t, kv.Value, data.Value)
assert.Equal(t, kv.Labels, data.Labels)
})
+ t.Run("put a different key, which label is same to timeout", func(t *testing.T) {
+ kv := &model.KVDoc{
+ Value: "1s",
+ Labels: map[string]string{"service": "utService"},
+ }
+ j, _ := json.Marshal(kv)
+ r, _ := http.NewRequest("PUT", "/v1/test/kie/kv/interval", bytes.NewBuffer(j))
+ noopH := &handler2.NoopAuthHandler{}
+ chain, _ := handler.CreateChain(common.Provider, "testchain1", noopH.Name())
+ r.Header.Set("Content-Type", "application/json")
+ r.Header.Set("sessionID", "test")
+ kvr := &v1.KVResource{}
+ c, _ := restfultest.New(kvr, chain)
+ resp := httptest.NewRecorder()
+ c.ServeHTTP(resp, r)
+
+ body, err := ioutil.ReadAll(resp.Body)
+ assert.NoError(t, err)
+ data := &model.KVDoc{}
+ err = json.Unmarshal(body, data)
+ assert.NoError(t, err)
+ assert.NotEmpty(t, data.ID)
+ assert.Equal(t, kv.Value, data.Value)
+ assert.Equal(t, kv.Labels, data.Labels)
+ })
t.Run("put kv,label is service and version", func(t *testing.T) {
kv := &model.KVDoc{
Value: "1s",
@@ -117,7 +142,7 @@ func TestKVResource_Put(t *testing.T) {
})
}
func TestKVResource_List(t *testing.T) {
- t.Run("list kv by service label, should return 2 kvs", func(t *testing.T) {
+ t.Run("list kv by service label, should return 3 kvs", func(t *testing.T) {
r, _ := http.NewRequest("GET", "/v1/test/kie/kv?label=service:utService", nil)
noopH := &handler2.NoopAuthHandler{}
chain, _ := handler.CreateChain(common.Provider, "testchain1", noopH.Name())
@@ -132,10 +157,10 @@ func TestKVResource_List(t *testing.T) {
result := &model.KVResponse{}
err = json.Unmarshal(body, result)
assert.NoError(t, err)
- assert.Equal(t, 2, len(result.Data))
+ assert.Equal(t, 3, len(result.Data))
})
var rev string
- t.Run("list kv by service label, exact match,should return 1 kv", func(t *testing.T) {
+ t.Run("list kv by service label, exact match,should return 2 kv", func(t *testing.T) {
r, _ := http.NewRequest("GET", "/v1/test/kie/kv?label=service:utService&match=exact", nil)
noopH := &handler2.NoopAuthHandler{}
chain, _ := handler.CreateChain(common.Provider, "testchain1", noopH.Name())
@@ -150,7 +175,7 @@ func TestKVResource_List(t *testing.T) {
result := &model.KVResponse{}
err = json.Unmarshal(body, result)
assert.NoError(t, err)
- assert.Equal(t, 1, len(result.Data))
+ assert.Equal(t, 2, len(result.Data))
rev = resp.Header().Get(common2.HeaderRevision)
})
t.Run("list kv by service label, with current rev param,should return 304 ", func(t *testing.T) {