|
@@ -2,6 +2,7 @@ package test
|
|
|
|
|
|
import (
|
|
import (
|
|
"fmt"
|
|
"fmt"
|
|
|
|
+ "git.sxidc.com/go-framework/baize/framework/core/data_protocol"
|
|
"git.sxidc.com/go-framework/baize/framework/core/infrastructure"
|
|
"git.sxidc.com/go-framework/baize/framework/core/infrastructure"
|
|
"git.sxidc.com/go-framework/baize/framework/core/infrastructure/message_queue"
|
|
"git.sxidc.com/go-framework/baize/framework/core/infrastructure/message_queue"
|
|
"git.sxidc.com/go-framework/baize/framework/core/infrastructure/message_queue/common"
|
|
"git.sxidc.com/go-framework/baize/framework/core/infrastructure/message_queue/common"
|
|
@@ -59,7 +60,7 @@ func testRedisMessageQueue(t *testing.T, redisMessageQueue *redis.MessageQueue)
|
|
wg.Add(2)
|
|
wg.Add(2)
|
|
|
|
|
|
err := redisMessageQueue.Subscribe("test1", "test-redis",
|
|
err := redisMessageQueue.Subscribe("test1", "test-redis",
|
|
- func(queue common.MessageQueue, topic string, event *common.CloudEvent) {
|
|
|
|
|
|
+ func(queue common.MessageQueue, topic string, event *data_protocol.CloudEvent) {
|
|
if event.ID != "1" {
|
|
if event.ID != "1" {
|
|
t.Fatalf("%+v\n", errors.New("消息ID不一致"))
|
|
t.Fatalf("%+v\n", errors.New("消息ID不一致"))
|
|
}
|
|
}
|
|
@@ -68,7 +69,7 @@ func testRedisMessageQueue(t *testing.T, redisMessageQueue *redis.MessageQueue)
|
|
t.Fatalf("%+v\n", errors.New("消息类型不一致"))
|
|
t.Fatalf("%+v\n", errors.New("消息类型不一致"))
|
|
}
|
|
}
|
|
|
|
|
|
- if event.Data != "test-message" {
|
|
|
|
|
|
+ if string(event.Data) != "test-message" {
|
|
t.Fatalf("%+v\n", errors.New("消息数据不一致"))
|
|
t.Fatalf("%+v\n", errors.New("消息数据不一致"))
|
|
}
|
|
}
|
|
|
|
|
|
@@ -81,7 +82,7 @@ func testRedisMessageQueue(t *testing.T, redisMessageQueue *redis.MessageQueue)
|
|
}
|
|
}
|
|
|
|
|
|
err = redisMessageQueue.Subscribe("test2", "test-redis",
|
|
err = redisMessageQueue.Subscribe("test2", "test-redis",
|
|
- func(queue common.MessageQueue, topic string, event *common.CloudEvent) {
|
|
|
|
|
|
+ func(queue common.MessageQueue, topic string, event *data_protocol.CloudEvent) {
|
|
if event.ID != "1" {
|
|
if event.ID != "1" {
|
|
t.Fatalf("%+v\n", errors.New("消息ID不一致"))
|
|
t.Fatalf("%+v\n", errors.New("消息ID不一致"))
|
|
}
|
|
}
|
|
@@ -90,7 +91,7 @@ func testRedisMessageQueue(t *testing.T, redisMessageQueue *redis.MessageQueue)
|
|
t.Fatalf("%+v\n", errors.New("消息类型不一致"))
|
|
t.Fatalf("%+v\n", errors.New("消息类型不一致"))
|
|
}
|
|
}
|
|
|
|
|
|
- if event.Data != "test-message" {
|
|
|
|
|
|
+ if string(event.Data) != "test-message" {
|
|
t.Fatalf("%+v\n", errors.New("消息数据不一致"))
|
|
t.Fatalf("%+v\n", errors.New("消息数据不一致"))
|
|
}
|
|
}
|
|
|
|
|
|
@@ -103,7 +104,7 @@ func testRedisMessageQueue(t *testing.T, redisMessageQueue *redis.MessageQueue)
|
|
}
|
|
}
|
|
|
|
|
|
err = redisMessageQueue.Publish("test-redis",
|
|
err = redisMessageQueue.Publish("test-redis",
|
|
- message_queue.NewCloudEvent("1", "test", "test-message"))
|
|
|
|
|
|
+ data_protocol.NewCloudEvent("1", "test", "baize-test.com", "application/text", []byte("test-message")))
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatalf("%+v\n", err)
|
|
t.Fatalf("%+v\n", err)
|
|
}
|
|
}
|
|
@@ -116,7 +117,7 @@ func testMqttMessageQueue(t *testing.T, mqttMessageQueue *mqtt.MessageQueue) {
|
|
wg.Add(2)
|
|
wg.Add(2)
|
|
|
|
|
|
err := mqttMessageQueue.Subscribe("test1", "test-mqtt",
|
|
err := mqttMessageQueue.Subscribe("test1", "test-mqtt",
|
|
- func(queue common.MessageQueue, topic string, event *common.CloudEvent) {
|
|
|
|
|
|
+ func(queue common.MessageQueue, topic string, event *data_protocol.CloudEvent) {
|
|
if event.ID != "1" {
|
|
if event.ID != "1" {
|
|
t.Fatalf("%+v\n", errors.New("消息ID不一致"))
|
|
t.Fatalf("%+v\n", errors.New("消息ID不一致"))
|
|
}
|
|
}
|
|
@@ -125,7 +126,7 @@ func testMqttMessageQueue(t *testing.T, mqttMessageQueue *mqtt.MessageQueue) {
|
|
t.Fatalf("%+v\n", errors.New("消息类型不一致"))
|
|
t.Fatalf("%+v\n", errors.New("消息类型不一致"))
|
|
}
|
|
}
|
|
|
|
|
|
- if event.Data != "test-message" {
|
|
|
|
|
|
+ if string(event.Data) != "test-message" {
|
|
t.Fatalf("%+v\n", errors.New("消息数据不一致"))
|
|
t.Fatalf("%+v\n", errors.New("消息数据不一致"))
|
|
}
|
|
}
|
|
|
|
|
|
@@ -138,7 +139,7 @@ func testMqttMessageQueue(t *testing.T, mqttMessageQueue *mqtt.MessageQueue) {
|
|
}
|
|
}
|
|
|
|
|
|
err = mqttMessageQueue.Subscribe("test2", "test-mqtt",
|
|
err = mqttMessageQueue.Subscribe("test2", "test-mqtt",
|
|
- func(queue common.MessageQueue, topic string, event *common.CloudEvent) {
|
|
|
|
|
|
+ func(queue common.MessageQueue, topic string, event *data_protocol.CloudEvent) {
|
|
if event.ID != "1" {
|
|
if event.ID != "1" {
|
|
t.Fatalf("%+v\n", errors.New("消息ID不一致"))
|
|
t.Fatalf("%+v\n", errors.New("消息ID不一致"))
|
|
}
|
|
}
|
|
@@ -147,7 +148,7 @@ func testMqttMessageQueue(t *testing.T, mqttMessageQueue *mqtt.MessageQueue) {
|
|
t.Fatalf("%+v\n", errors.New("消息类型不一致"))
|
|
t.Fatalf("%+v\n", errors.New("消息类型不一致"))
|
|
}
|
|
}
|
|
|
|
|
|
- if event.Data != "test-message" {
|
|
|
|
|
|
+ if string(event.Data) != "test-message" {
|
|
t.Fatalf("%+v\n", errors.New("消息数据不一致"))
|
|
t.Fatalf("%+v\n", errors.New("消息数据不一致"))
|
|
}
|
|
}
|
|
|
|
|
|
@@ -160,7 +161,7 @@ func testMqttMessageQueue(t *testing.T, mqttMessageQueue *mqtt.MessageQueue) {
|
|
}
|
|
}
|
|
|
|
|
|
err = mqttMessageQueue.Publish("test-mqtt",
|
|
err = mqttMessageQueue.Publish("test-mqtt",
|
|
- message_queue.NewCloudEvent("1", "test", "test-message"))
|
|
|
|
|
|
+ data_protocol.NewCloudEvent("1", "test", "baize-test.com", "application/text", []byte("test-message")))
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatalf("%+v\n", err)
|
|
t.Fatalf("%+v\n", err)
|
|
}
|
|
}
|
|
@@ -173,7 +174,7 @@ func testMessageQueue(t *testing.T, messageQueue common.MessageQueue) {
|
|
wg.Add(2)
|
|
wg.Add(2)
|
|
|
|
|
|
err := message_queue.Subscribe(messageQueue, "test1", "test-message-queue",
|
|
err := message_queue.Subscribe(messageQueue, "test1", "test-message-queue",
|
|
- func(queue common.MessageQueue, topic string, event *common.CloudEvent) {
|
|
|
|
|
|
+ func(queue common.MessageQueue, topic string, event *data_protocol.CloudEvent) {
|
|
if event.ID != "1" {
|
|
if event.ID != "1" {
|
|
t.Fatalf("%+v\n", errors.New("消息ID不一致"))
|
|
t.Fatalf("%+v\n", errors.New("消息ID不一致"))
|
|
}
|
|
}
|
|
@@ -182,7 +183,7 @@ func testMessageQueue(t *testing.T, messageQueue common.MessageQueue) {
|
|
t.Fatalf("%+v\n", errors.New("消息类型不一致"))
|
|
t.Fatalf("%+v\n", errors.New("消息类型不一致"))
|
|
}
|
|
}
|
|
|
|
|
|
- if event.Data != "test-message" {
|
|
|
|
|
|
+ if string(event.Data) != "test-message" {
|
|
t.Fatalf("%+v\n", errors.New("消息数据不一致"))
|
|
t.Fatalf("%+v\n", errors.New("消息数据不一致"))
|
|
}
|
|
}
|
|
|
|
|
|
@@ -195,7 +196,7 @@ func testMessageQueue(t *testing.T, messageQueue common.MessageQueue) {
|
|
}
|
|
}
|
|
|
|
|
|
err = message_queue.Subscribe(messageQueue, "test2", "test-message-queue",
|
|
err = message_queue.Subscribe(messageQueue, "test2", "test-message-queue",
|
|
- func(queue common.MessageQueue, topic string, event *common.CloudEvent) {
|
|
|
|
|
|
+ func(queue common.MessageQueue, topic string, event *data_protocol.CloudEvent) {
|
|
if event.ID != "1" {
|
|
if event.ID != "1" {
|
|
t.Fatalf("%+v\n", errors.New("消息ID不一致"))
|
|
t.Fatalf("%+v\n", errors.New("消息ID不一致"))
|
|
}
|
|
}
|
|
@@ -204,7 +205,7 @@ func testMessageQueue(t *testing.T, messageQueue common.MessageQueue) {
|
|
t.Fatalf("%+v\n", errors.New("消息类型不一致"))
|
|
t.Fatalf("%+v\n", errors.New("消息类型不一致"))
|
|
}
|
|
}
|
|
|
|
|
|
- if event.Data != "test-message" {
|
|
|
|
|
|
+ if string(event.Data) != "test-message" {
|
|
t.Fatalf("%+v\n", errors.New("消息数据不一致"))
|
|
t.Fatalf("%+v\n", errors.New("消息数据不一致"))
|
|
}
|
|
}
|
|
|
|
|
|
@@ -217,7 +218,7 @@ func testMessageQueue(t *testing.T, messageQueue common.MessageQueue) {
|
|
}
|
|
}
|
|
|
|
|
|
err = message_queue.Publish(messageQueue, "test-message-queue",
|
|
err = message_queue.Publish(messageQueue, "test-message-queue",
|
|
- message_queue.NewCloudEvent("1", "test", "test-message"))
|
|
|
|
|
|
+ data_protocol.NewCloudEvent("1", "test", "baize-test.com", "application/text", []byte("test-message")))
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Fatalf("%+v\n", err)
|
|
t.Fatalf("%+v\n", err)
|
|
}
|
|
}
|