Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test case for local transactions with multiple strands #698

Merged
merged 4 commits into from
Apr 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading