Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Apache RocketMQ
Rocketmq
提交
e447bd01
R
Rocketmq
项目概览
Apache RocketMQ
/
Rocketmq
上一次同步 大约 3 年
通知
267
Star
16139
Fork
68
代码
文件
提交
分支
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看板
提交
e447bd01
编写于
1月 22, 2017
作者:
S
stevenschew
提交者:
yukon
1月 22, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[ROCKETMQ-54] Add unit tests for rocketmq-namesrv
上级
11ff542c
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
313 addition
and
10 deletion
+313
-10
namesrv/src/test/java/org/apache/rocketmq/namesrv/NameServerInstanceTest.java
...a/org/apache/rocketmq/namesrv/NameServerInstanceTest.java
+47
-0
namesrv/src/test/java/org/apache/rocketmq/namesrv/NamesrvControllerTest.java
...va/org/apache/rocketmq/namesrv/NamesrvControllerTest.java
+47
-0
namesrv/src/test/java/org/apache/rocketmq/namesrv/kvconfig/KVConfigManagerTest.java
...apache/rocketmq/namesrv/kvconfig/KVConfigManagerTest.java
+54
-0
namesrv/src/test/java/org/apache/rocketmq/namesrv/kvconfig/KVConfigSerializeWrapperTest.java
...cketmq/namesrv/kvconfig/KVConfigSerializeWrapperTest.java
+53
-0
namesrv/src/test/java/org/apache/rocketmq/namesrv/processor/DefaultRequestProcessorTest.java
...cketmq/namesrv/processor/DefaultRequestProcessorTest.java
+9
-10
namesrv/src/test/java/org/apache/rocketmq/namesrv/routeinfo/RouteInfoManagerTest.java
...ache/rocketmq/namesrv/routeinfo/RouteInfoManagerTest.java
+103
-0
未找到文件。
namesrv/src/test/java/org/apache/rocketmq/namesrv/NameServerInstanceTest.java
0 → 100644
浏览文件 @
e447bd01
/*
* 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
;
import
org.apache.rocketmq.common.namesrv.NamesrvConfig
;
import
org.apache.rocketmq.remoting.netty.NettyServerConfig
;
import
org.junit.After
;
import
org.junit.Before
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
public
class
NameServerInstanceTest
{
protected
NamesrvController
nameSrvController
=
null
;
protected
NettyServerConfig
nettyServerConfig
=
new
NettyServerConfig
();
protected
NamesrvConfig
namesrvConfig
=
new
NamesrvConfig
();
@Before
public
void
startup
()
throws
Exception
{
nettyServerConfig
.
setListenPort
(
9876
);
nameSrvController
=
new
NamesrvController
(
namesrvConfig
,
nettyServerConfig
);
boolean
initResult
=
nameSrvController
.
initialize
();
assertThat
(
initResult
).
isTrue
();
nameSrvController
.
start
();
}
@After
public
void
shutdown
()
throws
Exception
{
if
(
nameSrvController
!=
null
)
{
nameSrvController
.
shutdown
();
}
//maybe need to clean the file store. But we do not suggest deleting anything.
}
}
namesrv/src/test/java/org/apache/rocketmq/namesrv/NamesrvControllerTest.java
0 → 100644
浏览文件 @
e447bd01
/*
* 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
;
import
org.apache.rocketmq.common.namesrv.NamesrvConfig
;
import
org.apache.rocketmq.remoting.netty.NettyServerConfig
;
import
org.junit.Test
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
public
class
NamesrvControllerTest
{
private
final
int
RESTART_NUM
=
2
;
/**
* Tests if the controller can be properly stopped and started.
*
* @throws Exception If fails.
*/
@Test
public
void
testRestart
()
throws
Exception
{
for
(
int
i
=
0
;
i
<
RESTART_NUM
;
i
++)
{
NamesrvController
namesrvController
=
new
NamesrvController
(
new
NamesrvConfig
(),
new
NettyServerConfig
()
);
boolean
initResult
=
namesrvController
.
initialize
();
assertThat
(
initResult
).
isEqualTo
(
true
);
namesrvController
.
start
();
namesrvController
.
shutdown
();
}
}
}
\ No newline at end of file
namesrv/src/test/java/org/apache/rocketmq/namesrv/kvconfig/KVConfigManagerTest.java
0 → 100644
浏览文件 @
e447bd01
/*
* 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.kvconfig
;
import
org.apache.rocketmq.common.namesrv.NamesrvUtil
;
import
org.apache.rocketmq.namesrv.NameServerInstanceTest
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Test
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
public
class
KVConfigManagerTest
extends
NameServerInstanceTest
{
private
KVConfigManager
kvConfigManager
;
@Before
public
void
setup
()
throws
Exception
{
kvConfigManager
=
new
KVConfigManager
(
nameSrvController
);
}
@Test
public
void
testPutKVConfig
()
{
kvConfigManager
.
load
();
kvConfigManager
.
putKVConfig
(
NamesrvUtil
.
NAMESPACE_ORDER_TOPIC_CONFIG
,
"UnitTest"
,
"test"
);
byte
[]
kvConfig
=
kvConfigManager
.
getKVListByNamespace
(
NamesrvUtil
.
NAMESPACE_ORDER_TOPIC_CONFIG
);
assertThat
(
kvConfig
).
isNotNull
();
String
value
=
kvConfigManager
.
getKVConfig
(
NamesrvUtil
.
NAMESPACE_ORDER_TOPIC_CONFIG
,
"UnitTest"
);
assertThat
(
value
).
isEqualTo
(
"test"
);
}
@Test
public
void
testDeleteKVConfig
()
{
kvConfigManager
.
deleteKVConfig
(
NamesrvUtil
.
NAMESPACE_ORDER_TOPIC_CONFIG
,
"UnitTest"
);
byte
[]
kvConfig
=
kvConfigManager
.
getKVListByNamespace
(
NamesrvUtil
.
NAMESPACE_ORDER_TOPIC_CONFIG
);
assertThat
(
kvConfig
).
isNull
();
Assert
.
assertTrue
(
kvConfig
==
null
);
String
value
=
kvConfigManager
.
getKVConfig
(
NamesrvUtil
.
NAMESPACE_ORDER_TOPIC_CONFIG
,
"UnitTest"
);
assertThat
(
value
).
isNull
();
}
}
\ No newline at end of file
namesrv/src/test/java/org/apache/rocketmq/namesrv/kvconfig/KVConfigSerializeWrapperTest.java
0 → 100644
浏览文件 @
e447bd01
/*
* 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.kvconfig
;
import
java.util.HashMap
;
import
org.apache.rocketmq.common.namesrv.NamesrvUtil
;
import
org.junit.Before
;
import
org.junit.Test
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
public
class
KVConfigSerializeWrapperTest
{
private
KVConfigSerializeWrapper
kvConfigSerializeWrapper
;
@Before
public
void
setup
()
throws
Exception
{
kvConfigSerializeWrapper
=
new
KVConfigSerializeWrapper
();
}
@Test
public
void
testEncodeAndDecode
()
{
HashMap
<
String
,
HashMap
<
String
,
String
>>
result
=
new
HashMap
<>();
HashMap
<
String
,
String
>
kvs
=
new
HashMap
<>();
kvs
.
put
(
"broker-name"
,
"default-broker"
);
kvs
.
put
(
"topic-name"
,
"default-topic"
);
kvs
.
put
(
"cid"
,
"default-consumer-name"
);
result
.
put
(
NamesrvUtil
.
NAMESPACE_ORDER_TOPIC_CONFIG
,
kvs
);
kvConfigSerializeWrapper
.
setConfigTable
(
result
);
byte
[]
serializeByte
=
KVConfigSerializeWrapper
.
encode
(
kvConfigSerializeWrapper
);
assertThat
(
serializeByte
).
isNotNull
();
KVConfigSerializeWrapper
deserializeObject
=
KVConfigSerializeWrapper
.
decode
(
serializeByte
,
KVConfigSerializeWrapper
.
class
);
assertThat
(
deserializeObject
.
getConfigTable
()).
containsKey
(
NamesrvUtil
.
NAMESPACE_ORDER_TOPIC_CONFIG
);
assertThat
(
deserializeObject
.
getConfigTable
().
get
(
NamesrvUtil
.
NAMESPACE_ORDER_TOPIC_CONFIG
).
get
(
"broker-name"
)).
isEqualTo
(
"default-broker"
);
assertThat
(
deserializeObject
.
getConfigTable
().
get
(
NamesrvUtil
.
NAMESPACE_ORDER_TOPIC_CONFIG
).
get
(
"topic-name"
)).
isEqualTo
(
"default-topic"
);
assertThat
(
deserializeObject
.
getConfigTable
().
get
(
NamesrvUtil
.
NAMESPACE_ORDER_TOPIC_CONFIG
).
get
(
"cid"
)).
isEqualTo
(
"default-consumer-name"
);
}
}
\ No newline at end of file
namesrv/src/test/java/org/apache/rocketmq/namesrv/processor/DefaultRequestProcessorTest.java
浏览文件 @
e447bd01
...
...
@@ -41,7 +41,8 @@ import org.junit.Test;
import
org.slf4j.Logger
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.*;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
when
;
public
class
DefaultRequestProcessorTest
{
/** Test Target */
...
...
@@ -218,10 +219,9 @@ public class DefaultRequestProcessorTest {
Field
brokerAddrTable
=
RouteInfoManager
.
class
.
getDeclaredField
(
"brokerAddrTable"
);
brokerAddrTable
.
setAccessible
(
true
);
assertThat
((
Map
)
brokerAddrTable
.
get
(
routes
)).
isEmpty
();
assertThat
((
Map
)
brokerAddrTable
.
get
(
routes
)).
isEmpty
();
}
private
static
RemotingCommand
genSampleRegisterCmd
(
boolean
reg
)
{
RegisterBrokerRequestHeader
header
=
new
RegisterBrokerRequestHeader
();
header
.
setBrokerName
(
"broker"
);
...
...
@@ -235,7 +235,6 @@ public class DefaultRequestProcessorTest {
return
request
;
}
private
static
void
setFinalStatic
(
Field
field
,
Object
newValue
)
throws
Exception
{
field
.
setAccessible
(
true
);
Field
modifiersField
=
Field
.
class
.
getDeclaredField
(
"modifiers"
);
...
...
namesrv/src/test/java/org/apache/rocketmq/namesrv/routeinfo/RouteInfoManagerTest.java
0 → 100644
浏览文件 @
e447bd01
/*
* 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
io.netty.channel.Channel
;
import
java.util.ArrayList
;
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.Assert
;
import
org.junit.Before
;
import
org.junit.Test
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
mock
;
public
class
RouteInfoManagerTest
{
private
RouteInfoManager
routeInfoManager
;
@Before
public
void
setup
()
{
routeInfoManager
=
new
RouteInfoManager
();
}
@Test
public
void
testGetAllClusterInfo
()
{
byte
[]
clusterInfo
=
routeInfoManager
.
getAllClusterInfo
();
assertThat
(
clusterInfo
).
isNotNull
();
}
@Test
public
void
testGetAllTopicList
()
{
byte
[]
topicInfo
=
routeInfoManager
.
getAllTopicList
();
Assert
.
assertTrue
(
topicInfo
!=
null
);
assertThat
(
topicInfo
).
isNotNull
();
}
@Test
public
void
testRegisterBroker
()
{
TopicConfigSerializeWrapper
topicConfigSerializeWrapper
=
mock
(
TopicConfigSerializeWrapper
.
class
);
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
);
assertThat
(
registerBrokerResult
).
isNotNull
();
}
@Test
public
void
testWipeWritePermOfBrokerByLock
()
{
int
result
=
routeInfoManager
.
wipeWritePermOfBrokerByLock
(
"default-broker-name"
);
assertThat
(
result
).
isEqualTo
(
0
);
}
@Test
public
void
testPickupTopicRouteData
()
{
TopicRouteData
result
=
routeInfoManager
.
pickupTopicRouteData
(
"unit_test"
);
assertThat
(
result
).
isNull
();
}
@Test
public
void
testGetSystemTopicList
()
{
byte
[]
topicList
=
routeInfoManager
.
getSystemTopicList
();
assertThat
(
topicList
).
isNotNull
();
}
@Test
public
void
testGetTopicsByCluster
()
{
byte
[]
topicList
=
routeInfoManager
.
getTopicsByCluster
(
"default-cluster"
);
assertThat
(
topicList
).
isNotNull
();
}
@Test
public
void
testGetUnitTopics
()
{
byte
[]
topicList
=
routeInfoManager
.
getUnitTopics
();
assertThat
(
topicList
).
isNotNull
();
}
@Test
public
void
testGetHasUnitSubTopicList
()
{
byte
[]
topicList
=
routeInfoManager
.
getHasUnitSubTopicList
();
assertThat
(
topicList
).
isNotNull
();
}
@Test
public
void
testGetHasUnitSubUnUnitTopicList
()
{
byte
[]
topicList
=
routeInfoManager
.
getHasUnitSubUnUnitTopicList
();
assertThat
(
topicList
).
isNotNull
();
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录