Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
22a7f0099
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2022
22a7f0099
Commits
b87b1330
Commit
b87b1330
authored
5 years ago
by
邹毅贤
Browse files
Options
Downloads
Patches
Plain Diff
add UT for app_router
parent
7fe41cf3
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
before_ut.bat
+2
-1
2 additions, 1 deletion
before_ut.bat
before_ut.sh
+2
-1
2 additions, 1 deletion
before_ut.sh
cluster/router/condition/app_router_test.go
+179
-0
179 additions, 0 deletions
cluster/router/condition/app_router_test.go
with
183 additions
and
2 deletions
before_ut.bat
+
2
−
1
View file @
b87b1330
...
...
@@ -19,4 +19,5 @@ md remoting\zookeeper\zookeeper-4unittest\contrib\fatjar config_center\zookeeper
curl
-L
https
://github.com/dubbogo/resources/raw/master/zookeeper
-
4
unitest
/contrib/fatjar
/
%zkJar%
-o
remoting
/zookeeper/zookeeper
-
4
unittest
/contrib/fatjar
/
%zkJar%
xcopy
/f
"remoting/zookeeper/zookeeper-4unittest/contrib/fatjar/
%zkJar%
"
"config_center/zookeeper/zookeeper-4unittest/contrib/fatjar/"
xcopy
/f
"remoting/zookeeper/zookeeper-4unittest/contrib/fatjar/
%zkJar%
"
"registry/zookeeper/zookeeper-4unittest/contrib/fatjar/"
xcopy
/f
"remoting/zookeeper/zookeeper-4unittest/contrib/fatjar/
%zkJar%
"
"cluster/router/chain/zookeeper-4unittest/contrib/fatjar/"
\ No newline at end of file
xcopy
/f
"remoting/zookeeper/zookeeper-4unittest/contrib/fatjar/
%zkJar%
"
"cluster/router/chain/zookeeper-4unittest/contrib/fatjar/"
xcopy
/f
"remoting/zookeeper/zookeeper-4unittest/contrib/fatjar/
%zkJar%
"
"cluster/router/condition/zookeeper-4unittest/contrib/fatjar/"
\ No newline at end of file
This diff is collapsed.
Click to expand it.
before_ut.sh
+
2
−
1
View file @
b87b1330
...
...
@@ -19,4 +19,5 @@ mkdir -p remoting/zookeeper/zookeeper-4unittest/contrib/fatjar config_center/zoo
wget
-P
"remoting/zookeeper/zookeeper-4unittest/contrib/fatjar"
https://github.com/dubbogo/resources/raw/master/zookeeper-4unitest/contrib/fatjar/zookeeper-3.4.9-fatjar.jar
cp
remoting/zookeeper/zookeeper-4unittest/contrib/fatjar/zookeeper-3.4.9-fatjar.jar config_center/zookeeper/zookeeper-4unittest/contrib/fatjar/
cp
remoting/zookeeper/zookeeper-4unittest/contrib/fatjar/zookeeper-3.4.9-fatjar.jar registry/zookeeper/zookeeper-4unittest/contrib/fatjar/
cp
remoting/zookeeper/zookeeper-4unittest/contrib/fatjar/zookeeper-3.4.9-fatjar.jar cluster/router/chain/zookeeper-4unittest/contrib/fatjar
\ No newline at end of file
cp
remoting/zookeeper/zookeeper-4unittest/contrib/fatjar/zookeeper-3.4.9-fatjar.jar cluster/router/chain/zookeeper-4unittest/contrib/fatjar
cp
remoting/zookeeper/zookeeper-4unittest/contrib/fatjar/zookeeper-3.4.9-fatjar.jar cluster/router/condition/zookeeper-4unittest/contrib/fatjar
\ No newline at end of file
This diff is collapsed.
Click to expand it.
cluster/router/condition/app_router_test.go
0 → 100644
+
179
−
0
View file @
b87b1330
/*
* 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
condition
import
(
"strconv"
"testing"
"time"
"github.com/apache/dubbo-go/config_center"
"github.com/apache/dubbo-go/remoting"
)
import
(
_
"github.com/apache/dubbo-go/config_center/zookeeper"
"github.com/stretchr/testify/assert"
)
import
(
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/config"
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/remoting/zookeeper"
)
func
TestNewAppRouter
(
t
*
testing
.
T
)
{
testYML
:=
`enabled: true
force: true
runtime: false
conditions:
- => host != 172.22.3.91
`
ts
,
z
,
_
,
err
:=
zookeeper
.
NewMockZookeeperClient
(
"test"
,
15
*
time
.
Second
)
assert
.
NoError
(
t
,
err
)
err
=
z
.
Create
(
"/dubbo/config/dubbo/test-condition.condition-router"
)
assert
.
NoError
(
t
,
err
)
_
,
err
=
z
.
Conn
.
Set
(
"/dubbo/config/dubbo/test-condition.condition-router"
,
[]
byte
(
testYML
),
0
)
assert
.
NoError
(
t
,
err
)
defer
ts
.
Stop
()
defer
z
.
Close
()
zkUrl
,
_
:=
common
.
NewURL
(
"zookeeper://127.0.0.1:"
+
strconv
.
Itoa
(
ts
.
Servers
[
0
]
.
Port
))
configuration
,
err
:=
extension
.
GetConfigCenterFactory
(
"zookeeper"
)
.
GetDynamicConfiguration
(
&
zkUrl
)
config
.
GetEnvInstance
()
.
SetDynamicConfiguration
(
configuration
)
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
configuration
)
appRouteURL
:=
getAppRouteURL
(
"test-condition"
)
appRouter
,
err
:=
NewAppRouter
(
appRouteURL
)
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
appRouter
)
assert
.
NotNil
(
t
,
appRouter
)
assert
.
NotNil
(
t
,
appRouter
.
RouterRule
())
rule
:=
appRouter
.
RouterRule
()
assert
.
Equal
(
t
,
""
,
rule
.
Scope
)
assert
.
True
(
t
,
rule
.
Force
)
assert
.
True
(
t
,
rule
.
Enabled
)
assert
.
True
(
t
,
rule
.
Valid
)
assert
.
Equal
(
t
,
testYML
,
rule
.
RawRule
)
assert
.
Equal
(
t
,
false
,
rule
.
Runtime
)
assert
.
Equal
(
t
,
false
,
rule
.
Dynamic
)
assert
.
Equal
(
t
,
""
,
rule
.
Key
)
assert
.
Equal
(
t
,
0
,
rule
.
Priority
)
}
func
TestGenerateConditions
(
t
*
testing
.
T
)
{
testYML
:=
`enabled: true
force: true
runtime: false
conditions:
- => host != 172.22.3.91
- host = 192.168.199.208 => host = 192.168.199.208
`
ts
,
z
,
_
,
err
:=
zookeeper
.
NewMockZookeeperClient
(
"test"
,
15
*
time
.
Second
)
assert
.
NoError
(
t
,
err
)
err
=
z
.
Create
(
"/dubbo/config/dubbo/test-condition.condition-router"
)
assert
.
NoError
(
t
,
err
)
_
,
err
=
z
.
Conn
.
Set
(
"/dubbo/config/dubbo/test-condition.condition-router"
,
[]
byte
(
testYML
),
0
)
assert
.
NoError
(
t
,
err
)
defer
ts
.
Stop
()
defer
z
.
Close
()
zkUrl
,
_
:=
common
.
NewURL
(
"zookeeper://127.0.0.1:"
+
strconv
.
Itoa
(
ts
.
Servers
[
0
]
.
Port
))
configuration
,
err
:=
extension
.
GetConfigCenterFactory
(
"zookeeper"
)
.
GetDynamicConfiguration
(
&
zkUrl
)
config
.
GetEnvInstance
()
.
SetDynamicConfiguration
(
configuration
)
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
configuration
)
appRouteURL
:=
getAppRouteURL
(
"test-condition"
)
appRouter
,
err
:=
NewAppRouter
(
appRouteURL
)
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
appRouter
)
rule
,
err
:=
Parse
(
testYML
)
assert
.
Nil
(
t
,
err
)
appRouter
.
generateConditions
(
rule
)
assert
.
Equal
(
t
,
2
,
len
(
appRouter
.
conditionRouters
))
}
func
TestProcess
(
t
*
testing
.
T
)
{
testYML
:=
`enabled: true
force: true
runtime: false
conditions:
- => host != 172.22.3.91
`
ts
,
z
,
_
,
err
:=
zookeeper
.
NewMockZookeeperClient
(
"test"
,
15
*
time
.
Second
)
assert
.
NoError
(
t
,
err
)
err
=
z
.
Create
(
"/dubbo/config/dubbo/test-condition.condition-router"
)
assert
.
NoError
(
t
,
err
)
_
,
err
=
z
.
Conn
.
Set
(
"/dubbo/config/dubbo/test-condition.condition-router"
,
[]
byte
(
testYML
),
0
)
assert
.
NoError
(
t
,
err
)
defer
ts
.
Stop
()
defer
z
.
Close
()
zkUrl
,
_
:=
common
.
NewURL
(
"zookeeper://127.0.0.1:"
+
strconv
.
Itoa
(
ts
.
Servers
[
0
]
.
Port
))
configuration
,
err
:=
extension
.
GetConfigCenterFactory
(
"zookeeper"
)
.
GetDynamicConfiguration
(
&
zkUrl
)
config
.
GetEnvInstance
()
.
SetDynamicConfiguration
(
configuration
)
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
configuration
)
appRouteURL
:=
getAppRouteURL
(
"test-condition"
)
appRouter
,
err
:=
NewAppRouter
(
appRouteURL
)
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
appRouter
)
assert
.
Equal
(
t
,
1
,
len
(
appRouter
.
conditionRouters
))
testNewYML
:=
`
enabled: true
force: true
runtime: false
conditions:
- => host != 172.22.3.91
- host = 192.168.199.208 => host = 192.168.199.208
`
appRouter
.
Process
(
&
config_center
.
ConfigChangeEvent
{
ConfigType
:
remoting
.
EventTypeDel
})
assert
.
Equal
(
t
,
0
,
len
(
appRouter
.
conditionRouters
))
appRouter
.
Process
(
&
config_center
.
ConfigChangeEvent
{
Value
:
testNewYML
,
ConfigType
:
remoting
.
EventTypeAdd
})
assert
.
Equal
(
t
,
2
,
len
(
appRouter
.
conditionRouters
))
}
func
getAppRouteURL
(
applicationKey
string
)
*
common
.
URL
{
url
,
_
:=
common
.
NewURL
(
"condition://0.0.0.0/com.foo.BarService"
)
url
.
AddParam
(
"application"
,
applicationKey
)
url
.
AddParam
(
"force"
,
"true"
)
return
&
url
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment