From 6f8507fdf508b6fcf81f7a62cafe1f4c59babb37 Mon Sep 17 00:00:00 2001 From: riyafa Date: Wed, 22 May 2019 09:48:34 +0530 Subject: [PATCH] Add more transaction related tests for Artemis --- .../src/main/ballerina/artemis/message.bal | 1 + .../messaging/artemis/LocalTransactionTest.java | 14 ++++++++++++++ .../artemis/consumers/transaction_consumer.bal | 9 +++++++-- .../artemis/producers/transaction_producer.bal | 16 +++++++++++++--- 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/stdlib/messaging/activemq-artemis/src/main/ballerina/artemis/message.bal b/stdlib/messaging/activemq-artemis/src/main/ballerina/artemis/message.bal index 369aa58ac871..889f30a5cdba 100644 --- a/stdlib/messaging/activemq-artemis/src/main/ballerina/artemis/message.bal +++ b/stdlib/messaging/activemq-artemis/src/main/ballerina/artemis/message.bal @@ -96,6 +96,7 @@ public type Message client object { # # + return - the `MessageConfiguration` of this message public function getConfig() returns MessageConfiguration { + self.configuration.freeze(); return self.configuration; } }; diff --git a/tests/ballerina-integration-test/src/test/java/org/ballerinalang/test/messaging/artemis/LocalTransactionTest.java b/tests/ballerina-integration-test/src/test/java/org/ballerinalang/test/messaging/artemis/LocalTransactionTest.java index b2ea8b547c5c..19ac401f49d3 100644 --- a/tests/ballerina-integration-test/src/test/java/org/ballerinalang/test/messaging/artemis/LocalTransactionTest.java +++ b/tests/ballerina-integration-test/src/test/java/org/ballerinalang/test/messaging/artemis/LocalTransactionTest.java @@ -23,6 +23,7 @@ import org.ballerinalang.launcher.util.CompileResult; import org.ballerinalang.model.values.BValue; import org.ballerinalang.test.util.TestUtils; +import org.ballerinalang.util.exceptions.BLangRuntimeException; import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -66,4 +67,17 @@ public void testSend() { String returnVal = BRunUtil.invoke(consumerResult, "transactionConsumerReceive", consumerVal)[0].stringValue(); Assert.assertEquals(returnVal, "Example Example ", "Invalid message received"); } + + @Test(description = "Tests transaction erring") + public void testErringSend() { + //Invoking this function is needed to make sure the queue is created before the sending + BValue[] consumerVal = BRunUtil.invoke(consumerResult, "createErringConsumer"); + try { + BRunUtil.invoke(producerResult, "testErringSend"); + } catch (BLangRuntimeException ex) { + // Ignore + } + String returnVal = BRunUtil.invoke(consumerResult, "receiveAndGetText", consumerVal)[0].stringValue(); + Assert.assertEquals(returnVal, "Example ", "Invalid message received"); + } } diff --git a/tests/ballerina-integration-test/src/test/resources/messaging/artemis/consumers/transaction_consumer.bal b/tests/ballerina-integration-test/src/test/resources/messaging/artemis/consumers/transaction_consumer.bal index eec54a87f2d0..646a4a117f0f 100644 --- a/tests/ballerina-integration-test/src/test/resources/messaging/artemis/consumers/transaction_consumer.bal +++ b/tests/ballerina-integration-test/src/test/resources/messaging/artemis/consumers/transaction_consumer.bal @@ -17,7 +17,7 @@ import ballerina/artemis; public function createSimpleConsumer() returns artemis:Consumer|error { - artemis:Listener lis = new artemis:Listener({host:"localhost", port:61616}); + artemis:Listener lis = new artemis:Listener({host: "localhost", port: 61616}); return lis.createAndGetConsumer({queueName: "example"}); } @@ -46,7 +46,12 @@ public function transactionConsumerReceive(artemis:Consumer consumer) returns st return msgTxt; } -function receiveAndGetText(artemis:Consumer consumer) returns string { +public function createErringConsumer() returns artemis:Consumer|error { + artemis:Listener lis = new artemis:Listener({host: "localhost", port: 61616}); + return lis.createAndGetConsumer({queueName: "example3"}); +} + +public function receiveAndGetText(artemis:Consumer consumer) returns string { string msgTxt = ""; var msg = consumer->receive(); if(msg is artemis:Message) { diff --git a/tests/ballerina-integration-test/src/test/resources/messaging/artemis/producers/transaction_producer.bal b/tests/ballerina-integration-test/src/test/resources/messaging/artemis/producers/transaction_producer.bal index d167a9acf389..5c11688f23c5 100644 --- a/tests/ballerina-integration-test/src/test/resources/messaging/artemis/producers/transaction_producer.bal +++ b/tests/ballerina-integration-test/src/test/resources/messaging/artemis/producers/transaction_producer.bal @@ -18,26 +18,36 @@ import ballerina/artemis; import ballerina/io; public function testSimpleTransactionSend() { - artemis:Producer prod = new({host:"localhost", port:61616}, "example"); + artemis:Producer prod = new({host: "localhost", port: 61616}, "example"); send(prod); transaction { send(prod); } } +public function testErringSend() { + artemis:Producer prod = new({host: "localhost", port: 61616}, "example3"); + send(prod); + transaction { + send(prod); + error err = error("Failed during send"); + panic err; + } +} + public function testTransactionSend() { artemis:Connection con = new("tcp://localhost:61616"); artemis:Session session = new(con); artemis:Producer prod = new(session, "example2"); - send(prod); transaction { send(prod); + send(prod); } } function send(artemis:Producer prod) { var err = prod->send("Example "); - if(err is error) { + if (err is error) { io:println("Error occurred sending message"); } }