Skip to content

Commit

Permalink
Merge pull request #698 from rdulmina/master
Browse files Browse the repository at this point in the history
Add test case for local transactions with multiple strands
  • Loading branch information
daneshk authored Apr 15, 2024
2 parents 22f19c6 + f668ceb commit bc1002d
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions ballerina/tests/local-transaction-test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,40 @@ function testLocalTransactionWithQueryRow() returns error? {
test:assertEquals(committedBlockExecuted, true);
}

type Customer1 record {
int customerId;
string firstName;
};

@test:Config {
groups: ["transaction"]
}
function testLocalTransactionWithStartAction() returns error? {
string|int? lastInsertId;
transaction {
future<error|string|int?> result = start callTransactionBranch();
lastInsertId = check wait result;
check commit;
}

MockClient dbClient = check new (url = localTransactionDB, user = user, password = password);
Customer1|error result = dbClient->queryRow(`SELECT * FROM Customers WHERE customerId = ${lastInsertId}`);
check dbClient.close();
if result is error {
test:assertFail(result.message());
}

test:assertEquals(result.firstName, "Ellis");
}

transactional function callTransactionBranch() returns error|string|int? {
MockClient dbClient = check new (url = localTransactionDB, user = user, password = password);
ParameterizedQuery query = `INSERT INTO Customers (firstName,lastName,registrationID,creditLimit,country)
VALUES ('Ellis', 'Smith', 555, 5000.75, 'USA')`;
ExecutionResult execResult = check dbClient->execute(query);
return execResult.lastInsertId;
}

isolated function getCount(MockClient dbClient, string id) returns int|error {
stream<TransactionResultCount, Error?> streamData = dbClient->query(
`Select COUNT(*) as countVal from Customers where registrationID = ${id}`);
Expand Down

0 comments on commit bc1002d

Please sign in to comment.