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/04/08 10:44:08 UTC

[servicecomb-mesher] branch master updated: Add UT to dubbo schema module (#111)

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-mesher.git


The following commit(s) were added to refs/heads/master by this push:
     new 6da101b  Add UT to dubbo schema module (#111)
6da101b is described below

commit 6da101bce1160a0639efda591aa084ad9ffffe56
Author: t-xinlin <t_...@sina.com>
AuthorDate: Wed Apr 8 18:44:00 2020 +0800

    Add UT to dubbo schema module (#111)
    
    * Add UT to dubbo schema module
    
    * Add UT to dubbo schema module
    
    * Add UT to schema cache
    
    * Add UT to schema cache
    
    Co-authored-by: “t_xinlin@sina.com <Happy100>
---
 proxy/protocol/dubbo/schema/cache_test.go  |  51 +++++++++++++
 proxy/protocol/dubbo/schema/schema_test.go | 118 +++++++++++++++++++++++++++++
 2 files changed, 169 insertions(+)

diff --git a/proxy/protocol/dubbo/schema/cache_test.go b/proxy/protocol/dubbo/schema/cache_test.go
new file mode 100644
index 0000000..77bd7f5
--- /dev/null
+++ b/proxy/protocol/dubbo/schema/cache_test.go
@@ -0,0 +1,51 @@
+/*
+ * 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 schema
+
+import (
+	"sync"
+	"testing"
+	"time"
+
+	"github.com/stretchr/testify/assert"
+)
+
+func TestFreshTicker(t *testing.T) {
+	r1 := newRefresher(time.Second * 2)
+	r1.Run()
+
+	a1, a2 := 0, 0
+	var wg sync.WaitGroup
+	wg.Add(2)
+
+	r1.Add(Job{Fn: func() {
+		a1++
+		wg.Done()
+	}})
+
+	r1.Add(Job{Fn: func() {
+		a2++
+		wg.Done()
+	}})
+
+	wg.Wait()
+
+	assert.Equal(t, a1, 1)
+	assert.Equal(t, a2, 1)
+
+}
diff --git a/proxy/protocol/dubbo/schema/schema_test.go b/proxy/protocol/dubbo/schema/schema_test.go
new file mode 100644
index 0000000..ce68475
--- /dev/null
+++ b/proxy/protocol/dubbo/schema/schema_test.go
@@ -0,0 +1,118 @@
+/*
+ * 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 schema
+
+import (
+	"github.com/stretchr/testify/assert"
+	"testing"
+)
+
+func Test_GetRspSchema(t *testing.T) {
+	res := make(map[string]*MethRespond, 0)
+	res["200"] = &MethRespond{
+		Status: "200",
+	}
+	m := DefMethod{
+		ownerSvc: "svc",
+		Path:     "/test/StringArray",
+		OperaID:  "StringArray",
+		Responds: res,
+	}
+
+	assert.NotNil(t, m.GetRspSchema(200))
+
+	assert.Nil(t, m.GetRspSchema(404))
+}
+
+func Test_GetParamNameAndWhere(t *testing.T) {
+	res := make(map[string]*MethRespond, 0)
+	res["200"] = &MethRespond{
+		Status: "200",
+	}
+
+	mParams := []MethParam{MethParam{
+		Name:  "para1",
+		Where: "query",
+		Indx:  0,
+	}, MethParam{
+		Name:  "para2",
+		Where: "body",
+		Indx:  1,
+	}}
+
+	m := DefMethod{
+		ownerSvc: "svc",
+		Path:     "/test/StringArray",
+		OperaID:  "StringArray",
+		Responds: res,
+		Paras:    mParams,
+	}
+
+	// case in query
+	name, indx := m.GetParamNameAndWhere(0)
+	assert.Equal(t, "para1", name)
+	assert.Equal(t, InQuery, indx)
+
+	// case in body
+	name, indx = m.GetParamNameAndWhere(1)
+	assert.Equal(t, "para2", name)
+	assert.Equal(t, InBody, indx)
+
+	// other
+	name, indx = m.GetParamNameAndWhere(2)
+	assert.Equal(t, 0, len(name))
+	assert.Equal(t, InQuery, indx)
+}
+
+func Test_GetParamSchema(t *testing.T) {
+	res := make(map[string]*MethRespond, 0)
+	res["200"] = &MethRespond{
+		Status: "200",
+	}
+
+	mParams := []MethParam{MethParam{
+		Name:  "para1",
+		Where: "query",
+		Indx:  0,
+	}, MethParam{
+		Name:  "para2",
+		Where: "body",
+		Indx:  1,
+	}}
+
+	m := DefMethod{
+		ownerSvc: "svc",
+		Path:     "/test/StringArray",
+		OperaID:  "StringArray",
+		Responds: res,
+		Paras:    mParams,
+	}
+
+	// case in query
+	param := m.GetParamSchema(0)
+	assert.Equal(t, "para1", param.Name)
+
+	// case in body
+	param = m.GetParamSchema(1)
+	assert.Equal(t, "para2", param.Name)
+
+	// other
+	param = m.GetParamSchema(2)
+	assert.Nil(t, param)
+
+}