Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
funky-eyes committed Mar 3, 2024
1 parent c67ad75 commit eef9e66
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,24 @@ public class SeataMQProducerSendTest {
private static final Logger LOGGER = LoggerFactory.getLogger(SeataMQProducerSendTest.class);


public static String TOPIC = "seata-test";
public static String NAME_SERVER = "127.0.0.1:9876";
private static final String TOPIC = "seata-test";
private static final String NAME_SERVER = "127.0.0.1:9876";

private static SeataMQProducer producer;

@BeforeAll
public static void before() throws MQClientException {
ConfigurationTestHelper.putConfig(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL, String.valueOf(ProtocolTestConstants.MOCK_SERVER_PORT));
MockServer.start(ProtocolTestConstants.MOCK_SERVER_PORT);
producer = SeataMQProducerFactory.createSingle(NAME_SERVER, "test");
// should start mq server here
}

@AfterAll
public static void after() {
MockServer.close();
ConfigurationTestHelper.removeConfig(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL);
producer.shutdown();
}

@Test
Expand All @@ -77,14 +81,12 @@ public void testSendCommit() throws MQBrokerException, RemotingException, Interr

CountDownLatch countDownLatch = new CountDownLatch(1);
MQPushConsumer consumer = startConsume(countDownLatch);
SeataMQProducer producer = SeataMQProducerFactory.createSingle(NAME_SERVER, "test");
producer.send(new Message(TOPIC, "testMessage".getBytes(StandardCharsets.UTF_8)));

tm.commit(RootContext.getXID());
LOGGER.info("global commit");
boolean await = countDownLatch.await(2, TimeUnit.SECONDS);
LOGGER.info("await:{}", await);
producer.shutdown();
consumer.shutdown();
}

Expand All @@ -96,7 +98,7 @@ public void testSendRollback()

CountDownLatch countDownLatch = new CountDownLatch(1);
MQPushConsumer consumer = startConsume(countDownLatch);
SeataMQProducer producer = SeataMQProducerFactory.createSingle(NAME_SERVER, "test");

producer.send(new Message(TOPIC, "testMessage".getBytes(StandardCharsets.UTF_8)));

tm.rollback(RootContext.getXID());
Expand All @@ -107,7 +109,6 @@ public void testSendRollback()
} catch (Exception e) {
Assertions.assertEquals(e.getClass(), InterruptedException.class);
} finally {
producer.shutdown();
consumer.shutdown();
}
}
Expand Down

0 comments on commit eef9e66

Please sign in to comment.