Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Apache RocketMQ
Rocketmq
提交
03b12166
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看板
提交
03b12166
编写于
1月 17, 2017
作者:
Y
yukon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[ROCKETMQ-52] Add unit tests for Validators and ThreadLocalIndex
上级
2a9769a9
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
94 addition
and
11 deletion
+94
-11
client/pom.xml
client/pom.xml
+4
-0
client/src/main/java/org/apache/rocketmq/client/Validators.java
.../src/main/java/org/apache/rocketmq/client/Validators.java
+4
-4
client/src/main/java/org/apache/rocketmq/client/common/ThreadLocalIndex.java
...a/org/apache/rocketmq/client/common/ThreadLocalIndex.java
+0
-4
client/src/main/java/org/apache/rocketmq/client/impl/producer/TopicPublishInfo.java
...pache/rocketmq/client/impl/producer/TopicPublishInfo.java
+1
-1
client/src/main/java/org/apache/rocketmq/client/latency/LatencyFaultToleranceImpl.java
...he/rocketmq/client/latency/LatencyFaultToleranceImpl.java
+1
-1
client/src/test/java/org/apache/rocketmq/client/ValidatorsTest.java
.../test/java/org/apache/rocketmq/client/ValidatorsTest.java
+51
-1
client/src/test/java/org/apache/rocketmq/client/common/ThreadLocalIndexTest.java
...g/apache/rocketmq/client/common/ThreadLocalIndexTest.java
+33
-0
未找到文件。
client/pom.xml
浏览文件 @
03b12166
...
...
@@ -38,5 +38,9 @@
<groupId>
org.slf4j
</groupId>
<artifactId>
slf4j-api
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-lang3
</artifactId>
</dependency>
</dependencies>
</project>
client/src/main/java/org/apache/rocketmq/client/Validators.java
浏览文件 @
03b12166
...
...
@@ -118,23 +118,23 @@ public class Validators {
*/
public
static
void
checkTopic
(
String
topic
)
throws
MQClientException
{
if
(
UtilAll
.
isBlank
(
topic
))
{
throw
new
MQClientException
(
"
t
he specified topic is blank"
,
null
);
throw
new
MQClientException
(
"
T
he specified topic is blank"
,
null
);
}
if
(!
regularExpressionMatcher
(
topic
,
PATTERN
))
{
throw
new
MQClientException
(
String
.
format
(
"
t
he specified topic[%s] contains illegal characters, allowing only %s"
,
topic
,
"
T
he specified topic[%s] contains illegal characters, allowing only %s"
,
topic
,
VALID_PATTERN_STR
),
null
);
}
if
(
topic
.
length
()
>
CHARACTER_MAX_LENGTH
)
{
throw
new
MQClientException
(
"
t
he specified topic is longer than topic max length 255."
,
null
);
throw
new
MQClientException
(
"
T
he specified topic is longer than topic max length 255."
,
null
);
}
//whether the same with system reserved keyword
if
(
topic
.
equals
(
MixAll
.
DEFAULT_TOPIC
))
{
throw
new
MQClientException
(
String
.
format
(
"
t
he topic[%s] is conflict with default topic."
,
topic
),
null
);
String
.
format
(
"
T
he topic[%s] is conflict with default topic."
,
topic
),
null
);
}
}
}
client/src/main/java/org/apache/rocketmq/client/common/ThreadLocalIndex.java
浏览文件 @
03b12166
...
...
@@ -23,10 +23,6 @@ public class ThreadLocalIndex {
private
final
ThreadLocal
<
Integer
>
threadLocalIndex
=
new
ThreadLocal
<
Integer
>();
private
final
Random
random
=
new
Random
();
public
ThreadLocalIndex
(
int
value
)
{
}
public
int
getAndIncrement
()
{
Integer
index
=
this
.
threadLocalIndex
.
get
();
if
(
null
==
index
)
{
...
...
client/src/main/java/org/apache/rocketmq/client/impl/producer/TopicPublishInfo.java
浏览文件 @
03b12166
...
...
@@ -27,7 +27,7 @@ public class TopicPublishInfo {
private
boolean
orderTopic
=
false
;
private
boolean
haveTopicRouterInfo
=
false
;
private
List
<
MessageQueue
>
messageQueueList
=
new
ArrayList
<
MessageQueue
>();
private
volatile
ThreadLocalIndex
sendWhichQueue
=
new
ThreadLocalIndex
(
0
);
private
volatile
ThreadLocalIndex
sendWhichQueue
=
new
ThreadLocalIndex
();
private
TopicRouteData
topicRouteData
;
public
boolean
isOrderTopic
()
{
...
...
client/src/main/java/org/apache/rocketmq/client/latency/LatencyFaultToleranceImpl.java
浏览文件 @
03b12166
...
...
@@ -27,7 +27,7 @@ import org.apache.rocketmq.client.common.ThreadLocalIndex;
public
class
LatencyFaultToleranceImpl
implements
LatencyFaultTolerance
<
String
>
{
private
final
ConcurrentHashMap
<
String
,
FaultItem
>
faultItemTable
=
new
ConcurrentHashMap
<
String
,
FaultItem
>(
16
);
private
final
ThreadLocalIndex
whichItemWorst
=
new
ThreadLocalIndex
(
0
);
private
final
ThreadLocalIndex
whichItemWorst
=
new
ThreadLocalIndex
();
@Override
public
void
updateFaultItem
(
final
String
name
,
final
long
currentLatency
,
final
long
notAvailableDuration
)
{
...
...
client/src/test/java/org/apache/rocketmq/client/ValidatorsTest.java
浏览文件 @
03b12166
...
...
@@ -17,17 +17,67 @@
package
org.apache.rocketmq.client
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.rocketmq.client.exception.MQClientException
;
import
org.apache.rocketmq.common.MixAll
;
import
org.junit.Test
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Fail
.
failBecauseExceptionWasNotThrown
;
public
class
ValidatorsTest
{
@Test
public
void
t
opicValidatorTest
()
throws
MQClientException
{
public
void
t
estCheckTopic_Success
()
throws
MQClientException
{
Validators
.
checkTopic
(
"Hello"
);
Validators
.
checkTopic
(
"%RETRY%Hello"
);
Validators
.
checkTopic
(
"_%RETRY%Hello"
);
Validators
.
checkTopic
(
"-%RETRY%Hello"
);
Validators
.
checkTopic
(
"223-%RETRY%Hello"
);
}
@Test
public
void
testCheckTopic_HasIllegalCharacters
()
{
String
illegalTopic
=
"TOPIC&*^"
;
try
{
Validators
.
checkTopic
(
illegalTopic
);
failBecauseExceptionWasNotThrown
(
MQClientException
.
class
);
}
catch
(
MQClientException
e
)
{
assertThat
(
e
).
hasMessageStartingWith
(
String
.
format
(
"The specified topic[%s] contains illegal characters, allowing only %s"
,
illegalTopic
,
Validators
.
VALID_PATTERN_STR
));
}
}
@Test
public
void
testCheckTopic_UseDefaultTopic
()
{
String
defaultTopic
=
MixAll
.
DEFAULT_TOPIC
;
try
{
Validators
.
checkTopic
(
defaultTopic
);
failBecauseExceptionWasNotThrown
(
MQClientException
.
class
);
}
catch
(
MQClientException
e
)
{
assertThat
(
e
).
hasMessageStartingWith
(
String
.
format
(
"The topic[%s] is conflict with default topic."
,
defaultTopic
));
}
}
@Test
public
void
testCheckTopic_BlankTopic
()
{
String
blankTopic
=
""
;
try
{
Validators
.
checkTopic
(
blankTopic
);
failBecauseExceptionWasNotThrown
(
MQClientException
.
class
);
}
catch
(
MQClientException
e
)
{
assertThat
(
e
).
hasMessageStartingWith
(
"The specified topic is blank"
);
}
}
@Test
public
void
testCheckTopic_TooLongTopic
()
{
String
tooLongTopic
=
StringUtils
.
rightPad
(
"TooLongTopic"
,
Validators
.
CHARACTER_MAX_LENGTH
+
1
,
"_"
);
assertThat
(
tooLongTopic
.
length
()).
isGreaterThan
(
Validators
.
CHARACTER_MAX_LENGTH
);
try
{
Validators
.
checkTopic
(
tooLongTopic
);
failBecauseExceptionWasNotThrown
(
MQClientException
.
class
);
}
catch
(
MQClientException
e
)
{
assertThat
(
e
).
hasMessageStartingWith
(
"The specified topic is longer than topic max length 255."
);
}
}
}
client/src/test/java/org/apache/rocketmq/client/common/ThreadLocalIndexTest.java
0 → 100644
浏览文件 @
03b12166
/*
* 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.client.common
;
import
org.junit.Test
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
public
class
ThreadLocalIndexTest
{
@Test
public
void
getAndIncrement
()
throws
Exception
{
ThreadLocalIndex
localIndex
=
new
ThreadLocalIndex
();
int
initialVal
=
localIndex
.
getAndIncrement
();
assertThat
(
localIndex
.
getAndIncrement
()).
isEqualTo
(
initialVal
+
1
);
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录