Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Kwan的解忧杂货铺@新空间代码工作室
Rocketmq
提交
a9addc3c
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看板
提交
a9addc3c
编写于
12月 08, 2021
作者:
D
dongeforever
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add tests for command
上级
48db31b4
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
147 addition
and
25 deletion
+147
-25
broker/src/main/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessor.java
...pache/rocketmq/broker/processor/AdminBrokerProcessor.java
+1
-1
broker/src/main/java/org/apache/rocketmq/broker/topic/TopicQueueMappingCleanService.java
.../rocketmq/broker/topic/TopicQueueMappingCleanService.java
+2
-1
client/src/main/java/org/apache/rocketmq/client/impl/MQClientAPIImpl.java
...java/org/apache/rocketmq/client/impl/MQClientAPIImpl.java
+1
-1
common/src/main/java/org/apache/rocketmq/common/protocol/header/GetTopicConfigRequestHeader.java
...q/common/protocol/header/GetTopicConfigRequestHeader.java
+2
-10
test/src/main/java/org/apache/rocketmq/test/util/MQAdminTestUtils.java
.../java/org/apache/rocketmq/test/util/MQAdminTestUtils.java
+74
-0
test/src/test/java/org/apache/rocketmq/test/statictopic/StaticTopicIT.java
...a/org/apache/rocketmq/test/statictopic/StaticTopicIT.java
+59
-8
tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExtImpl.java
...rg/apache/rocketmq/tools/admin/DefaultMQAdminExtImpl.java
+1
-0
tools/src/main/java/org/apache/rocketmq/tools/command/topic/RemappingStaticTopicSubCommand.java
...q/tools/command/topic/RemappingStaticTopicSubCommand.java
+5
-3
tools/src/main/java/org/apache/rocketmq/tools/command/topic/UpdateStaticTopicSubCommand.java
...etmq/tools/command/topic/UpdateStaticTopicSubCommand.java
+2
-1
未找到文件。
broker/src/main/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessor.java
浏览文件 @
a9addc3c
...
@@ -1996,7 +1996,7 @@ public class AdminBrokerProcessor extends AsyncNettyRequestProcessor implements
...
@@ -1996,7 +1996,7 @@ public class AdminBrokerProcessor extends AsyncNettyRequestProcessor implements
return
response
;
return
response
;
}
}
TopicQueueMappingDetail
topicQueueMappingDetail
=
null
;
TopicQueueMappingDetail
topicQueueMappingDetail
=
null
;
if
(
Boolean
.
TRUE
.
equals
(
requestHeader
.
get
WithMapping
()))
{
if
(
Boolean
.
TRUE
.
equals
(
requestHeader
.
get
Lo
()))
{
topicQueueMappingDetail
=
this
.
brokerController
.
getTopicQueueMappingManager
().
getTopicQueueMapping
(
requestHeader
.
getTopic
());
topicQueueMappingDetail
=
this
.
brokerController
.
getTopicQueueMappingManager
().
getTopicQueueMapping
(
requestHeader
.
getTopic
());
}
}
String
content
=
JSONObject
.
toJSONString
(
new
TopicConfigAndQueueMapping
(
topicConfig
,
topicQueueMappingDetail
));
String
content
=
JSONObject
.
toJSONString
(
new
TopicConfigAndQueueMapping
(
topicConfig
,
topicQueueMappingDetail
));
...
...
broker/src/main/java/org/apache/rocketmq/broker/topic/TopicQueueMappingCleanService.java
浏览文件 @
a9addc3c
...
@@ -134,6 +134,7 @@ public class TopicQueueMappingCleanService extends ServiceThread {
...
@@ -134,6 +134,7 @@ public class TopicQueueMappingCleanService extends ServiceThread {
GetTopicStatsInfoRequestHeader
header
=
new
GetTopicStatsInfoRequestHeader
();
GetTopicStatsInfoRequestHeader
header
=
new
GetTopicStatsInfoRequestHeader
();
header
.
setTopic
(
topic
);
header
.
setTopic
(
topic
);
header
.
setBname
(
broker
);
header
.
setBname
(
broker
);
header
.
setLo
(
false
);
try
{
try
{
RpcRequest
rpcRequest
=
new
RpcRequest
(
RequestCode
.
GET_TOPIC_STATS_INFO
,
header
,
null
);
RpcRequest
rpcRequest
=
new
RpcRequest
(
RequestCode
.
GET_TOPIC_STATS_INFO
,
header
,
null
);
RpcResponse
rpcResponse
=
rpcClient
.
invoke
(
rpcRequest
,
brokerConfig
.
getForwardTimeout
()).
get
();
RpcResponse
rpcResponse
=
rpcClient
.
invoke
(
rpcRequest
,
brokerConfig
.
getForwardTimeout
()).
get
();
...
@@ -261,7 +262,7 @@ public class TopicQueueMappingCleanService extends ServiceThread {
...
@@ -261,7 +262,7 @@ public class TopicQueueMappingCleanService extends ServiceThread {
GetTopicConfigRequestHeader
header
=
new
GetTopicConfigRequestHeader
();
GetTopicConfigRequestHeader
header
=
new
GetTopicConfigRequestHeader
();
header
.
setTopic
(
topic
);
header
.
setTopic
(
topic
);
header
.
setBname
(
broker
);
header
.
setBname
(
broker
);
header
.
set
WithMapping
(
true
);
header
.
set
Lo
(
true
);
try
{
try
{
RpcRequest
rpcRequest
=
new
RpcRequest
(
RequestCode
.
GET_TOPIC_CONFIG
,
header
,
null
);
RpcRequest
rpcRequest
=
new
RpcRequest
(
RequestCode
.
GET_TOPIC_CONFIG
,
header
,
null
);
RpcResponse
rpcResponse
=
rpcClient
.
invoke
(
rpcRequest
,
brokerConfig
.
getForwardTimeout
()).
get
();
RpcResponse
rpcResponse
=
rpcClient
.
invoke
(
rpcRequest
,
brokerConfig
.
getForwardTimeout
()).
get
();
...
...
client/src/main/java/org/apache/rocketmq/client/impl/MQClientAPIImpl.java
浏览文件 @
a9addc3c
...
@@ -2581,7 +2581,7 @@ public class MQClientAPIImpl {
...
@@ -2581,7 +2581,7 @@ public class MQClientAPIImpl {
RemotingTimeoutException
,
RemotingSendRequestException
,
RemotingConnectException
,
MQBrokerException
{
RemotingTimeoutException
,
RemotingSendRequestException
,
RemotingConnectException
,
MQBrokerException
{
GetTopicConfigRequestHeader
header
=
new
GetTopicConfigRequestHeader
();
GetTopicConfigRequestHeader
header
=
new
GetTopicConfigRequestHeader
();
header
.
setTopic
(
topic
);
header
.
setTopic
(
topic
);
header
.
set
WithMapping
(
true
);
header
.
set
Lo
(
true
);
RemotingCommand
request
=
RemotingCommand
.
createRequestCommand
(
RequestCode
.
GET_TOPIC_CONFIG
,
header
);
RemotingCommand
request
=
RemotingCommand
.
createRequestCommand
(
RequestCode
.
GET_TOPIC_CONFIG
,
header
);
RemotingCommand
response
=
this
.
remotingClient
RemotingCommand
response
=
this
.
remotingClient
.
invokeSync
(
MixAll
.
brokerVIPChannel
(
this
.
clientConfig
.
isVipChannelEnabled
(),
brokerAddr
),
request
,
timeoutMillis
);
.
invokeSync
(
MixAll
.
brokerVIPChannel
(
this
.
clientConfig
.
isVipChannelEnabled
(),
brokerAddr
),
request
,
timeoutMillis
);
...
...
common/src/main/java/org/apache/rocketmq/common/protocol/header/GetTopicConfigRequestHeader.java
浏览文件 @
a9addc3c
...
@@ -18,11 +18,12 @@
...
@@ -18,11 +18,12 @@
package
org.apache.rocketmq.common.protocol.header
;
package
org.apache.rocketmq.common.protocol.header
;
import
org.apache.rocketmq.common.rpc.RpcRequestHeader
;
import
org.apache.rocketmq.common.rpc.RpcRequestHeader
;
import
org.apache.rocketmq.common.rpc.TopicRequestHeader
;
import
org.apache.rocketmq.remoting.CommandCustomHeader
;
import
org.apache.rocketmq.remoting.CommandCustomHeader
;
import
org.apache.rocketmq.remoting.annotation.CFNotNull
;
import
org.apache.rocketmq.remoting.annotation.CFNotNull
;
import
org.apache.rocketmq.remoting.exception.RemotingCommandException
;
import
org.apache.rocketmq.remoting.exception.RemotingCommandException
;
public
class
GetTopicConfigRequestHeader
extends
Rp
cRequestHeader
{
public
class
GetTopicConfigRequestHeader
extends
Topi
cRequestHeader
{
@Override
@Override
public
void
checkFields
()
throws
RemotingCommandException
{
public
void
checkFields
()
throws
RemotingCommandException
{
}
}
...
@@ -30,7 +31,6 @@ public class GetTopicConfigRequestHeader extends RpcRequestHeader {
...
@@ -30,7 +31,6 @@ public class GetTopicConfigRequestHeader extends RpcRequestHeader {
@CFNotNull
@CFNotNull
private
String
topic
;
private
String
topic
;
private
Boolean
withMapping
;
/**
/**
* @return the topic
* @return the topic
...
@@ -45,12 +45,4 @@ public class GetTopicConfigRequestHeader extends RpcRequestHeader {
...
@@ -45,12 +45,4 @@ public class GetTopicConfigRequestHeader extends RpcRequestHeader {
public
void
setTopic
(
String
topic
)
{
public
void
setTopic
(
String
topic
)
{
this
.
topic
=
topic
;
this
.
topic
=
topic
;
}
}
public
Boolean
getWithMapping
()
{
return
withMapping
;
}
public
void
setWithMapping
(
Boolean
withMapping
)
{
this
.
withMapping
=
withMapping
;
}
}
}
\ No newline at end of file
test/src/main/java/org/apache/rocketmq/test/util/MQAdminTestUtils.java
浏览文件 @
a9addc3c
...
@@ -22,9 +22,16 @@ import java.util.Map;
...
@@ -22,9 +22,16 @@ import java.util.Map;
import
java.util.Set
;
import
java.util.Set
;
import
java.util.UUID
;
import
java.util.UUID
;
import
java.util.concurrent.ForkJoinPool
;
import
java.util.concurrent.ForkJoinPool
;
import
java.util.stream.Collectors
;
import
org.apache.commons.cli.CommandLine
;
import
org.apache.commons.cli.Options
;
import
org.apache.commons.cli.PosixParser
;
import
org.apache.log4j.Logger
;
import
org.apache.log4j.Logger
;
import
org.apache.rocketmq.acl.common.AclUtils
;
import
org.apache.rocketmq.client.exception.MQBrokerException
;
import
org.apache.rocketmq.client.exception.MQBrokerException
;
import
org.apache.rocketmq.client.exception.MQClientException
;
import
org.apache.rocketmq.client.exception.MQClientException
;
import
org.apache.rocketmq.common.MixAll
;
import
org.apache.rocketmq.common.admin.TopicStatsTable
;
import
org.apache.rocketmq.common.admin.TopicStatsTable
;
import
org.apache.rocketmq.common.protocol.body.ClusterInfo
;
import
org.apache.rocketmq.common.protocol.body.ClusterInfo
;
import
org.apache.rocketmq.common.protocol.route.BrokerData
;
import
org.apache.rocketmq.common.protocol.route.BrokerData
;
...
@@ -34,9 +41,16 @@ import org.apache.rocketmq.common.statictopic.TopicQueueMappingUtils;
...
@@ -34,9 +41,16 @@ import org.apache.rocketmq.common.statictopic.TopicQueueMappingUtils;
import
org.apache.rocketmq.common.statictopic.TopicRemappingDetailWrapper
;
import
org.apache.rocketmq.common.statictopic.TopicRemappingDetailWrapper
;
import
org.apache.rocketmq.common.subscription.SubscriptionGroupConfig
;
import
org.apache.rocketmq.common.subscription.SubscriptionGroupConfig
;
import
org.apache.rocketmq.remoting.exception.RemotingException
;
import
org.apache.rocketmq.remoting.exception.RemotingException
;
import
org.apache.rocketmq.srvutil.ServerUtil
;
import
org.apache.rocketmq.test.client.rmq.RMQNormalConsumer
;
import
org.apache.rocketmq.test.client.rmq.RMQNormalProducer
;
import
org.apache.rocketmq.test.listener.rmq.concurrent.RMQNormalListener
;
import
org.apache.rocketmq.tools.admin.DefaultMQAdminExt
;
import
org.apache.rocketmq.tools.admin.DefaultMQAdminExt
;
import
org.apache.rocketmq.tools.admin.MQAdminUtils
;
import
org.apache.rocketmq.tools.admin.MQAdminUtils
;
import
org.apache.rocketmq.tools.command.CommandUtil
;
import
org.apache.rocketmq.tools.command.CommandUtil
;
import
org.apache.rocketmq.tools.command.MQAdminStartup
;
import
org.apache.rocketmq.tools.command.topic.RemappingStaticTopicSubCommand
;
import
org.apache.rocketmq.tools.command.topic.UpdateStaticTopicSubCommand
;
public
class
MQAdminTestUtils
{
public
class
MQAdminTestUtils
{
private
static
Logger
log
=
Logger
.
getLogger
(
MQAdminTestUtils
.
class
);
private
static
Logger
log
=
Logger
.
getLogger
(
MQAdminTestUtils
.
class
);
...
@@ -231,5 +245,65 @@ public class MQAdminTestUtils {
...
@@ -231,5 +245,65 @@ public class MQAdminTestUtils {
}
}
public
static
void
createStaticTopicWithCommand
(
String
topic
,
int
queueNum
,
Set
<
String
>
brokers
,
String
cluster
,
String
nameservers
)
throws
Exception
{
UpdateStaticTopicSubCommand
cmd
=
new
UpdateStaticTopicSubCommand
();
Options
options
=
ServerUtil
.
buildCommandlineOptions
(
new
Options
());
String
[]
args
;
if
(
cluster
!=
null
)
{
args
=
new
String
[]
{
"-c"
,
cluster
,
"-t"
,
topic
,
"-qn"
,
String
.
valueOf
(
queueNum
),
"-n"
,
nameservers
};
}
else
{
String
brokerStr
=
String
.
join
(
","
,
brokers
);
args
=
new
String
[]
{
"-b"
,
brokerStr
,
"-t"
,
topic
,
"-qn"
,
String
.
valueOf
(
queueNum
),
"-n"
,
nameservers
};
}
final
CommandLine
commandLine
=
ServerUtil
.
parseCmdLine
(
"mqadmin "
+
cmd
.
commandName
(),
args
,
cmd
.
buildCommandlineOptions
(
options
),
new
PosixParser
());
if
(
null
==
commandLine
)
{
return
;
}
if
(
commandLine
.
hasOption
(
'n'
))
{
String
namesrvAddr
=
commandLine
.
getOptionValue
(
'n'
);
System
.
setProperty
(
MixAll
.
NAMESRV_ADDR_PROPERTY
,
namesrvAddr
);
}
cmd
.
execute
(
commandLine
,
options
,
null
);
}
public
static
void
remappingStaticTopicWithCommand
(
String
topic
,
Set
<
String
>
brokers
,
String
cluster
,
String
nameservers
)
throws
Exception
{
RemappingStaticTopicSubCommand
cmd
=
new
RemappingStaticTopicSubCommand
();
Options
options
=
ServerUtil
.
buildCommandlineOptions
(
new
Options
());
String
[]
args
;
if
(
cluster
!=
null
)
{
args
=
new
String
[]
{
"-c"
,
cluster
,
"-t"
,
topic
,
"-n"
,
nameservers
};
}
else
{
String
brokerStr
=
String
.
join
(
","
,
brokers
);
args
=
new
String
[]
{
"-b"
,
brokerStr
,
"-t"
,
topic
,
"-n"
,
nameservers
};
}
final
CommandLine
commandLine
=
ServerUtil
.
parseCmdLine
(
"mqadmin "
+
cmd
.
commandName
(),
args
,
cmd
.
buildCommandlineOptions
(
options
),
new
PosixParser
());
if
(
null
==
commandLine
)
{
return
;
}
if
(
commandLine
.
hasOption
(
'n'
))
{
String
namesrvAddr
=
commandLine
.
getOptionValue
(
'n'
);
System
.
setProperty
(
MixAll
.
NAMESRV_ADDR_PROPERTY
,
namesrvAddr
);
}
cmd
.
execute
(
commandLine
,
options
,
null
);
}
}
}
test/src/test/java/org/apache/rocketmq/test/statictopic/StaticTopicIT.java
浏览文件 @
a9addc3c
...
@@ -2,7 +2,11 @@ package org.apache.rocketmq.test.statictopic;
...
@@ -2,7 +2,11 @@ package org.apache.rocketmq.test.statictopic;
import
com.google.common.collect.ImmutableList
;
import
com.google.common.collect.ImmutableList
;
import
com.google.common.collect.ImmutableSet
;
import
com.google.common.collect.ImmutableSet
;
import
org.apache.commons.cli.CommandLine
;
import
org.apache.commons.cli.Options
;
import
org.apache.commons.cli.PosixParser
;
import
org.apache.log4j.Logger
;
import
org.apache.log4j.Logger
;
import
org.apache.rocketmq.acl.common.AclUtils
;
import
org.apache.rocketmq.broker.BrokerController
;
import
org.apache.rocketmq.broker.BrokerController
;
import
org.apache.rocketmq.common.MixAll
;
import
org.apache.rocketmq.common.MixAll
;
import
org.apache.rocketmq.common.admin.ConsumeStats
;
import
org.apache.rocketmq.common.admin.ConsumeStats
;
...
@@ -14,6 +18,7 @@ import org.apache.rocketmq.common.statictopic.LogicQueueMappingItem;
...
@@ -14,6 +18,7 @@ import org.apache.rocketmq.common.statictopic.LogicQueueMappingItem;
import
org.apache.rocketmq.common.statictopic.TopicConfigAndQueueMapping
;
import
org.apache.rocketmq.common.statictopic.TopicConfigAndQueueMapping
;
import
org.apache.rocketmq.common.statictopic.TopicQueueMappingOne
;
import
org.apache.rocketmq.common.statictopic.TopicQueueMappingOne
;
import
org.apache.rocketmq.common.statictopic.TopicQueueMappingUtils
;
import
org.apache.rocketmq.common.statictopic.TopicQueueMappingUtils
;
import
org.apache.rocketmq.srvutil.ServerUtil
;
import
org.apache.rocketmq.test.base.BaseConf
;
import
org.apache.rocketmq.test.base.BaseConf
;
import
org.apache.rocketmq.test.client.rmq.RMQNormalConsumer
;
import
org.apache.rocketmq.test.client.rmq.RMQNormalConsumer
;
import
org.apache.rocketmq.test.client.rmq.RMQNormalProducer
;
import
org.apache.rocketmq.test.client.rmq.RMQNormalProducer
;
...
@@ -23,10 +28,12 @@ import org.apache.rocketmq.test.util.MQRandomUtils;
...
@@ -23,10 +28,12 @@ import org.apache.rocketmq.test.util.MQRandomUtils;
import
org.apache.rocketmq.test.util.VerifyUtils
;
import
org.apache.rocketmq.test.util.VerifyUtils
;
import
org.apache.rocketmq.tools.admin.DefaultMQAdminExt
;
import
org.apache.rocketmq.tools.admin.DefaultMQAdminExt
;
import
org.apache.rocketmq.tools.admin.MQAdminUtils
;
import
org.apache.rocketmq.tools.admin.MQAdminUtils
;
import
org.apache.rocketmq.tools.command.MQAdminStartup
;
import
org.junit.After
;
import
org.junit.After
;
import
org.junit.Assert
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Before
;
import
org.junit.FixMethodOrder
;
import
org.junit.FixMethodOrder
;
import
org.junit.Ignore
;
import
org.junit.Test
;
import
org.junit.Test
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
...
@@ -56,6 +63,51 @@ public class StaticTopicIT extends BaseConf {
...
@@ -56,6 +63,51 @@ public class StaticTopicIT extends BaseConf {
defaultMQAdminExt
.
start
();
defaultMQAdminExt
.
start
();
}
}
@Test
public
void
testCommandsWithCluster
()
throws
Exception
{
//This case is used to mock the env to test the command manually
String
topic
=
"static"
+
MQRandomUtils
.
getRandomTopic
();
RMQNormalProducer
producer
=
getProducer
(
nsAddr
,
topic
);
RMQNormalConsumer
consumer
=
getConsumer
(
nsAddr
,
topic
,
"*"
,
new
RMQNormalListener
());
int
queueNum
=
10
;
int
msgEachQueue
=
100
;
{
MQAdminTestUtils
.
createStaticTopicWithCommand
(
topic
,
queueNum
,
null
,
clusterName
,
nsAddr
);
sendMessagesAndCheck
(
producer
,
getBrokers
(),
topic
,
queueNum
,
msgEachQueue
,
0
);
//consume and check
consumeMessagesAndCheck
(
producer
,
consumer
,
topic
,
queueNum
,
msgEachQueue
,
0
,
1
);
}
{
MQAdminTestUtils
.
remappingStaticTopicWithCommand
(
topic
,
null
,
clusterName
,
nsAddr
);
Thread
.
sleep
(
500
);
sendMessagesAndCheck
(
producer
,
getBrokers
(),
topic
,
queueNum
,
msgEachQueue
,
100
);
}
}
@Test
public
void
testCommandsWithBrokers
()
throws
Exception
{
//This case is used to mock the env to test the command manually
String
topic
=
"static"
+
MQRandomUtils
.
getRandomTopic
();
RMQNormalProducer
producer
=
getProducer
(
nsAddr
,
topic
);
RMQNormalConsumer
consumer
=
getConsumer
(
nsAddr
,
topic
,
"*"
,
new
RMQNormalListener
());
int
queueNum
=
10
;
int
msgEachQueue
=
100
;
{
Set
<
String
>
brokers
=
ImmutableSet
.
of
(
broker1Name
);
MQAdminTestUtils
.
createStaticTopicWithCommand
(
topic
,
queueNum
,
brokers
,
null
,
nsAddr
);
sendMessagesAndCheck
(
producer
,
brokers
,
topic
,
queueNum
,
msgEachQueue
,
0
);
//consume and check
consumeMessagesAndCheck
(
producer
,
consumer
,
topic
,
queueNum
,
msgEachQueue
,
0
,
1
);
}
{
Set
<
String
>
brokers
=
ImmutableSet
.
of
(
broker2Name
);
MQAdminTestUtils
.
remappingStaticTopicWithCommand
(
topic
,
brokers
,
null
,
nsAddr
);
Thread
.
sleep
(
500
);
sendMessagesAndCheck
(
producer
,
brokers
,
topic
,
queueNum
,
msgEachQueue
,
TopicQueueMappingUtils
.
DEFAULT_BLOCK_SEQ_SIZE
);
consumeMessagesAndCheck
(
producer
,
consumer
,
topic
,
queueNum
,
msgEachQueue
,
0
,
2
);
}
}
@Test
@Test
public
void
testNoTargetBrokers
()
throws
Exception
{
public
void
testNoTargetBrokers
()
throws
Exception
{
...
@@ -89,7 +141,7 @@ public class StaticTopicIT extends BaseConf {
...
@@ -89,7 +141,7 @@ public class StaticTopicIT extends BaseConf {
}
}
private
void
sendMessagesAndCheck
(
RMQNormalProducer
producer
,
Set
<
String
>
targetBrokers
,
String
topic
,
int
queueNum
,
int
msgEachQueue
,
int
gen
)
throws
Exception
{
private
void
sendMessagesAndCheck
(
RMQNormalProducer
producer
,
Set
<
String
>
targetBrokers
,
String
topic
,
int
queueNum
,
int
msgEachQueue
,
long
baseOffset
)
throws
Exception
{
ClientMetadata
clientMetadata
=
MQAdminUtils
.
getBrokerAndTopicMetadata
(
topic
,
defaultMQAdminExt
);
ClientMetadata
clientMetadata
=
MQAdminUtils
.
getBrokerAndTopicMetadata
(
topic
,
defaultMQAdminExt
);
List
<
MessageQueue
>
messageQueueList
=
producer
.
getMessageQueue
();
List
<
MessageQueue
>
messageQueueList
=
producer
.
getMessageQueue
();
Assert
.
assertEquals
(
queueNum
,
messageQueueList
.
size
());
Assert
.
assertEquals
(
queueNum
,
messageQueueList
.
size
());
...
@@ -109,12 +161,12 @@ public class StaticTopicIT extends BaseConf {
...
@@ -109,12 +161,12 @@ public class StaticTopicIT extends BaseConf {
Thread
.
sleep
(
100
);
Thread
.
sleep
(
100
);
for
(
MessageQueue
messageQueue:
messageQueueList
)
{
for
(
MessageQueue
messageQueue:
messageQueueList
)
{
Assert
.
assertEquals
(
0
,
defaultMQAdminExt
.
minOffset
(
messageQueue
));
Assert
.
assertEquals
(
0
,
defaultMQAdminExt
.
minOffset
(
messageQueue
));
Assert
.
assertEquals
(
msgEachQueue
+
gen
*
TopicQueueMappingUtils
.
DEFAULT_BLOCK_SEQ_SIZE
,
defaultMQAdminExt
.
maxOffset
(
messageQueue
));
Assert
.
assertEquals
(
msgEachQueue
+
baseOffset
,
defaultMQAdminExt
.
maxOffset
(
messageQueue
));
}
}
TopicStatsTable
topicStatsTable
=
defaultMQAdminExt
.
examineTopicStats
(
topic
);
TopicStatsTable
topicStatsTable
=
defaultMQAdminExt
.
examineTopicStats
(
topic
);
for
(
MessageQueue
messageQueue:
messageQueueList
)
{
for
(
MessageQueue
messageQueue:
messageQueueList
)
{
Assert
.
assertEquals
(
0
,
topicStatsTable
.
getOffsetTable
().
get
(
messageQueue
).
getMinOffset
());
Assert
.
assertEquals
(
0
,
topicStatsTable
.
getOffsetTable
().
get
(
messageQueue
).
getMinOffset
());
Assert
.
assertEquals
(
msgEachQueue
+
gen
*
TopicQueueMappingUtils
.
DEFAULT_BLOCK_SEQ_SIZE
,
topicStatsTable
.
getOffsetTable
().
get
(
messageQueue
).
getMaxOffset
());
Assert
.
assertEquals
(
msgEachQueue
+
baseOffset
,
topicStatsTable
.
getOffsetTable
().
get
(
messageQueue
).
getMaxOffset
());
}
}
}
}
...
@@ -214,7 +266,6 @@ public class StaticTopicIT extends BaseConf {
...
@@ -214,7 +266,6 @@ public class StaticTopicIT extends BaseConf {
sendMessagesAndCheck
(
producer
,
targetBrokers
,
topic
,
queueNum
,
msgEachQueue
,
0
);
sendMessagesAndCheck
(
producer
,
targetBrokers
,
topic
,
queueNum
,
msgEachQueue
,
0
);
consumeMessagesAndCheck
(
producer
,
consumer
,
topic
,
queueNum
,
msgEachQueue
,
0
,
1
);
consumeMessagesAndCheck
(
producer
,
consumer
,
topic
,
queueNum
,
msgEachQueue
,
0
,
1
);
}
}
System
.
out
.
println
(
"============================================================="
);
//remapping the static topic
//remapping the static topic
{
{
Set
<
String
>
targetBrokers
=
ImmutableSet
.
of
(
broker2Name
);
Set
<
String
>
targetBrokers
=
ImmutableSet
.
of
(
broker2Name
);
...
@@ -228,7 +279,7 @@ public class StaticTopicIT extends BaseConf {
...
@@ -228,7 +279,7 @@ public class StaticTopicIT extends BaseConf {
Assert
.
assertEquals
(
TopicQueueMappingUtils
.
DEFAULT_BLOCK_SEQ_SIZE
,
mappingOne
.
getItems
().
get
(
mappingOne
.
getItems
().
size
()
-
1
).
getLogicOffset
());
Assert
.
assertEquals
(
TopicQueueMappingUtils
.
DEFAULT_BLOCK_SEQ_SIZE
,
mappingOne
.
getItems
().
get
(
mappingOne
.
getItems
().
size
()
-
1
).
getLogicOffset
());
}
}
Thread
.
sleep
(
500
);
Thread
.
sleep
(
500
);
sendMessagesAndCheck
(
producer
,
targetBrokers
,
topic
,
queueNum
,
msgEachQueue
,
1
);
sendMessagesAndCheck
(
producer
,
targetBrokers
,
topic
,
queueNum
,
msgEachQueue
,
TopicQueueMappingUtils
.
DEFAULT_BLOCK_SEQ_SIZE
);
consumeMessagesAndCheck
(
producer
,
consumer
,
topic
,
queueNum
,
msgEachQueue
,
0
,
2
);
consumeMessagesAndCheck
(
producer
,
consumer
,
topic
,
queueNum
,
msgEachQueue
,
0
,
2
);
}
}
}
}
...
@@ -261,7 +312,7 @@ public class StaticTopicIT extends BaseConf {
...
@@ -261,7 +312,7 @@ public class StaticTopicIT extends BaseConf {
MQAdminTestUtils
.
remappingStaticTopic
(
topic
,
targetBrokers
,
defaultMQAdminExt
);
MQAdminTestUtils
.
remappingStaticTopic
(
topic
,
targetBrokers
,
defaultMQAdminExt
);
//make the metadata
//make the metadata
Thread
.
sleep
(
500
);
Thread
.
sleep
(
500
);
sendMessagesAndCheck
(
producer
,
targetBrokers
,
topic
,
queueNum
,
msgEachQueue
,
i
+
1
);
sendMessagesAndCheck
(
producer
,
targetBrokers
,
topic
,
queueNum
,
msgEachQueue
,
(
i
+
1
)
*
TopicQueueMappingUtils
.
DEFAULT_BLOCK_SEQ_SIZE
);
}
}
consumer
=
getConsumer
(
nsAddr
,
group
,
topic
,
"*"
,
new
RMQNormalListener
());
consumer
=
getConsumer
(
nsAddr
,
group
,
topic
,
"*"
,
new
RMQNormalListener
());
consumeMessagesAndCheck
(
producer
,
consumer
,
topic
,
queueNum
,
msgEachQueue
,
1
,
brokers
.
size
());
consumeMessagesAndCheck
(
producer
,
consumer
,
topic
,
queueNum
,
msgEachQueue
,
1
,
brokers
.
size
());
...
@@ -289,7 +340,7 @@ public class StaticTopicIT extends BaseConf {
...
@@ -289,7 +340,7 @@ public class StaticTopicIT extends BaseConf {
MQAdminTestUtils
.
remappingStaticTopic
(
topic
,
targetBrokers
,
defaultMQAdminExt
);
MQAdminTestUtils
.
remappingStaticTopic
(
topic
,
targetBrokers
,
defaultMQAdminExt
);
//leave the time to refresh the metadata
//leave the time to refresh the metadata
Thread
.
sleep
(
500
);
Thread
.
sleep
(
500
);
sendMessagesAndCheck
(
producer
,
targetBrokers
,
topic
,
queueNum
,
msgEachQueue
,
1
);
sendMessagesAndCheck
(
producer
,
targetBrokers
,
topic
,
queueNum
,
msgEachQueue
,
1
*
TopicQueueMappingUtils
.
DEFAULT_BLOCK_SEQ_SIZE
);
}
}
//remapping to broker3Name
//remapping to broker3Name
...
@@ -298,7 +349,7 @@ public class StaticTopicIT extends BaseConf {
...
@@ -298,7 +349,7 @@ public class StaticTopicIT extends BaseConf {
MQAdminTestUtils
.
remappingStaticTopic
(
topic
,
targetBrokers
,
defaultMQAdminExt
);
MQAdminTestUtils
.
remappingStaticTopic
(
topic
,
targetBrokers
,
defaultMQAdminExt
);
//leave the time to refresh the metadata
//leave the time to refresh the metadata
Thread
.
sleep
(
500
);
Thread
.
sleep
(
500
);
sendMessagesAndCheck
(
producer
,
targetBrokers
,
topic
,
queueNum
,
msgEachQueue
,
2
);
sendMessagesAndCheck
(
producer
,
targetBrokers
,
topic
,
queueNum
,
msgEachQueue
,
2
*
TopicQueueMappingUtils
.
DEFAULT_BLOCK_SEQ_SIZE
);
}
}
// 1 -> 2 -> 3, currently 1 should not has any mappings
// 1 -> 2 -> 3, currently 1 should not has any mappings
...
...
tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExtImpl.java
浏览文件 @
a9addc3c
...
@@ -268,6 +268,7 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner {
...
@@ -268,6 +268,7 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner {
}
}
}
}
if
(
topicStatsTable
.
getOffsetTable
().
isEmpty
())
{
if
(
topicStatsTable
.
getOffsetTable
().
isEmpty
())
{
throw
new
MQClientException
(
"Not found the topic stats info"
,
null
);
throw
new
MQClientException
(
"Not found the topic stats info"
,
null
);
}
}
...
...
tools/src/main/java/org/apache/rocketmq/tools/command/topic/RemappingStaticTopicSubCommand.java
浏览文件 @
a9addc3c
...
@@ -20,13 +20,12 @@ import org.apache.commons.cli.CommandLine;
...
@@ -20,13 +20,12 @@ import org.apache.commons.cli.CommandLine;
import
org.apache.commons.cli.Option
;
import
org.apache.commons.cli.Option
;
import
org.apache.commons.cli.OptionGroup
;
import
org.apache.commons.cli.OptionGroup
;
import
org.apache.commons.cli.Options
;
import
org.apache.commons.cli.Options
;
import
org.apache.rocketmq.client.MQAdmin
;
import
org.apache.rocketmq.common.MixAll
;
import
org.apache.rocketmq.common.MixAll
;
import
org.apache.rocketmq.common.protocol.body.ClusterInfo
;
import
org.apache.rocketmq.common.rpc.ClientMetadata
;
import
org.apache.rocketmq.common.statictopic.TopicConfigAndQueueMapping
;
import
org.apache.rocketmq.common.statictopic.TopicConfigAndQueueMapping
;
import
org.apache.rocketmq.common.statictopic.TopicQueueMappingOne
;
import
org.apache.rocketmq.common.statictopic.TopicQueueMappingOne
;
import
org.apache.rocketmq.common.statictopic.TopicQueueMappingUtils
;
import
org.apache.rocketmq.common.statictopic.TopicQueueMappingUtils
;
import
org.apache.rocketmq.common.protocol.body.ClusterInfo
;
import
org.apache.rocketmq.common.rpc.ClientMetadata
;
import
org.apache.rocketmq.common.statictopic.TopicRemappingDetailWrapper
;
import
org.apache.rocketmq.common.statictopic.TopicRemappingDetailWrapper
;
import
org.apache.rocketmq.remoting.RPCHook
;
import
org.apache.rocketmq.remoting.RPCHook
;
import
org.apache.rocketmq.srvutil.ServerUtil
;
import
org.apache.rocketmq.srvutil.ServerUtil
;
...
@@ -91,6 +90,7 @@ public class RemappingStaticTopicSubCommand implements SubCommand {
...
@@ -91,6 +90,7 @@ public class RemappingStaticTopicSubCommand implements SubCommand {
defaultMQAdminExt
.
setInstanceName
(
Long
.
toString
(
System
.
currentTimeMillis
()));
defaultMQAdminExt
.
setInstanceName
(
Long
.
toString
(
System
.
currentTimeMillis
()));
try
{
try
{
defaultMQAdminExt
.
start
();
String
topic
=
commandLine
.
getOptionValue
(
't'
).
trim
();
String
topic
=
commandLine
.
getOptionValue
(
't'
).
trim
();
String
mapFileName
=
commandLine
.
getOptionValue
(
'f'
).
trim
();
String
mapFileName
=
commandLine
.
getOptionValue
(
'f'
).
trim
();
...
@@ -137,6 +137,7 @@ public class RemappingStaticTopicSubCommand implements SubCommand {
...
@@ -137,6 +137,7 @@ public class RemappingStaticTopicSubCommand implements SubCommand {
Set
<
String
>
targetBrokers
=
new
HashSet
<>();
Set
<
String
>
targetBrokers
=
new
HashSet
<>();
try
{
try
{
defaultMQAdminExt
.
start
();
if
((!
commandLine
.
hasOption
(
"b"
)
&&
!
commandLine
.
hasOption
(
'c'
)))
{
if
((!
commandLine
.
hasOption
(
"b"
)
&&
!
commandLine
.
hasOption
(
'c'
)))
{
ServerUtil
.
printCommandLineHelp
(
"mqadmin "
+
this
.
commandName
(),
options
);
ServerUtil
.
printCommandLineHelp
(
"mqadmin "
+
this
.
commandName
(),
options
);
return
;
return
;
...
@@ -148,6 +149,7 @@ public class RemappingStaticTopicSubCommand implements SubCommand {
...
@@ -148,6 +149,7 @@ public class RemappingStaticTopicSubCommand implements SubCommand {
||
clusterInfo
.
getClusterAddrTable
().
isEmpty
())
{
||
clusterInfo
.
getClusterAddrTable
().
isEmpty
())
{
throw
new
RuntimeException
(
"The Cluster info is empty"
);
throw
new
RuntimeException
(
"The Cluster info is empty"
);
}
}
clientMetadata
.
refreshClusterInfo
(
clusterInfo
);
{
{
if
(
commandLine
.
hasOption
(
"b"
))
{
if
(
commandLine
.
hasOption
(
"b"
))
{
String
brokerStrs
=
commandLine
.
getOptionValue
(
"b"
).
trim
();
String
brokerStrs
=
commandLine
.
getOptionValue
(
"b"
).
trim
();
...
...
tools/src/main/java/org/apache/rocketmq/tools/command/topic/UpdateStaticTopicSubCommand.java
浏览文件 @
a9addc3c
...
@@ -92,9 +92,9 @@ public class UpdateStaticTopicSubCommand implements SubCommand {
...
@@ -92,9 +92,9 @@ public class UpdateStaticTopicSubCommand implements SubCommand {
RPCHook
rpcHook
)
throws
SubCommandException
{
RPCHook
rpcHook
)
throws
SubCommandException
{
DefaultMQAdminExt
defaultMQAdminExt
=
new
DefaultMQAdminExt
(
rpcHook
);
DefaultMQAdminExt
defaultMQAdminExt
=
new
DefaultMQAdminExt
(
rpcHook
);
defaultMQAdminExt
.
setInstanceName
(
Long
.
toString
(
System
.
currentTimeMillis
()));
defaultMQAdminExt
.
setInstanceName
(
Long
.
toString
(
System
.
currentTimeMillis
()));
ClientMetadata
clientMetadata
=
new
ClientMetadata
();
try
{
try
{
defaultMQAdminExt
.
start
();
String
topic
=
commandLine
.
getOptionValue
(
't'
).
trim
();
String
topic
=
commandLine
.
getOptionValue
(
't'
).
trim
();
String
mapFileName
=
commandLine
.
getOptionValue
(
'f'
).
trim
();
String
mapFileName
=
commandLine
.
getOptionValue
(
'f'
).
trim
();
String
mapData
=
MixAll
.
file2String
(
mapFileName
);
String
mapData
=
MixAll
.
file2String
(
mapFileName
);
...
@@ -139,6 +139,7 @@ public class UpdateStaticTopicSubCommand implements SubCommand {
...
@@ -139,6 +139,7 @@ public class UpdateStaticTopicSubCommand implements SubCommand {
Set
<
String
>
targetBrokers
=
new
HashSet
<>();
Set
<
String
>
targetBrokers
=
new
HashSet
<>();
try
{
try
{
defaultMQAdminExt
.
start
();
if
((!
commandLine
.
hasOption
(
"b"
)
&&
!
commandLine
.
hasOption
(
'c'
))
if
((!
commandLine
.
hasOption
(
"b"
)
&&
!
commandLine
.
hasOption
(
'c'
))
||
!
commandLine
.
hasOption
(
"qn"
))
{
||
!
commandLine
.
hasOption
(
"qn"
))
{
ServerUtil
.
printCommandLineHelp
(
"mqadmin "
+
this
.
commandName
(),
options
);
ServerUtil
.
printCommandLineHelp
(
"mqadmin "
+
this
.
commandName
(),
options
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录