Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Apache RocketMQ
Rocketmq
提交
ed2d6267
R
Rocketmq
项目概览
Apache RocketMQ
/
Rocketmq
上一次同步 大约 3 年
通知
268
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看板
提交
ed2d6267
编写于
11月 29, 2021
作者:
D
dongeforever
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add a basic produce test for static topic
上级
c1d4b8b5
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
54 addition
and
7 deletion
+54
-7
broker/src/main/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessor.java
...pache/rocketmq/broker/processor/AdminBrokerProcessor.java
+14
-7
client/src/main/java/org/apache/rocketmq/client/impl/producer/DefaultMQProducerImpl.java
.../rocketmq/client/impl/producer/DefaultMQProducerImpl.java
+1
-0
test/src/main/java/org/apache/rocketmq/test/client/rmq/RMQNormalProducer.java
...rg/apache/rocketmq/test/client/rmq/RMQNormalProducer.java
+9
-0
test/src/main/java/org/apache/rocketmq/test/clientinterface/AbstractMQProducer.java
...che/rocketmq/test/clientinterface/AbstractMQProducer.java
+1
-0
test/src/test/java/org/apache/rocketmq/test/base/BaseConf.java
...src/test/java/org/apache/rocketmq/test/base/BaseConf.java
+2
-0
test/src/test/java/org/apache/rocketmq/test/smoke/StaticTopicIT.java
...st/java/org/apache/rocketmq/test/smoke/StaticTopicIT.java
+25
-0
tools/src/main/java/org/apache/rocketmq/tools/command/topic/UpdateStaticTopicSubCommand.java
...etmq/tools/command/topic/UpdateStaticTopicSubCommand.java
+2
-0
未找到文件。
broker/src/main/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessor.java
浏览文件 @
ed2d6267
...
...
@@ -767,14 +767,21 @@ public class AdminBrokerProcessor extends AsyncNettyRequestProcessor implements
try
{
requestHeader
.
setBname
(
mappingItem
.
getBname
());
requestHeader
.
setPhysical
(
true
);
//TODO check if it is leader
RpcRequest
rpcRequest
=
new
RpcRequest
(
RequestCode
.
GET_MIN_OFFSET
,
requestHeader
,
null
);
RpcResponse
rpcResponse
=
this
.
brokerController
.
getBrokerOuterAPI
().
getRpcClient
().
invoke
(
rpcRequest
,
this
.
brokerController
.
getBrokerConfig
().
getForwardTimeout
()).
get
();
if
(
rpcResponse
.
getException
()
!=
null
)
{
throw
rpcResponse
.
getException
();
requestHeader
.
setQueueId
(
mappingItem
.
getQueueId
());
long
physicalOffset
;
//run in local
if
(
mappingItem
.
getBname
().
equals
(
mappingDetail
.
getBname
()))
{
physicalOffset
=
this
.
brokerController
.
getMessageStore
().
getMinOffsetInQueue
(
mappingDetail
.
getTopic
(),
mappingItem
.
getQueueId
());
}
else
{
RpcRequest
rpcRequest
=
new
RpcRequest
(
RequestCode
.
GET_MIN_OFFSET
,
requestHeader
,
null
);
RpcResponse
rpcResponse
=
this
.
brokerController
.
getBrokerOuterAPI
().
getRpcClient
().
invoke
(
rpcRequest
,
this
.
brokerController
.
getBrokerConfig
().
getForwardTimeout
()).
get
();
if
(
rpcResponse
.
getException
()
!=
null
)
{
throw
rpcResponse
.
getException
();
}
GetMinOffsetResponseHeader
offsetResponseHeader
=
(
GetMinOffsetResponseHeader
)
rpcResponse
.
getHeader
();
physicalOffset
=
offsetResponseHeader
.
getOffset
();
}
GetMinOffsetResponseHeader
offsetResponseHeader
=
(
GetMinOffsetResponseHeader
)
rpcResponse
.
getHeader
();
long
offset
=
mappingItem
.
computeStaticQueueOffsetUpToEnd
(
offsetResponseHeader
.
getOffset
());
long
offset
=
mappingItem
.
computeStaticQueueOffsetUpToEnd
(
physicalOffset
);
final
RemotingCommand
response
=
RemotingCommand
.
createResponseCommand
(
GetMinOffsetResponseHeader
.
class
);
final
GetMinOffsetResponseHeader
responseHeader
=
(
GetMinOffsetResponseHeader
)
response
.
readCustomHeader
();
...
...
client/src/main/java/org/apache/rocketmq/client/impl/producer/DefaultMQProducerImpl.java
浏览文件 @
ed2d6267
...
...
@@ -725,6 +725,7 @@ public class DefaultMQProducerImpl implements MQProducerInner {
String
brokerAddr
=
this
.
mQClientFactory
.
findBrokerAddressInPublish
(
brokerName
);
if
(
null
==
brokerAddr
)
{
tryToFindTopicPublishInfo
(
mq
.
getTopic
());
brokerName
=
this
.
mQClientFactory
.
getBrokerNameFromMessageQueue
(
mq
);
brokerAddr
=
this
.
mQClientFactory
.
findBrokerAddressInPublish
(
brokerName
);
}
...
...
test/src/main/java/org/apache/rocketmq/test/client/rmq/RMQNormalProducer.java
浏览文件 @
ed2d6267
...
...
@@ -132,6 +132,12 @@ public class RMQNormalProducer extends AbstractMQProducer {
}
}
public
void
send
(
int
num
,
MessageQueue
mq
)
{
for
(
int
i
=
0
;
i
<
num
;
i
++)
{
sendMQ
((
Message
)
getMessageByTag
(
null
),
mq
);
}
}
public
ResultWrapper
sendMQ
(
Message
msg
,
MessageQueue
mq
)
{
org
.
apache
.
rocketmq
.
client
.
producer
.
SendResult
metaqResult
=
null
;
try
{
...
...
@@ -145,6 +151,9 @@ public class RMQNormalProducer extends AbstractMQProducer {
sendResult
.
setSendResult
(
metaqResult
.
getSendStatus
().
equals
(
SendStatus
.
SEND_OK
));
sendResult
.
setBrokerIp
(
metaqResult
.
getMessageQueue
().
getBrokerName
());
msgBodys
.
addData
(
new
String
(
msg
.
getBody
()));
if
(
originMsgs
.
getAllData
().
contains
(
msg
))
{
System
.
out
.
println
(
"Hash collision"
);
}
originMsgs
.
addData
(
msg
);
originMsgIndex
.
put
(
new
String
(
msg
.
getBody
()),
metaqResult
);
}
catch
(
Exception
e
)
{
...
...
test/src/main/java/org/apache/rocketmq/test/clientinterface/AbstractMQProducer.java
浏览文件 @
ed2d6267
...
...
@@ -34,6 +34,7 @@ public abstract class AbstractMQProducer extends MQCollector implements MQProduc
protected
String
producerInstanceName
=
null
;
protected
boolean
isDebug
=
false
;
public
AbstractMQProducer
(
String
topic
)
{
super
();
producerGroupName
=
RandomUtil
.
getStringByUUID
();
...
...
test/src/test/java/org/apache/rocketmq/test/base/BaseConf.java
浏览文件 @
ed2d6267
...
...
@@ -32,6 +32,7 @@ import org.apache.rocketmq.broker.BrokerController;
import
org.apache.rocketmq.client.consumer.MQPullConsumer
;
import
org.apache.rocketmq.client.consumer.MQPushConsumer
;
import
org.apache.rocketmq.client.exception.MQClientException
;
import
org.apache.rocketmq.client.producer.DefaultMQProducer
;
import
org.apache.rocketmq.client.producer.MQProducer
;
import
org.apache.rocketmq.client.producer.TransactionListener
;
import
org.apache.rocketmq.common.MQVersion
;
...
...
@@ -129,6 +130,7 @@ public class BaseConf {
return
mqAdminExt
;
}
public
static
RMQNormalProducer
getProducer
(
String
nsAddr
,
String
topic
)
{
return
getProducer
(
nsAddr
,
topic
,
false
);
}
...
...
test/src/test/java/org/apache/rocketmq/test/smoke/StaticTopicIT.java
浏览文件 @
ed2d6267
package
org.apache.rocketmq.test.smoke
;
import
org.apache.log4j.Logger
;
import
org.apache.rocketmq.common.MixAll
;
import
org.apache.rocketmq.common.message.MessageQueue
;
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.TopicQueueMappingOne
;
import
org.apache.rocketmq.common.statictopic.TopicQueueMappingUtils
;
import
org.apache.rocketmq.test.base.BaseConf
;
import
org.apache.rocketmq.test.client.rmq.RMQNormalProducer
;
import
org.apache.rocketmq.test.util.MQRandomUtils
;
import
org.apache.rocketmq.tools.admin.DefaultMQAdminExt
;
import
org.junit.After
;
...
...
@@ -17,6 +20,7 @@ import org.junit.Test;
import
java.util.ArrayList
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
...
...
@@ -61,6 +65,7 @@ public class StaticTopicIT extends BaseConf {
@Test
public
void
testCreateAndRemappingStaticTopic
()
throws
Exception
{
String
topic
=
"static"
+
MQRandomUtils
.
getRandomTopic
();
RMQNormalProducer
producer
=
getProducer
(
nsAddr
,
topic
);
int
queueNum
=
10
;
Map
<
String
,
TopicConfigAndQueueMapping
>
localBrokerConfigMap
=
createStaticTopic
(
topic
,
queueNum
,
getBrokers
());
{
...
...
@@ -77,6 +82,26 @@ public class StaticTopicIT extends BaseConf {
Map
<
Integer
,
TopicQueueMappingOne
>
globalIdMap
=
TopicQueueMappingUtils
.
checkAndBuildMappingItems
(
new
ArrayList
<>(
getMappingDetailFromConfig
(
remoteBrokerConfigMap
.
values
())),
false
,
true
);
Assert
.
assertEquals
(
queueNum
,
globalIdMap
.
size
());
}
List
<
MessageQueue
>
messageQueueList
=
producer
.
getMessageQueue
();
Assert
.
assertEquals
(
queueNum
,
messageQueueList
.
size
());
producer
.
setDebug
(
true
);
for
(
int
i
=
0
;
i
<
queueNum
;
i
++)
{
MessageQueue
messageQueue
=
messageQueueList
.
get
(
i
);
Assert
.
assertEquals
(
topic
,
messageQueue
.
getTopic
());
Assert
.
assertEquals
(
i
,
messageQueue
.
getQueueId
());
Assert
.
assertEquals
(
MixAll
.
LOGICAL_QUEUE_MOCK_BROKER_NAME
,
messageQueue
.
getBrokerName
());
}
for
(
MessageQueue
messageQueue:
messageQueueList
)
{
producer
.
send
(
100
,
messageQueue
);
}
//leave the time to build the cq
Thread
.
sleep
(
500
);
for
(
MessageQueue
messageQueue:
messageQueueList
)
{
Assert
.
assertEquals
(
0
,
defaultMQAdminExt
.
minOffset
(
messageQueue
));
Assert
.
assertEquals
(
100
,
defaultMQAdminExt
.
maxOffset
(
messageQueue
));
}
Assert
.
assertEquals
(
100
*
queueNum
,
producer
.
getAllOriginMsg
().
size
());
Assert
.
assertEquals
(
0
,
producer
.
getSendErrorMsg
().
size
());
/*{
Set<String> targetBrokers = Collections.singleton(broker1Name);
Map<String, TopicConfigAndQueueMapping> brokerConfigMapFromRemote = defaultMQAdminExt.examineTopicConfigAll(clientMetadata, topic);
...
...
tools/src/main/java/org/apache/rocketmq/tools/command/topic/UpdateStaticTopicSubCommand.java
浏览文件 @
ed2d6267
...
...
@@ -215,6 +215,8 @@ public class UpdateStaticTopicSubCommand implements SubCommand {
String
oldMappingDataFile
=
TopicQueueMappingUtils
.
writeToTemp
(
oldWrapper
,
false
);
System
.
out
.
println
(
"The old mapping data is written to file "
+
oldMappingDataFile
);
}
//add the existed brokers to target brokers
targetBrokers
.
addAll
(
brokerConfigMap
.
keySet
());
//calculate the new data
TopicRemappingDetailWrapper
newWrapper
=
TopicQueueMappingUtils
.
createTopicConfigMapping
(
topic
,
queueNum
,
targetBrokers
,
new
HashSet
<>(),
brokerConfigMap
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录