You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by vi...@apache.org on 2020/07/01 02:56:54 UTC

[dubbo-go-hessian2] 02/02: add unit test

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

victory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-go-hessian2.git

commit 4116f3b07ec181b00f045ab56d2ce49a5d1dd8c2
Author: cvictory <sh...@gmail.com>
AuthorDate: Wed Jul 1 10:56:24 2020 +0800

    add unit test
---
 java_unknown_exception.go      |  8 +++++---
 java_unknown_exception_test.go | 43 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 3 deletions(-)

diff --git a/java_unknown_exception.go b/java_unknown_exception.go
index 45f5a00..5ea5a49 100644
--- a/java_unknown_exception.go
+++ b/java_unknown_exception.go
@@ -26,7 +26,9 @@ import (
 	"github.com/apache/dubbo-go-hessian2/java_exception"
 )
 
-var mutex sync.Mutex
+var (
+	expRegMutex sync.Mutex
+)
 
 func checkAndGetException(cls classInfo) (structInfo, bool) {
 
@@ -48,8 +50,8 @@ func checkAndGetException(cls classInfo) (structInfo, bool) {
 		if throwable, ok = getStructInfo(cls.javaName); ok {
 			return throwable, true
 		}
-		mutex.Lock()
-		defer mutex.Unlock()
+		expRegMutex.Lock()
+		defer expRegMutex.Unlock()
 		RegisterPOJO(newBizException(cls.javaName))
 		if throwable, ok = getStructInfo(cls.javaName); ok {
 			return throwable, true
diff --git a/java_unknown_exception_test.go b/java_unknown_exception_test.go
new file mode 100644
index 0000000..fa14ed3
--- /dev/null
+++ b/java_unknown_exception_test.go
@@ -0,0 +1,43 @@
+/*
+ * 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 hessian
+
+import (
+	"github.com/stretchr/testify/assert"
+	"testing"
+)
+
+func TestCheckAndGetException(t *testing.T) {
+	clazzInfo1 := classInfo{
+		javaName:      "com.test.UserDefinedException",
+		fieldNameList: []string{"detailMessage", "code", "suppressedExceptions", "stackTrace", "cause"},
+	}
+	s, b := checkAndGetException(clazzInfo1)
+	assert.True(t, b)
+
+	assert.Equal(t, s.javaName, "com.test.UserDefinedException")
+	assert.Equal(t, s.goName, "hessian.UnknownException")
+
+	clazzInfo2 := classInfo{
+		javaName:      "com.test.UserDefinedException",
+		fieldNameList: []string{"detailMessage", "code", "suppressedExceptions", "cause"},
+	}
+	s, b = checkAndGetException(clazzInfo2)
+	assert.False(t, b)
+	assert.Equal(t, s, structInfo{})
+}