Skip to content

Commit

Permalink
Add more transaction related tests for Artemis
Browse files Browse the repository at this point in the history
  • Loading branch information
riyafa committed May 22, 2019
1 parent ee1e797 commit c0ed565
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"});
}

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

0 comments on commit c0ed565

Please sign in to comment.