Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小五666\n哈哈
Rocketmq
提交
a172c769
R
Rocketmq
项目概览
小五666\n哈哈
/
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看板
提交
a172c769
编写于
11月 25, 2021
作者:
D
dongeforever
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Finish the test for utils of createStaticTopic
上级
1dacb667
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
82 addition
and
5 deletion
+82
-5
common/src/main/java/org/apache/rocketmq/common/statictopic/TopicQueueMappingUtils.java
...e/rocketmq/common/statictopic/TopicQueueMappingUtils.java
+7
-5
common/src/test/java/org/apache/rocketmq/common/statictopic/TopicMappingUtilsTest.java
...he/rocketmq/common/statictopic/TopicMappingUtilsTest.java
+75
-0
未找到文件。
common/src/main/java/org/apache/rocketmq/common/statictopic/TopicQueueMappingUtils.java
浏览文件 @
a172c769
...
...
@@ -263,6 +263,9 @@ public class TopicQueueMappingUtils {
throw
new
RuntimeException
(
"The start offset dose not begin from 0"
);
}
TopicConfig
topicConfig
=
brokerConfigMap
.
get
(
item
.
getBname
());
if
(
topicConfig
==
null
)
{
throw
new
RuntimeException
(
"The broker dose not exist"
);
}
if
(
item
.
getQueueId
()
>=
topicConfig
.
getWriteQueueNums
())
{
throw
new
RuntimeException
(
"The physical queue id is overflow the write queues"
);
}
...
...
@@ -406,7 +409,7 @@ public class TopicQueueMappingUtils {
}
TopicConfigAndQueueMapping
configMapping
;
if
(!
brokerConfigMap
.
containsKey
(
broker
))
{
configMapping
=
new
TopicConfigAndQueueMapping
(
new
TopicConfig
(
topic
),
new
TopicQueueMappingDetail
(
topic
,
0
,
broker
,
-
1
));
configMapping
=
new
TopicConfigAndQueueMapping
(
new
TopicConfig
(
topic
),
new
TopicQueueMappingDetail
(
topic
,
0
,
broker
,
System
.
currentTimeMillis
()
));
configMapping
.
setWriteQueueNums
(
1
);
configMapping
.
setReadQueueNums
(
1
);
brokerConfigMap
.
put
(
broker
,
configMapping
);
...
...
@@ -416,7 +419,7 @@ public class TopicQueueMappingUtils {
configMapping
.
setReadQueueNums
(
configMapping
.
getReadQueueNums
()
+
1
);
}
LogicQueueMappingItem
mappingItem
=
new
LogicQueueMappingItem
(
0
,
configMapping
.
getWriteQueueNums
()
-
1
,
broker
,
0
,
0
,
-
1
,
-
1
,
-
1
);
TopicQueueMappingDetail
.
putMappingInfo
(
configMapping
.
getMappingDetail
(),
queueId
,
ImmutableList
.
of
(
mappingItem
));
TopicQueueMappingDetail
.
putMappingInfo
(
configMapping
.
getMappingDetail
(),
queueId
,
new
ArrayList
<
LogicQueueMappingItem
>(
Collections
.
singletonList
(
mappingItem
)
));
}
// set the topic config
...
...
@@ -508,10 +511,9 @@ public class TopicQueueMappingUtils {
LogicQueueMappingItem
last
=
items
.
get
(
items
.
size
()
-
1
);
items
.
add
(
new
LogicQueueMappingItem
(
last
.
getGen
()
+
1
,
mapInConfig
.
getWriteQueueNums
()
-
1
,
mapInBroker
,
0
,
0
,
-
1
,
-
1
,
-
1
));
ImmutableList
<
LogicQueueMappingItem
>
resultItems
=
ImmutableList
.
copyOf
(
items
);
//Use the same object
TopicQueueMappingDetail
.
putMappingInfo
(
mapInConfig
.
getMappingDetail
(),
queueId
,
resultI
tems
);
TopicQueueMappingDetail
.
putMappingInfo
(
mapOutConfig
.
getMappingDetail
(),
queueId
,
resultI
tems
);
TopicQueueMappingDetail
.
putMappingInfo
(
mapInConfig
.
getMappingDetail
(),
queueId
,
i
tems
);
TopicQueueMappingDetail
.
putMappingInfo
(
mapOutConfig
.
getMappingDetail
(),
queueId
,
i
tems
);
}
for
(
Map
.
Entry
<
String
,
TopicConfigAndQueueMapping
>
entry
:
brokerConfigMap
.
entrySet
())
{
...
...
common/src/test/java/org/apache/rocketmq/common/statictopic/TopicMappingUtilsTest.java
浏览文件 @
a172c769
...
...
@@ -5,6 +5,7 @@ import org.junit.Assert;
import
org.junit.Test
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.List
;
...
...
@@ -110,6 +111,7 @@ public class TopicMappingUtilsTest {
TopicConfigAndQueueMapping
configMapping
=
entry
.
getValue
();
Assert
.
assertEquals
(
5
,
configMapping
.
getReadQueueNums
());
Assert
.
assertEquals
(
5
,
configMapping
.
getWriteQueueNums
());
Assert
.
assertTrue
(
configMapping
.
getMappingDetail
().
epoch
>
System
.
currentTimeMillis
());
for
(
List
<
LogicQueueMappingItem
>
items:
configMapping
.
getMappingDetail
().
getHostedQueues
().
values
())
{
for
(
LogicQueueMappingItem
item:
items
)
{
Assert
.
assertEquals
(
0
,
item
.
getStartOffset
());
...
...
@@ -121,4 +123,77 @@ public class TopicMappingUtilsTest {
}
}
}
@Test
public
void
testCreateStaticTopic_Error
()
{
String
topic
=
"static"
;
int
queueNum
=
10
;
Map
<
String
,
TopicConfigAndQueueMapping
>
brokerConfigMap
=
new
HashMap
<
String
,
TopicConfigAndQueueMapping
>();
Set
<
String
>
targetBrokers
=
buildTargetBrokers
(
2
);
TopicRemappingDetailWrapper
wrapper
=
TopicQueueMappingUtils
.
createTopicConfigMapping
(
topic
,
queueNum
,
targetBrokers
,
brokerConfigMap
);
Assert
.
assertEquals
(
wrapper
.
getBrokerConfigMap
(),
brokerConfigMap
);
Assert
.
assertEquals
(
2
,
brokerConfigMap
.
size
());
TopicConfigAndQueueMapping
configMapping
=
brokerConfigMap
.
values
().
iterator
().
next
();
List
<
LogicQueueMappingItem
>
items
=
configMapping
.
getMappingDetail
().
getHostedQueues
().
values
().
iterator
().
next
();
Map
.
Entry
<
Long
,
Integer
>
maxEpochNum
=
TopicQueueMappingUtils
.
checkConsistenceOfTopicConfigAndQueueMapping
(
topic
,
brokerConfigMap
);
int
exceptionNum
=
0
;
try
{
configMapping
.
getMappingDetail
().
setTopic
(
"xxxx"
);
TopicQueueMappingUtils
.
checkConsistenceOfTopicConfigAndQueueMapping
(
topic
,
brokerConfigMap
);
}
catch
(
RuntimeException
ignore
)
{
exceptionNum
++;
configMapping
.
getMappingDetail
().
setTopic
(
topic
);
TopicQueueMappingUtils
.
checkConsistenceOfTopicConfigAndQueueMapping
(
topic
,
brokerConfigMap
);
}
try
{
configMapping
.
getMappingDetail
().
setTotalQueues
(
1
);
TopicQueueMappingUtils
.
checkConsistenceOfTopicConfigAndQueueMapping
(
topic
,
brokerConfigMap
);
}
catch
(
RuntimeException
ignore
)
{
exceptionNum
++;
configMapping
.
getMappingDetail
().
setTotalQueues
(
10
);
TopicQueueMappingUtils
.
checkConsistenceOfTopicConfigAndQueueMapping
(
topic
,
brokerConfigMap
);
}
try
{
configMapping
.
getMappingDetail
().
setEpoch
(
0
);
TopicQueueMappingUtils
.
checkConsistenceOfTopicConfigAndQueueMapping
(
topic
,
brokerConfigMap
);
}
catch
(
RuntimeException
ignore
)
{
exceptionNum
++;
configMapping
.
getMappingDetail
().
setEpoch
(
maxEpochNum
.
getKey
());
TopicQueueMappingUtils
.
checkConsistenceOfTopicConfigAndQueueMapping
(
topic
,
brokerConfigMap
);
}
try
{
configMapping
.
getMappingDetail
().
getHostedQueues
().
put
(
10000
,
new
ArrayList
<
LogicQueueMappingItem
>(
Collections
.
singletonList
(
new
LogicQueueMappingItem
(
1
,
1
,
targetBrokers
.
iterator
().
next
(),
0
,
0
,
-
1
,
-
1
,
-
1
))));
TopicQueueMappingUtils
.
checkAndBuildMappingItems
(
TopicQueueMappingUtils
.
getMappingDetailFromConfig
(
brokerConfigMap
.
values
()),
false
,
true
);
}
catch
(
RuntimeException
ignore
)
{
exceptionNum
++;
configMapping
.
getMappingDetail
().
getHostedQueues
().
remove
(
10000
);
TopicQueueMappingUtils
.
checkAndBuildMappingItems
(
TopicQueueMappingUtils
.
getMappingDetailFromConfig
(
brokerConfigMap
.
values
()),
false
,
true
);
}
try
{
configMapping
.
setWriteQueueNums
(
1
);
TopicQueueMappingUtils
.
checkPhysicalQueueConsistence
(
brokerConfigMap
);
}
catch
(
RuntimeException
ignore
)
{
exceptionNum
++;
configMapping
.
setWriteQueueNums
(
5
);
TopicQueueMappingUtils
.
checkPhysicalQueueConsistence
(
brokerConfigMap
);
}
try
{
items
.
add
(
new
LogicQueueMappingItem
(
1
,
1
,
targetBrokers
.
iterator
().
next
(),
0
,
0
,
-
1
,
-
1
,
-
1
));
Map
<
Integer
,
TopicQueueMappingOne
>
map
=
TopicQueueMappingUtils
.
checkAndBuildMappingItems
(
TopicQueueMappingUtils
.
getMappingDetailFromConfig
(
brokerConfigMap
.
values
()),
false
,
true
);
TopicQueueMappingUtils
.
checkIfReusePhysicalQueue
(
map
.
values
());
}
catch
(
RuntimeException
ignore
)
{
exceptionNum
++;
items
.
remove
(
items
.
size
()
-
1
);
Map
<
Integer
,
TopicQueueMappingOne
>
map
=
TopicQueueMappingUtils
.
checkAndBuildMappingItems
(
TopicQueueMappingUtils
.
getMappingDetailFromConfig
(
brokerConfigMap
.
values
()),
false
,
true
);
TopicQueueMappingUtils
.
checkIfReusePhysicalQueue
(
map
.
values
());
}
Assert
.
assertEquals
(
6
,
exceptionNum
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录