Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Kwan的解忧杂货铺@新空间代码工作室
Rocketmq
提交
9cae8c1b
R
Rocketmq
项目概览
Kwan的解忧杂货铺@新空间代码工作室
/
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看板
提交
9cae8c1b
编写于
12月 06, 2021
作者:
D
dongeforever
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add decode encode test for topic queue manager
上级
12915b80
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
115 addition
and
0 deletion
+115
-0
broker/src/main/java/org/apache/rocketmq/broker/topic/TopicQueueMappingManager.java
...pache/rocketmq/broker/topic/TopicQueueMappingManager.java
+3
-0
broker/src/test/java/org/apache/rocketmq/broker/topic/TopicQueueMappingManagerTest.java
...e/rocketmq/broker/topic/TopicQueueMappingManagerTest.java
+112
-0
未找到文件。
broker/src/main/java/org/apache/rocketmq/broker/topic/TopicQueueMappingManager.java
浏览文件 @
9cae8c1b
...
...
@@ -77,6 +77,7 @@ public class TopicQueueMappingManager extends ConfigManager {
boolean
updated
=
false
;
TopicQueueMappingDetail
oldDetail
=
null
;
try
{
if
(
lock
.
tryLock
(
LOCK_TIMEOUT_MILLIS
,
TimeUnit
.
MILLISECONDS
))
{
locked
=
true
;
}
else
{
...
...
@@ -85,6 +86,8 @@ public class TopicQueueMappingManager extends ConfigManager {
if
(
newDetail
==
null
)
{
return
;
}
assert
newDetail
.
getBname
().
equals
(
this
.
brokerController
.
getBrokerConfig
().
getBrokerName
());
newDetail
.
getHostedQueues
().
forEach
((
queueId
,
items
)
->
{
TopicQueueMappingUtils
.
checkLogicQueueMappingItemOffset
(
items
);
});
...
...
broker/src/test/java/org/apache/rocketmq/broker/topic/TopicQueueMappingManagerTest.java
0 → 100644
浏览文件 @
9cae8c1b
/*
* 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.broker.topic
;
import
org.apache.rocketmq.broker.BrokerController
;
import
org.apache.rocketmq.common.BrokerConfig
;
import
org.apache.rocketmq.common.statictopic.TopicQueueMappingDetail
;
import
org.apache.rocketmq.common.statictopic.TopicQueueMappingUtils
;
import
org.apache.rocketmq.common.statictopic.TopicRemappingDetailWrapper
;
import
org.apache.rocketmq.store.config.MessageStoreConfig
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
java.nio.file.Files
;
import
java.nio.file.Paths
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.UUID
;
import
static
org
.
mockito
.
Mockito
.
when
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
TopicQueueMappingManagerTest
{
@Mock
private
BrokerController
brokerController
;
private
static
final
String
broker1Name
=
"broker1"
;
@Before
public
void
before
()
{
BrokerConfig
brokerConfig
=
new
BrokerConfig
();
brokerConfig
.
setBrokerName
(
broker1Name
);
when
(
brokerController
.
getBrokerConfig
()).
thenReturn
(
brokerConfig
);
MessageStoreConfig
messageStoreConfig
=
new
MessageStoreConfig
();
messageStoreConfig
.
setStorePathRootDir
(
System
.
getProperty
(
"java.io.tmpdir"
));
messageStoreConfig
.
setDeleteWhen
(
"01;02;03;04;05;06;07;08;09;10;11;12;13;14;15;16;17;18;19;20;21;22;23;00"
);
when
(
brokerController
.
getMessageStoreConfig
()).
thenReturn
(
messageStoreConfig
);
}
private
void
delete
(
TopicQueueMappingManager
topicQueueMappingManager
)
throws
Exception
{
if
(
topicQueueMappingManager
==
null
)
{
return
;
}
Files
.
deleteIfExists
(
Paths
.
get
(
topicQueueMappingManager
.
configFilePath
()));
Files
.
deleteIfExists
(
Paths
.
get
(
topicQueueMappingManager
.
configFilePath
()
+
".bak"
));
}
@Test
public
void
testEncodeDecode
()
throws
Exception
{
Map
<
String
,
TopicQueueMappingDetail
>
mappingDetailMap
=
new
HashMap
<>();
TopicQueueMappingManager
topicQueueMappingManager
=
null
;
Set
<
String
>
brokers
=
new
HashSet
<
String
>();
brokers
.
add
(
broker1Name
);
{
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
String
topic
=
UUID
.
randomUUID
().
toString
();
int
queueNum
=
10
;
TopicRemappingDetailWrapper
topicRemappingDetailWrapper
=
TopicQueueMappingUtils
.
createTopicConfigMapping
(
topic
,
queueNum
,
brokers
,
new
HashMap
<>());
Assert
.
assertEquals
(
1
,
topicRemappingDetailWrapper
.
getBrokerConfigMap
().
size
());
TopicQueueMappingDetail
topicQueueMappingDetail
=
topicRemappingDetailWrapper
.
getBrokerConfigMap
().
values
().
iterator
().
next
().
getMappingDetail
();
Assert
.
assertEquals
(
queueNum
,
topicQueueMappingDetail
.
getHostedQueues
().
size
());
mappingDetailMap
.
put
(
topic
,
topicQueueMappingDetail
);
}
}
{
topicQueueMappingManager
=
new
TopicQueueMappingManager
(
brokerController
);
Assert
.
assertTrue
(
topicQueueMappingManager
.
load
());
Assert
.
assertEquals
(
0
,
topicQueueMappingManager
.
getTopicQueueMappingTable
().
size
());
for
(
TopicQueueMappingDetail
mappingDetail
:
mappingDetailMap
.
values
())
{
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
topicQueueMappingManager
.
updateTopicQueueMapping
(
mappingDetail
,
false
);
}
}
topicQueueMappingManager
.
persist
();
}
{
topicQueueMappingManager
=
new
TopicQueueMappingManager
(
brokerController
);
Assert
.
assertTrue
(
topicQueueMappingManager
.
load
());
Assert
.
assertEquals
(
mappingDetailMap
.
size
(),
topicQueueMappingManager
.
getTopicQueueMappingTable
().
size
());
for
(
TopicQueueMappingDetail
topicQueueMappingDetail:
topicQueueMappingManager
.
getTopicQueueMappingTable
().
values
())
{
Assert
.
assertEquals
(
topicQueueMappingDetail
,
mappingDetailMap
.
get
(
topicQueueMappingDetail
.
getTopic
()));
}
}
delete
(
topicQueueMappingManager
);
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录