Java源码示例:org.wso2.carbon.automation.extensions.servers.jmsserver.client.JMSTopicMessagePublisher

示例1
@Test(groups = {"wso2.esb"}, description = "Test transaction rollback : ESBJAVA-4863 and ESBJAVA-4293")
public void transactionRolBackWhenErrorTest() throws Exception {
    logViewerClient = new LogViewerClient(contextUrls.getBackEndUrl(), getSessionCookie());
    logViewerClient.clearLogs();
    JMSTopicMessagePublisher mbTopicMessageProducer = new JMSTopicMessagePublisher(
            MessageBrokerConfigurationProvider.getBrokerConfig());
    mbTopicMessageProducer.connect("MyNewTopic");
    mbTopicMessageProducer.publish("<message>Hi</message>");
    mbTopicMessageProducer.disconnect();

    int rollbackCount = 0;
    long startTime = System.currentTimeMillis();

    while (rollbackCount < 10 && (System.currentTimeMillis() - startTime) < 30000) {
        LogEvent[] logs = logViewerClient.getAllRemoteSystemLogs();
        if(logs == null){
            continue;
        }
        rollbackCount = 0;
        for (LogEvent event : logs) {
            if(log != null) {
                String message = event.getMessage();
                if (message.contains("### I am Event subscriber (inbound endpoint) ###")) {
                    rollbackCount++;
                }
            }
        }

        Thread.sleep(1000);
    }
    //if the message failed to mediate ESB rollback the message. Then message broker try 10 times
    //to send the message again. So total count is 11 including the first try
    Assert.assertEquals(rollbackCount, 11,  "ESB does not process message again after rollback");
}