Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
转角邂逅
Rocketmq
提交
712dec57
R
Rocketmq
项目概览
转角邂逅
/
Rocketmq
与 Fork 源项目一致
Fork自
Apache RocketMQ / Rocketmq
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rocketmq
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
712dec57
编写于
1月 22, 2017
作者:
S
stevenschew
提交者:
yukon
1月 22, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[ROCKETMQ-54] Polish unit tests for rocketmq-namesrv
上级
881aef5d
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
195 addition
and
7 deletion
+195
-7
namesrv/src/test/java/org/apache/rocketmq/namesrv/NamesrvControllerTest.java
...va/org/apache/rocketmq/namesrv/NamesrvControllerTest.java
+2
-3
namesrv/src/test/java/org/apache/rocketmq/namesrv/processor/ClusterTestRequestProcessorTest.java
...mq/namesrv/processor/ClusterTestRequestProcessorTest.java
+112
-0
namesrv/src/test/java/org/apache/rocketmq/namesrv/processor/DefaultRequestProcessorTest.java
...cketmq/namesrv/processor/DefaultRequestProcessorTest.java
+0
-1
namesrv/src/test/java/org/apache/rocketmq/namesrv/routeinfo/BrokerHousekeepingServiceTest.java
...etmq/namesrv/routeinfo/BrokerHousekeepingServiceTest.java
+59
-0
namesrv/src/test/java/org/apache/rocketmq/namesrv/routeinfo/RouteInfoManagerTest.java
...ache/rocketmq/namesrv/routeinfo/RouteInfoManagerTest.java
+22
-3
未找到文件。
namesrv/src/test/java/org/apache/rocketmq/namesrv/NamesrvControllerTest.java
浏览文件 @
712dec57
...
...
@@ -23,7 +23,7 @@ import org.junit.Test;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
public
class
NamesrvControllerTest
{
private
final
int
RESTART_
NUM
=
2
;
private
final
static
int
RESTART
NUM
=
2
;
/**
* Tests if the controller can be properly stopped and started.
...
...
@@ -32,7 +32,7 @@ public class NamesrvControllerTest {
*/
@Test
public
void
testRestart
()
throws
Exception
{
for
(
int
i
=
0
;
i
<
RESTART
_
NUM
;
i
++)
{
for
(
int
i
=
0
;
i
<
RESTARTNUM
;
i
++)
{
NamesrvController
namesrvController
=
new
NamesrvController
(
new
NamesrvConfig
(),
new
NettyServerConfig
()
...
...
@@ -43,5 +43,4 @@ public class NamesrvControllerTest {
namesrvController
.
shutdown
();
}
}
}
\ No newline at end of file
namesrv/src/test/java/org/apache/rocketmq/namesrv/processor/ClusterTestRequestProcessorTest.java
0 → 100644
浏览文件 @
712dec57
/*
* 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
org.apache.rocketmq.namesrv.processor
;
import
io.netty.channel.ChannelHandlerContext
;
import
java.lang.reflect.Field
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
org.apache.rocketmq.client.ClientConfig
;
import
org.apache.rocketmq.client.exception.MQClientException
;
import
org.apache.rocketmq.client.impl.MQClientAPIImpl
;
import
org.apache.rocketmq.client.impl.MQClientManager
;
import
org.apache.rocketmq.client.impl.factory.MQClientInstance
;
import
org.apache.rocketmq.common.namesrv.NamesrvConfig
;
import
org.apache.rocketmq.common.protocol.ResponseCode
;
import
org.apache.rocketmq.common.protocol.route.BrokerData
;
import
org.apache.rocketmq.common.protocol.route.TopicRouteData
;
import
org.apache.rocketmq.namesrv.NamesrvController
;
import
org.apache.rocketmq.remoting.CommandCustomHeader
;
import
org.apache.rocketmq.remoting.exception.RemotingCommandException
;
import
org.apache.rocketmq.remoting.exception.RemotingException
;
import
org.apache.rocketmq.remoting.netty.NettyServerConfig
;
import
org.apache.rocketmq.remoting.protocol.RemotingCommand
;
import
org.apache.rocketmq.tools.admin.DefaultMQAdminExt
;
import
org.apache.rocketmq.tools.admin.DefaultMQAdminExtImpl
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
ArgumentMatchers
.
anyLong
;
import
static
org
.
mockito
.
ArgumentMatchers
.
anyString
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
when
;
public
class
ClusterTestRequestProcessorTest
{
private
ClusterTestRequestProcessor
clusterTestProcessor
;
private
DefaultMQAdminExtImpl
defaultMQAdminExtImpl
;
private
MQClientInstance
mqClientInstance
=
MQClientManager
.
getInstance
().
getAndCreateMQClientInstance
(
new
ClientConfig
());
private
MQClientAPIImpl
mQClientAPIImpl
;
private
ChannelHandlerContext
ctx
;
@Before
public
void
init
()
throws
NoSuchFieldException
,
IllegalAccessException
,
RemotingException
,
MQClientException
,
InterruptedException
{
NamesrvController
namesrvController
=
new
NamesrvController
(
new
NamesrvConfig
(),
new
NettyServerConfig
()
);
clusterTestProcessor
=
new
ClusterTestRequestProcessor
(
namesrvController
,
"default-producer"
);
mQClientAPIImpl
=
mock
(
MQClientAPIImpl
.
class
);
DefaultMQAdminExt
defaultMQAdminExt
=
new
DefaultMQAdminExt
();
defaultMQAdminExtImpl
=
new
DefaultMQAdminExtImpl
(
defaultMQAdminExt
,
1000
);
ctx
=
mock
(
ChannelHandlerContext
.
class
);
Field
field
=
DefaultMQAdminExtImpl
.
class
.
getDeclaredField
(
"mqClientInstance"
);
field
.
setAccessible
(
true
);
field
.
set
(
defaultMQAdminExtImpl
,
mqClientInstance
);
field
=
MQClientInstance
.
class
.
getDeclaredField
(
"mQClientAPIImpl"
);
field
.
setAccessible
(
true
);
field
.
set
(
mqClientInstance
,
mQClientAPIImpl
);
field
=
ClusterTestRequestProcessor
.
class
.
getDeclaredField
(
"adminExt"
);
field
.
setAccessible
(
true
);
field
.
set
(
clusterTestProcessor
,
defaultMQAdminExt
);
TopicRouteData
topicRouteData
=
new
TopicRouteData
();
List
<
BrokerData
>
brokerDatas
=
new
ArrayList
<>();
HashMap
<
Long
,
String
>
brokerAddrs
=
new
HashMap
<>();
brokerAddrs
.
put
(
1234
l
,
"127.0.0.1:10911"
);
BrokerData
brokerData
=
new
BrokerData
();
brokerData
.
setCluster
(
"default-cluster"
);
brokerData
.
setBrokerName
(
"default-broker"
);
brokerData
.
setBrokerAddrs
(
brokerAddrs
);
brokerDatas
.
add
(
brokerData
);
topicRouteData
.
setBrokerDatas
(
brokerDatas
);
when
(
mQClientAPIImpl
.
getTopicRouteInfoFromNameServer
(
anyString
(),
anyLong
())).
thenReturn
(
topicRouteData
);
}
@After
public
void
terminate
()
{
}
@Test
public
void
testGetRouteInfoByTopic
()
throws
RemotingCommandException
{
RemotingCommand
request
=
RemotingCommand
.
createRequestCommand
(
12
,
new
CommandCustomHeader
()
{
@Override
public
void
checkFields
()
throws
RemotingCommandException
{
}
});
RemotingCommand
remoting
=
clusterTestProcessor
.
getRouteInfoByTopic
(
ctx
,
request
);
assertThat
(
remoting
.
getCode
()).
isEqualTo
(
ResponseCode
.
TOPIC_NOT_EXIST
);
assertThat
(
remoting
.
getBody
()).
isNull
();
assertThat
(
remoting
.
getRemark
()).
isNotNull
();
}
}
\ No newline at end of file
namesrv/src/test/java/org/apache/rocketmq/namesrv/processor/DefaultRequestProcessorTest.java
浏览文件 @
712dec57
...
...
@@ -45,7 +45,6 @@ import static org.mockito.Mockito.mock;
import
static
org
.
mockito
.
Mockito
.
when
;
public
class
DefaultRequestProcessorTest
{
/** Test Target */
private
DefaultRequestProcessor
defaultRequestProcessor
;
private
NamesrvController
namesrvController
;
...
...
namesrv/src/test/java/org/apache/rocketmq/namesrv/routeinfo/BrokerHousekeepingServiceTest.java
0 → 100644
浏览文件 @
712dec57
/*
* 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
org.apache.rocketmq.namesrv.routeinfo
;
import
org.apache.rocketmq.common.namesrv.NamesrvConfig
;
import
org.apache.rocketmq.namesrv.NamesrvController
;
import
org.apache.rocketmq.remoting.netty.NettyServerConfig
;
import
org.junit.AfterClass
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
public
class
BrokerHousekeepingServiceTest
{
private
static
BrokerHousekeepingService
brokerHousekeepingService
;
@BeforeClass
public
static
void
setup
()
{
NamesrvController
namesrvController
=
new
NamesrvController
(
new
NamesrvConfig
(),
new
NettyServerConfig
()
);
brokerHousekeepingService
=
new
BrokerHousekeepingService
(
namesrvController
);
}
@AfterClass
public
static
void
terminate
()
{
}
@Test
public
void
testOnChannelClose
()
{
brokerHousekeepingService
.
onChannelClose
(
"127.0.0.1:9876"
,
null
);
}
@Test
public
void
testOnChannelException
()
{
brokerHousekeepingService
.
onChannelException
(
"127.0.0.1:9876"
,
null
);
}
@Test
public
void
testOnChannelIdle
()
{
brokerHousekeepingService
.
onChannelException
(
"127.0.0.1:9876"
,
null
);
}
}
\ No newline at end of file
namesrv/src/test/java/org/apache/rocketmq/namesrv/routeinfo/RouteInfoManagerTest.java
浏览文件 @
712dec57
...
...
@@ -18,9 +18,12 @@ package org.apache.rocketmq.namesrv.routeinfo;
import
io.netty.channel.Channel
;
import
java.util.ArrayList
;
import
java.util.concurrent.ConcurrentHashMap
;
import
org.apache.rocketmq.common.TopicConfig
;
import
org.apache.rocketmq.common.namesrv.RegisterBrokerResult
;
import
org.apache.rocketmq.common.protocol.body.TopicConfigSerializeWrapper
;
import
org.apache.rocketmq.common.protocol.route.TopicRouteData
;
import
org.junit.After
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Test
;
...
...
@@ -30,11 +33,18 @@ import static org.mockito.Mockito.mock;
public
class
RouteInfoManagerTest
{
private
RouteInfoManager
routeInfoManager
;
private
static
RouteInfoManager
routeInfoManager
;
@Before
public
void
setup
()
{
routeInfoManager
=
new
RouteInfoManager
();
testRegisterBroker
();
}
@After
public
void
terminate
()
{
routeInfoManager
.
printAllPeriodically
();
routeInfoManager
.
unregisterBroker
(
"default-cluster"
,
"127.0.0.1:10911"
,
"default-broker"
,
1234
);
}
@Test
...
...
@@ -52,7 +62,16 @@ public class RouteInfoManagerTest {
@Test
public
void
testRegisterBroker
()
{
TopicConfigSerializeWrapper
topicConfigSerializeWrapper
=
mock
(
TopicConfigSerializeWrapper
.
class
);
TopicConfigSerializeWrapper
topicConfigSerializeWrapper
=
new
TopicConfigSerializeWrapper
();
ConcurrentHashMap
<
String
,
TopicConfig
>
topicConfigConcurrentHashMap
=
new
ConcurrentHashMap
<>();
TopicConfig
topicConfig
=
new
TopicConfig
();
topicConfig
.
setWriteQueueNums
(
8
);
topicConfig
.
setTopicName
(
"unit-test"
);
topicConfig
.
setPerm
(
6
);
topicConfig
.
setReadQueueNums
(
8
);
topicConfig
.
setOrder
(
false
);
topicConfigConcurrentHashMap
.
put
(
"unit-test"
,
topicConfig
);
topicConfigSerializeWrapper
.
setTopicConfigTable
(
topicConfigConcurrentHashMap
);
Channel
channel
=
mock
(
Channel
.
class
);
RegisterBrokerResult
registerBrokerResult
=
routeInfoManager
.
registerBroker
(
"default-cluster"
,
"127.0.0.1:10911"
,
"default-broker"
,
1234
,
"127.0.0.1:1001"
,
topicConfigSerializeWrapper
,
new
ArrayList
<
String
>(),
channel
);
...
...
@@ -61,7 +80,7 @@ public class RouteInfoManagerTest {
@Test
public
void
testWipeWritePermOfBrokerByLock
()
{
int
result
=
routeInfoManager
.
wipeWritePermOfBrokerByLock
(
"default-broker
-name
"
);
int
result
=
routeInfoManager
.
wipeWritePermOfBrokerByLock
(
"default-broker"
);
assertThat
(
result
).
isEqualTo
(
0
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录