Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Kwan的解忧杂货铺@新空间代码工作室
Rocketmq
提交
cb7e032f
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看板
提交
cb7e032f
编写于
11月 24, 2021
作者:
D
dongeforever
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Finish the test for createStaticTopic
上级
a493ca44
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
150 addition
and
15 deletion
+150
-15
common/src/main/java/org/apache/rocketmq/common/statictopic/LogicQueueMappingItem.java
...he/rocketmq/common/statictopic/LogicQueueMappingItem.java
+37
-0
common/src/main/java/org/apache/rocketmq/common/statictopic/TopicConfigAndQueueMapping.java
...cketmq/common/statictopic/TopicConfigAndQueueMapping.java
+24
-0
common/src/main/java/org/apache/rocketmq/common/statictopic/TopicQueueMappingDetail.java
.../rocketmq/common/statictopic/TopicQueueMappingDetail.java
+23
-0
common/src/main/java/org/apache/rocketmq/common/statictopic/TopicQueueMappingInfo.java
...he/rocketmq/common/statictopic/TopicQueueMappingInfo.java
+30
-0
common/src/test/java/org/apache/rocketmq/common/statictopic/TopicQueueMappingTest.java
...he/rocketmq/common/statictopic/TopicQueueMappingTest.java
+2
-0
test/src/test/java/org/apache/rocketmq/test/smoke/StaticTopicIT.java
...st/java/org/apache/rocketmq/test/smoke/StaticTopicIT.java
+34
-15
未找到文件。
common/src/main/java/org/apache/rocketmq/common/statictopic/LogicQueueMappingItem.java
浏览文件 @
cb7e032f
package
org.apache.rocketmq.common.statictopic
;
import
org.apache.commons.lang3.builder.EqualsBuilder
;
import
org.apache.commons.lang3.builder.HashCodeBuilder
;
import
org.apache.rocketmq.remoting.protocol.RemotingSerializable
;
public
class
LogicQueueMappingItem
extends
RemotingSerializable
{
...
...
@@ -135,6 +137,41 @@ public class LogicQueueMappingItem extends RemotingSerializable {
this
.
startOffset
=
startOffset
;
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
return
true
;
if
(!(
o
instanceof
LogicQueueMappingItem
))
return
false
;
LogicQueueMappingItem
item
=
(
LogicQueueMappingItem
)
o
;
return
new
EqualsBuilder
()
.
append
(
gen
,
item
.
gen
)
.
append
(
queueId
,
item
.
queueId
)
.
append
(
logicOffset
,
item
.
logicOffset
)
.
append
(
startOffset
,
item
.
startOffset
)
.
append
(
endOffset
,
item
.
endOffset
)
.
append
(
timeOfStart
,
item
.
timeOfStart
)
.
append
(
timeOfEnd
,
item
.
timeOfEnd
)
.
append
(
bname
,
item
.
bname
)
.
isEquals
();
}
@Override
public
int
hashCode
()
{
return
new
HashCodeBuilder
(
17
,
37
)
.
append
(
gen
)
.
append
(
queueId
)
.
append
(
bname
)
.
append
(
logicOffset
)
.
append
(
startOffset
)
.
append
(
endOffset
)
.
append
(
timeOfStart
)
.
append
(
timeOfEnd
)
.
toHashCode
();
}
@Override
public
String
toString
()
{
return
"LogicQueueMappingItem{"
+
...
...
common/src/main/java/org/apache/rocketmq/common/statictopic/TopicConfigAndQueueMapping.java
浏览文件 @
cb7e032f
...
...
@@ -16,6 +16,8 @@
*/
package
org.apache.rocketmq.common.statictopic
;
import
org.apache.commons.lang3.builder.EqualsBuilder
;
import
org.apache.commons.lang3.builder.HashCodeBuilder
;
import
org.apache.rocketmq.common.TopicConfig
;
public
class
TopicConfigAndQueueMapping
extends
TopicConfig
{
...
...
@@ -36,4 +38,26 @@ public class TopicConfigAndQueueMapping extends TopicConfig {
public
void
setMappingDetail
(
TopicQueueMappingDetail
mappingDetail
)
{
this
.
mappingDetail
=
mappingDetail
;
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
return
true
;
if
(!(
o
instanceof
TopicConfigAndQueueMapping
))
return
false
;
TopicConfigAndQueueMapping
that
=
(
TopicConfigAndQueueMapping
)
o
;
return
new
EqualsBuilder
()
.
appendSuper
(
super
.
equals
(
o
))
.
append
(
mappingDetail
,
that
.
mappingDetail
)
.
isEquals
();
}
@Override
public
int
hashCode
()
{
return
new
HashCodeBuilder
(
17
,
37
)
.
appendSuper
(
super
.
hashCode
())
.
append
(
mappingDetail
)
.
toHashCode
();
}
}
common/src/main/java/org/apache/rocketmq/common/statictopic/TopicQueueMappingDetail.java
浏览文件 @
cb7e032f
...
...
@@ -16,6 +16,9 @@
*/
package
org.apache.rocketmq.common.statictopic
;
import
org.apache.commons.lang3.builder.EqualsBuilder
;
import
org.apache.commons.lang3.builder.HashCodeBuilder
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
...
...
@@ -124,4 +127,24 @@ public class TopicQueueMappingDetail extends TopicQueueMappingInfo {
public
void
setHostedQueues
(
ConcurrentMap
<
Integer
,
List
<
LogicQueueMappingItem
>>
hostedQueues
)
{
this
.
hostedQueues
=
hostedQueues
;
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
return
true
;
if
(!(
o
instanceof
TopicQueueMappingDetail
))
return
false
;
TopicQueueMappingDetail
that
=
(
TopicQueueMappingDetail
)
o
;
return
new
EqualsBuilder
()
.
append
(
hostedQueues
,
that
.
hostedQueues
)
.
isEquals
();
}
@Override
public
int
hashCode
()
{
return
new
HashCodeBuilder
(
17
,
37
)
.
append
(
hostedQueues
)
.
toHashCode
();
}
}
common/src/main/java/org/apache/rocketmq/common/statictopic/TopicQueueMappingInfo.java
浏览文件 @
cb7e032f
...
...
@@ -16,6 +16,8 @@
*/
package
org.apache.rocketmq.common.statictopic
;
import
org.apache.commons.lang3.builder.EqualsBuilder
;
import
org.apache.commons.lang3.builder.HashCodeBuilder
;
import
org.apache.rocketmq.remoting.protocol.RemotingSerializable
;
import
java.util.concurrent.ConcurrentHashMap
;
...
...
@@ -93,5 +95,33 @@ public class TopicQueueMappingInfo extends RemotingSerializable {
this
.
currIdMap
=
currIdMap
;
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
return
true
;
if
(!(
o
instanceof
TopicQueueMappingInfo
))
return
false
;
TopicQueueMappingInfo
info
=
(
TopicQueueMappingInfo
)
o
;
return
new
EqualsBuilder
()
.
append
(
totalQueues
,
info
.
totalQueues
)
.
append
(
epoch
,
info
.
epoch
)
.
append
(
dirty
,
info
.
dirty
)
.
append
(
topic
,
info
.
topic
)
.
append
(
bname
,
info
.
bname
)
.
append
(
currIdMap
,
info
.
currIdMap
)
.
isEquals
();
}
@Override
public
int
hashCode
()
{
return
new
HashCodeBuilder
(
17
,
37
)
.
append
(
topic
)
.
append
(
totalQueues
)
.
append
(
bname
)
.
append
(
epoch
)
.
append
(
dirty
)
.
append
(
currIdMap
)
.
toHashCode
();
}
}
common/src/test/java/org/apache/rocketmq/common/statictopic/TopicQueueMappingTest.java
浏览文件 @
cb7e032f
...
...
@@ -31,6 +31,7 @@ public class TopicQueueMappingTest {
//test the decode encode
{
LogicQueueMappingItem
mappingItemFromJson
=
RemotingSerializable
.
fromJson
(
mappingItemJson
,
LogicQueueMappingItem
.
class
);
Assert
.
assertEquals
(
mappingItem
,
mappingItemFromJson
);
Assert
.
assertEquals
(
mappingItemJson
,
RemotingSerializable
.
toJson
(
mappingItemFromJson
,
false
));
}
TopicQueueMappingDetail
mappingDetail
=
new
TopicQueueMappingDetail
(
"test"
,
1
,
"broker01"
,
System
.
currentTimeMillis
());
...
...
@@ -48,6 +49,7 @@ public class TopicQueueMappingTest {
TopicQueueMappingDetail
mappingDetailFromJson
=
RemotingSerializable
.
decode
(
mappingDetailJson
.
getBytes
(),
TopicQueueMappingDetail
.
class
);
Assert
.
assertEquals
(
1
,
mappingDetailFromJson
.
getHostedQueues
().
size
());
Assert
.
assertEquals
(
1
,
mappingDetailFromJson
.
getHostedQueues
().
get
(
0
).
size
());
Assert
.
assertEquals
(
mappingItem
,
mappingDetailFromJson
.
getHostedQueues
().
get
(
0
).
get
(
0
));
Assert
.
assertEquals
(
mappingDetailJson
,
RemotingSerializable
.
toJson
(
mappingDetailFromJson
,
false
));
}
}
...
...
test/src/test/java/org/apache/rocketmq/test/smoke/StaticTopicIT.java
浏览文件 @
cb7e032f
...
...
@@ -6,6 +6,7 @@ import org.apache.rocketmq.common.rpc.ClientMetadata;
import
org.apache.rocketmq.common.statictopic.TopicConfigAndQueueMapping
;
import
org.apache.rocketmq.common.statictopic.TopicQueueMappingOne
;
import
org.apache.rocketmq.common.statictopic.TopicQueueMappingUtils
;
import
org.apache.rocketmq.common.statictopic.TopicRemappingDetailWrapper
;
import
org.apache.rocketmq.test.base.BaseConf
;
import
org.apache.rocketmq.test.util.MQRandomUtils
;
import
org.apache.rocketmq.tools.admin.DefaultMQAdminExt
;
...
...
@@ -16,6 +17,8 @@ import org.junit.FixMethodOrder;
import
org.junit.Test
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.Map
;
import
java.util.Set
;
...
...
@@ -42,32 +45,48 @@ public class StaticTopicIT extends BaseConf {
clientMetadata
.
refreshClusterInfo
(
clusterInfo
);
}
public
Map
<
String
,
TopicConfigAndQueueMapping
>
createStaticTopic
(
String
topic
,
int
queueNum
,
Set
<
String
>
targetBrokers
)
throws
Exception
{
Map
<
String
,
TopicConfigAndQueueMapping
>
brokerConfigMap
=
defaultMQAdminExt
.
examineTopicConfigAll
(
clientMetadata
,
topic
);
Assert
.
assertTrue
(
brokerConfigMap
.
isEmpty
());
TopicQueueMappingUtils
.
createTopicConfigMapping
(
topic
,
queueNum
,
targetBrokers
,
brokerConfigMap
);
//If some succeed, and others fail, it will cause inconsistent data
for
(
Map
.
Entry
<
String
,
TopicConfigAndQueueMapping
>
entry
:
brokerConfigMap
.
entrySet
())
{
String
broker
=
entry
.
getKey
();
String
addr
=
clientMetadata
.
findMasterBrokerAddr
(
broker
);
TopicConfigAndQueueMapping
configMapping
=
entry
.
getValue
();
defaultMQAdminExt
.
createStaticTopic
(
addr
,
defaultMQAdminExt
.
getCreateTopicKey
(),
configMapping
,
configMapping
.
getMappingDetail
(),
false
);
}
return
brokerConfigMap
;
}
@Test
public
void
testCreateStaticTopic
()
throws
Exception
{
public
void
testCreate
AndRemapping
StaticTopic
()
throws
Exception
{
String
topic
=
"static"
+
MQRandomUtils
.
getRandomTopic
();
int
queueNum
=
10
;
Set
<
String
>
brokers
=
getBrokers
();
//create topic
Map
<
String
,
TopicConfigAndQueueMapping
>
brokerConfigMap
=
createStaticTopic
(
topic
,
queueNum
,
getBrokers
());
{
Map
<
String
,
TopicConfigAndQueueMapping
>
brokerConfigMap
=
defaultMQAdminExt
.
examineTopicConfigAll
(
clientMetadata
,
topic
);
Assert
.
assertTrue
(
brokerConfigMap
.
isEmpty
());
TopicQueueMappingUtils
.
createTopicConfigMapping
(
topic
,
queueNum
,
getBrokers
(),
brokerConfigMap
);
//If some succeed, and others fail, it will cause inconsistent data
for
(
Map
.
Entry
<
String
,
TopicConfigAndQueueMapping
>
entry
:
brokerConfigMap
.
entrySet
())
{
Map
<
String
,
TopicConfigAndQueueMapping
>
brokerConfigMapFromRemote
=
defaultMQAdminExt
.
examineTopicConfigAll
(
clientMetadata
,
topic
);
Assert
.
assertEquals
(
2
,
brokerConfigMapFromRemote
.
size
());
for
(
Map
.
Entry
<
String
,
TopicConfigAndQueueMapping
>
entry:
brokerConfigMapFromRemote
.
entrySet
())
{
String
broker
=
entry
.
getKey
();
String
addr
=
clientMetadata
.
findMasterBrokerAddr
(
broker
);
TopicConfigAndQueueMapping
configMapping
=
entry
.
getValue
();
defaultMQAdminExt
.
createStaticTopic
(
addr
,
defaultMQAdminExt
.
getCreateTopicKey
(),
configMapping
,
configMapping
.
getMappingDetail
(),
false
);
TopicConfigAndQueueMapping
configMappingLocal
=
brokerConfigMap
.
get
(
broker
);
Assert
.
assertNotNull
(
configMappingLocal
);
Assert
.
assertEquals
(
configMapping
,
configMappingLocal
);
}
TopicQueueMappingUtils
.
checkConsistenceOfTopicConfigAndQueueMapping
(
topic
,
brokerConfigMapFromRemote
);
Map
<
Integer
,
TopicQueueMappingOne
>
globalIdMap
=
TopicQueueMappingUtils
.
checkAndBuildMappingItems
(
new
ArrayList
<>(
getMappingDetailFromConfig
(
brokerConfigMapFromRemote
.
values
())),
false
,
true
);
Assert
.
assertEquals
(
queueNum
,
globalIdMap
.
size
());
}
Map
<
String
,
TopicConfigAndQueueMapping
>
brokerConfigMap
=
defaultMQAdminExt
.
examineTopicConfigAll
(
clientMetadata
,
topic
);
TopicQueueMappingUtils
.
checkConsistenceOfTopicConfigAndQueueMapping
(
topic
,
brokerConfigMap
);
Map
<
Integer
,
TopicQueueMappingOne
>
globalIdMap
=
TopicQueueMappingUtils
.
checkAndBuildMappingItems
(
new
ArrayList
<>(
getMappingDetailFromConfig
(
brokerConfigMap
.
values
())),
false
,
true
);
Assert
.
assertEquals
(
queueNum
,
globalIdMap
.
size
());
/*{
Set<String> targetBrokers = Collections.singleton(broker1Name);
Map<String, TopicConfigAndQueueMapping> brokerConfigMapFromRemote = defaultMQAdminExt.examineTopicConfigAll(clientMetadata, topic);
TopicRemappingDetailWrapper wrapper = TopicQueueMappingUtils.remappingStaticTopic(topic, brokerConfigMapFromRemote, targetBrokers);
}*/
}
@After
public
void
tearDown
()
{
super
.
shutdown
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录