From 856986a18186e38fee69c641a5666ac24f9b3451 Mon Sep 17 00:00:00 2001 From: WB01031309 Date: Fri, 19 May 2023 11:21:22 +0800 Subject: [PATCH 01/13] Add normal and delay test --- golang/message/delay_test.go | 101 ++++++++++++++++++++++++++++++++++ golang/message/normal_test.go | 90 ++++++++++++++++++++++++++++++ 2 files changed, 191 insertions(+) create mode 100644 golang/message/delay_test.go create mode 100644 golang/message/normal_test.go diff --git a/golang/message/delay_test.go b/golang/message/delay_test.go new file mode 100644 index 0000000..494ef56 --- /dev/null +++ b/golang/message/delay_test.go @@ -0,0 +1,101 @@ +package rocketmqtest + +import ( + "context" + "fmt" + . "rocketmq-go-e2e/utils" + "testing" + "time" + + rmq_client "github.com/apache/rocketmq-clients/golang" +) + +func TestSendDelayMassage(t *testing.T) { + type args struct { + name, testTopic, nameServer, grpcEndpoint, clusterName, ak, sk, cm, msgtag, keys, body string + deliveryTimestamp int + } + tests := []struct { + name string + args args + want string + }{ + { + name: "Send delay messages synchronously with the body size of 4M+1, expect send failed", + args: args{ + testTopic: GetTopicName(), + nameServer: NAMESERVER, + grpcEndpoint: GRPC_ENDPOINT, + clusterName: CLUSTER_NAME, + ak: "", + sk: "", + cm: GetGroupName(), + msgtag: RandomString(8), + keys: RandomString(8), + body: RandomString(4*1024*1024 + 1), + deliveryTimestamp: 10, + }, + want: "", + }, + { + name: "Send delay messages synchronously with the body size of 4M, expect send success", + args: args{ + testTopic: GetTopicName(), + nameServer: NAMESERVER, + grpcEndpoint: GRPC_ENDPOINT, + clusterName: CLUSTER_NAME, + ak: "", + sk: "", + cm: GetGroupName(), + msgtag: RandomString(8), + keys: RandomString(8), + body: RandomString(4 * 1024 * 1024), + deliveryTimestamp: 10, + }, + want: "", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + CreateDelayTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) + + // new producer instance + producer := BuildProducer(tt.args.grpcEndpoint, tt.args.ak, tt.args.sk, tt.args.testTopic) + // graceful stop producer + defer producer.GracefulStop() + + msg := &rmq_client.Message{ + // 为当前消息设置 Topic。 + Topic: tt.args.testTopic, + // 消息体。 + Body: []byte(tt.args.body), + } + + if tt.args.keys != "" { + // 设置消息索引键,可根据关键字精确查找某条消息。 + msg.SetKeys(tt.args.keys) + } + + if tt.args.msgtag != "" { + // 设置消息 Tag,用于消费端根据指定 Tag 过滤消息。 + msg.SetTag(tt.args.msgtag) + } + + if tt.args.deliveryTimestamp != 0 { + // 设置延时时间 + delay := time.Duration(tt.args.deliveryTimestamp) * time.Second + sendTime := time.Now().Add(delay) + msg.SetDelayTimestamp(sendTime) + } + + // 发送消息,需要关注发送结果,并捕获失败等异常。 + resp, err := producer.Send(context.TODO(), msg) + if err != nil { + t.Errorf("failed to send delay message, err:%s", err) + } + for i := 0; i < len(resp); i++ { + fmt.Printf("%#v\n", resp[i]) + } + }) + } +} diff --git a/golang/message/normal_test.go b/golang/message/normal_test.go new file mode 100644 index 0000000..83fdda8 --- /dev/null +++ b/golang/message/normal_test.go @@ -0,0 +1,90 @@ +package rocketmqtest + +import ( + "context" + "fmt" + . "rocketmq-go-e2e/utils" + "testing" + + rmq_client "github.com/apache/rocketmq-clients/golang" +) + +func TestSendNormalMassage(t *testing.T) { + type args struct { + name, testTopic, nameServer, grpcEndpoint, clusterName, ak, sk, cm, msgtag, keys, body string + } + tests := []struct { + name string + args args + want string + }{ + { + name: "Send normal messages synchronously with the body size of 4M+1, expect send failed", + args: args{ + testTopic: GetTopicName(), + nameServer: NAMESERVER, + grpcEndpoint: GRPC_ENDPOINT, + clusterName: CLUSTER_NAME, + ak: "", + sk: "", + cm: GetGroupName(), + msgtag: RandomString(8), + keys: RandomString(8), + body: RandomString(4*1024*1024 + 1), + }, + want: "", + }, + { + name: "Send normal messages synchronously with the body size of 4M, expect send success", + args: args{ + testTopic: GetTopicName(), + nameServer: NAMESERVER, + grpcEndpoint: GRPC_ENDPOINT, + clusterName: CLUSTER_NAME, + ak: "", + sk: "", + cm: GetGroupName(), + msgtag: RandomString(8), + keys: RandomString(8), + body: RandomString(4 * 1024 * 1024), + }, + want: "", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + CreateTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) + + // new producer instance + producer := BuildProducer(tt.args.grpcEndpoint, tt.args.ak, tt.args.sk, tt.args.testTopic) + // graceful stop producer + defer producer.GracefulStop() + + msg := &rmq_client.Message{ + // 为当前消息设置 Topic。 + Topic: tt.args.testTopic, + // 消息体。 + Body: []byte(tt.args.body), + } + + if tt.args.keys != "" { + // 设置消息索引键,可根据关键字精确查找某条消息。 + msg.SetKeys(tt.args.keys) + } + + if tt.args.msgtag != "" { + // 设置消息 Tag,用于消费端根据指定 Tag 过滤消息。 + msg.SetTag(tt.args.msgtag) + } + + // 发送消息,需要关注发送结果,并捕获失败等异常。 + resp, err := producer.Send(context.TODO(), msg) + if err != nil { + t.Errorf("failed to send normal message, err:%s", err) + } + for i := 0; i < len(resp); i++ { + fmt.Printf("%#v\n", resp[i]) + } + }) + } +} From cb167ea7516236fc346d4d3e8d4f2dd304ffb5e4 Mon Sep 17 00:00:00 2001 From: WB01031309 Date: Thu, 25 May 2023 15:19:16 +0800 Subject: [PATCH 02/13] Add message test --- golang/message/delay_test.go | 5 -- golang/message/message_content_test.go | 99 ++++++++++++++++++++++++++ golang/message/message_key_test.go | 99 ++++++++++++++++++++++++++ golang/message/normal_test.go | 5 -- 4 files changed, 198 insertions(+), 10 deletions(-) create mode 100644 golang/message/message_content_test.go create mode 100644 golang/message/message_key_test.go diff --git a/golang/message/delay_test.go b/golang/message/delay_test.go index 494ef56..bd0fc39 100644 --- a/golang/message/delay_test.go +++ b/golang/message/delay_test.go @@ -18,7 +18,6 @@ func TestSendDelayMassage(t *testing.T) { tests := []struct { name string args args - want string }{ { name: "Send delay messages synchronously with the body size of 4M+1, expect send failed", @@ -29,13 +28,11 @@ func TestSendDelayMassage(t *testing.T) { clusterName: CLUSTER_NAME, ak: "", sk: "", - cm: GetGroupName(), msgtag: RandomString(8), keys: RandomString(8), body: RandomString(4*1024*1024 + 1), deliveryTimestamp: 10, }, - want: "", }, { name: "Send delay messages synchronously with the body size of 4M, expect send success", @@ -46,13 +43,11 @@ func TestSendDelayMassage(t *testing.T) { clusterName: CLUSTER_NAME, ak: "", sk: "", - cm: GetGroupName(), msgtag: RandomString(8), keys: RandomString(8), body: RandomString(4 * 1024 * 1024), deliveryTimestamp: 10, }, - want: "", }, } for _, tt := range tests { diff --git a/golang/message/message_content_test.go b/golang/message/message_content_test.go new file mode 100644 index 0000000..94a5766 --- /dev/null +++ b/golang/message/message_content_test.go @@ -0,0 +1,99 @@ +package rocketmqtest + +import ( + "context" + "fmt" + . "rocketmq-go-e2e/utils" + "testing" + + rmq_client "github.com/apache/rocketmq-clients/golang" +) + +func TestMessageContent(t *testing.T) { + type args struct { + name, testTopic, nameServer, grpcEndpoint, clusterName, ak, sk, cm, msgtag, keys, body string + } + tests := []struct { + name string + args args + }{ + { + name: "Send normal message, setting message body with space character, expect consume success", + args: args{ + testTopic: GetTopicName(), + nameServer: NAMESERVER, + grpcEndpoint: GRPC_ENDPOINT, + clusterName: CLUSTER_NAME, + ak: "", + sk: "", + msgtag: RandomString(8), + keys: RandomString(8), + body: " ", + }, + }, + { + name: "Send normal message, setting message body with chinese character, expect consume success", + args: args{ + testTopic: GetTopicName(), + nameServer: NAMESERVER, + grpcEndpoint: GRPC_ENDPOINT, + clusterName: CLUSTER_NAME, + ak: "", + sk: "", + msgtag: RandomString(8), + keys: RandomString(8), + body: "中文字符", + }, + }, + { + name: "Send normal message, setting message body with emoji(😱) character, expect consume success", + args: args{ + testTopic: GetTopicName(), + nameServer: NAMESERVER, + grpcEndpoint: GRPC_ENDPOINT, + clusterName: CLUSTER_NAME, + ak: "", + sk: "", + msgtag: RandomString(8), + keys: RandomString(8), + body: "😱", + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + CreateTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) + + // new producer instance + producer := BuildProducer(tt.args.grpcEndpoint, tt.args.ak, tt.args.sk, tt.args.testTopic) + // graceful stop producer + defer producer.GracefulStop() + + msg := &rmq_client.Message{ + // 为当前消息设置 Topic。 + Topic: tt.args.testTopic, + // 消息体。 + Body: []byte(tt.args.body), + } + + if tt.args.keys != "" { + // 设置消息索引键,可根据关键字精确查找某条消息。 + msg.SetKeys(tt.args.keys) + } + + if tt.args.msgtag != "" { + // 设置消息 Tag,用于消费端根据指定 Tag 过滤消息。 + msg.SetTag(tt.args.msgtag) + } + + // 发送消息,需要关注发送结果,并捕获失败等异常。 + resp, err := producer.Send(context.TODO(), msg) + if err != nil { + t.Errorf("failed to send normal message, err:%s", err) + } + for i := 0; i < len(resp); i++ { + fmt.Printf("%#v\n", resp[i]) + } + }) + } +} diff --git a/golang/message/message_key_test.go b/golang/message/message_key_test.go new file mode 100644 index 0000000..64e34c1 --- /dev/null +++ b/golang/message/message_key_test.go @@ -0,0 +1,99 @@ +package rocketmqtest + +import ( + "context" + "fmt" + . "rocketmq-go-e2e/utils" + "testing" + + rmq_client "github.com/apache/rocketmq-clients/golang" +) + +func TestMessageKey(t *testing.T) { + type args struct { + name, testTopic, nameServer, grpcEndpoint, clusterName, ak, sk, cm, msgtag, keys, body string + } + tests := []struct { + name string + args args + }{ + { + name: "Message Key equals 16KB, expect send success", + args: args{ + testTopic: GetTopicName(), + nameServer: NAMESERVER, + grpcEndpoint: GRPC_ENDPOINT, + clusterName: CLUSTER_NAME, + ak: "", + sk: "", + msgtag: RandomString(8), + keys: RandomString(16 * 1024), + body: RandomString(64), + }, + }, + { + name: "Message Key beyond 16KB, expect send failed", + args: args{ + testTopic: GetTopicName(), + nameServer: NAMESERVER, + grpcEndpoint: GRPC_ENDPOINT, + clusterName: CLUSTER_NAME, + ak: "", + sk: "", + msgtag: RandomString(8), + keys: RandomString(16*1024 + 1), + body: RandomString(64), + }, + }, + { + name: "Message Key contains invisible characters \u0000 , expect send failed", + args: args{ + testTopic: GetTopicName(), + nameServer: NAMESERVER, + grpcEndpoint: GRPC_ENDPOINT, + clusterName: CLUSTER_NAME, + ak: "", + sk: "", + msgtag: RandomString(8), + keys: "\u0000", + body: RandomString(64), + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + CreateTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) + + // new producer instance + producer := BuildProducer(tt.args.grpcEndpoint, tt.args.ak, tt.args.sk, tt.args.testTopic) + // graceful stop producer + defer producer.GracefulStop() + + msg := &rmq_client.Message{ + // 为当前消息设置 Topic。 + Topic: tt.args.testTopic, + // 消息体。 + Body: []byte(tt.args.body), + } + + if tt.args.keys != "" { + // 设置消息索引键,可根据关键字精确查找某条消息。 + msg.SetKeys(tt.args.keys) + } + + if tt.args.msgtag != "" { + // 设置消息 Tag,用于消费端根据指定 Tag 过滤消息。 + msg.SetTag(tt.args.msgtag) + } + + // 发送消息,需要关注发送结果,并捕获失败等异常。 + resp, err := producer.Send(context.TODO(), msg) + if err != nil { + t.Errorf("failed to send normal message, err:%s", err) + } + for i := 0; i < len(resp); i++ { + fmt.Printf("%#v\n", resp[i]) + } + }) + } +} diff --git a/golang/message/normal_test.go b/golang/message/normal_test.go index 83fdda8..ec1dbeb 100644 --- a/golang/message/normal_test.go +++ b/golang/message/normal_test.go @@ -16,7 +16,6 @@ func TestSendNormalMassage(t *testing.T) { tests := []struct { name string args args - want string }{ { name: "Send normal messages synchronously with the body size of 4M+1, expect send failed", @@ -27,12 +26,10 @@ func TestSendNormalMassage(t *testing.T) { clusterName: CLUSTER_NAME, ak: "", sk: "", - cm: GetGroupName(), msgtag: RandomString(8), keys: RandomString(8), body: RandomString(4*1024*1024 + 1), }, - want: "", }, { name: "Send normal messages synchronously with the body size of 4M, expect send success", @@ -43,12 +40,10 @@ func TestSendNormalMassage(t *testing.T) { clusterName: CLUSTER_NAME, ak: "", sk: "", - cm: GetGroupName(), msgtag: RandomString(8), keys: RandomString(8), body: RandomString(4 * 1024 * 1024), }, - want: "", }, } for _, tt := range tests { From 2a674c92c2d26d65c441eb478ed4ac58aa42f0ef Mon Sep 17 00:00:00 2001 From: WB01031309 Date: Fri, 26 May 2023 15:56:20 +0800 Subject: [PATCH 03/13] Add MessageKeyContentWithChinese and MessageWithMultiKey test --- golang/go.sum | 6 ++ golang/message/message_key_test.go | 145 +++++++++++++++++++++++++++++ golang/utils/CheckUtils.go | 18 +++- 3 files changed, 167 insertions(+), 2 deletions(-) diff --git a/golang/go.sum b/golang/go.sum index eda5a6a..406c1cb 100644 --- a/golang/go.sum +++ b/golang/go.sum @@ -355,6 +355,12 @@ google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEY google.golang.org/genproto v0.0.0-20200527145253-8367513e4ece/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA= google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 h1:KpwkzHKEF7B9Zxg18WzOa7djJ+Ha5DzthMyZYQfEn2A= google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1/go.mod h1:nKE/iIaLqn2bQwXBg8f1g2Ylh6r5MN5CmZvuzZCgsCU= +google.golang.org/genproto v0.0.0-20230526015343-6ee61e4f9d5f h1:DwRdHa3+SynqBR2tx3LVtzJrGooL9hg1OCAfBdQAk1A= +google.golang.org/genproto v0.0.0-20230526015343-6ee61e4f9d5f/go.mod h1:9ExIQyXL5hZrHzQceCwuSYwZZ5QZBazOcprJ5rgs3lY= +google.golang.org/genproto/googleapis/api v0.0.0-20230526015343-6ee61e4f9d5f h1:dJhNU2ZodW2tHjMhmDOrcRSahqR0wgfOEBs8nSmVx5Y= +google.golang.org/genproto/googleapis/api v0.0.0-20230526015343-6ee61e4f9d5f/go.mod h1:vHYtlOoi6TsQ3Uk2yxR7NI5z8uoV+3pZtR4jmHIkRig= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230526015343-6ee61e4f9d5f h1:QNVuVEP2S7NNxLdNdOq0RiW3c9pW4gIpUUd+GAOjk1Y= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230526015343-6ee61e4f9d5f/go.mod h1:66JfowdXAEgad5O9NnYcsNPLCPZJD++2L9X0PCMODrA= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= diff --git a/golang/message/message_key_test.go b/golang/message/message_key_test.go index 64e34c1..3734d79 100644 --- a/golang/message/message_key_test.go +++ b/golang/message/message_key_test.go @@ -4,7 +4,9 @@ import ( "context" "fmt" . "rocketmq-go-e2e/utils" + "sync" "testing" + "time" rmq_client "github.com/apache/rocketmq-clients/golang" ) @@ -97,3 +99,146 @@ func TestMessageKey(t *testing.T) { }) } } + +func TestMessageKeyContentWithChinese(t *testing.T) { + type args struct { + name, testTopic, nameServer, grpcEndpoint, clusterName, ak, sk, cm, msgtag, keys, body string + } + tests := []struct { + name string + args args + }{ + { + name: "Message key contains Chinese, expect send and consume success", + args: args{ + testTopic: GetTopicName(), + nameServer: NAMESERVER, + grpcEndpoint: GRPC_ENDPOINT, + clusterName: CLUSTER_NAME, + ak: "", + sk: "", + cm: GetGroupName(), + msgtag: RandomString(8), + keys: RandomString(64), + body: "中文字符", + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + var wg sync.WaitGroup + // maximum number of messages received at one time + var maxMessageNum int32 = 32 + // invisibleDuration should > 20s + var invisibleDuration = time.Second * 20 + var msgCount = 10 + + CreateTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) + simpleConsumer := BuildSimpleConsumer(tt.args.grpcEndpoint, tt.args.cm, tt.args.msgtag, tt.args.ak, tt.args.sk, tt.args.testTopic) + + // graceful stop simpleConsumer + defer simpleConsumer.GracefulStop() + + // new producer instance + producer := BuildProducer(tt.args.grpcEndpoint, tt.args.ak, tt.args.sk, tt.args.testTopic) + // graceful stop producer + defer producer.GracefulStop() + + var recvMsgCollector *RecvMsgsCollector + var sendMsgCollector *SendMsgsCollector + wg.Add(1) + + go func() { + recvMsgCollector = RecvMessage(simpleConsumer, maxMessageNum, invisibleDuration, 10) + wg.Done() + }() + go func() { + sendMsgCollector = SendNormalMessage(producer, tt.args.testTopic, "test", tt.args.msgtag, msgCount, tt.args.keys) + }() + wg.Wait() + + CheckMsgsWithMsgBody(t, sendMsgCollector, recvMsgCollector) + }) + } +} + +func TestMessageWithMultiKey(t *testing.T) { + type args struct { + name, testTopic, nameServer, grpcEndpoint, clusterName, ak, sk, cm, msgtag, keys, body string + } + tests := []struct { + name string + args args + }{ + { + name: "The message contains multiple keys, expect send and consume success", + args: args{ + testTopic: GetTopicName(), + nameServer: NAMESERVER, + grpcEndpoint: GRPC_ENDPOINT, + clusterName: CLUSTER_NAME, + ak: "", + sk: "", + cm: GetGroupName(), + msgtag: RandomString(8), + keys: RandomString(64), + body: RandomString(64), + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + var wg sync.WaitGroup + // maximum number of messages received at one time + var maxMessageNum int32 = 32 + // invisibleDuration should > 20s + var invisibleDuration = time.Second * 20 + var msgCount = 10 + var k1 = RandomString(64) + + CreateTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) + simpleConsumer := BuildSimpleConsumer(tt.args.grpcEndpoint, tt.args.cm, tt.args.msgtag, tt.args.ak, tt.args.sk, tt.args.testTopic) + + // graceful stop simpleConsumer + defer simpleConsumer.GracefulStop() + + // new producer instance + producer := BuildProducer(tt.args.grpcEndpoint, tt.args.ak, tt.args.sk, tt.args.testTopic) + // graceful stop producer + defer producer.GracefulStop() + + msg := &rmq_client.Message{ + // 为当前消息设置 Topic。 + Topic: tt.args.testTopic, + // 消息体。 + Body: []byte(tt.args.body), + } + + if tt.args.keys != "" { + // 设置消息索引键,可根据关键字精确查找某条消息。 + //添加索引键 + msg.SetKeys(tt.args.keys, k1) + } + + if tt.args.msgtag != "" { + // 设置消息 Tag,用于消费端根据指定 Tag 过滤消息。 + msg.SetTag(tt.args.msgtag) + } + + var recvMsgCollector *RecvMsgsCollector + var sendMsgCollector *SendMsgsCollector + wg.Add(1) + + go func() { + recvMsgCollector = RecvMessage(simpleConsumer, maxMessageNum, invisibleDuration, 10) + wg.Done() + }() + go func() { + sendMsgCollector = SendNormalMessage(producer, tt.args.testTopic, "test", tt.args.msgtag, msgCount, tt.args.keys) + }() + wg.Wait() + + CheckMsgsWithMsgBody(t, sendMsgCollector, recvMsgCollector) + }) + } +} diff --git a/golang/utils/CheckUtils.go b/golang/utils/CheckUtils.go index 7375491..56c1be4 100644 --- a/golang/utils/CheckUtils.go +++ b/golang/utils/CheckUtils.go @@ -18,12 +18,13 @@ package utils import ( - rmq_client "github.com/apache/rocketmq-clients/golang" - "github.com/stretchr/testify/assert" "math" "sort" "testing" "time" + + rmq_client "github.com/apache/rocketmq-clients/golang" + "github.com/stretchr/testify/assert" ) // check msg with msgId received only once @@ -75,3 +76,16 @@ func CheckFIFOMsgsWithMsgId(t *testing.T, sendMsgsCollector *SendMsgsCollector, func CheckTransactionMsgsWithMsgId(t *testing.T, sendMsgsCollector *SendMsgsCollector, recvMsgsCollector *RecvMsgsCollector) { CheckMsgsWithMsgId(t, sendMsgsCollector, recvMsgsCollector) } + +func CheckMsgsWithMsgBody(t *testing.T, sendMsgsCollector *SendMsgsCollector, recvMsgsCollector *RecvMsgsCollector) { + var sendMsg string + var recvMsg string + for _, msg := range sendMsgsCollector.SendMsgs { + sendMsg = string(msg.Body) + } + for _, msg1 := range recvMsgsCollector.RecvMsgViews { + recvMsg = string(msg1.GetBody()) + } + + assert.Equal(t, sendMsg, recvMsg) +} From c440d5c591800e529ba67bdfe885e85f4fea1101 Mon Sep 17 00:00:00 2001 From: WB01031309 Date: Fri, 26 May 2023 16:40:06 +0800 Subject: [PATCH 04/13] Add MessageKeyContentWithChinese and MessageWithMultiKey test --- golang/utils/CheckUtils.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/golang/utils/CheckUtils.go b/golang/utils/CheckUtils.go index 56c1be4..7d80ca2 100644 --- a/golang/utils/CheckUtils.go +++ b/golang/utils/CheckUtils.go @@ -80,11 +80,11 @@ func CheckTransactionMsgsWithMsgId(t *testing.T, sendMsgsCollector *SendMsgsColl func CheckMsgsWithMsgBody(t *testing.T, sendMsgsCollector *SendMsgsCollector, recvMsgsCollector *RecvMsgsCollector) { var sendMsg string var recvMsg string - for _, msg := range sendMsgsCollector.SendMsgs { - sendMsg = string(msg.Body) + for _, sed := range sendMsgsCollector.SendMsgs { + sendMsg = string(sed.Body) } - for _, msg1 := range recvMsgsCollector.RecvMsgViews { - recvMsg = string(msg1.GetBody()) + for _, recv := range recvMsgsCollector.RecvMsgViews { + recvMsg = string(recv.GetBody()) } assert.Equal(t, sendMsg, recvMsg) From 26524e7ccd9d1712cd8c7bef8a400cc08769f971 Mon Sep 17 00:00:00 2001 From: WB01031309 Date: Tue, 30 May 2023 16:15:54 +0800 Subject: [PATCH 05/13] Add message_tag test --- golang/bin/run.sh | 2 +- golang/go.mod | 4 +- golang/go.sum | 6 + golang/message/message_key_test.go | 4 +- golang/message/message_tag_test.go | 176 +++++++++++++++++++++++++++++ 5 files changed, 188 insertions(+), 4 deletions(-) create mode 100644 golang/message/message_tag_test.go diff --git a/golang/bin/run.sh b/golang/bin/run.sh index c0d37d0..c91746b 100644 --- a/golang/bin/run.sh +++ b/golang/bin/run.sh @@ -21,4 +21,4 @@ cd ../common && mvn -Prelease -DskipTests clean package -U # set env for mqadmin (use source to set linux env variables in current shell) cd ../rocketmq-admintools && source bin/env.sh # run go e2e test case with latest client version -cd ../golang && go get -u github.com/apache/rocketmq-clients/golang && go test ./mqgotest/... -timeout 2m -v +cd ../golang && go get -u github.com/apache/rocketmq-clients/golang && go test ./mqgotest/... -timeout 2m -v && go test ./message/... -timeout 2m -v diff --git a/golang/go.mod b/golang/go.mod index 8196eff..4a7feae 100644 --- a/golang/go.mod +++ b/golang/go.mod @@ -36,7 +36,9 @@ require ( golang.org/x/sys v0.8.0 // indirect golang.org/x/text v0.9.0 // indirect google.golang.org/api v0.124.0 // indirect - google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect + google.golang.org/genproto v0.0.0-20230526203410-71b5a4ffd15e // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20230526203410-71b5a4ffd15e // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20230526203410-71b5a4ffd15e // indirect google.golang.org/grpc v1.55.0 // indirect google.golang.org/protobuf v1.30.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/golang/go.sum b/golang/go.sum index 406c1cb..715fc33 100644 --- a/golang/go.sum +++ b/golang/go.sum @@ -357,10 +357,16 @@ google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 h1:KpwkzHKEF7B9Zxg google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1/go.mod h1:nKE/iIaLqn2bQwXBg8f1g2Ylh6r5MN5CmZvuzZCgsCU= google.golang.org/genproto v0.0.0-20230526015343-6ee61e4f9d5f h1:DwRdHa3+SynqBR2tx3LVtzJrGooL9hg1OCAfBdQAk1A= google.golang.org/genproto v0.0.0-20230526015343-6ee61e4f9d5f/go.mod h1:9ExIQyXL5hZrHzQceCwuSYwZZ5QZBazOcprJ5rgs3lY= +google.golang.org/genproto v0.0.0-20230526203410-71b5a4ffd15e h1:Ao9GzfUMPH3zjVfzXG5rlWlk+Q8MXWKwWpwVQE1MXfw= +google.golang.org/genproto v0.0.0-20230526203410-71b5a4ffd15e/go.mod h1:zqTuNwFlFRsw5zIts5VnzLQxSRqh+CGOTVMlYbY0Eyk= google.golang.org/genproto/googleapis/api v0.0.0-20230526015343-6ee61e4f9d5f h1:dJhNU2ZodW2tHjMhmDOrcRSahqR0wgfOEBs8nSmVx5Y= google.golang.org/genproto/googleapis/api v0.0.0-20230526015343-6ee61e4f9d5f/go.mod h1:vHYtlOoi6TsQ3Uk2yxR7NI5z8uoV+3pZtR4jmHIkRig= +google.golang.org/genproto/googleapis/api v0.0.0-20230526203410-71b5a4ffd15e h1:AZX1ra8YbFMSb7+1pI8S9v4rrgRR7jU1FmuFSSjTVcQ= +google.golang.org/genproto/googleapis/api v0.0.0-20230526203410-71b5a4ffd15e/go.mod h1:vHYtlOoi6TsQ3Uk2yxR7NI5z8uoV+3pZtR4jmHIkRig= google.golang.org/genproto/googleapis/rpc v0.0.0-20230526015343-6ee61e4f9d5f h1:QNVuVEP2S7NNxLdNdOq0RiW3c9pW4gIpUUd+GAOjk1Y= google.golang.org/genproto/googleapis/rpc v0.0.0-20230526015343-6ee61e4f9d5f/go.mod h1:66JfowdXAEgad5O9NnYcsNPLCPZJD++2L9X0PCMODrA= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230526203410-71b5a4ffd15e h1:NumxXLPfHSndr3wBBdeKiVHjGVFzi9RX2HwwQke94iY= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230526203410-71b5a4ffd15e/go.mod h1:66JfowdXAEgad5O9NnYcsNPLCPZJD++2L9X0PCMODrA= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= diff --git a/golang/message/message_key_test.go b/golang/message/message_key_test.go index 3734d79..37e2087 100644 --- a/golang/message/message_key_test.go +++ b/golang/message/message_key_test.go @@ -153,7 +153,7 @@ func TestMessageKeyContentWithChinese(t *testing.T) { wg.Done() }() go func() { - sendMsgCollector = SendNormalMessage(producer, tt.args.testTopic, "test", tt.args.msgtag, msgCount, tt.args.keys) + sendMsgCollector = SendNormalMessage(producer, tt.args.testTopic, tt.args.body, tt.args.msgtag, msgCount, tt.args.keys) }() wg.Wait() @@ -234,7 +234,7 @@ func TestMessageWithMultiKey(t *testing.T) { wg.Done() }() go func() { - sendMsgCollector = SendNormalMessage(producer, tt.args.testTopic, "test", tt.args.msgtag, msgCount, tt.args.keys) + sendMsgCollector = SendNormalMessage(producer, tt.args.testTopic, tt.args.body, tt.args.msgtag, msgCount, tt.args.keys) }() wg.Wait() diff --git a/golang/message/message_tag_test.go b/golang/message/message_tag_test.go new file mode 100644 index 0000000..741b239 --- /dev/null +++ b/golang/message/message_tag_test.go @@ -0,0 +1,176 @@ +package rocketmqtest + +import ( + "context" + "fmt" + . "rocketmq-go-e2e/utils" + "sync" + "testing" + "time" + + rmq_client "github.com/apache/rocketmq-clients/golang" +) + +func TestMessageTag(t *testing.T) { + type args struct { + name, testTopic, nameServer, grpcEndpoint, clusterName, ak, sk, cm, msgtag, keys, body string + } + tests := []struct { + name string + args args + }{ + { + name: "Message Tag beyond 16KB,, expect send failed", + args: args{ + testTopic: GetTopicName(), + nameServer: NAMESERVER, + grpcEndpoint: GRPC_ENDPOINT, + clusterName: CLUSTER_NAME, + ak: "", + sk: "", + msgtag: RandomString(16*1024 + 1), + keys: RandomString(8), + body: "test", + }, + }, + { + name: "Message Tag equals 16KB, expect send success", + args: args{ + testTopic: GetTopicName(), + nameServer: NAMESERVER, + grpcEndpoint: GRPC_ENDPOINT, + clusterName: CLUSTER_NAME, + ak: "", + sk: "", + msgtag: RandomString(64 * 1024), + keys: RandomString(64), + body: RandomString(64), + }, + }, + { + name: "Message Tag contains invisible characters \u0000 , expect send failed", + args: args{ + testTopic: GetTopicName(), + nameServer: NAMESERVER, + grpcEndpoint: GRPC_ENDPOINT, + clusterName: CLUSTER_NAME, + ak: "", + sk: "", + msgtag: "\u0000", + keys: RandomString(64), + body: RandomString(64), + }, + }, + { + name: "Message Tag contains |, expect send failed", + args: args{ + testTopic: GetTopicName(), + nameServer: NAMESERVER, + grpcEndpoint: GRPC_ENDPOINT, + clusterName: CLUSTER_NAME, + ak: "", + sk: "", + msgtag: "tag|", + keys: RandomString(64), + body: RandomString(64), + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + CreateTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) + // new producer instance + producer := BuildProducer(tt.args.grpcEndpoint, tt.args.ak, tt.args.sk, tt.args.testTopic) + // graceful stop producer + defer producer.GracefulStop() + + msg := &rmq_client.Message{ + // 为当前消息设置 Topic。 + Topic: tt.args.testTopic, + // 消息体。 + Body: []byte(tt.args.body), + } + + if tt.args.keys != "" { + // 设置消息索引键,可根据关键字精确查找某条消息。 + msg.SetKeys(tt.args.keys) + } + + if tt.args.msgtag != "" { + // 设置消息 Tag,用于消费端根据指定 Tag 过滤消息。 + msg.SetTag(tt.args.msgtag) + } + + // 发送消息,需要关注发送结果,并捕获失败等异常。 + resp, err := producer.Send(context.TODO(), msg) + if err != nil { + t.Errorf("failed to send normal message, err:%s", err) + } + for i := 0; i < len(resp); i++ { + fmt.Printf("%#v\n", resp[i]) + } + }) + } +} + +func TestMessageTagContentWithChinese(t *testing.T) { + type args struct { + name, testTopic, nameServer, grpcEndpoint, clusterName, ak, sk, cm, msgtag, keys, body string + } + tests := []struct { + name string + args args + }{ + { + name: "Message Tag contains Chinese, expect send and consume success", + args: args{ + testTopic: GetTopicName(), + nameServer: NAMESERVER, + grpcEndpoint: GRPC_ENDPOINT, + clusterName: CLUSTER_NAME, + ak: "", + sk: "", + cm: GetGroupName(), + msgtag: "中文字符", + keys: RandomString(64), + body: RandomString(64), + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + var wg sync.WaitGroup + // maximum number of messages received at one time + var maxMessageNum int32 = 32 + // invisibleDuration should > 20s + var invisibleDuration = time.Second * 20 + var msgCount = 10 + + CreateTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) + simpleConsumer := BuildSimpleConsumer(tt.args.grpcEndpoint, tt.args.cm, tt.args.msgtag, tt.args.ak, tt.args.sk, tt.args.testTopic) + + // graceful stop simpleConsumer + defer simpleConsumer.GracefulStop() + + // new producer instance + producer := BuildProducer(tt.args.grpcEndpoint, tt.args.ak, tt.args.sk, tt.args.testTopic) + // graceful stop producer + defer producer.GracefulStop() + + var recvMsgCollector *RecvMsgsCollector + var sendMsgCollector *SendMsgsCollector + wg.Add(1) + + go func() { + recvMsgCollector = RecvMessage(simpleConsumer, maxMessageNum, invisibleDuration, 10) + wg.Done() + }() + go func() { + sendMsgCollector = SendNormalMessage(producer, tt.args.testTopic, tt.args.body, tt.args.msgtag, msgCount, tt.args.keys) + }() + wg.Wait() + + CheckMsgsWithMsgBody(t, sendMsgCollector, recvMsgCollector) + }) + } +} From 630b9ca669ddbfb393a2d2d2400619723ff3a018 Mon Sep 17 00:00:00 2001 From: WB01031309 Date: Wed, 31 May 2023 15:04:31 +0800 Subject: [PATCH 06/13] modify message_body_content_test.go --- golang/go.mod | 8 ++-- golang/go.sum | 8 ++++ ...t_test.go => message_body_content_test.go} | 37 ++++++++++++++----- 3 files changed, 39 insertions(+), 14 deletions(-) rename golang/message/{message_content_test.go => message_body_content_test.go} (71%) diff --git a/golang/go.mod b/golang/go.mod index 4a7feae..69d4553 100644 --- a/golang/go.mod +++ b/golang/go.mod @@ -35,10 +35,10 @@ require ( golang.org/x/sync v0.2.0 // indirect golang.org/x/sys v0.8.0 // indirect golang.org/x/text v0.9.0 // indirect - google.golang.org/api v0.124.0 // indirect - google.golang.org/genproto v0.0.0-20230526203410-71b5a4ffd15e // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20230526203410-71b5a4ffd15e // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20230526203410-71b5a4ffd15e // indirect + google.golang.org/api v0.125.0 // indirect + google.golang.org/genproto v0.0.0-20230530153820-e85fd2cbaebc // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect google.golang.org/grpc v1.55.0 // indirect google.golang.org/protobuf v1.30.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/golang/go.sum b/golang/go.sum index 715fc33..2b7107b 100644 --- a/golang/go.sum +++ b/golang/go.sum @@ -327,6 +327,8 @@ google.golang.org/api v0.123.0 h1:yHVU//vA+qkOhm4reEC9LtzHVUCN/IqqNRl1iQ9xE20= google.golang.org/api v0.123.0/go.mod h1:gcitW0lvnyWjSp9nKxAbdHKIZ6vF4aajGueeslZOyms= google.golang.org/api v0.124.0 h1:dP6Ef1VgOGqQ8eiv4GiY8RhmeyqzovcXBYPDUYG8Syo= google.golang.org/api v0.124.0/go.mod h1:xu2HQurE5gi/3t1aFCvhPD781p0a3p11sdunTJ2BlP4= +google.golang.org/api v0.125.0 h1:7xGvEY4fyWbhWMHf3R2/4w7L4fXyfpRGE9g6lp8+DCk= +google.golang.org/api v0.125.0/go.mod h1:mBwVAtz+87bEN6CbA1GtZPDOqY2R5ONPqJeIlvyo4Aw= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= @@ -359,14 +361,20 @@ google.golang.org/genproto v0.0.0-20230526015343-6ee61e4f9d5f h1:DwRdHa3+SynqBR2 google.golang.org/genproto v0.0.0-20230526015343-6ee61e4f9d5f/go.mod h1:9ExIQyXL5hZrHzQceCwuSYwZZ5QZBazOcprJ5rgs3lY= google.golang.org/genproto v0.0.0-20230526203410-71b5a4ffd15e h1:Ao9GzfUMPH3zjVfzXG5rlWlk+Q8MXWKwWpwVQE1MXfw= google.golang.org/genproto v0.0.0-20230526203410-71b5a4ffd15e/go.mod h1:zqTuNwFlFRsw5zIts5VnzLQxSRqh+CGOTVMlYbY0Eyk= +google.golang.org/genproto v0.0.0-20230530153820-e85fd2cbaebc h1:8DyZCyvI8mE1IdLy/60bS+52xfymkE72wv1asokgtao= +google.golang.org/genproto v0.0.0-20230530153820-e85fd2cbaebc/go.mod h1:xZnkP7mREFX5MORlOPEzLMr+90PPZQ2QWzrVTWfAq64= google.golang.org/genproto/googleapis/api v0.0.0-20230526015343-6ee61e4f9d5f h1:dJhNU2ZodW2tHjMhmDOrcRSahqR0wgfOEBs8nSmVx5Y= google.golang.org/genproto/googleapis/api v0.0.0-20230526015343-6ee61e4f9d5f/go.mod h1:vHYtlOoi6TsQ3Uk2yxR7NI5z8uoV+3pZtR4jmHIkRig= google.golang.org/genproto/googleapis/api v0.0.0-20230526203410-71b5a4ffd15e h1:AZX1ra8YbFMSb7+1pI8S9v4rrgRR7jU1FmuFSSjTVcQ= google.golang.org/genproto/googleapis/api v0.0.0-20230526203410-71b5a4ffd15e/go.mod h1:vHYtlOoi6TsQ3Uk2yxR7NI5z8uoV+3pZtR4jmHIkRig= +google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc h1:kVKPf/IiYSBWEWtkIn6wZXwWGCnLKcC8oWfZvXjsGnM= +google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc/go.mod h1:vHYtlOoi6TsQ3Uk2yxR7NI5z8uoV+3pZtR4jmHIkRig= google.golang.org/genproto/googleapis/rpc v0.0.0-20230526015343-6ee61e4f9d5f h1:QNVuVEP2S7NNxLdNdOq0RiW3c9pW4gIpUUd+GAOjk1Y= google.golang.org/genproto/googleapis/rpc v0.0.0-20230526015343-6ee61e4f9d5f/go.mod h1:66JfowdXAEgad5O9NnYcsNPLCPZJD++2L9X0PCMODrA= google.golang.org/genproto/googleapis/rpc v0.0.0-20230526203410-71b5a4ffd15e h1:NumxXLPfHSndr3wBBdeKiVHjGVFzi9RX2HwwQke94iY= google.golang.org/genproto/googleapis/rpc v0.0.0-20230526203410-71b5a4ffd15e/go.mod h1:66JfowdXAEgad5O9NnYcsNPLCPZJD++2L9X0PCMODrA= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc h1:XSJ8Vk1SWuNr8S18z1NZSziL0CPIXLCCMDOEFtHBOFc= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc/go.mod h1:66JfowdXAEgad5O9NnYcsNPLCPZJD++2L9X0PCMODrA= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= diff --git a/golang/message/message_content_test.go b/golang/message/message_body_content_test.go similarity index 71% rename from golang/message/message_content_test.go rename to golang/message/message_body_content_test.go index 94a5766..939167f 100644 --- a/golang/message/message_content_test.go +++ b/golang/message/message_body_content_test.go @@ -1,10 +1,10 @@ package rocketmqtest import ( - "context" - "fmt" . "rocketmq-go-e2e/utils" + "sync" "testing" + "time" rmq_client "github.com/apache/rocketmq-clients/golang" ) @@ -26,6 +26,7 @@ func TestMessageContent(t *testing.T) { clusterName: CLUSTER_NAME, ak: "", sk: "", + cm: GetGroupName(), msgtag: RandomString(8), keys: RandomString(8), body: " ", @@ -40,6 +41,7 @@ func TestMessageContent(t *testing.T) { clusterName: CLUSTER_NAME, ak: "", sk: "", + cm: GetGroupName(), msgtag: RandomString(8), keys: RandomString(8), body: "中文字符", @@ -54,6 +56,7 @@ func TestMessageContent(t *testing.T) { clusterName: CLUSTER_NAME, ak: "", sk: "", + cm: GetGroupName(), msgtag: RandomString(8), keys: RandomString(8), body: "😱", @@ -62,7 +65,15 @@ func TestMessageContent(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + var wg sync.WaitGroup + // maximum number of messages received at one time + var maxMessageNum int32 = 32 + // invisibleDuration should > 20s + var invisibleDuration = time.Second * 20 + var msgCount = 10 + CreateTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) + simpleConsumer := BuildSimpleConsumer(tt.args.grpcEndpoint, tt.args.cm, tt.args.msgtag, tt.args.ak, tt.args.sk, tt.args.testTopic) // new producer instance producer := BuildProducer(tt.args.grpcEndpoint, tt.args.ak, tt.args.sk, tt.args.testTopic) @@ -86,14 +97,20 @@ func TestMessageContent(t *testing.T) { msg.SetTag(tt.args.msgtag) } - // 发送消息,需要关注发送结果,并捕获失败等异常。 - resp, err := producer.Send(context.TODO(), msg) - if err != nil { - t.Errorf("failed to send normal message, err:%s", err) - } - for i := 0; i < len(resp); i++ { - fmt.Printf("%#v\n", resp[i]) - } + var recvMsgCollector *RecvMsgsCollector + var sendMsgCollector *SendMsgsCollector + wg.Add(1) + + go func() { + recvMsgCollector = RecvMessage(simpleConsumer, maxMessageNum, invisibleDuration, 10) + wg.Done() + }() + go func() { + sendMsgCollector = SendNormalMessage(producer, tt.args.testTopic, tt.args.body, tt.args.msgtag, msgCount, tt.args.keys) + }() + wg.Wait() + + CheckMsgsWithMsgBody(t, sendMsgCollector, recvMsgCollector) }) } } From d6f8bf719b01a75381940391d296ab7b22737da3 Mon Sep 17 00:00:00 2001 From: WB01031309 Date: Fri, 2 Jun 2023 17:29:28 +0800 Subject: [PATCH 07/13] Modify the document according to the review comments --- golang/go.mod | 2 +- golang/go.sum | 2 + golang/message/delay_test.go | 41 ++++---------- golang/message/message_body_content_test.go | 21 +------ golang/message/message_key_test.go | 51 +++-------------- golang/message/message_tag_test.go | 31 +++-------- golang/message/normal_test.go | 61 ++++++++------------- golang/utils/CreateMessageUtils.go | 13 +++++ 8 files changed, 69 insertions(+), 153 deletions(-) create mode 100644 golang/utils/CreateMessageUtils.go diff --git a/golang/go.mod b/golang/go.mod index 69d4553..be50935 100644 --- a/golang/go.mod +++ b/golang/go.mod @@ -21,7 +21,7 @@ require ( github.com/golang/mock v1.6.0 // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/google/uuid v1.3.0 // indirect - github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.2 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect github.com/leodido/go-urn v1.2.4 // indirect github.com/natefinch/lumberjack v2.0.0+incompatible // indirect github.com/pmezard/go-difflib v1.0.0 // indirect diff --git a/golang/go.sum b/golang/go.sum index 2b7107b..f54c1b7 100644 --- a/golang/go.sum +++ b/golang/go.sum @@ -117,6 +117,8 @@ github.com/grpc-ecosystem/grpc-gateway v1.14.6/go.mod h1:zdiPV4Yse/1gnckTHtghG4G github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.2 h1:gDLXvp5S9izjldquuoAhDzccbskOL6tDC5jMSyx3zxE= github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.2/go.mod h1:7pdNwVWBBHGiCxa9lAszqCJMbfTISJ7oMftp8+UGV08= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 h1:YBftPWNWd4WwGqtY2yeZL2ef8rHAxPBD8KFhJpmcqms= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0/go.mod h1:YN5jB8ie0yfIUg6VvR9Kz84aCaG7AsGZnLjhHbUqwPg= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= diff --git a/golang/message/delay_test.go b/golang/message/delay_test.go index bd0fc39..f0b7582 100644 --- a/golang/message/delay_test.go +++ b/golang/message/delay_test.go @@ -2,15 +2,12 @@ package rocketmqtest import ( "context" - "fmt" . "rocketmq-go-e2e/utils" "testing" "time" - - rmq_client "github.com/apache/rocketmq-clients/golang" ) -func TestSendDelayMassage(t *testing.T) { +func TestDelayMessageSize(t *testing.T) { type args struct { name, testTopic, nameServer, grpcEndpoint, clusterName, ak, sk, cm, msgtag, keys, body string deliveryTimestamp int @@ -59,38 +56,24 @@ func TestSendDelayMassage(t *testing.T) { // graceful stop producer defer producer.GracefulStop() - msg := &rmq_client.Message{ - // 为当前消息设置 Topic。 - Topic: tt.args.testTopic, - // 消息体。 - Body: []byte(tt.args.body), - } + // 为当前消息设置 Topic 和 消息体。 + msg := CreateDelayMessage(tt.args.testTopic, tt.args.body) - if tt.args.keys != "" { - // 设置消息索引键,可根据关键字精确查找某条消息。 - msg.SetKeys(tt.args.keys) - } + // 设置消息 Tag,用于消费端根据指定 Tag 过滤消息。 + msg.SetTag(tt.args.msgtag) + // 设置消息索引键,可根据关键字精确查找某条消息。 + msg.SetKeys(tt.args.keys) - if tt.args.msgtag != "" { - // 设置消息 Tag,用于消费端根据指定 Tag 过滤消息。 - msg.SetTag(tt.args.msgtag) - } - - if tt.args.deliveryTimestamp != 0 { - // 设置延时时间 - delay := time.Duration(tt.args.deliveryTimestamp) * time.Second - sendTime := time.Now().Add(delay) - msg.SetDelayTimestamp(sendTime) - } + // 设置延时时间 + delay := time.Duration(tt.args.deliveryTimestamp) * time.Second + sendTime := time.Now().Add(delay) + msg.SetDelayTimestamp(sendTime) // 发送消息,需要关注发送结果,并捕获失败等异常。 - resp, err := producer.Send(context.TODO(), msg) + _, err := producer.Send(context.TODO(), msg) if err != nil { t.Errorf("failed to send delay message, err:%s", err) } - for i := 0; i < len(resp); i++ { - fmt.Printf("%#v\n", resp[i]) - } }) } } diff --git a/golang/message/message_body_content_test.go b/golang/message/message_body_content_test.go index 939167f..6bf3f74 100644 --- a/golang/message/message_body_content_test.go +++ b/golang/message/message_body_content_test.go @@ -5,11 +5,9 @@ import ( "sync" "testing" "time" - - rmq_client "github.com/apache/rocketmq-clients/golang" ) -func TestMessageContent(t *testing.T) { +func TestMessageBodyContent(t *testing.T) { type args struct { name, testTopic, nameServer, grpcEndpoint, clusterName, ak, sk, cm, msgtag, keys, body string } @@ -80,23 +78,6 @@ func TestMessageContent(t *testing.T) { // graceful stop producer defer producer.GracefulStop() - msg := &rmq_client.Message{ - // 为当前消息设置 Topic。 - Topic: tt.args.testTopic, - // 消息体。 - Body: []byte(tt.args.body), - } - - if tt.args.keys != "" { - // 设置消息索引键,可根据关键字精确查找某条消息。 - msg.SetKeys(tt.args.keys) - } - - if tt.args.msgtag != "" { - // 设置消息 Tag,用于消费端根据指定 Tag 过滤消息。 - msg.SetTag(tt.args.msgtag) - } - var recvMsgCollector *RecvMsgsCollector var sendMsgCollector *SendMsgsCollector wg.Add(1) diff --git a/golang/message/message_key_test.go b/golang/message/message_key_test.go index 37e2087..8d96e07 100644 --- a/golang/message/message_key_test.go +++ b/golang/message/message_key_test.go @@ -2,16 +2,13 @@ package rocketmqtest import ( "context" - "fmt" . "rocketmq-go-e2e/utils" "sync" "testing" "time" - - rmq_client "github.com/apache/rocketmq-clients/golang" ) -func TestMessageKey(t *testing.T) { +func TestMessageKeySize(t *testing.T) { type args struct { name, testTopic, nameServer, grpcEndpoint, clusterName, ak, sk, cm, msgtag, keys, body string } @@ -71,31 +68,19 @@ func TestMessageKey(t *testing.T) { // graceful stop producer defer producer.GracefulStop() - msg := &rmq_client.Message{ - // 为当前消息设置 Topic。 - Topic: tt.args.testTopic, - // 消息体。 - Body: []byte(tt.args.body), - } + // 为当前消息设置 Topic 和 消息体。 + msg := CreateDelayMessage(tt.args.testTopic, tt.args.body) - if tt.args.keys != "" { - // 设置消息索引键,可根据关键字精确查找某条消息。 - msg.SetKeys(tt.args.keys) - } - - if tt.args.msgtag != "" { - // 设置消息 Tag,用于消费端根据指定 Tag 过滤消息。 - msg.SetTag(tt.args.msgtag) - } + // 设置消息 Tag,用于消费端根据指定 Tag 过滤消息。 + msg.SetTag(tt.args.msgtag) + // 设置消息索引键,可根据关键字精确查找某条消息。 + msg.SetKeys(tt.args.keys) // 发送消息,需要关注发送结果,并捕获失败等异常。 - resp, err := producer.Send(context.TODO(), msg) + _, err := producer.Send(context.TODO(), msg) if err != nil { t.Errorf("failed to send normal message, err:%s", err) } - for i := 0; i < len(resp); i++ { - fmt.Printf("%#v\n", resp[i]) - } }) } } @@ -207,24 +192,6 @@ func TestMessageWithMultiKey(t *testing.T) { // graceful stop producer defer producer.GracefulStop() - msg := &rmq_client.Message{ - // 为当前消息设置 Topic。 - Topic: tt.args.testTopic, - // 消息体。 - Body: []byte(tt.args.body), - } - - if tt.args.keys != "" { - // 设置消息索引键,可根据关键字精确查找某条消息。 - //添加索引键 - msg.SetKeys(tt.args.keys, k1) - } - - if tt.args.msgtag != "" { - // 设置消息 Tag,用于消费端根据指定 Tag 过滤消息。 - msg.SetTag(tt.args.msgtag) - } - var recvMsgCollector *RecvMsgsCollector var sendMsgCollector *SendMsgsCollector wg.Add(1) @@ -234,7 +201,7 @@ func TestMessageWithMultiKey(t *testing.T) { wg.Done() }() go func() { - sendMsgCollector = SendNormalMessage(producer, tt.args.testTopic, tt.args.body, tt.args.msgtag, msgCount, tt.args.keys) + sendMsgCollector = SendNormalMessage(producer, tt.args.testTopic, tt.args.body, tt.args.msgtag, msgCount, tt.args.keys, k1) }() wg.Wait() diff --git a/golang/message/message_tag_test.go b/golang/message/message_tag_test.go index 741b239..380a10a 100644 --- a/golang/message/message_tag_test.go +++ b/golang/message/message_tag_test.go @@ -2,16 +2,13 @@ package rocketmqtest import ( "context" - "fmt" . "rocketmq-go-e2e/utils" "sync" "testing" "time" - - rmq_client "github.com/apache/rocketmq-clients/golang" ) -func TestMessageTag(t *testing.T) { +func TestMessageTagSizeAndSpecialCharacter(t *testing.T) { type args struct { name, testTopic, nameServer, grpcEndpoint, clusterName, ak, sk, cm, msgtag, keys, body string } @@ -84,31 +81,19 @@ func TestMessageTag(t *testing.T) { // graceful stop producer defer producer.GracefulStop() - msg := &rmq_client.Message{ - // 为当前消息设置 Topic。 - Topic: tt.args.testTopic, - // 消息体。 - Body: []byte(tt.args.body), - } - - if tt.args.keys != "" { - // 设置消息索引键,可根据关键字精确查找某条消息。 - msg.SetKeys(tt.args.keys) - } + // 为当前消息设置 Topic 和 消息体。 + msg := CreateDelayMessage(tt.args.testTopic, tt.args.body) - if tt.args.msgtag != "" { - // 设置消息 Tag,用于消费端根据指定 Tag 过滤消息。 - msg.SetTag(tt.args.msgtag) - } + // 设置消息 Tag,用于消费端根据指定 Tag 过滤消息。 + msg.SetTag(tt.args.msgtag) + // 设置消息索引键,可根据关键字精确查找某条消息。 + msg.SetKeys(tt.args.keys) // 发送消息,需要关注发送结果,并捕获失败等异常。 - resp, err := producer.Send(context.TODO(), msg) + _, err := producer.Send(context.TODO(), msg) if err != nil { t.Errorf("failed to send normal message, err:%s", err) } - for i := 0; i < len(resp); i++ { - fmt.Printf("%#v\n", resp[i]) - } }) } } diff --git a/golang/message/normal_test.go b/golang/message/normal_test.go index ec1dbeb..161f804 100644 --- a/golang/message/normal_test.go +++ b/golang/message/normal_test.go @@ -2,14 +2,11 @@ package rocketmqtest import ( "context" - "fmt" . "rocketmq-go-e2e/utils" "testing" - - rmq_client "github.com/apache/rocketmq-clients/golang" ) -func TestSendNormalMassage(t *testing.T) { +func TestNormalMessageSize(t *testing.T) { type args struct { name, testTopic, nameServer, grpcEndpoint, clusterName, ak, sk, cm, msgtag, keys, body string } @@ -17,20 +14,20 @@ func TestSendNormalMassage(t *testing.T) { name string args args }{ - { - name: "Send normal messages synchronously with the body size of 4M+1, expect send failed", - args: args{ - testTopic: GetTopicName(), - nameServer: NAMESERVER, - grpcEndpoint: GRPC_ENDPOINT, - clusterName: CLUSTER_NAME, - ak: "", - sk: "", - msgtag: RandomString(8), - keys: RandomString(8), - body: RandomString(4*1024*1024 + 1), - }, - }, + //{ + // name: "Send normal messages synchronously with the body size of 4M+1, expect send failed", + // args: args{ + // testTopic: GetTopicName(), + // nameServer: NAMESERVER, + // grpcEndpoint: GRPC_ENDPOINT, + // clusterName: CLUSTER_NAME, + // ak: "", + // sk: "", + // msgtag: RandomString(8), + // keys: RandomString(8), + // body: RandomString(4*1024*1024 + 1), + // }, + //}, { name: "Send normal messages synchronously with the body size of 4M, expect send success", args: args{ @@ -42,7 +39,7 @@ func TestSendNormalMassage(t *testing.T) { sk: "", msgtag: RandomString(8), keys: RandomString(8), - body: RandomString(4 * 1024 * 1024), + body: RandomString(4 * 1024 * 500), }, }, } @@ -55,31 +52,19 @@ func TestSendNormalMassage(t *testing.T) { // graceful stop producer defer producer.GracefulStop() - msg := &rmq_client.Message{ - // 为当前消息设置 Topic。 - Topic: tt.args.testTopic, - // 消息体。 - Body: []byte(tt.args.body), - } + // 为当前消息设置 Topic 和 消息体。 + msg := CreateDelayMessage(tt.args.testTopic, tt.args.body) - if tt.args.keys != "" { - // 设置消息索引键,可根据关键字精确查找某条消息。 - msg.SetKeys(tt.args.keys) - } - - if tt.args.msgtag != "" { - // 设置消息 Tag,用于消费端根据指定 Tag 过滤消息。 - msg.SetTag(tt.args.msgtag) - } + // 设置消息 Tag,用于消费端根据指定 Tag 过滤消息。 + msg.SetTag(tt.args.msgtag) + // 设置消息索引键,可根据关键字精确查找某条消息。 + msg.SetKeys(tt.args.keys) // 发送消息,需要关注发送结果,并捕获失败等异常。 - resp, err := producer.Send(context.TODO(), msg) + _, err := producer.Send(context.TODO(), msg) if err != nil { t.Errorf("failed to send normal message, err:%s", err) } - for i := 0; i < len(resp); i++ { - fmt.Printf("%#v\n", resp[i]) - } }) } } diff --git a/golang/utils/CreateMessageUtils.go b/golang/utils/CreateMessageUtils.go new file mode 100644 index 0000000..46814ed --- /dev/null +++ b/golang/utils/CreateMessageUtils.go @@ -0,0 +1,13 @@ +package utils + +import ( + rmq_client "github.com/apache/rocketmq-clients/golang" +) + +func CreateDelayMessage(topic, body string) *rmq_client.Message { + msg := &rmq_client.Message{ + Topic: topic, + Body: []byte(body), + } + return msg +} From 7cd0bc12faefacfe4bbd1b2e5102a65148fe12ac Mon Sep 17 00:00:00 2001 From: WB01031309 Date: Mon, 5 Jun 2023 09:38:10 +0800 Subject: [PATCH 08/13] Modify the document according to the review comments --- golang/message/normal_test.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/golang/message/normal_test.go b/golang/message/normal_test.go index 161f804..99f6e31 100644 --- a/golang/message/normal_test.go +++ b/golang/message/normal_test.go @@ -14,20 +14,20 @@ func TestNormalMessageSize(t *testing.T) { name string args args }{ - //{ - // name: "Send normal messages synchronously with the body size of 4M+1, expect send failed", - // args: args{ - // testTopic: GetTopicName(), - // nameServer: NAMESERVER, - // grpcEndpoint: GRPC_ENDPOINT, - // clusterName: CLUSTER_NAME, - // ak: "", - // sk: "", - // msgtag: RandomString(8), - // keys: RandomString(8), - // body: RandomString(4*1024*1024 + 1), - // }, - //}, + { + name: "Send normal messages synchronously with the body size of 4M+1, expect send failed", + args: args{ + testTopic: GetTopicName(), + nameServer: NAMESERVER, + grpcEndpoint: GRPC_ENDPOINT, + clusterName: CLUSTER_NAME, + ak: "", + sk: "", + msgtag: RandomString(8), + keys: RandomString(8), + body: RandomString(4*1024*1024 + 1), + }, + }, { name: "Send normal messages synchronously with the body size of 4M, expect send success", args: args{ @@ -39,7 +39,7 @@ func TestNormalMessageSize(t *testing.T) { sk: "", msgtag: RandomString(8), keys: RandomString(8), - body: RandomString(4 * 1024 * 500), + body: RandomString(4 * 1024 * 1024), }, }, } From c7403c91a2318e2d4f1a41598e803dd0317626b9 Mon Sep 17 00:00:00 2001 From: WB01031309 Date: Mon, 5 Jun 2023 16:37:58 +0800 Subject: [PATCH 09/13] Modify the document according to the review comments --- golang/go.mod | 2 +- golang/go.sum | 2 ++ golang/message/message_body_content_test.go | 2 +- golang/message/message_key_test.go | 8 ++++---- golang/message/message_tag_test.go | 2 +- golang/utils/CheckUtils.go | 13 ------------- 6 files changed, 9 insertions(+), 20 deletions(-) diff --git a/golang/go.mod b/golang/go.mod index be50935..1ad0c04 100644 --- a/golang/go.mod +++ b/golang/go.mod @@ -15,7 +15,7 @@ require ( github.com/gabriel-vasile/mimetype v1.4.2 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect - github.com/go-playground/validator/v10 v10.14.0 // indirect + github.com/go-playground/validator/v10 v10.14.1 // indirect github.com/golang/glog v1.1.1 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/mock v1.6.0 // indirect diff --git a/golang/go.sum b/golang/go.sum index f54c1b7..b81d32a 100644 --- a/golang/go.sum +++ b/golang/go.sum @@ -60,6 +60,8 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg/+t63MyGU2n5js= github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= +github.com/go-playground/validator/v10 v10.14.1 h1:9c50NUPC30zyuKprjL3vNZ0m5oG+jU0zvx4AqHGnv4k= +github.com/go-playground/validator/v10 v10.14.1/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/glog v1.1.1 h1:jxpi2eWoU84wbX9iIEyAeeoac3FLuifZpY9tcNUD9kw= github.com/golang/glog v1.1.1/go.mod h1:zR+okUeTbrL6EL3xHUDxZuEtGv04p5shwip1+mL/rLQ= diff --git a/golang/message/message_body_content_test.go b/golang/message/message_body_content_test.go index 6bf3f74..8c1cc77 100644 --- a/golang/message/message_body_content_test.go +++ b/golang/message/message_body_content_test.go @@ -91,7 +91,7 @@ func TestMessageBodyContent(t *testing.T) { }() wg.Wait() - CheckMsgsWithMsgBody(t, sendMsgCollector, recvMsgCollector) + CheckMsgsWithAll(t, sendMsgCollector, recvMsgCollector) }) } } diff --git a/golang/message/message_key_test.go b/golang/message/message_key_test.go index 8d96e07..75dc30b 100644 --- a/golang/message/message_key_test.go +++ b/golang/message/message_key_test.go @@ -104,8 +104,8 @@ func TestMessageKeyContentWithChinese(t *testing.T) { sk: "", cm: GetGroupName(), msgtag: RandomString(8), - keys: RandomString(64), - body: "中文字符", + keys: "中文字符", + body: RandomString(8), }, }, } @@ -142,7 +142,7 @@ func TestMessageKeyContentWithChinese(t *testing.T) { }() wg.Wait() - CheckMsgsWithMsgBody(t, sendMsgCollector, recvMsgCollector) + CheckMsgsWithAll(t, sendMsgCollector, recvMsgCollector) }) } } @@ -205,7 +205,7 @@ func TestMessageWithMultiKey(t *testing.T) { }() wg.Wait() - CheckMsgsWithMsgBody(t, sendMsgCollector, recvMsgCollector) + CheckMsgsWithAll(t, sendMsgCollector, recvMsgCollector) }) } } diff --git a/golang/message/message_tag_test.go b/golang/message/message_tag_test.go index 380a10a..6599913 100644 --- a/golang/message/message_tag_test.go +++ b/golang/message/message_tag_test.go @@ -155,7 +155,7 @@ func TestMessageTagContentWithChinese(t *testing.T) { }() wg.Wait() - CheckMsgsWithMsgBody(t, sendMsgCollector, recvMsgCollector) + CheckMsgsWithAll(t, sendMsgCollector, recvMsgCollector) }) } } diff --git a/golang/utils/CheckUtils.go b/golang/utils/CheckUtils.go index 7d80ca2..1644448 100644 --- a/golang/utils/CheckUtils.go +++ b/golang/utils/CheckUtils.go @@ -76,16 +76,3 @@ func CheckFIFOMsgsWithMsgId(t *testing.T, sendMsgsCollector *SendMsgsCollector, func CheckTransactionMsgsWithMsgId(t *testing.T, sendMsgsCollector *SendMsgsCollector, recvMsgsCollector *RecvMsgsCollector) { CheckMsgsWithMsgId(t, sendMsgsCollector, recvMsgsCollector) } - -func CheckMsgsWithMsgBody(t *testing.T, sendMsgsCollector *SendMsgsCollector, recvMsgsCollector *RecvMsgsCollector) { - var sendMsg string - var recvMsg string - for _, sed := range sendMsgsCollector.SendMsgs { - sendMsg = string(sed.Body) - } - for _, recv := range recvMsgsCollector.RecvMsgViews { - recvMsg = string(recv.GetBody()) - } - - assert.Equal(t, sendMsg, recvMsg) -} From 65d0ed7dffbf5364a312d0b285112aa81f6ae95f Mon Sep 17 00:00:00 2001 From: WB01031309 Date: Tue, 6 Jun 2023 11:03:58 +0800 Subject: [PATCH 10/13] Modify the document according to the review comments --- golang/message/{delay_test.go => delay_message_size_test.go} | 2 +- golang/message/message_abnormal_test.go | 1 + golang/message/message_key_test.go | 2 +- golang/message/message_tag_test.go | 2 +- golang/message/message_user_property_test.go | 1 + golang/message/{normal_test.go => normal_message_size_test.go} | 2 +- golang/producer/producer_Init_test.go | 1 + golang/utils/CreateMessageUtils.go | 2 +- 8 files changed, 8 insertions(+), 5 deletions(-) rename golang/message/{delay_test.go => delay_message_size_test.go} (97%) create mode 100644 golang/message/message_abnormal_test.go create mode 100644 golang/message/message_user_property_test.go rename golang/message/{normal_test.go => normal_message_size_test.go} (96%) create mode 100644 golang/producer/producer_Init_test.go diff --git a/golang/message/delay_test.go b/golang/message/delay_message_size_test.go similarity index 97% rename from golang/message/delay_test.go rename to golang/message/delay_message_size_test.go index f0b7582..885e62a 100644 --- a/golang/message/delay_test.go +++ b/golang/message/delay_message_size_test.go @@ -57,7 +57,7 @@ func TestDelayMessageSize(t *testing.T) { defer producer.GracefulStop() // 为当前消息设置 Topic 和 消息体。 - msg := CreateDelayMessage(tt.args.testTopic, tt.args.body) + msg := CreateMessage(tt.args.testTopic, tt.args.body) // 设置消息 Tag,用于消费端根据指定 Tag 过滤消息。 msg.SetTag(tt.args.msgtag) diff --git a/golang/message/message_abnormal_test.go b/golang/message/message_abnormal_test.go new file mode 100644 index 0000000..251ab95 --- /dev/null +++ b/golang/message/message_abnormal_test.go @@ -0,0 +1 @@ +package rocketmqtest diff --git a/golang/message/message_key_test.go b/golang/message/message_key_test.go index 75dc30b..893768d 100644 --- a/golang/message/message_key_test.go +++ b/golang/message/message_key_test.go @@ -69,7 +69,7 @@ func TestMessageKeySize(t *testing.T) { defer producer.GracefulStop() // 为当前消息设置 Topic 和 消息体。 - msg := CreateDelayMessage(tt.args.testTopic, tt.args.body) + msg := CreateMessage(tt.args.testTopic, tt.args.body) // 设置消息 Tag,用于消费端根据指定 Tag 过滤消息。 msg.SetTag(tt.args.msgtag) diff --git a/golang/message/message_tag_test.go b/golang/message/message_tag_test.go index 6599913..ed73cec 100644 --- a/golang/message/message_tag_test.go +++ b/golang/message/message_tag_test.go @@ -82,7 +82,7 @@ func TestMessageTagSizeAndSpecialCharacter(t *testing.T) { defer producer.GracefulStop() // 为当前消息设置 Topic 和 消息体。 - msg := CreateDelayMessage(tt.args.testTopic, tt.args.body) + msg := CreateMessage(tt.args.testTopic, tt.args.body) // 设置消息 Tag,用于消费端根据指定 Tag 过滤消息。 msg.SetTag(tt.args.msgtag) diff --git a/golang/message/message_user_property_test.go b/golang/message/message_user_property_test.go new file mode 100644 index 0000000..251ab95 --- /dev/null +++ b/golang/message/message_user_property_test.go @@ -0,0 +1 @@ +package rocketmqtest diff --git a/golang/message/normal_test.go b/golang/message/normal_message_size_test.go similarity index 96% rename from golang/message/normal_test.go rename to golang/message/normal_message_size_test.go index 99f6e31..d600668 100644 --- a/golang/message/normal_test.go +++ b/golang/message/normal_message_size_test.go @@ -53,7 +53,7 @@ func TestNormalMessageSize(t *testing.T) { defer producer.GracefulStop() // 为当前消息设置 Topic 和 消息体。 - msg := CreateDelayMessage(tt.args.testTopic, tt.args.body) + msg := CreateMessage(tt.args.testTopic, tt.args.body) // 设置消息 Tag,用于消费端根据指定 Tag 过滤消息。 msg.SetTag(tt.args.msgtag) diff --git a/golang/producer/producer_Init_test.go b/golang/producer/producer_Init_test.go new file mode 100644 index 0000000..30f1d3d --- /dev/null +++ b/golang/producer/producer_Init_test.go @@ -0,0 +1 @@ +package producer diff --git a/golang/utils/CreateMessageUtils.go b/golang/utils/CreateMessageUtils.go index 46814ed..e410a6b 100644 --- a/golang/utils/CreateMessageUtils.go +++ b/golang/utils/CreateMessageUtils.go @@ -4,7 +4,7 @@ import ( rmq_client "github.com/apache/rocketmq-clients/golang" ) -func CreateDelayMessage(topic, body string) *rmq_client.Message { +func CreateMessage(topic, body string) *rmq_client.Message { msg := &rmq_client.Message{ Topic: topic, Body: []byte(body), From 41121bc5f9484e8efa3d80687777a165f5187967 Mon Sep 17 00:00:00 2001 From: WB01031309 Date: Fri, 9 Jun 2023 19:48:29 +0800 Subject: [PATCH 11/13] optimize code --- golang/common/common.go | 1 + golang/message/delay_message_size_test.go | 20 ++---------- golang/message/message_body_content_test.go | 18 +++++------ golang/message/message_key_test.go | 34 +++++---------------- golang/message/message_tag_test.go | 25 +++------------ golang/message/normal_message_size_test.go | 15 ++------- golang/mqgotest/delay/delaymsg_test.go | 13 +++----- golang/mqgotest/fifo/ordermsg_test.go | 9 ++---- golang/utils/ClientUtils.go | 9 +++--- 9 files changed, 37 insertions(+), 107 deletions(-) create mode 100644 golang/common/common.go diff --git a/golang/common/common.go b/golang/common/common.go new file mode 100644 index 0000000..805d0c7 --- /dev/null +++ b/golang/common/common.go @@ -0,0 +1 @@ +package common diff --git a/golang/message/delay_message_size_test.go b/golang/message/delay_message_size_test.go index 885e62a..57f38ed 100644 --- a/golang/message/delay_message_size_test.go +++ b/golang/message/delay_message_size_test.go @@ -1,7 +1,6 @@ package rocketmqtest import ( - "context" . "rocketmq-go-e2e/utils" "testing" "time" @@ -56,24 +55,11 @@ func TestDelayMessageSize(t *testing.T) { // graceful stop producer defer producer.GracefulStop() - // 为当前消息设置 Topic 和 消息体。 - msg := CreateMessage(tt.args.testTopic, tt.args.body) + msg := BuildDelayMessage(tt.args.testTopic, tt.args.body, tt.args.msgtag, time.Duration(tt.args.deliveryTimestamp), tt.args.keys) - // 设置消息 Tag,用于消费端根据指定 Tag 过滤消息。 - msg.SetTag(tt.args.msgtag) - // 设置消息索引键,可根据关键字精确查找某条消息。 - msg.SetKeys(tt.args.keys) + sendMsgCollector := NewSendMsgsCollector() - // 设置延时时间 - delay := time.Duration(tt.args.deliveryTimestamp) * time.Second - sendTime := time.Now().Add(delay) - msg.SetDelayTimestamp(sendTime) - - // 发送消息,需要关注发送结果,并捕获失败等异常。 - _, err := producer.Send(context.TODO(), msg) - if err != nil { - t.Errorf("failed to send delay message, err:%s", err) - } + SendMessage(producer, msg, sendMsgCollector) }) } } diff --git a/golang/message/message_body_content_test.go b/golang/message/message_body_content_test.go index 8c1cc77..b4ba783 100644 --- a/golang/message/message_body_content_test.go +++ b/golang/message/message_body_content_test.go @@ -4,7 +4,6 @@ import ( . "rocketmq-go-e2e/utils" "sync" "testing" - "time" ) func TestMessageBodyContent(t *testing.T) { @@ -63,12 +62,11 @@ func TestMessageBodyContent(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - var wg sync.WaitGroup - // maximum number of messages received at one time - var maxMessageNum int32 = 32 - // invisibleDuration should > 20s - var invisibleDuration = time.Second * 20 - var msgCount = 10 + var ( + wg sync.WaitGroup + recvMsgCollector *RecvMsgsCollector + sendMsgCollector *SendMsgsCollector + ) CreateTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) simpleConsumer := BuildSimpleConsumer(tt.args.grpcEndpoint, tt.args.cm, tt.args.msgtag, tt.args.ak, tt.args.sk, tt.args.testTopic) @@ -78,16 +76,14 @@ func TestMessageBodyContent(t *testing.T) { // graceful stop producer defer producer.GracefulStop() - var recvMsgCollector *RecvMsgsCollector - var sendMsgCollector *SendMsgsCollector wg.Add(1) go func() { - recvMsgCollector = RecvMessage(simpleConsumer, maxMessageNum, invisibleDuration, 10) + recvMsgCollector = RecvMessage(simpleConsumer, MaxMessageNum, InvisibleDuration, 10) wg.Done() }() go func() { - sendMsgCollector = SendNormalMessage(producer, tt.args.testTopic, tt.args.body, tt.args.msgtag, msgCount, tt.args.keys) + sendMsgCollector = SendNormalMessage(producer, tt.args.testTopic, tt.args.body, tt.args.msgtag, MsgCount, tt.args.keys) }() wg.Wait() diff --git a/golang/message/message_key_test.go b/golang/message/message_key_test.go index 893768d..cd20f55 100644 --- a/golang/message/message_key_test.go +++ b/golang/message/message_key_test.go @@ -1,11 +1,9 @@ package rocketmqtest import ( - "context" . "rocketmq-go-e2e/utils" "sync" "testing" - "time" ) func TestMessageKeySize(t *testing.T) { @@ -68,19 +66,11 @@ func TestMessageKeySize(t *testing.T) { // graceful stop producer defer producer.GracefulStop() - // 为当前消息设置 Topic 和 消息体。 - msg := CreateMessage(tt.args.testTopic, tt.args.body) + msg := BuildNormalMessage(tt.args.testTopic, tt.args.body, tt.args.msgtag, tt.args.keys) - // 设置消息 Tag,用于消费端根据指定 Tag 过滤消息。 - msg.SetTag(tt.args.msgtag) - // 设置消息索引键,可根据关键字精确查找某条消息。 - msg.SetKeys(tt.args.keys) + sendMsgCollector := NewSendMsgsCollector() - // 发送消息,需要关注发送结果,并捕获失败等异常。 - _, err := producer.Send(context.TODO(), msg) - if err != nil { - t.Errorf("failed to send normal message, err:%s", err) - } + SendMessage(producer, msg, sendMsgCollector) }) } } @@ -112,11 +102,6 @@ func TestMessageKeyContentWithChinese(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { var wg sync.WaitGroup - // maximum number of messages received at one time - var maxMessageNum int32 = 32 - // invisibleDuration should > 20s - var invisibleDuration = time.Second * 20 - var msgCount = 10 CreateTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) simpleConsumer := BuildSimpleConsumer(tt.args.grpcEndpoint, tt.args.cm, tt.args.msgtag, tt.args.ak, tt.args.sk, tt.args.testTopic) @@ -134,11 +119,11 @@ func TestMessageKeyContentWithChinese(t *testing.T) { wg.Add(1) go func() { - recvMsgCollector = RecvMessage(simpleConsumer, maxMessageNum, invisibleDuration, 10) + recvMsgCollector = RecvMessage(simpleConsumer, MaxMessageNum, InvisibleDuration, 10) wg.Done() }() go func() { - sendMsgCollector = SendNormalMessage(producer, tt.args.testTopic, tt.args.body, tt.args.msgtag, msgCount, tt.args.keys) + sendMsgCollector = SendNormalMessage(producer, tt.args.testTopic, tt.args.body, tt.args.msgtag, MsgCount, tt.args.keys) }() wg.Wait() @@ -174,11 +159,6 @@ func TestMessageWithMultiKey(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { var wg sync.WaitGroup - // maximum number of messages received at one time - var maxMessageNum int32 = 32 - // invisibleDuration should > 20s - var invisibleDuration = time.Second * 20 - var msgCount = 10 var k1 = RandomString(64) CreateTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) @@ -197,11 +177,11 @@ func TestMessageWithMultiKey(t *testing.T) { wg.Add(1) go func() { - recvMsgCollector = RecvMessage(simpleConsumer, maxMessageNum, invisibleDuration, 10) + recvMsgCollector = RecvMessage(simpleConsumer, MaxMessageNum, InvisibleDuration, 10) wg.Done() }() go func() { - sendMsgCollector = SendNormalMessage(producer, tt.args.testTopic, tt.args.body, tt.args.msgtag, msgCount, tt.args.keys, k1) + sendMsgCollector = SendNormalMessage(producer, tt.args.testTopic, tt.args.body, tt.args.msgtag, MsgCount, tt.args.keys, k1) }() wg.Wait() diff --git a/golang/message/message_tag_test.go b/golang/message/message_tag_test.go index ed73cec..e21a32c 100644 --- a/golang/message/message_tag_test.go +++ b/golang/message/message_tag_test.go @@ -1,11 +1,9 @@ package rocketmqtest import ( - "context" . "rocketmq-go-e2e/utils" "sync" "testing" - "time" ) func TestMessageTagSizeAndSpecialCharacter(t *testing.T) { @@ -81,19 +79,11 @@ func TestMessageTagSizeAndSpecialCharacter(t *testing.T) { // graceful stop producer defer producer.GracefulStop() - // 为当前消息设置 Topic 和 消息体。 - msg := CreateMessage(tt.args.testTopic, tt.args.body) + msg := BuildNormalMessage(tt.args.testTopic, tt.args.body, tt.args.msgtag, tt.args.keys) - // 设置消息 Tag,用于消费端根据指定 Tag 过滤消息。 - msg.SetTag(tt.args.msgtag) - // 设置消息索引键,可根据关键字精确查找某条消息。 - msg.SetKeys(tt.args.keys) + sendMsgCollector := NewSendMsgsCollector() - // 发送消息,需要关注发送结果,并捕获失败等异常。 - _, err := producer.Send(context.TODO(), msg) - if err != nil { - t.Errorf("failed to send normal message, err:%s", err) - } + SendMessage(producer, msg, sendMsgCollector) }) } } @@ -125,11 +115,6 @@ func TestMessageTagContentWithChinese(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { var wg sync.WaitGroup - // maximum number of messages received at one time - var maxMessageNum int32 = 32 - // invisibleDuration should > 20s - var invisibleDuration = time.Second * 20 - var msgCount = 10 CreateTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) simpleConsumer := BuildSimpleConsumer(tt.args.grpcEndpoint, tt.args.cm, tt.args.msgtag, tt.args.ak, tt.args.sk, tt.args.testTopic) @@ -147,11 +132,11 @@ func TestMessageTagContentWithChinese(t *testing.T) { wg.Add(1) go func() { - recvMsgCollector = RecvMessage(simpleConsumer, maxMessageNum, invisibleDuration, 10) + recvMsgCollector = RecvMessage(simpleConsumer, MaxMessageNum, InvisibleDuration, 10) wg.Done() }() go func() { - sendMsgCollector = SendNormalMessage(producer, tt.args.testTopic, tt.args.body, tt.args.msgtag, msgCount, tt.args.keys) + sendMsgCollector = SendNormalMessage(producer, tt.args.testTopic, tt.args.body, tt.args.msgtag, MsgCount, tt.args.keys) }() wg.Wait() diff --git a/golang/message/normal_message_size_test.go b/golang/message/normal_message_size_test.go index d600668..9b1c0b2 100644 --- a/golang/message/normal_message_size_test.go +++ b/golang/message/normal_message_size_test.go @@ -1,7 +1,6 @@ package rocketmqtest import ( - "context" . "rocketmq-go-e2e/utils" "testing" ) @@ -52,19 +51,11 @@ func TestNormalMessageSize(t *testing.T) { // graceful stop producer defer producer.GracefulStop() - // 为当前消息设置 Topic 和 消息体。 - msg := CreateMessage(tt.args.testTopic, tt.args.body) + msg := BuildNormalMessage(tt.args.testTopic, tt.args.body, tt.args.msgtag, tt.args.keys) - // 设置消息 Tag,用于消费端根据指定 Tag 过滤消息。 - msg.SetTag(tt.args.msgtag) - // 设置消息索引键,可根据关键字精确查找某条消息。 - msg.SetKeys(tt.args.keys) + sendMsgCollector := NewSendMsgsCollector() - // 发送消息,需要关注发送结果,并捕获失败等异常。 - _, err := producer.Send(context.TODO(), msg) - if err != nil { - t.Errorf("failed to send normal message, err:%s", err) - } + SendMessage(producer, msg, sendMsgCollector) }) } } diff --git a/golang/mqgotest/delay/delaymsg_test.go b/golang/mqgotest/delay/delaymsg_test.go index 6ae5d8c..547ee89 100644 --- a/golang/mqgotest/delay/delaymsg_test.go +++ b/golang/mqgotest/delay/delaymsg_test.go @@ -65,7 +65,7 @@ func TestDelayMsg(t *testing.T) { }() go func() { for i := 0; i < msgCount; i++ { - var msg = BuildDelayMessage(testTopic, "test", msgtag, time.Duration(delaySeconds), keys) + msg := BuildDelayMessage(testTopic, "test", msgtag, time.Duration(delaySeconds), keys) SendMessage(producer, msg, sendMsgCollector) } }() @@ -80,10 +80,6 @@ func TestDelayMsgAsync(t *testing.T) { wg sync.WaitGroup recvMsgCollector *RecvMsgsCollector sendMsgCollector = NewSendMsgsCollector() - // maximum number of messages received at one time - maxMessageNum int32 = 32 - // invisibleDuration should > 20s - invisibleDuration = time.Second * 20 // receive messages in a loop testTopic = GetTopicName() nameServer = NAMESERVER @@ -94,7 +90,6 @@ func TestDelayMsgAsync(t *testing.T) { cm = GetGroupName() msgtag = RandomString(8) keys = RandomString(8) - msgCount = 10 delaySeconds = 2 ) @@ -110,12 +105,12 @@ func TestDelayMsgAsync(t *testing.T) { wg.Add(1) go func() { - recvMsgCollector = RecvMessage(simpleConsumer, maxMessageNum, invisibleDuration, int64(20+delaySeconds)) + recvMsgCollector = RecvMessage(simpleConsumer, MaxMessageNum, InvisibleDuration, int64(20+delaySeconds)) wg.Done() }() go func() { - for i := 0; i < msgCount; i++ { - var msg = BuildDelayMessage(testTopic, "test", msgtag, time.Duration(delaySeconds), keys) + for i := 0; i < MsgCount; i++ { + msg := BuildDelayMessage(testTopic, "test", msgtag, time.Duration(delaySeconds), keys) SendMessageAsync(producer, msg, sendMsgCollector) } }() diff --git a/golang/mqgotest/fifo/ordermsg_test.go b/golang/mqgotest/fifo/ordermsg_test.go index 8f08d18..a7a3d8b 100644 --- a/golang/mqgotest/fifo/ordermsg_test.go +++ b/golang/mqgotest/fifo/ordermsg_test.go @@ -20,7 +20,6 @@ import ( . "rocketmq-go-e2e/utils" "sync" "testing" - "time" ) func TestFiFOMsg(t *testing.T) { @@ -29,10 +28,6 @@ func TestFiFOMsg(t *testing.T) { wg sync.WaitGroup recvMsgCollector *RecvMsgsCollector sendMsgCollector = NewSendMsgsCollector() - // maximum number of messages received at one time - maxMessageNum int32 = 32 - // invisibleDuration should > 20s - invisibleDuration = time.Second * 20 // receive messages in a loop testTopic = GetTopicName() nameServer = NAMESERVER @@ -60,13 +55,13 @@ func TestFiFOMsg(t *testing.T) { wg.Add(1) go func() { - recvMsgCollector = RecvMessage(simpleConsumer, maxMessageNum, invisibleDuration, 60) + recvMsgCollector = RecvMessage(simpleConsumer, MaxMessageNum, InvisibleDuration, 60) wg.Done() }() go func() { for i := 0; i < msgCount; i++ { - var msg = BuildFIFOMessage(testTopic, "test", msgtag, cm, keys) + msg := BuildFIFOMessage(testTopic, "test", msgtag, cm, keys) SendMessage(producer, msg, sendMsgCollector) } }() diff --git a/golang/utils/ClientUtils.go b/golang/utils/ClientUtils.go index 93db756..7deeaea 100644 --- a/golang/utils/ClientUtils.go +++ b/golang/utils/ClientUtils.go @@ -29,12 +29,13 @@ import ( ) var ( + MsgCount = 10 // maximum waiting time for receive func awaitDuration = time.Second * 5 - // maximum number of messages received at one time - maxMessageNum int32 = 32 - // invisibleDuration should > 20s - invisibleDuration = time.Second * 20 + // MaxMessageNum maximum number of messages received at one time + MaxMessageNum int32 = 32 + // InvisibleDuration should > 20s + InvisibleDuration = time.Second * 20 // receive messages in a loop GRPC_ENDPOINT = os.Getenv("GRPC_ENDPOINT") NAMESERVER = os.Getenv("NAMESERVER") From 41710f8d0c54a1b34869dd59e4b9182cb306bf74 Mon Sep 17 00:00:00 2001 From: WB01031309 Date: Thu, 15 Jun 2023 17:34:52 +0800 Subject: [PATCH 12/13] add server test file --- golang/bin/run.sh | 2 +- golang/go.mod | 12 +- golang/go.sum | 14 + golang/message/normal_message_size_test.go | 61 ---- .../client/consumer/consumer_group_test.go | 1 + .../consumer/push_consumer_init_test.go | 1 + .../consumer/simple_consumer_init_test.go | 311 ++++++++++++++++++ .../message/message_abnormal_test.go | 0 .../message/message_body_content_test.go | 0 golang/{ => pkg}/message/message_key_test.go | 37 +-- .../message/message_size_test.go} | 55 ++++ golang/{ => pkg}/message/message_tag_test.go | 0 .../message/message_user_property_test.go | 0 golang/pkg/server/delay/delaymsg_test.go | 170 ++++++++++ golang/pkg/server/normal/normalmsg_test.go | 114 +++++++ golang/pkg/server/order/ordermsg_test.go | 84 +++++ .../pkg/server/transaction/transmsg_test.go | 81 +++++ golang/pkg/simple/simple_ack_test.go | 145 ++++++++ golang/producer/producer_Init_test.go | 1 - golang/utils/CreateMessageUtils.go | 13 - 20 files changed, 987 insertions(+), 115 deletions(-) delete mode 100644 golang/message/normal_message_size_test.go create mode 100644 golang/pkg/client/consumer/consumer_group_test.go create mode 100644 golang/pkg/client/consumer/push_consumer_init_test.go create mode 100644 golang/pkg/client/consumer/simple_consumer_init_test.go rename golang/{ => pkg}/message/message_abnormal_test.go (100%) rename golang/{ => pkg}/message/message_body_content_test.go (100%) rename golang/{ => pkg}/message/message_key_test.go (81%) rename golang/{message/delay_message_size_test.go => pkg/message/message_size_test.go} (55%) rename golang/{ => pkg}/message/message_tag_test.go (100%) rename golang/{ => pkg}/message/message_user_property_test.go (100%) create mode 100644 golang/pkg/server/delay/delaymsg_test.go create mode 100644 golang/pkg/server/normal/normalmsg_test.go create mode 100644 golang/pkg/server/order/ordermsg_test.go create mode 100644 golang/pkg/server/transaction/transmsg_test.go create mode 100644 golang/pkg/simple/simple_ack_test.go delete mode 100644 golang/producer/producer_Init_test.go delete mode 100644 golang/utils/CreateMessageUtils.go diff --git a/golang/bin/run.sh b/golang/bin/run.sh index c91746b..7bb3d0c 100644 --- a/golang/bin/run.sh +++ b/golang/bin/run.sh @@ -21,4 +21,4 @@ cd ../common && mvn -Prelease -DskipTests clean package -U # set env for mqadmin (use source to set linux env variables in current shell) cd ../rocketmq-admintools && source bin/env.sh # run go e2e test case with latest client version -cd ../golang && go get -u github.com/apache/rocketmq-clients/golang && go test ./mqgotest/... -timeout 2m -v && go test ./message/... -timeout 2m -v +cd ../golang && go get -u github.com/apache/rocketmq-clients/golang && go test ./mqgotest/... -timeout 2m -v && go test ./pkg/... -timeout 2m -v diff --git a/golang/go.mod b/golang/go.mod index 1ad0c04..9e28ad8 100644 --- a/golang/go.mod +++ b/golang/go.mod @@ -30,12 +30,12 @@ require ( go.uber.org/atomic v1.11.0 // indirect go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.24.0 // indirect - golang.org/x/crypto v0.9.0 // indirect - golang.org/x/net v0.10.0 // indirect - golang.org/x/sync v0.2.0 // indirect - golang.org/x/sys v0.8.0 // indirect - golang.org/x/text v0.9.0 // indirect - google.golang.org/api v0.125.0 // indirect + golang.org/x/crypto v0.10.0 // indirect + golang.org/x/net v0.11.0 // indirect + golang.org/x/sync v0.3.0 // indirect + golang.org/x/sys v0.9.0 // indirect + golang.org/x/text v0.10.0 // indirect + google.golang.org/api v0.127.0 // indirect google.golang.org/genproto v0.0.0-20230530153820-e85fd2cbaebc // indirect google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect diff --git a/golang/go.sum b/golang/go.sum index b81d32a..896a1bd 100644 --- a/golang/go.sum +++ b/golang/go.sum @@ -176,6 +176,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= +golang.org/x/crypto v0.10.0 h1:LKqV2xt9+kDzSTfOhx4FrkEBcMrAgHSYgzywV9zcGmM= +golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -229,6 +231,8 @@ golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/net v0.11.0 h1:Gi2tvZIJyBtO9SDr1q9h5hEQCp/4L2RQ+ar0qjx2oNU= +golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -244,6 +248,8 @@ golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI= golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= +golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -270,6 +276,8 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s= +golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -278,6 +286,8 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.10.0 h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58= +golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -333,6 +343,10 @@ google.golang.org/api v0.124.0 h1:dP6Ef1VgOGqQ8eiv4GiY8RhmeyqzovcXBYPDUYG8Syo= google.golang.org/api v0.124.0/go.mod h1:xu2HQurE5gi/3t1aFCvhPD781p0a3p11sdunTJ2BlP4= google.golang.org/api v0.125.0 h1:7xGvEY4fyWbhWMHf3R2/4w7L4fXyfpRGE9g6lp8+DCk= google.golang.org/api v0.125.0/go.mod h1:mBwVAtz+87bEN6CbA1GtZPDOqY2R5ONPqJeIlvyo4Aw= +google.golang.org/api v0.126.0 h1:q4GJq+cAdMAC7XP7njvQ4tvohGLiSlytuL4BQxbIZ+o= +google.golang.org/api v0.126.0/go.mod h1:mBwVAtz+87bEN6CbA1GtZPDOqY2R5ONPqJeIlvyo4Aw= +google.golang.org/api v0.127.0 h1:v7rj0vA0imM3Ou81k1eyFxQNScLzn71EyGnJDr+V/XI= +google.golang.org/api v0.127.0/go.mod h1:Y611qgqaE92On/7g65MQgxYul3c0rEB894kniWLY750= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= diff --git a/golang/message/normal_message_size_test.go b/golang/message/normal_message_size_test.go deleted file mode 100644 index 9b1c0b2..0000000 --- a/golang/message/normal_message_size_test.go +++ /dev/null @@ -1,61 +0,0 @@ -package rocketmqtest - -import ( - . "rocketmq-go-e2e/utils" - "testing" -) - -func TestNormalMessageSize(t *testing.T) { - type args struct { - name, testTopic, nameServer, grpcEndpoint, clusterName, ak, sk, cm, msgtag, keys, body string - } - tests := []struct { - name string - args args - }{ - { - name: "Send normal messages synchronously with the body size of 4M+1, expect send failed", - args: args{ - testTopic: GetTopicName(), - nameServer: NAMESERVER, - grpcEndpoint: GRPC_ENDPOINT, - clusterName: CLUSTER_NAME, - ak: "", - sk: "", - msgtag: RandomString(8), - keys: RandomString(8), - body: RandomString(4*1024*1024 + 1), - }, - }, - { - name: "Send normal messages synchronously with the body size of 4M, expect send success", - args: args{ - testTopic: GetTopicName(), - nameServer: NAMESERVER, - grpcEndpoint: GRPC_ENDPOINT, - clusterName: CLUSTER_NAME, - ak: "", - sk: "", - msgtag: RandomString(8), - keys: RandomString(8), - body: RandomString(4 * 1024 * 1024), - }, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - CreateTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) - - // new producer instance - producer := BuildProducer(tt.args.grpcEndpoint, tt.args.ak, tt.args.sk, tt.args.testTopic) - // graceful stop producer - defer producer.GracefulStop() - - msg := BuildNormalMessage(tt.args.testTopic, tt.args.body, tt.args.msgtag, tt.args.keys) - - sendMsgCollector := NewSendMsgsCollector() - - SendMessage(producer, msg, sendMsgCollector) - }) - } -} diff --git a/golang/pkg/client/consumer/consumer_group_test.go b/golang/pkg/client/consumer/consumer_group_test.go new file mode 100644 index 0000000..b78b46c --- /dev/null +++ b/golang/pkg/client/consumer/consumer_group_test.go @@ -0,0 +1 @@ +package consumer diff --git a/golang/pkg/client/consumer/push_consumer_init_test.go b/golang/pkg/client/consumer/push_consumer_init_test.go new file mode 100644 index 0000000..b78b46c --- /dev/null +++ b/golang/pkg/client/consumer/push_consumer_init_test.go @@ -0,0 +1 @@ +package consumer diff --git a/golang/pkg/client/consumer/simple_consumer_init_test.go b/golang/pkg/client/consumer/simple_consumer_init_test.go new file mode 100644 index 0000000..65361c2 --- /dev/null +++ b/golang/pkg/client/consumer/simple_consumer_init_test.go @@ -0,0 +1,311 @@ +package consumer + +import ( + "log" + . "rocketmq-go-e2e/utils" + "testing" + + rmq_client "github.com/apache/rocketmq-clients/golang" + "github.com/apache/rocketmq-clients/golang/credentials" +) + +func TestSimpleConsumerInit(t *testing.T) { + type args struct { + name, testTopic, nameServer, grpcEndpoint, clusterName, ak, sk, cm, msgtag, keys, body string + } + tests := []struct { + name string + args args + }{ + { + name: "SimpleConsumer all parameters are set properly, expect start success", + args: args{ + testTopic: GetTopicName(), + nameServer: NAMESERVER, + grpcEndpoint: GRPC_ENDPOINT, + clusterName: CLUSTER_NAME, + ak: "", + sk: "", + cm: GetGroupName(), + msgtag: RandomString(8), + keys: RandomString(8), + body: RandomString(8), + }, + }, + { + name: "Without setting 'ClientConfiguration' of the consumer client, expect start failed", + args: args{ + testTopic: GetTopicName(), + nameServer: "", + grpcEndpoint: "", + clusterName: CLUSTER_NAME, + ak: "", + sk: "", + cm: GetGroupName(), + msgtag: RandomString(8), + keys: RandomString(8), + body: RandomString(8), + }, + }, + { + name: "Without setting 'ConsumerGroup' of the consumer client, expect start failed", + args: args{ + testTopic: GetTopicName(), + nameServer: NAMESERVER, + grpcEndpoint: GRPC_ENDPOINT, + clusterName: CLUSTER_NAME, + ak: "", + sk: "", + cm: "", + msgtag: RandomString(8), + keys: RandomString(8), + body: RandomString(8), + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + CreateTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) + + simpleConsumer, err := rmq_client.NewSimpleConsumer(&rmq_client.Config{ + Endpoint: tt.args.grpcEndpoint, + ConsumerGroup: tt.args.cm, + Credentials: &credentials.SessionCredentials{ + AccessKey: tt.args.ak, + AccessSecret: tt.args.sk, + }, + }, + //rmq_client.WithAwaitDuration(time.Second*10), + rmq_client.WithSubscriptionExpressions(map[string]*rmq_client.FilterExpression{ + tt.args.testTopic: rmq_client.NewFilterExpression(tt.args.msgtag), + }), + ) + if err != nil { + log.Fatal(err) + } + + // start simpleConsumer + err = simpleConsumer.Start() + if err != nil { + log.Fatal(err) + } + }) + } +} + +//func TestNoSubscription(t *testing.T) { +// type args struct { +// name, testTopic, nameServer, grpcEndpoint, clusterName, ak, sk, cm, msgtag, keys, body string +// } +// tests := []struct { +// name string +// args args +// }{ +// { +// //todo 未设置Subscription依然可以启动成功 +// name: "Without setting 'AwaitDuration' of the consumer client, expect start failed", +// args: args{ +// testTopic: GetTopicName(), +// nameServer: NAMESERVER, +// grpcEndpoint: GRPC_ENDPOINT, +// clusterName: CLUSTER_NAME, +// ak: "", +// sk: "", +// cm: GetGroupName(), +// msgtag: RandomString(8), +// keys: RandomString(8), +// body: RandomString(8), +// }, +// }, +// } +// for _, tt := range tests { +// t.Run(tt.name, func(t *testing.T) { +// CreateTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) +// +// simpleConsumer, err := rmq_client.NewSimpleConsumer(&rmq_client.Config{ +// Endpoint: tt.args.grpcEndpoint, +// ConsumerGroup: tt.args.cm, +// Credentials: &credentials.SessionCredentials{ +// AccessKey: tt.args.ak, +// AccessSecret: tt.args.sk, +// }, +// }, +// rmq_client.WithAwaitDuration(time.Second*10), +// rmq_client.WithSubscriptionExpressions(map[string]*rmq_client.FilterExpression{ +// tt.args.testTopic: rmq_client.NewFilterExpression(tt.args.msgtag), +// }), +// ) +// if err != nil { +// log.Fatal(err) +// } +// +// // start simpleConsumer +// err = simpleConsumer.Start() +// if err != nil { +// log.Fatal(err) +// } +// }) +// } +//} +// +//func TestNoAwaitDuration(t *testing.T) { +// type args struct { +// name, testTopic, nameServer, grpcEndpoint, clusterName, ak, sk, cm, msgtag, keys, body string +// } +// tests := []struct { +// name string +// args args +// }{ +// { +// //todo 未设置AwaitDuration依然可以启动成功 +// name: "Without setting 'AwaitDuration' of the consumer client, expect start failed", +// args: args{ +// testTopic: GetTopicName(), +// nameServer: NAMESERVER, +// grpcEndpoint: GRPC_ENDPOINT, +// clusterName: CLUSTER_NAME, +// ak: "", +// sk: "", +// cm: GetGroupName(), +// msgtag: RandomString(8), +// keys: RandomString(8), +// body: RandomString(8), +// }, +// }, +// } +// for _, tt := range tests { +// t.Run(tt.name, func(t *testing.T) { +// CreateTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) +// +// simpleConsumer, err := rmq_client.NewSimpleConsumer(&rmq_client.Config{ +// Endpoint: tt.args.grpcEndpoint, +// ConsumerGroup: tt.args.cm, +// Credentials: &credentials.SessionCredentials{ +// AccessKey: tt.args.ak, +// AccessSecret: tt.args.sk, +// }, +// }, +// rmq_client.WithSubscriptionExpressions(map[string]*rmq_client.FilterExpression{ +// tt.args.testTopic: rmq_client.NewFilterExpression(tt.args.msgtag), +// }), +// ) +// if err != nil { +// log.Fatal(err) +// } +// +// // start simpleConsumer +// err = simpleConsumer.Start() +// if err != nil { +// log.Fatal(err) +// } +// }) +// } +//} +// +//func TestEmptySubscription(t *testing.T) { +// type args struct { +// name, testTopic, nameServer, grpcEndpoint, clusterName, ak, sk, cm, msgtag, keys, body string +// } +// tests := []struct { +// name string +// args args +// }{ +// { +// // todo 未通过 +// name: "Error setting 'SubscriptionExpressions' empty of the consumer client, except start failed", +// args: args{ +// testTopic: GetTopicName(), +// nameServer: NAMESERVER, +// grpcEndpoint: GRPC_ENDPOINT, +// clusterName: CLUSTER_NAME, +// ak: "", +// sk: "", +// cm: GetGroupName(), +// msgtag: RandomString(8), +// keys: RandomString(8), +// body: RandomString(8), +// }, +// }, +// } +// for _, tt := range tests { +// t.Run(tt.name, func(t *testing.T) { +// CreateTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) +// +// simpleConsumer, err := rmq_client.NewSimpleConsumer(&rmq_client.Config{ +// Endpoint: tt.args.grpcEndpoint, +// ConsumerGroup: tt.args.cm, +// Credentials: &credentials.SessionCredentials{ +// AccessKey: tt.args.ak, +// AccessSecret: tt.args.sk, +// }, +// }, +// rmq_client.WithAwaitDuration(time.Second*10), +// rmq_client.WithSubscriptionExpressions(map[string]*rmq_client.FilterExpression{}), +// ) +// if err != nil { +// log.Fatal(err) +// } +// +// // start simpleConsumer +// err = simpleConsumer.Start() +// if err != nil { +// log.Fatal(err) +// } +// }) +// } +//} +// +//func TestAwaitDurationIs0s(t *testing.T) { +// type args struct { +// name, testTopic, nameServer, grpcEndpoint, clusterName, ak, sk, cm, msgtag, keys, body string +// } +// tests := []struct { +// name string +// args args +// }{ +// { +// //todo 测试未通过 +// name: "Error setting 'MaxMessageNum=0' of the consumer client, except start failed", +// args: args{ +// testTopic: GetTopicName(), +// nameServer: NAMESERVER, +// grpcEndpoint: GRPC_ENDPOINT, +// clusterName: CLUSTER_NAME, +// ak: "", +// sk: "", +// cm: GetGroupName(), +// msgtag: RandomString(8), +// keys: RandomString(8), +// body: RandomString(8), +// }, +// }, +// } +// for _, tt := range tests { +// t.Run(tt.name, func(t *testing.T) { +// CreateTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) +// +// simpleConsumer, err := rmq_client.NewSimpleConsumer(&rmq_client.Config{ +// Endpoint: tt.args.grpcEndpoint, +// ConsumerGroup: tt.args.cm, +// Credentials: &credentials.SessionCredentials{ +// AccessKey: tt.args.ak, +// AccessSecret: tt.args.sk, +// }, +// }, +// rmq_client.WithAwaitDuration(time.Second*0), +// rmq_client.WithSubscriptionExpressions(map[string]*rmq_client.FilterExpression{ +// tt.args.testTopic: rmq_client.NewFilterExpression(tt.args.msgtag), +// }), +// ) +// if err != nil { +// log.Fatal(err) +// } +// +// // start simpleConsumer +// err = simpleConsumer.Start() +// if err != nil { +// log.Fatal(err) +// } +// }) +// } +//} diff --git a/golang/message/message_abnormal_test.go b/golang/pkg/message/message_abnormal_test.go similarity index 100% rename from golang/message/message_abnormal_test.go rename to golang/pkg/message/message_abnormal_test.go diff --git a/golang/message/message_body_content_test.go b/golang/pkg/message/message_body_content_test.go similarity index 100% rename from golang/message/message_body_content_test.go rename to golang/pkg/message/message_body_content_test.go diff --git a/golang/message/message_key_test.go b/golang/pkg/message/message_key_test.go similarity index 81% rename from golang/message/message_key_test.go rename to golang/pkg/message/message_key_test.go index cd20f55..efbb4fd 100644 --- a/golang/message/message_key_test.go +++ b/golang/pkg/message/message_key_test.go @@ -75,16 +75,15 @@ func TestMessageKeySize(t *testing.T) { } } -func TestMessageKeyContentWithChinese(t *testing.T) { +func TestMessageKeyContent(t *testing.T) { type args struct { - name, testTopic, nameServer, grpcEndpoint, clusterName, ak, sk, cm, msgtag, keys, body string + testTopic, nameServer, grpcEndpoint, clusterName, ak, sk, cm, msgtag, keys, body string } tests := []struct { name string args args }{ { - name: "Message key contains Chinese, expect send and consume success", args: args{ testTopic: GetTopicName(), nameServer: NAMESERVER, @@ -100,7 +99,7 @@ func TestMessageKeyContentWithChinese(t *testing.T) { }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { + t.Run("Message key contains Chinese, expect send and consume success", func(t *testing.T) { var wg sync.WaitGroup CreateTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) @@ -129,35 +128,7 @@ func TestMessageKeyContentWithChinese(t *testing.T) { CheckMsgsWithAll(t, sendMsgCollector, recvMsgCollector) }) - } -} - -func TestMessageWithMultiKey(t *testing.T) { - type args struct { - name, testTopic, nameServer, grpcEndpoint, clusterName, ak, sk, cm, msgtag, keys, body string - } - tests := []struct { - name string - args args - }{ - { - name: "The message contains multiple keys, expect send and consume success", - args: args{ - testTopic: GetTopicName(), - nameServer: NAMESERVER, - grpcEndpoint: GRPC_ENDPOINT, - clusterName: CLUSTER_NAME, - ak: "", - sk: "", - cm: GetGroupName(), - msgtag: RandomString(8), - keys: RandomString(64), - body: RandomString(64), - }, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { + t.Run("The message contains multiple keys, expect send and consume success", func(t *testing.T) { var wg sync.WaitGroup var k1 = RandomString(64) diff --git a/golang/message/delay_message_size_test.go b/golang/pkg/message/message_size_test.go similarity index 55% rename from golang/message/delay_message_size_test.go rename to golang/pkg/message/message_size_test.go index 57f38ed..9e441c2 100644 --- a/golang/message/delay_message_size_test.go +++ b/golang/pkg/message/message_size_test.go @@ -6,6 +6,61 @@ import ( "time" ) +func TestNormalMessageSize(t *testing.T) { + type args struct { + name, testTopic, nameServer, grpcEndpoint, clusterName, ak, sk, cm, msgtag, keys, body string + } + tests := []struct { + name string + args args + }{ + { + name: "Send normal messages synchronously with the body size of 4M+1, expect send failed", + args: args{ + testTopic: GetTopicName(), + nameServer: NAMESERVER, + grpcEndpoint: GRPC_ENDPOINT, + clusterName: CLUSTER_NAME, + ak: "", + sk: "", + msgtag: RandomString(8), + keys: RandomString(8), + body: RandomString(4*1024*1024 + 1), + }, + }, + { + name: "Send normal messages synchronously with the body size of 4M, expect send success", + args: args{ + testTopic: GetTopicName(), + nameServer: NAMESERVER, + grpcEndpoint: GRPC_ENDPOINT, + clusterName: CLUSTER_NAME, + ak: "", + sk: "", + msgtag: RandomString(8), + keys: RandomString(8), + body: RandomString(4 * 1024 * 1024), + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + CreateTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) + + // new producer instance + producer := BuildProducer(tt.args.grpcEndpoint, tt.args.ak, tt.args.sk, tt.args.testTopic) + // graceful stop producer + defer producer.GracefulStop() + + msg := BuildNormalMessage(tt.args.testTopic, tt.args.body, tt.args.msgtag, tt.args.keys) + + sendMsgCollector := NewSendMsgsCollector() + + SendMessage(producer, msg, sendMsgCollector) + }) + } +} + func TestDelayMessageSize(t *testing.T) { type args struct { name, testTopic, nameServer, grpcEndpoint, clusterName, ak, sk, cm, msgtag, keys, body string diff --git a/golang/message/message_tag_test.go b/golang/pkg/message/message_tag_test.go similarity index 100% rename from golang/message/message_tag_test.go rename to golang/pkg/message/message_tag_test.go diff --git a/golang/message/message_user_property_test.go b/golang/pkg/message/message_user_property_test.go similarity index 100% rename from golang/message/message_user_property_test.go rename to golang/pkg/message/message_user_property_test.go diff --git a/golang/pkg/server/delay/delaymsg_test.go b/golang/pkg/server/delay/delaymsg_test.go new file mode 100644 index 0000000..80ecc40 --- /dev/null +++ b/golang/pkg/server/delay/delaymsg_test.go @@ -0,0 +1,170 @@ +/* + * 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 delay_test + +import ( + . "rocketmq-go-e2e/utils" + "sync" + "testing" + "time" +) + +func TestDelaySendMessage(t *testing.T) { + type args struct { + testTopic, nameServer, grpcEndpoint, clusterName, ak, sk, cm, msgtag, keys, body string + } + tests := []struct { + args args + }{ + { + args: args{ + testTopic: GetTopicName(), + nameServer: NAMESERVER, + grpcEndpoint: GRPC_ENDPOINT, + clusterName: CLUSTER_NAME, + ak: "", + sk: "", + cm: GetGroupName(), + msgtag: RandomString(8), + keys: RandomString(8), + body: RandomString(8), + }, + }, + } + for _, tt := range tests { + t.Run("Send 10 messages, set the message delivery time to 30 seconds after the current system time, and expect to consume all 10 messages after 30 seconds.", func(t *testing.T) { + var ( + wg sync.WaitGroup + msgCount = 10 + delaySeconds = 30 + ) + CreateDelayTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) + + simpleConsumer := BuildSimpleConsumer(tt.args.grpcEndpoint, tt.args.cm, tt.args.msgtag, tt.args.ak, tt.args.sk, tt.args.testTopic) + + // graceful stop simpleConsumer + defer simpleConsumer.GracefulStop() + + // new producer instance + producer := BuildProducer(tt.args.grpcEndpoint, tt.args.ak, tt.args.sk, tt.args.testTopic) + + // graceful stop producer + defer producer.GracefulStop() + + var recvMsgCollector *RecvMsgsCollector + sendMsgCollector := NewSendMsgsCollector() + + wg.Add(1) + + go func() { + recvMsgCollector = RecvMessage(simpleConsumer, MaxMessageNum, InvisibleDuration, int64(10+delaySeconds)) + wg.Done() + }() + go func() { + for i := 0; i < msgCount; i++ { + msg := BuildDelayMessage(tt.args.testTopic, tt.args.body, tt.args.msgtag, time.Duration(delaySeconds), tt.args.keys) + SendMessage(producer, msg, sendMsgCollector) + } + }() + wg.Wait() + + CheckMsgsWithMsgId(t, sendMsgCollector, recvMsgCollector) + }) + t.Run("Send 10 messages, set the message delivery time to 10 seconds before the current system time, the expected timing will not take effect, and all 10 messages can be consumed immediately.", func(t *testing.T) { + var ( + wg sync.WaitGroup + msgCount = 10 + delaySeconds = 30 + ) + CreateDelayTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) + + simpleConsumer := BuildSimpleConsumer(tt.args.grpcEndpoint, tt.args.cm, tt.args.msgtag, tt.args.ak, tt.args.sk, tt.args.testTopic) + + // graceful stop simpleConsumer + defer simpleConsumer.GracefulStop() + + // new producer instance + producer := BuildProducer(tt.args.grpcEndpoint, tt.args.ak, tt.args.sk, tt.args.testTopic) + + // graceful stop producer + defer producer.GracefulStop() + + var recvMsgCollector *RecvMsgsCollector + sendMsgCollector := NewSendMsgsCollector() + + wg.Add(1) + + go func() { + recvMsgCollector = RecvMessage(simpleConsumer, MaxMessageNum, InvisibleDuration, int64(10+delaySeconds)) + wg.Done() + }() + go func() { + for i := 0; i < msgCount; i++ { + duration, _ := time.ParseDuration("-10s") // 定义时间差量为10秒前 + timeBefore10s := time.Now().Add(duration) + elapsedTime := time.Since(timeBefore10s) + msg := BuildDelayMessage(tt.args.testTopic, "test", tt.args.msgtag, elapsedTime, tt.args.keys) + SendMessage(producer, msg, sendMsgCollector) + } + }() + wg.Wait() + + CheckMsgsWithMsgId(t, sendMsgCollector, recvMsgCollector) + }) + t.Run("Send a message and set the delivery time of the message to 24 hours and 5 seconds from the current system time. The expected message delivery fails.", func(t *testing.T) { + var ( + wg sync.WaitGroup + msgCount = 10 + delaySeconds = 30 + ) + CreateDelayTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) + + simpleConsumer := BuildSimpleConsumer(tt.args.grpcEndpoint, tt.args.cm, tt.args.msgtag, tt.args.ak, tt.args.sk, tt.args.testTopic) + + // graceful stop simpleConsumer + defer simpleConsumer.GracefulStop() + + // new producer instance + producer := BuildProducer(tt.args.grpcEndpoint, tt.args.ak, tt.args.sk, tt.args.testTopic) + + // graceful stop producer + defer producer.GracefulStop() + + var recvMsgCollector *RecvMsgsCollector + sendMsgCollector := NewSendMsgsCollector() + + wg.Add(1) + + go func() { + recvMsgCollector = RecvMessage(simpleConsumer, MaxMessageNum, InvisibleDuration, int64(10+delaySeconds)) + wg.Done() + }() + go func() { + for i := 0; i < msgCount; i++ { + duration, _ := time.ParseDuration("24h5s") // 定义时间差量为24小时零5秒后 + msg := BuildDelayMessage(tt.args.testTopic, "test", tt.args.msgtag, duration, tt.args.keys) + SendMessage(producer, msg, sendMsgCollector) + } + }() + wg.Wait() + + CheckMsgsWithMsgId(t, sendMsgCollector, recvMsgCollector) + //todo 添加运行失败,但是不报错的逻辑 + }) + } +} diff --git a/golang/pkg/server/normal/normalmsg_test.go b/golang/pkg/server/normal/normalmsg_test.go new file mode 100644 index 0000000..3adbad0 --- /dev/null +++ b/golang/pkg/server/normal/normalmsg_test.go @@ -0,0 +1,114 @@ +/* + * 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 normal_test + +import ( + . "rocketmq-go-e2e/utils" + "sync" + "testing" +) + +func TestMessageSyncAndASyncTransfer(t *testing.T) { + type args struct { + testTopic, nameServer, grpcEndpoint, clusterName, ak, sk, cm, msgtag, keys, body string + } + tests := []struct { + args args + }{ + { + args: args{ + testTopic: GetTopicName(), + nameServer: NAMESERVER, + grpcEndpoint: GRPC_ENDPOINT, + clusterName: CLUSTER_NAME, + ak: "", + sk: "", + cm: GetGroupName(), + msgtag: RandomString(8), + keys: RandomString(8), + body: RandomString(8), + }, + }, + } + for _, tt := range tests { + t.Run("The synchronous test message is sent normally, expecting success", func(t *testing.T) { + var wg sync.WaitGroup + CreateTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) + + simpleConsumer := BuildSimpleConsumer(tt.args.grpcEndpoint, tt.args.cm, tt.args.msgtag, tt.args.ak, tt.args.sk, tt.args.testTopic) + + // graceful stop simpleConsumer + defer simpleConsumer.GracefulStop() + + // new producer instance + producer := BuildProducer(tt.args.grpcEndpoint, tt.args.ak, tt.args.sk, tt.args.testTopic) + + // graceful stop producer + defer producer.GracefulStop() + + var recvMsgCollector *RecvMsgsCollector + var sendMsgCollector *SendMsgsCollector + + wg.Add(1) + + go func() { + recvMsgCollector = RecvMessage(simpleConsumer, MaxMessageNum, InvisibleDuration, 10) + wg.Done() + }() + go func() { + sendMsgCollector = SendNormalMessage(producer, tt.args.testTopic, "test", tt.args.msgtag, 10, tt.args.keys) + }() + wg.Wait() + + CheckMsgsWithMsgId(t, sendMsgCollector, recvMsgCollector) + }) + t.Run("The asynchronous test message is sent normally, expecting success", func(t *testing.T) { + var wg sync.WaitGroup + CreateTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) + + simpleConsumer := BuildSimpleConsumer(tt.args.grpcEndpoint, tt.args.cm, tt.args.msgtag, tt.args.ak, tt.args.sk, tt.args.testTopic) + + // graceful stop simpleConsumer + defer simpleConsumer.GracefulStop() + + // new producer instance + producer := BuildProducer(tt.args.grpcEndpoint, tt.args.ak, tt.args.sk, tt.args.testTopic) + + // graceful stop producer + defer producer.GracefulStop() + + msg := BuildNormalMessage(tt.args.testTopic, tt.args.body, tt.args.msgtag, tt.args.keys) + + var recvMsgCollector *RecvMsgsCollector + sendMsgCollector := NewSendMsgsCollector() + + wg.Add(1) + + go func() { + recvMsgCollector = RecvMessage(simpleConsumer, MaxMessageNum, InvisibleDuration, 10) + wg.Done() + }() + go func() { + SendMessageAsync(producer, msg, sendMsgCollector) + }() + wg.Wait() + + CheckMsgsWithMsgId(t, sendMsgCollector, recvMsgCollector) + }) + } +} diff --git a/golang/pkg/server/order/ordermsg_test.go b/golang/pkg/server/order/ordermsg_test.go new file mode 100644 index 0000000..b830151 --- /dev/null +++ b/golang/pkg/server/order/ordermsg_test.go @@ -0,0 +1,84 @@ +/* + * 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 order_test + +import ( + . "rocketmq-go-e2e/utils" + "sync" + "testing" +) + +func TestOrderSendOrderly(t *testing.T) { + type args struct { + testTopic, nameServer, grpcEndpoint, clusterName, ak, sk, cm, msgtag, keys, body string + } + tests := []struct { + name string + args args + }{ + { + args: args{ + testTopic: GetTopicName(), + nameServer: NAMESERVER, + grpcEndpoint: GRPC_ENDPOINT, + clusterName: CLUSTER_NAME, + ak: "", + sk: "", + cm: GetGroupName(), + msgtag: RandomString(8), + keys: RandomString(8), + body: RandomString(8), + }, + }, + } + for _, tt := range tests { + t.Run("Send 100 sequential messages synchronously, set 2 Messagegroups, and expect these 100 messages to be sequentially consumed by PushConsumer", func(t *testing.T) { + var wg sync.WaitGroup + CreateFIFOTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) + + simpleConsumer := BuildSimpleConsumer(tt.args.grpcEndpoint, tt.args.cm, tt.args.msgtag, tt.args.ak, tt.args.sk, tt.args.testTopic) + + // graceful stop simpleConsumer + defer simpleConsumer.GracefulStop() + + // new producer instance + producer := BuildProducer(tt.args.grpcEndpoint, tt.args.ak, tt.args.sk, tt.args.testTopic) + + // graceful stop producer + defer producer.GracefulStop() + + var recvMsgCollector *RecvMsgsCollector + sendMsgCollector := NewSendMsgsCollector() + + wg.Add(1) + + go func() { + recvMsgCollector = RecvMessage(simpleConsumer, MaxMessageNum, InvisibleDuration, 10) + wg.Done() + }() + go func() { + for i := 0; i <= 100; i++ { + msg := BuildFIFOMessage(tt.args.testTopic, tt.args.body, tt.args.msgtag, tt.args.cm, tt.args.keys) + SendMessage(producer, msg, sendMsgCollector) + } + }() + wg.Wait() + + CheckMsgsWithMsgId(t, sendMsgCollector, recvMsgCollector) + }) + } +} diff --git a/golang/pkg/server/transaction/transmsg_test.go b/golang/pkg/server/transaction/transmsg_test.go new file mode 100644 index 0000000..7fa6ecf --- /dev/null +++ b/golang/pkg/server/transaction/transmsg_test.go @@ -0,0 +1,81 @@ +/* + * 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 transaction_test + +import ( + . "rocketmq-go-e2e/utils" + "sync" + "testing" +) + +func TestSendTransactionMessage(t *testing.T) { + type args struct { + testTopic, nameServer, grpcEndpoint, clusterName, ak, sk, cm, msgtag, keys, body string + } + tests := []struct { + args args + }{ + { + args: args{ + testTopic: GetTopicName(), + nameServer: NAMESERVER, + grpcEndpoint: GRPC_ENDPOINT, + clusterName: CLUSTER_NAME, + ak: "", + sk: "", + cm: GetGroupName(), + msgtag: RandomString(8), + keys: RandomString(8), + body: RandomString(8), + }, + }, + } + for _, tt := range tests { + t.Run("The synchronous test message is sent normally, expecting success", func(t *testing.T) { + var wg sync.WaitGroup + CreateTransactionTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) + + simpleConsumer := BuildSimpleConsumer(tt.args.grpcEndpoint, tt.args.cm, tt.args.msgtag, tt.args.ak, tt.args.sk, tt.args.testTopic) + + // graceful stop simpleConsumer + defer simpleConsumer.GracefulStop() + + // new producer instance + producer := BuildProducer(tt.args.grpcEndpoint, tt.args.ak, tt.args.sk, tt.args.testTopic) + + // graceful stop producer + defer producer.GracefulStop() + + var recvMsgCollector *RecvMsgsCollector + var sendMsgCollector *SendMsgsCollector + + wg.Add(1) + + go func() { + recvMsgCollector = RecvMessage(simpleConsumer, MaxMessageNum, InvisibleDuration, 10) + wg.Done() + }() + go func() { + sendMsgCollector = SendTransactionMessage(producer, tt.args.testTopic, "test", tt.args.msgtag, 11, tt.args.keys) + }() + wg.Wait() + + CheckMsgsWithMsgId(t, sendMsgCollector, recvMsgCollector) + }) + } +} diff --git a/golang/pkg/simple/simple_ack_test.go b/golang/pkg/simple/simple_ack_test.go new file mode 100644 index 0000000..a6d8750 --- /dev/null +++ b/golang/pkg/simple/simple_ack_test.go @@ -0,0 +1,145 @@ +package simple + +import ( + . "rocketmq-go-e2e/utils" + "sync" + "testing" +) + +func TestMessageBodyContent(t *testing.T) { + type args struct { + testTopic, nameServer, grpcEndpoint, clusterName, ak, sk, cm, msgtag, keys, body string + } + tests := []struct { + args args + }{ + { + args: args{ + testTopic: GetTopicName(), + nameServer: NAMESERVER, + grpcEndpoint: GRPC_ENDPOINT, + clusterName: CLUSTER_NAME, + ak: "", + sk: "", + cm: GetGroupName(), + msgtag: RandomString(8), + keys: RandomString(8), + body: RandomString(8), + }, + }, + } + for _, tt := range tests { + t.Run("Send 20 normal messages synchronously and expect consume with receive() and ack() messages successful", func(t *testing.T) { + var ( + wg sync.WaitGroup + recvMsgCollector *RecvMsgsCollector + sendMsgCollector *SendMsgsCollector + ) + + CreateTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) + simpleConsumer := BuildSimpleConsumer(tt.args.grpcEndpoint, tt.args.cm, tt.args.msgtag, tt.args.ak, tt.args.sk, tt.args.testTopic) + + // new producer instance + producer := BuildProducer(tt.args.grpcEndpoint, tt.args.ak, tt.args.sk, tt.args.testTopic) + // graceful stop producer + defer producer.GracefulStop() + + wg.Add(1) + + go func() { + sendMsgCollector = SendNormalMessage(producer, tt.args.testTopic, tt.args.body, tt.args.msgtag, 20, tt.args.keys) + }() + + go func() { + recvMsgCollector = RecvMessage(simpleConsumer, MaxMessageNum, InvisibleDuration, 30) + wg.Done() + }() + wg.Wait() + CheckMsgsWithAll(t, sendMsgCollector, recvMsgCollector) + }) + t.Run("Send 20 normal messages synchronously. Expect consume with receiveAsync() and ack() messages successful", func(t *testing.T) { + var ( + wg sync.WaitGroup + recvMsgCollector *RecvMsgsCollector + sendMsgCollector *SendMsgsCollector + ) + + CreateTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) + simpleConsumer := BuildSimpleConsumer(tt.args.grpcEndpoint, tt.args.cm, tt.args.msgtag, tt.args.ak, tt.args.sk, tt.args.testTopic) + + // new producer instance + producer := BuildProducer(tt.args.grpcEndpoint, tt.args.ak, tt.args.sk, tt.args.testTopic) + // graceful stop producer + defer producer.GracefulStop() + + wg.Add(1) + + go func() { + sendMsgCollector = SendNormalMessageAsync(producer, tt.args.testTopic, tt.args.body, tt.args.msgtag, 20, tt.args.keys) + }() + + go func() { + recvMsgCollector = RecvMessage(simpleConsumer, MaxMessageNum, InvisibleDuration, 30) + wg.Done() + }() + wg.Wait() + CheckMsgsWithAll(t, sendMsgCollector, recvMsgCollector) + }) + } +} + +//func TestNormal_simple_receive_ackAsync(t *testing.T) { +// type args struct { +// name, testTopic, nameServer, grpcEndpoint, clusterName, ak, sk, cm, msgtag, keys, body string +// } +// tests := []struct { +// name string +// args args +// }{ +// { +// name: "Send 20 normal messages synchronously and expect consume with receive() and ackAsync() messages successful", +// args: args{ +// testTopic: GetTopicName(), +// nameServer: NAMESERVER, +// grpcEndpoint: GRPC_ENDPOINT, +// clusterName: CLUSTER_NAME, +// ak: "", +// sk: "", +// cm: GetGroupName(), +// msgtag: RandomString(8), +// keys: RandomString(8), +// body: RandomString(8), +// }, +// }, +// } +// for _, tt := range tests { +// t.Run(tt.name, func(t *testing.T) { +// var ( +// wg sync.WaitGroup +// recvMsgCollector *RecvMsgsCollector +// sendMsgCollector *SendMsgsCollector +// ) +// +// CreateTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) +// simpleConsumer := BuildSimpleConsumer(tt.args.grpcEndpoint, tt.args.cm, tt.args.msgtag, tt.args.ak, tt.args.sk, tt.args.testTopic) +// +// // new producer instance +// producer := BuildProducer(tt.args.grpcEndpoint, tt.args.ak, tt.args.sk, tt.args.testTopic) +// // graceful stop producer +// defer producer.GracefulStop() +// +// wg.Add(1) +// +// go func() { +// sendMsgCollector = SendNormalMessageAsync(producer, tt.args.testTopic, tt.args.body, tt.args.msgtag, 20, tt.args.keys) +// }() +// +// go func() { +// recvMsgCollector = RecvMessage(simpleConsumer, MaxMessageNum, InvisibleDuration, 30) +// wg.Done() +// }() +// wg.Wait() +// CheckMsgsWithAll(t, sendMsgCollector, recvMsgCollector) +// }) +// } +//} diff --git a/golang/producer/producer_Init_test.go b/golang/producer/producer_Init_test.go deleted file mode 100644 index 30f1d3d..0000000 --- a/golang/producer/producer_Init_test.go +++ /dev/null @@ -1 +0,0 @@ -package producer diff --git a/golang/utils/CreateMessageUtils.go b/golang/utils/CreateMessageUtils.go deleted file mode 100644 index e410a6b..0000000 --- a/golang/utils/CreateMessageUtils.go +++ /dev/null @@ -1,13 +0,0 @@ -package utils - -import ( - rmq_client "github.com/apache/rocketmq-clients/golang" -) - -func CreateMessage(topic, body string) *rmq_client.Message { - msg := &rmq_client.Message{ - Topic: topic, - Body: []byte(body), - } - return msg -} From c698666e36fc2dd1fb2b99a01fe67b11c924b83e Mon Sep 17 00:00:00 2001 From: WB01031309 Date: Mon, 3 Jul 2023 15:26:28 +0800 Subject: [PATCH 13/13] add golang test --- golang/common/common.go | 1 - golang/go.mod | 10 +- golang/go.sum | 10 + .../client/consumer/consumer_group_test.go | 1 - .../consumer/push_consumer_init_test.go | 1 - .../consumer/simple_consumer_init_test.go | 261 +----------------- golang/pkg/message/message_abnormal_test.go | 1 - golang/pkg/message/message_key_test.go | 9 +- golang/pkg/message/message_size_test.go | 19 +- golang/pkg/message/message_tag_test.go | 9 +- .../pkg/message/message_user_property_test.go | 1 - golang/pkg/producer/producer_init_test.go | 123 +++++++++ .../pkg/server/transaction/transmsg_test.go | 32 ++- golang/pkg/simple/simple_ack_test.go | 56 ---- 14 files changed, 199 insertions(+), 335 deletions(-) delete mode 100644 golang/common/common.go delete mode 100644 golang/pkg/client/consumer/consumer_group_test.go delete mode 100644 golang/pkg/client/consumer/push_consumer_init_test.go delete mode 100644 golang/pkg/message/message_abnormal_test.go delete mode 100644 golang/pkg/message/message_user_property_test.go create mode 100644 golang/pkg/producer/producer_init_test.go diff --git a/golang/common/common.go b/golang/common/common.go deleted file mode 100644 index 805d0c7..0000000 --- a/golang/common/common.go +++ /dev/null @@ -1 +0,0 @@ -package common diff --git a/golang/go.mod b/golang/go.mod index 9e28ad8..1e6b5b5 100644 --- a/golang/go.mod +++ b/golang/go.mod @@ -35,11 +35,11 @@ require ( golang.org/x/sync v0.3.0 // indirect golang.org/x/sys v0.9.0 // indirect golang.org/x/text v0.10.0 // indirect - google.golang.org/api v0.127.0 // indirect + google.golang.org/api v0.129.0 // indirect google.golang.org/genproto v0.0.0-20230530153820-e85fd2cbaebc // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect - google.golang.org/grpc v1.55.0 // indirect - google.golang.org/protobuf v1.30.0 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20230629202037-9506855d4529 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20230629202037-9506855d4529 // indirect + google.golang.org/grpc v1.56.1 // indirect + google.golang.org/protobuf v1.31.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/golang/go.sum b/golang/go.sum index 896a1bd..3fbff5f 100644 --- a/golang/go.sum +++ b/golang/go.sum @@ -347,6 +347,8 @@ google.golang.org/api v0.126.0 h1:q4GJq+cAdMAC7XP7njvQ4tvohGLiSlytuL4BQxbIZ+o= google.golang.org/api v0.126.0/go.mod h1:mBwVAtz+87bEN6CbA1GtZPDOqY2R5ONPqJeIlvyo4Aw= google.golang.org/api v0.127.0 h1:v7rj0vA0imM3Ou81k1eyFxQNScLzn71EyGnJDr+V/XI= google.golang.org/api v0.127.0/go.mod h1:Y611qgqaE92On/7g65MQgxYul3c0rEB894kniWLY750= +google.golang.org/api v0.129.0 h1:2XbdjjNfFPXQyufzQVwPf1RRnHH8Den2pfNE2jw7L8w= +google.golang.org/api v0.129.0/go.mod h1:dFjiXlanKwWE3612X97llhsoI36FAoIiRj3aTl5b/zE= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= @@ -387,12 +389,16 @@ google.golang.org/genproto/googleapis/api v0.0.0-20230526203410-71b5a4ffd15e h1: google.golang.org/genproto/googleapis/api v0.0.0-20230526203410-71b5a4ffd15e/go.mod h1:vHYtlOoi6TsQ3Uk2yxR7NI5z8uoV+3pZtR4jmHIkRig= google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc h1:kVKPf/IiYSBWEWtkIn6wZXwWGCnLKcC8oWfZvXjsGnM= google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc/go.mod h1:vHYtlOoi6TsQ3Uk2yxR7NI5z8uoV+3pZtR4jmHIkRig= +google.golang.org/genproto/googleapis/api v0.0.0-20230629202037-9506855d4529 h1:s5YSX+ZH5b5vS9rnpGymvIyMpLRJizowqDlOuyjXnTk= +google.golang.org/genproto/googleapis/api v0.0.0-20230629202037-9506855d4529/go.mod h1:vHYtlOoi6TsQ3Uk2yxR7NI5z8uoV+3pZtR4jmHIkRig= google.golang.org/genproto/googleapis/rpc v0.0.0-20230526015343-6ee61e4f9d5f h1:QNVuVEP2S7NNxLdNdOq0RiW3c9pW4gIpUUd+GAOjk1Y= google.golang.org/genproto/googleapis/rpc v0.0.0-20230526015343-6ee61e4f9d5f/go.mod h1:66JfowdXAEgad5O9NnYcsNPLCPZJD++2L9X0PCMODrA= google.golang.org/genproto/googleapis/rpc v0.0.0-20230526203410-71b5a4ffd15e h1:NumxXLPfHSndr3wBBdeKiVHjGVFzi9RX2HwwQke94iY= google.golang.org/genproto/googleapis/rpc v0.0.0-20230526203410-71b5a4ffd15e/go.mod h1:66JfowdXAEgad5O9NnYcsNPLCPZJD++2L9X0PCMODrA= google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc h1:XSJ8Vk1SWuNr8S18z1NZSziL0CPIXLCCMDOEFtHBOFc= google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc/go.mod h1:66JfowdXAEgad5O9NnYcsNPLCPZJD++2L9X0PCMODrA= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230629202037-9506855d4529 h1:DEH99RbiLZhMxrpEJCZ0A+wdTe0EOgou/poSLx9vWf4= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230629202037-9506855d4529/go.mod h1:66JfowdXAEgad5O9NnYcsNPLCPZJD++2L9X0PCMODrA= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= @@ -406,6 +412,8 @@ google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3Iji google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= google.golang.org/grpc v1.55.0 h1:3Oj82/tFSCeUrRTg/5E/7d/W5A1tj6Ky1ABAuZuv5ag= google.golang.org/grpc v1.55.0/go.mod h1:iYEXKGkEBhg1PjZQvoYEVPTDkHo1/bjTnfwTeGONTY8= +google.golang.org/grpc v1.56.1 h1:z0dNfjIl0VpaZ9iSVjA6daGatAYwPGstTjt5vkRMFkQ= +google.golang.org/grpc v1.56.1/go.mod h1:I9bI3vqKfayGqPUAwGdOSu7kt6oIJLixfffKrpXqQ9s= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -420,6 +428,8 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0 google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= +google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/golang/pkg/client/consumer/consumer_group_test.go b/golang/pkg/client/consumer/consumer_group_test.go deleted file mode 100644 index b78b46c..0000000 --- a/golang/pkg/client/consumer/consumer_group_test.go +++ /dev/null @@ -1 +0,0 @@ -package consumer diff --git a/golang/pkg/client/consumer/push_consumer_init_test.go b/golang/pkg/client/consumer/push_consumer_init_test.go deleted file mode 100644 index b78b46c..0000000 --- a/golang/pkg/client/consumer/push_consumer_init_test.go +++ /dev/null @@ -1 +0,0 @@ -package consumer diff --git a/golang/pkg/client/consumer/simple_consumer_init_test.go b/golang/pkg/client/consumer/simple_consumer_init_test.go index 65361c2..b1c4b1e 100644 --- a/golang/pkg/client/consumer/simple_consumer_init_test.go +++ b/golang/pkg/client/consumer/simple_consumer_init_test.go @@ -1,9 +1,9 @@ package consumer import ( - "log" . "rocketmq-go-e2e/utils" "testing" + "time" rmq_client "github.com/apache/rocketmq-clients/golang" "github.com/apache/rocketmq-clients/golang/credentials" @@ -32,36 +32,6 @@ func TestSimpleConsumerInit(t *testing.T) { body: RandomString(8), }, }, - { - name: "Without setting 'ClientConfiguration' of the consumer client, expect start failed", - args: args{ - testTopic: GetTopicName(), - nameServer: "", - grpcEndpoint: "", - clusterName: CLUSTER_NAME, - ak: "", - sk: "", - cm: GetGroupName(), - msgtag: RandomString(8), - keys: RandomString(8), - body: RandomString(8), - }, - }, - { - name: "Without setting 'ConsumerGroup' of the consumer client, expect start failed", - args: args{ - testTopic: GetTopicName(), - nameServer: NAMESERVER, - grpcEndpoint: GRPC_ENDPOINT, - clusterName: CLUSTER_NAME, - ak: "", - sk: "", - cm: "", - msgtag: RandomString(8), - keys: RandomString(8), - body: RandomString(8), - }, - }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -75,237 +45,24 @@ func TestSimpleConsumerInit(t *testing.T) { AccessSecret: tt.args.sk, }, }, - //rmq_client.WithAwaitDuration(time.Second*10), + rmq_client.WithAwaitDuration(time.Second*10), rmq_client.WithSubscriptionExpressions(map[string]*rmq_client.FilterExpression{ - tt.args.testTopic: rmq_client.NewFilterExpression(tt.args.msgtag), + tt.args.testTopic: rmq_client.NewFilterExpression("*"), }), ) if err != nil { - log.Fatal(err) + t.Fail() + t.Log("Error: ", err) } + defer simpleConsumer.GracefulStop() + // start simpleConsumer err = simpleConsumer.Start() if err != nil { - log.Fatal(err) + t.Fail() + t.Log("Error: ", err) } }) } } - -//func TestNoSubscription(t *testing.T) { -// type args struct { -// name, testTopic, nameServer, grpcEndpoint, clusterName, ak, sk, cm, msgtag, keys, body string -// } -// tests := []struct { -// name string -// args args -// }{ -// { -// //todo 未设置Subscription依然可以启动成功 -// name: "Without setting 'AwaitDuration' of the consumer client, expect start failed", -// args: args{ -// testTopic: GetTopicName(), -// nameServer: NAMESERVER, -// grpcEndpoint: GRPC_ENDPOINT, -// clusterName: CLUSTER_NAME, -// ak: "", -// sk: "", -// cm: GetGroupName(), -// msgtag: RandomString(8), -// keys: RandomString(8), -// body: RandomString(8), -// }, -// }, -// } -// for _, tt := range tests { -// t.Run(tt.name, func(t *testing.T) { -// CreateTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) -// -// simpleConsumer, err := rmq_client.NewSimpleConsumer(&rmq_client.Config{ -// Endpoint: tt.args.grpcEndpoint, -// ConsumerGroup: tt.args.cm, -// Credentials: &credentials.SessionCredentials{ -// AccessKey: tt.args.ak, -// AccessSecret: tt.args.sk, -// }, -// }, -// rmq_client.WithAwaitDuration(time.Second*10), -// rmq_client.WithSubscriptionExpressions(map[string]*rmq_client.FilterExpression{ -// tt.args.testTopic: rmq_client.NewFilterExpression(tt.args.msgtag), -// }), -// ) -// if err != nil { -// log.Fatal(err) -// } -// -// // start simpleConsumer -// err = simpleConsumer.Start() -// if err != nil { -// log.Fatal(err) -// } -// }) -// } -//} -// -//func TestNoAwaitDuration(t *testing.T) { -// type args struct { -// name, testTopic, nameServer, grpcEndpoint, clusterName, ak, sk, cm, msgtag, keys, body string -// } -// tests := []struct { -// name string -// args args -// }{ -// { -// //todo 未设置AwaitDuration依然可以启动成功 -// name: "Without setting 'AwaitDuration' of the consumer client, expect start failed", -// args: args{ -// testTopic: GetTopicName(), -// nameServer: NAMESERVER, -// grpcEndpoint: GRPC_ENDPOINT, -// clusterName: CLUSTER_NAME, -// ak: "", -// sk: "", -// cm: GetGroupName(), -// msgtag: RandomString(8), -// keys: RandomString(8), -// body: RandomString(8), -// }, -// }, -// } -// for _, tt := range tests { -// t.Run(tt.name, func(t *testing.T) { -// CreateTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) -// -// simpleConsumer, err := rmq_client.NewSimpleConsumer(&rmq_client.Config{ -// Endpoint: tt.args.grpcEndpoint, -// ConsumerGroup: tt.args.cm, -// Credentials: &credentials.SessionCredentials{ -// AccessKey: tt.args.ak, -// AccessSecret: tt.args.sk, -// }, -// }, -// rmq_client.WithSubscriptionExpressions(map[string]*rmq_client.FilterExpression{ -// tt.args.testTopic: rmq_client.NewFilterExpression(tt.args.msgtag), -// }), -// ) -// if err != nil { -// log.Fatal(err) -// } -// -// // start simpleConsumer -// err = simpleConsumer.Start() -// if err != nil { -// log.Fatal(err) -// } -// }) -// } -//} -// -//func TestEmptySubscription(t *testing.T) { -// type args struct { -// name, testTopic, nameServer, grpcEndpoint, clusterName, ak, sk, cm, msgtag, keys, body string -// } -// tests := []struct { -// name string -// args args -// }{ -// { -// // todo 未通过 -// name: "Error setting 'SubscriptionExpressions' empty of the consumer client, except start failed", -// args: args{ -// testTopic: GetTopicName(), -// nameServer: NAMESERVER, -// grpcEndpoint: GRPC_ENDPOINT, -// clusterName: CLUSTER_NAME, -// ak: "", -// sk: "", -// cm: GetGroupName(), -// msgtag: RandomString(8), -// keys: RandomString(8), -// body: RandomString(8), -// }, -// }, -// } -// for _, tt := range tests { -// t.Run(tt.name, func(t *testing.T) { -// CreateTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) -// -// simpleConsumer, err := rmq_client.NewSimpleConsumer(&rmq_client.Config{ -// Endpoint: tt.args.grpcEndpoint, -// ConsumerGroup: tt.args.cm, -// Credentials: &credentials.SessionCredentials{ -// AccessKey: tt.args.ak, -// AccessSecret: tt.args.sk, -// }, -// }, -// rmq_client.WithAwaitDuration(time.Second*10), -// rmq_client.WithSubscriptionExpressions(map[string]*rmq_client.FilterExpression{}), -// ) -// if err != nil { -// log.Fatal(err) -// } -// -// // start simpleConsumer -// err = simpleConsumer.Start() -// if err != nil { -// log.Fatal(err) -// } -// }) -// } -//} -// -//func TestAwaitDurationIs0s(t *testing.T) { -// type args struct { -// name, testTopic, nameServer, grpcEndpoint, clusterName, ak, sk, cm, msgtag, keys, body string -// } -// tests := []struct { -// name string -// args args -// }{ -// { -// //todo 测试未通过 -// name: "Error setting 'MaxMessageNum=0' of the consumer client, except start failed", -// args: args{ -// testTopic: GetTopicName(), -// nameServer: NAMESERVER, -// grpcEndpoint: GRPC_ENDPOINT, -// clusterName: CLUSTER_NAME, -// ak: "", -// sk: "", -// cm: GetGroupName(), -// msgtag: RandomString(8), -// keys: RandomString(8), -// body: RandomString(8), -// }, -// }, -// } -// for _, tt := range tests { -// t.Run(tt.name, func(t *testing.T) { -// CreateTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) -// -// simpleConsumer, err := rmq_client.NewSimpleConsumer(&rmq_client.Config{ -// Endpoint: tt.args.grpcEndpoint, -// ConsumerGroup: tt.args.cm, -// Credentials: &credentials.SessionCredentials{ -// AccessKey: tt.args.ak, -// AccessSecret: tt.args.sk, -// }, -// }, -// rmq_client.WithAwaitDuration(time.Second*0), -// rmq_client.WithSubscriptionExpressions(map[string]*rmq_client.FilterExpression{ -// tt.args.testTopic: rmq_client.NewFilterExpression(tt.args.msgtag), -// }), -// ) -// if err != nil { -// log.Fatal(err) -// } -// -// // start simpleConsumer -// err = simpleConsumer.Start() -// if err != nil { -// log.Fatal(err) -// } -// }) -// } -//} diff --git a/golang/pkg/message/message_abnormal_test.go b/golang/pkg/message/message_abnormal_test.go deleted file mode 100644 index 251ab95..0000000 --- a/golang/pkg/message/message_abnormal_test.go +++ /dev/null @@ -1 +0,0 @@ -package rocketmqtest diff --git a/golang/pkg/message/message_key_test.go b/golang/pkg/message/message_key_test.go index efbb4fd..0d65345 100644 --- a/golang/pkg/message/message_key_test.go +++ b/golang/pkg/message/message_key_test.go @@ -1,6 +1,7 @@ package rocketmqtest import ( + "context" . "rocketmq-go-e2e/utils" "sync" "testing" @@ -68,9 +69,11 @@ func TestMessageKeySize(t *testing.T) { msg := BuildNormalMessage(tt.args.testTopic, tt.args.body, tt.args.msgtag, tt.args.keys) - sendMsgCollector := NewSendMsgsCollector() - - SendMessage(producer, msg, sendMsgCollector) + _, err := producer.Send(context.TODO(), msg) + if err != nil { + t.Fail() + t.Log("Error: ", err) + } }) } } diff --git a/golang/pkg/message/message_size_test.go b/golang/pkg/message/message_size_test.go index 9e441c2..eea9a64 100644 --- a/golang/pkg/message/message_size_test.go +++ b/golang/pkg/message/message_size_test.go @@ -1,11 +1,14 @@ package rocketmqtest import ( + "context" . "rocketmq-go-e2e/utils" "testing" "time" ) +// todo Golang中不能发送4M的消息,初步认为是版本问题,后期将继续跟进 + func TestNormalMessageSize(t *testing.T) { type args struct { name, testTopic, nameServer, grpcEndpoint, clusterName, ak, sk, cm, msgtag, keys, body string @@ -54,9 +57,11 @@ func TestNormalMessageSize(t *testing.T) { msg := BuildNormalMessage(tt.args.testTopic, tt.args.body, tt.args.msgtag, tt.args.keys) - sendMsgCollector := NewSendMsgsCollector() - - SendMessage(producer, msg, sendMsgCollector) + _, err := producer.Send(context.TODO(), msg) + if err != nil { + t.Fail() + t.Log("Error: ", err) + } }) } } @@ -112,9 +117,11 @@ func TestDelayMessageSize(t *testing.T) { msg := BuildDelayMessage(tt.args.testTopic, tt.args.body, tt.args.msgtag, time.Duration(tt.args.deliveryTimestamp), tt.args.keys) - sendMsgCollector := NewSendMsgsCollector() - - SendMessage(producer, msg, sendMsgCollector) + _, err := producer.Send(context.TODO(), msg) + if err != nil { + t.Fail() + t.Log("Error: ", err) + } }) } } diff --git a/golang/pkg/message/message_tag_test.go b/golang/pkg/message/message_tag_test.go index e21a32c..049be10 100644 --- a/golang/pkg/message/message_tag_test.go +++ b/golang/pkg/message/message_tag_test.go @@ -1,6 +1,7 @@ package rocketmqtest import ( + "context" . "rocketmq-go-e2e/utils" "sync" "testing" @@ -81,9 +82,11 @@ func TestMessageTagSizeAndSpecialCharacter(t *testing.T) { msg := BuildNormalMessage(tt.args.testTopic, tt.args.body, tt.args.msgtag, tt.args.keys) - sendMsgCollector := NewSendMsgsCollector() - - SendMessage(producer, msg, sendMsgCollector) + _, err := producer.Send(context.TODO(), msg) + if err != nil { + t.Fail() + t.Log("Error: ", err) + } }) } } diff --git a/golang/pkg/message/message_user_property_test.go b/golang/pkg/message/message_user_property_test.go deleted file mode 100644 index 251ab95..0000000 --- a/golang/pkg/message/message_user_property_test.go +++ /dev/null @@ -1 +0,0 @@ -package rocketmqtest diff --git a/golang/pkg/producer/producer_init_test.go b/golang/pkg/producer/producer_init_test.go new file mode 100644 index 0000000..67443e3 --- /dev/null +++ b/golang/pkg/producer/producer_init_test.go @@ -0,0 +1,123 @@ +package producer + +import ( + . "rocketmq-go-e2e/utils" + "sync" + "testing" + "time" + + rmq_client "github.com/apache/rocketmq-clients/golang" + "github.com/apache/rocketmq-clients/golang/credentials" +) + +func TestProducerInit(t *testing.T) { + type args struct { + testTopic, nameServer, grpcEndpoint, clusterName, ak, sk, cm, msgtag, keys, body string + } + tests := []struct { + args args + }{ + { + args: args{ + testTopic: GetTopicName(), + nameServer: NAMESERVER, + grpcEndpoint: GRPC_ENDPOINT, + clusterName: CLUSTER_NAME, + ak: "", + sk: "", + cm: GetGroupName(), + msgtag: RandomString(8), + keys: RandomString(8), + body: RandomString(8), + }, + }, + } + for _, tt := range tests { + t.Run("Producer is normally set,expected success", func(t *testing.T) { + var wg sync.WaitGroup + CreateTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) + + simpleConsumer := BuildSimpleConsumer(tt.args.grpcEndpoint, tt.args.cm, tt.args.msgtag, tt.args.ak, tt.args.sk, tt.args.testTopic) + + // graceful stop simpleConsumer + defer simpleConsumer.GracefulStop() + + // new producer instance + producer := BuildProducer(tt.args.grpcEndpoint, tt.args.ak, tt.args.sk, tt.args.testTopic) + + // graceful stop producer + defer producer.GracefulStop() + + var recvMsgCollector *RecvMsgsCollector + var sendMsgCollector *SendMsgsCollector + + wg.Add(1) + + go func() { + recvMsgCollector = RecvMessage(simpleConsumer, MaxMessageNum, InvisibleDuration, 10) + wg.Done() + }() + go func() { + sendMsgCollector = SendNormalMessage(producer, tt.args.testTopic, "test", tt.args.msgtag, 10, tt.args.keys) + }() + wg.Wait() + + CheckMsgsWithMsgId(t, sendMsgCollector, recvMsgCollector) + }) + t.Run("The NAMESERVER_ADDR setting of the Producer failed, expect failed", func(t *testing.T) { + var wg sync.WaitGroup + CreateTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) + + simpleConsumer, err := rmq_client.NewSimpleConsumer(&rmq_client.Config{ + Endpoint: "https://www.aliyun.com", + ConsumerGroup: tt.args.cm, + Credentials: &credentials.SessionCredentials{ + AccessKey: tt.args.ak, + AccessSecret: tt.args.sk, + }, + }, + rmq_client.WithAwaitDuration(time.Second*10), + rmq_client.WithSubscriptionExpressions(map[string]*rmq_client.FilterExpression{ + tt.args.testTopic: rmq_client.NewFilterExpression(tt.args.msgtag), + }), + ) + if err != nil { + t.Fail() + t.Log("Error: ", err) + return + } + // start simpleConsumer + err = simpleConsumer.Start() + if err != nil { + t.Fail() + t.Log("Error: ", err) + } + + // graceful stop simpleConsumer + defer simpleConsumer.GracefulStop() + + // new producer instance + producer := BuildProducer(tt.args.grpcEndpoint, tt.args.ak, tt.args.sk, tt.args.testTopic) + + // graceful stop producer + defer producer.GracefulStop() + + var recvMsgCollector *RecvMsgsCollector + var sendMsgCollector *SendMsgsCollector + + wg.Add(1) + + go func() { + recvMsgCollector = RecvMessage(simpleConsumer, MaxMessageNum, InvisibleDuration, 10) + wg.Done() + + }() + go func() { + sendMsgCollector = SendNormalMessage(producer, tt.args.testTopic, "test", tt.args.msgtag, 10, tt.args.keys) + }() + wg.Wait() + + CheckMsgsWithMsgId(t, sendMsgCollector, recvMsgCollector) + }) + } +} diff --git a/golang/pkg/server/transaction/transmsg_test.go b/golang/pkg/server/transaction/transmsg_test.go index 7fa6ecf..0b15036 100644 --- a/golang/pkg/server/transaction/transmsg_test.go +++ b/golang/pkg/server/transaction/transmsg_test.go @@ -18,9 +18,12 @@ package transaction_test import ( + "log" . "rocketmq-go-e2e/utils" "sync" "testing" + + rmq_client "github.com/apache/rocketmq-clients/golang" ) func TestSendTransactionMessage(t *testing.T) { @@ -47,7 +50,11 @@ func TestSendTransactionMessage(t *testing.T) { } for _, tt := range tests { t.Run("The synchronous test message is sent normally, expecting success", func(t *testing.T) { - var wg sync.WaitGroup + var ( + recvMsgCollector *RecvMsgsCollector + sendMsgCollector *SendMsgsCollector + wg sync.WaitGroup + ) CreateTransactionTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) simpleConsumer := BuildSimpleConsumer(tt.args.grpcEndpoint, tt.args.cm, tt.args.msgtag, tt.args.ak, tt.args.sk, tt.args.testTopic) @@ -56,14 +63,29 @@ func TestSendTransactionMessage(t *testing.T) { defer simpleConsumer.GracefulStop() // new producer instance - producer := BuildProducer(tt.args.grpcEndpoint, tt.args.ak, tt.args.sk, tt.args.testTopic) + var checker = &rmq_client.TransactionChecker{ + Check: func(msgView *rmq_client.MessageView) rmq_client.TransactionResolution { + log.Printf("check transaction message: %v", msgView) + sendMsgCollector.MsgIds = append(sendMsgCollector.MsgIds, msgView.GetMessageId()) + msg := &rmq_client.Message{ + Topic: msgView.GetTopic(), + Body: msgView.GetBody(), + Tag: msgView.GetTag(), + } + msg.SetKeys(msgView.GetKeys()...) + //msg.SetMessageGroup(*msgView.GetMessageGroup()) + //msg.SetDelayTimestamp(*msgView.GetDeliveryTimestamp()) + sendMsgCollector.SendMsgs = append(sendMsgCollector.SendMsgs, msg) + return rmq_client.COMMIT + }, + } + + // new producer instance + producer := BuildTransactionProducer(tt.args.grpcEndpoint, tt.args.ak, tt.args.sk, checker, tt.args.testTopic) // graceful stop producer defer producer.GracefulStop() - var recvMsgCollector *RecvMsgsCollector - var sendMsgCollector *SendMsgsCollector - wg.Add(1) go func() { diff --git a/golang/pkg/simple/simple_ack_test.go b/golang/pkg/simple/simple_ack_test.go index a6d8750..04c6b16 100644 --- a/golang/pkg/simple/simple_ack_test.go +++ b/golang/pkg/simple/simple_ack_test.go @@ -87,59 +87,3 @@ func TestMessageBodyContent(t *testing.T) { }) } } - -//func TestNormal_simple_receive_ackAsync(t *testing.T) { -// type args struct { -// name, testTopic, nameServer, grpcEndpoint, clusterName, ak, sk, cm, msgtag, keys, body string -// } -// tests := []struct { -// name string -// args args -// }{ -// { -// name: "Send 20 normal messages synchronously and expect consume with receive() and ackAsync() messages successful", -// args: args{ -// testTopic: GetTopicName(), -// nameServer: NAMESERVER, -// grpcEndpoint: GRPC_ENDPOINT, -// clusterName: CLUSTER_NAME, -// ak: "", -// sk: "", -// cm: GetGroupName(), -// msgtag: RandomString(8), -// keys: RandomString(8), -// body: RandomString(8), -// }, -// }, -// } -// for _, tt := range tests { -// t.Run(tt.name, func(t *testing.T) { -// var ( -// wg sync.WaitGroup -// recvMsgCollector *RecvMsgsCollector -// sendMsgCollector *SendMsgsCollector -// ) -// -// CreateTopic(tt.args.testTopic, "", tt.args.clusterName, tt.args.nameServer) -// simpleConsumer := BuildSimpleConsumer(tt.args.grpcEndpoint, tt.args.cm, tt.args.msgtag, tt.args.ak, tt.args.sk, tt.args.testTopic) -// -// // new producer instance -// producer := BuildProducer(tt.args.grpcEndpoint, tt.args.ak, tt.args.sk, tt.args.testTopic) -// // graceful stop producer -// defer producer.GracefulStop() -// -// wg.Add(1) -// -// go func() { -// sendMsgCollector = SendNormalMessageAsync(producer, tt.args.testTopic, tt.args.body, tt.args.msgtag, 20, tt.args.keys) -// }() -// -// go func() { -// recvMsgCollector = RecvMessage(simpleConsumer, MaxMessageNum, InvisibleDuration, 30) -// wg.Done() -// }() -// wg.Wait() -// CheckMsgsWithAll(t, sendMsgCollector, recvMsgCollector) -// }) -// } -//}