Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
Rocketmq
提交
f529670c
R
Rocketmq
项目概览
s920243400
/
Rocketmq
与 Fork 源项目一致
Fork自
Apache RocketMQ / Rocketmq
通知
1
Star
1
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看板
提交
f529670c
编写于
1月 22, 2017
作者:
Y
yukon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[ROCKETMQ-53] Polish unit tests for rocketmq-common
上级
13f4297e
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
104 addition
and
84 deletion
+104
-84
common/src/test/java/org/apache/rocketmq/common/BrokerConfigTest.java
...est/java/org/apache/rocketmq/common/BrokerConfigTest.java
+3
-3
common/src/test/java/org/apache/rocketmq/common/MixAllTest.java
.../src/test/java/org/apache/rocketmq/common/MixAllTest.java
+6
-6
common/src/test/java/org/apache/rocketmq/common/RemotingUtilTest.java
...est/java/org/apache/rocketmq/common/RemotingUtilTest.java
+6
-4
common/src/test/java/org/apache/rocketmq/common/UtilAllTest.java
...src/test/java/org/apache/rocketmq/common/UtilAllTest.java
+56
-62
common/src/test/java/org/apache/rocketmq/common/filter/FilterAPITest.java
...java/org/apache/rocketmq/common/filter/FilterAPITest.java
+26
-4
common/src/test/java/org/apache/rocketmq/common/protocol/ConsumeStatusTest.java
...rg/apache/rocketmq/common/protocol/ConsumeStatusTest.java
+7
-5
未找到文件。
common/src/test/java/org/apache/rocketmq/common/BrokerConfigTest.java
浏览文件 @
f529670c
...
...
@@ -16,15 +16,15 @@
*/
package
org.apache.rocketmq.common
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
public
class
BrokerConfigTest
{
@Test
public
void
testConsumerFallBehindThresholdOverflow
()
{
long
expect
=
1024L
*
1024
*
1024
*
16
;
Assert
.
assertEquals
(
expect
,
new
BrokerConfig
().
getConsumerFallbehindThreshold
()
);
assertThat
(
new
BrokerConfig
().
getConsumerFallbehindThreshold
()).
isEqualTo
(
expect
);
}
}
\ No newline at end of file
common/src/test/java/org/apache/rocketmq/common/MixAllTest.java
浏览文件 @
f529670c
...
...
@@ -17,19 +17,19 @@
package
org.apache.rocketmq.common
;
import
org.junit.Test
;
import
org.junit.Assert
;
import
java.net.InetAddress
;
import
java.util.List
;
import
org.junit.Test
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
public
class
MixAllTest
{
@Test
public
void
test
()
throws
Exception
{
public
void
test
GetLocalInetAddress
()
throws
Exception
{
List
<
String
>
localInetAddress
=
MixAll
.
getLocalInetAddress
();
String
local
=
InetAddress
.
getLocalHost
().
getHostAddress
();
Assert
.
assertTrue
(
localInetAddress
.
contains
(
"127.0.0.1"
)
);
Assert
.
assertTrue
(
localInetAddress
.
contains
(
local
)
);
assertThat
(
localInetAddress
).
contains
(
"127.0.0.1"
);
assertThat
(
localInetAddress
).
contains
(
local
);
}
}
common/src/test/java/org/apache/rocketmq/common/RemotingUtilTest.java
浏览文件 @
f529670c
...
...
@@ -17,13 +17,15 @@
package
org.apache.rocketmq.common
;
import
org.apache.rocketmq.remoting.common.RemotingUtil
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
public
class
RemotingUtilTest
{
@Test
public
void
test
()
throws
Exception
{
String
a
=
RemotingUtil
.
getLocalAddress
();
Assert
.
assertTrue
(
a
.
length
()
>
0
);
public
void
testGetLocalAddress
()
throws
Exception
{
String
localAddress
=
RemotingUtil
.
getLocalAddress
();
assertThat
(
localAddress
).
isNotNull
();
assertThat
(
localAddress
.
length
()).
isGreaterThan
(
0
);
}
}
common/src/test/java/org/apache/rocketmq/common/UtilAllTest.java
浏览文件 @
f529670c
...
...
@@ -17,106 +17,90 @@
package
org.apache.rocketmq.common
;
import
java.net.URL
;
import
java.util.Properties
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
within
;
public
class
UtilAllTest
{
@Test
public
void
test_currentStackTrace
()
{
System
.
out
.
println
(
UtilAll
.
currentStackTrace
());
public
void
testCurrentStackTrace
()
{
String
currentStackTrace
=
UtilAll
.
currentStackTrace
();
assertThat
(
currentStackTrace
).
contains
(
"UtilAll.currentStackTrace"
);
assertThat
(
currentStackTrace
).
contains
(
"UtilAllTest.testCurrentStackTrace("
);
}
@Test
public
void
test_a
()
{
URL
url
=
this
.
getClass
().
getProtectionDomain
().
getCodeSource
().
getLocation
();
System
.
out
.
println
(
url
);
System
.
out
.
println
(
url
.
getPath
());
}
@Test
public
void
test_resetClassProperties
()
{
public
void
testProperties2Object
()
{
DemoConfig
demoConfig
=
new
DemoConfig
();
MixAll
.
properties2Object
(
new
Properties
(),
demoConfig
);
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
"demoWidth"
,
"123"
);
properties
.
setProperty
(
"demoLength"
,
"456"
);
properties
.
setProperty
(
"demoOK"
,
"true"
);
properties
.
setProperty
(
"demoName"
,
"TestDemo"
);
MixAll
.
properties2Object
(
properties
,
demoConfig
);
assertThat
(
demoConfig
.
getDemoLength
()).
isEqualTo
(
456
);
assertThat
(
demoConfig
.
getDemoWidth
()).
isEqualTo
(
123
);
assertThat
(
demoConfig
.
isDemoOK
()).
isTrue
();
assertThat
(
demoConfig
.
getDemoName
()).
isEqualTo
(
"TestDemo"
);
}
@Test
public
void
test
_p
roperties2String
()
{
public
void
test
P
roperties2String
()
{
DemoConfig
demoConfig
=
new
DemoConfig
();
demoConfig
.
setDemoLength
(
123
);
demoConfig
.
setDemoWidth
(
456
);
demoConfig
.
setDemoName
(
"TestDemo"
);
demoConfig
.
setDemoOK
(
true
);
Properties
properties
=
MixAll
.
object2Properties
(
demoConfig
);
System
.
out
.
println
(
MixAll
.
properties2String
(
properties
));
assertThat
(
properties
.
getProperty
(
"demoLength"
)).
isEqualTo
(
"123"
);
assertThat
(
properties
.
getProperty
(
"demoWidth"
)).
isEqualTo
(
"456"
);
assertThat
(
properties
.
getProperty
(
"demoOK"
)).
isEqualTo
(
"true"
);
assertThat
(
properties
.
getProperty
(
"demoName"
)).
isEqualTo
(
"TestDemo"
);
}
@Test
public
void
test
_t
imeMillisToHumanString
()
{
System
.
out
.
println
(
UtilAll
.
timeMillisToHumanString
()
);
public
void
test
T
imeMillisToHumanString
()
{
assertThat
(
UtilAll
.
timeMillisToHumanString
(
1485078178610L
)).
isEqualTo
(
"20170122174258610"
);
}
@Test
public
void
test
_i
sPropertiesEqual
()
{
public
void
test
I
sPropertiesEqual
()
{
final
Properties
p1
=
new
Properties
();
final
Properties
p2
=
new
Properties
();
p1
.
setProperty
(
"a"
,
"1"
);
p1
.
setProperty
(
"b"
,
"2"
);
p2
.
setProperty
(
"a"
,
"1"
);
p2
.
setProperty
(
"b"
,
"2"
);
// p2.setProperty("c", "3");
assertT
rue
(
MixAll
.
isPropertiesEqual
(
p1
,
p2
)
);
assertT
hat
(
MixAll
.
isPropertiesEqual
(
p1
,
p2
)).
isTrue
(
);
}
@Test
public
void
test_getpid
()
{
int
pid
=
UtilAll
.
getPid
();
System
.
out
.
println
(
"PID = "
+
pid
);
assertTrue
(
pid
>
0
);
public
void
testGetPid
()
{
assertThat
(
UtilAll
.
getPid
()).
isGreaterThan
(
0
);
}
@Test
public
void
test_getDiskPartitionSpaceUsedPercent
()
{
assertEquals
(-
1
,
UtilAll
.
getDiskPartitionSpaceUsedPercent
(
null
),
0
);
assertEquals
(-
1
,
UtilAll
.
getDiskPartitionSpaceUsedPercent
(
""
),
0
);
assertEquals
(-
1
,
UtilAll
.
getDiskPartitionSpaceUsedPercent
(
"nonExistingPath"
),
0
);
public
void
testGetDiskPartitionSpaceUsedPercent
()
{
String
tmpDir
=
System
.
getProperty
(
"java.io.tmpdir"
);
assertNotEquals
(-
1
,
UtilAll
.
getDiskPartitionSpaceUsedPercent
(
tmpDir
),
0
);
assertThat
(
UtilAll
.
getDiskPartitionSpaceUsedPercent
(
null
)).
isCloseTo
(-
1
,
within
(
0.000001
));
assertThat
(
UtilAll
.
getDiskPartitionSpaceUsedPercent
(
""
)).
isCloseTo
(-
1
,
within
(
0.000001
));
assertThat
(
UtilAll
.
getDiskPartitionSpaceUsedPercent
(
"nonExistingPath"
)).
isCloseTo
(-
1
,
within
(
0.000001
));
assertThat
(
UtilAll
.
getDiskPartitionSpaceUsedPercent
(
tmpDir
)).
isNotCloseTo
(-
1
,
within
(
0.000001
));
}
@Test
public
void
test_isBlank
()
{
{
boolean
result
=
UtilAll
.
isBlank
(
"Hello "
);
assertTrue
(!
result
);
}
{
boolean
result
=
UtilAll
.
isBlank
(
" Hello"
);
assertTrue
(!
result
);
}
{
boolean
result
=
UtilAll
.
isBlank
(
"He llo"
);
assertTrue
(!
result
);
}
{
boolean
result
=
UtilAll
.
isBlank
(
" "
);
assertTrue
(
result
);
}
{
boolean
result
=
UtilAll
.
isBlank
(
"Hello"
);
assertTrue
(!
result
);
}
public
void
testIsBlank
()
{
assertThat
(
UtilAll
.
isBlank
(
"Hello "
)).
isFalse
();
assertThat
(
UtilAll
.
isBlank
(
" Hello"
)).
isFalse
();
assertThat
(
UtilAll
.
isBlank
(
"He llo"
)).
isFalse
();
assertThat
(
UtilAll
.
isBlank
(
" "
)).
isTrue
();
assertThat
(
UtilAll
.
isBlank
(
"Hello"
)).
isFalse
();
}
static
class
DemoConfig
{
...
...
@@ -125,7 +109,7 @@ public class UtilAllTest {
private
boolean
demoOK
=
false
;
private
String
demoName
=
"haha"
;
public
int
getDemoWidth
()
{
int
getDemoWidth
()
{
return
demoWidth
;
}
...
...
@@ -153,8 +137,18 @@ public class UtilAllTest {
return
demoName
;
}
public
void
setDemoN
field
ame
(
String
demoName
)
{
public
void
setDemoName
(
String
demoName
)
{
this
.
demoName
=
demoName
;
}
@Override
public
String
toString
()
{
return
"DemoConfig{"
+
"demoWidth="
+
demoWidth
+
", demoLength="
+
demoLength
+
", demoOK="
+
demoOK
+
", demoName='"
+
demoName
+
'\''
+
'}'
;
}
}
}
common/src/test/java/org/apache/rocketmq/common/filter/FilterAPITest.java
浏览文件 @
f529670c
...
...
@@ -17,17 +17,31 @@
package
org.apache.rocketmq.common.filter
;
import
java.util.HashSet
;
import
java.util.Set
;
import
org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData
;
import
org.apache.rocketmq.remoting.protocol.RemotingSerializable
;
import
org.junit.Test
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
public
class
FilterAPITest
{
private
String
topic
=
"FooBar"
;
private
String
group
=
"FooBarGroup"
;
private
String
subString
=
"TAG1 || Tag2 || tag3"
;
@Test
public
void
testBuildSubscriptionData
()
throws
Exception
{
SubscriptionData
subscriptionData
=
FilterAPI
.
buildSubscriptionData
(
"ConsumerGroup1"
,
"TestTopic"
,
"TAG1 || Tag2 || tag3"
);
System
.
out
.
println
(
subscriptionData
);
FilterAPI
.
buildSubscriptionData
(
group
,
topic
,
subString
);
assertThat
(
subscriptionData
.
getTopic
()).
isEqualTo
(
topic
);
assertThat
(
subscriptionData
.
getSubString
()).
isEqualTo
(
subString
);
String
[]
tags
=
subString
.
split
(
"\\|\\|"
);
Set
<
String
>
tagSet
=
new
HashSet
<>();
for
(
String
tag
:
tags
)
{
tagSet
.
add
(
tag
.
trim
());
}
assertThat
(
subscriptionData
.
getTagsSet
()).
isEqualTo
(
tagSet
);
}
@Test
...
...
@@ -35,7 +49,15 @@ public class FilterAPITest {
SubscriptionData
subscriptionData
=
FilterAPI
.
buildSubscriptionData
(
"ConsumerGroup1"
,
"TestTopic"
,
"TAG1 || Tag2 || tag3"
);
subscriptionData
.
setFilterClassSource
(
"java hello"
);
String
json
=
RemotingSerializable
.
toJson
(
subscriptionData
,
true
);
System
.
out
.
println
(
json
);
String
prettyJson
=
RemotingSerializable
.
toJson
(
subscriptionData
,
true
);
long
subVersion
=
subscriptionData
.
getSubVersion
();
assertThat
(
prettyJson
).
isEqualTo
(
"{\n"
+
"\t\"classFilterMode\":false,\n"
+
"\t\"codeSet\":[2567159,2598904,3552217],\n"
+
"\t\"subString\":\"TAG1 || Tag2 || tag3\",\n"
+
"\t\"subVersion\":"
+
subVersion
+
",\n"
+
"\t\"tagsSet\":[\"TAG1\",\"Tag2\",\"tag3\"],\n"
+
"\t\"topic\":\"TestTopic\"\n"
+
"}"
);
}
}
common/src/test/java/org/apache/rocketmq/common/protocol/ConsumeStatusTest.java
浏览文件 @
f529670c
...
...
@@ -19,22 +19,24 @@ package org.apache.rocketmq.common.protocol;
import
org.apache.rocketmq.common.protocol.body.ConsumeStatus
;
import
org.apache.rocketmq.remoting.protocol.RemotingSerializable
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
within
;
public
class
ConsumeStatusTest
{
@Test
public
void
decodeTest
()
throws
Exception
{
public
void
testFromJson
()
throws
Exception
{
ConsumeStatus
cs
=
new
ConsumeStatus
();
cs
.
setConsumeFailedTPS
(
10
);
cs
.
setPullRT
(
100
);
cs
.
setPullTPS
(
1000
);
String
json
=
RemotingSerializable
.
toJson
(
cs
,
true
);
ConsumeStatus
fromJson
=
RemotingSerializable
.
fromJson
(
json
,
ConsumeStatus
.
class
);
Assert
.
assertEquals
(
fromJson
.
getPullRT
(),
cs
.
getPullRT
(),
0.0001
);
Assert
.
assertEquals
(
fromJson
.
getPullTPS
(),
cs
.
getPullTPS
(),
0.0001
);
Assert
.
assertEquals
(
fromJson
.
getConsumeFailedTPS
(),
cs
.
getConsumeFailedTPS
(),
0.0001
);
assertThat
(
fromJson
.
getPullRT
()).
isCloseTo
(
cs
.
getPullRT
(),
within
(
0.0001
)
);
assertThat
(
fromJson
.
getPullTPS
()).
isCloseTo
(
cs
.
getPullTPS
(),
within
(
0.0001
)
);
assertThat
(
fromJson
.
getConsumeFailedTPS
()).
isCloseTo
(
cs
.
getConsumeFailedTPS
(),
within
(
0.0001
)
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录