|
49 | 49 | import org.apache.rocketmq.common.message.Message;
|
50 | 50 | import org.apache.rocketmq.common.message.MessageExt;
|
51 | 51 | import org.apache.rocketmq.common.message.MessageQueue;
|
| 52 | +import org.apache.rocketmq.common.protocol.route.QueueData; |
| 53 | +import org.apache.rocketmq.common.protocol.route.TopicRouteData; |
52 | 54 | import org.apache.rocketmq.remoting.protocol.LanguageCode;
|
| 55 | +import org.apache.rocketmq.tools.admin.DefaultMQAdminExt; |
53 | 56 |
|
54 | 57 | import org.junit.jupiter.api.AfterAll;
|
55 | 58 | import org.junit.jupiter.api.Assertions;
|
|
77 | 80 | import java.util.Map;
|
78 | 81 | import java.util.Set;
|
79 | 82 | import java.util.UUID;
|
| 83 | +import java.util.stream.Collectors; |
80 | 84 |
|
81 | 85 | import static org.apache.seatunnel.e2e.connector.rocketmq.RocketMqContainer.NAMESRV_PORT;
|
82 | 86 |
|
@@ -204,6 +208,42 @@ public void testTextFormatSinkRocketMq(TestContainer container)
|
204 | 208 | Assertions.assertEquals(10, data.size());
|
205 | 209 | }
|
206 | 210 |
|
| 211 | + @TestTemplate |
| 212 | + public void testSourceRocketMqTextTagToConsole(TestContainer container) |
| 213 | + throws IOException, InterruptedException { |
| 214 | + String topic = "test_topic_text_tag"; |
| 215 | + String tag = "tag_test"; |
| 216 | + |
| 217 | + // delete topic if exist |
| 218 | + deleteTopicIfExist(topic); |
| 219 | + |
| 220 | + DefaultSeaTunnelRowSerializer serializer = |
| 221 | + new DefaultSeaTunnelRowSerializer( |
| 222 | + topic, tag, SEATUNNEL_ROW_TYPE, SchemaFormat.TEXT, DEFAULT_FIELD_DELIMITER); |
| 223 | + generateTestData(serializer::serializeRow, topic, 0, 32); |
| 224 | + Container.ExecResult execResult = |
| 225 | + container.executeJob("/rocketmq-source_text_tag_to_console.conf"); |
| 226 | + Assertions.assertEquals(0, execResult.getExitCode(), execResult.getStderr()); |
| 227 | + } |
| 228 | + |
| 229 | + @TestTemplate |
| 230 | + public void testSourceRocketMqTextErrorTagToConsole(TestContainer container) |
| 231 | + throws IOException, InterruptedException { |
| 232 | + String topic = "test_topic_text_error_tag"; |
| 233 | + String tag = "test_error_tag"; |
| 234 | + |
| 235 | + // delete topic if exist |
| 236 | + deleteTopicIfExist(topic); |
| 237 | + |
| 238 | + DefaultSeaTunnelRowSerializer serializer = |
| 239 | + new DefaultSeaTunnelRowSerializer( |
| 240 | + topic, tag, SEATUNNEL_ROW_TYPE, SchemaFormat.TEXT, DEFAULT_FIELD_DELIMITER); |
| 241 | + generateTestData(serializer::serializeRow, topic, 0, 32); |
| 242 | + Container.ExecResult execResult = |
| 243 | + container.executeJob("/rocketmq-source_text_error_tag_to_console.conf"); |
| 244 | + Assertions.assertEquals(0, execResult.getExitCode(), execResult.getStderr()); |
| 245 | + } |
| 246 | + |
207 | 247 | @TestTemplate
|
208 | 248 | public void testSourceRocketMqTextToConsole(TestContainer container)
|
209 | 249 | throws IOException, InterruptedException {
|
@@ -458,4 +498,32 @@ public RocketMqBaseConfiguration newConfiguration() {
|
458 | 498 | interface ProducerRecordConverter {
|
459 | 499 | Message convert(SeaTunnelRow row);
|
460 | 500 | }
|
| 501 | + |
| 502 | + private void deleteTopicIfExist(String topicName) { |
| 503 | + DefaultMQAdminExt admin = new DefaultMQAdminExt(); |
| 504 | + admin.setInstanceName(UUID.randomUUID().toString()); |
| 505 | + try { |
| 506 | + admin.start(); |
| 507 | + TopicRouteData topicRouteData = admin.examineTopicRouteInfo(topicName); |
| 508 | + if (topicRouteData != null |
| 509 | + && topicRouteData.getQueueDatas() != null |
| 510 | + && !topicRouteData.getQueueDatas().isEmpty()) { |
| 511 | + Set<String> brokerNames = |
| 512 | + topicRouteData.getQueueDatas().stream() |
| 513 | + .map(QueueData::getBrokerName) |
| 514 | + .collect(Collectors.toSet()); |
| 515 | + admin.deleteTopicInBroker(brokerNames, topicName); |
| 516 | + admin.deleteTopicInNameServer(brokerNames, topicName, "delete_topic"); |
| 517 | + log.info("Deleted topic: {}", topicName); |
| 518 | + } else { |
| 519 | + log.info("Topic {} does not exist", topicName); |
| 520 | + } |
| 521 | + } catch (Exception e) { |
| 522 | + log.warn("Failed to delete topic {}: {}", topicName, e.getMessage()); |
| 523 | + } finally { |
| 524 | + if (admin != null) { |
| 525 | + admin.shutdown(); |
| 526 | + } |
| 527 | + } |
| 528 | + } |
461 | 529 | }
|
0 commit comments