Skip to content

Commit

Permalink
Merge branch 'main' into listner
Browse files Browse the repository at this point in the history
  • Loading branch information
RDPerera authored Oct 23, 2023
2 parents 48e83c9 + d0b8b8d commit 4e6007d
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# See: https://help.github.com/articles/about-codeowners/

# These owners will be the default owners for everything in the repo.
* @indikasampath2000 @abeykoon @RolandHewage @SkNuwanTissera
* @NipunaRanasinghe @ayeshLK
6 changes: 3 additions & 3 deletions .github/workflows/build-with-bal-test-native.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ jobs:
- name: Set up GraalVM
uses: graalvm/setup-graalvm@v1
with:
version: 'latest'
java-version: '17.0.7'
components: 'native-image'
java-version: '17'
distribution: 'graalvm-community'
github-token: ${{ secrets.GITHUB_TOKEN }}
set-java-home: 'false'

- name: Check GraalVM installation
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dev-stg-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }}
JAVA_OPTS: -DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true
run: |
./gradlew build -x test
./gradlew build -x test -x :azure-service-bus-examples:build
# Perform Trivy scan
- name: Run Trivy vulnerability scanner
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }}
JAVA_OPTS: -DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true
run: |
./gradlew build -x test
./gradlew build -x test -x :azure-service-bus-examples:build
# Perform Trivy scan
- name: Run Trivy vulnerability scanner
Expand Down
29 changes: 14 additions & 15 deletions ballerina/receiver.bal
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ public isolated client class MessageReceiver {
isolated remote function complete(@display {label: "Message"} Message message)
returns Error? {
if message?.lockToken.toString() != DEFAULT_MESSAGE_LOCK_TOKEN {
return complete(self, message?.lockToken.toString());
return complete(self, message);
}
return createError("Failed to complete message with ID " + message?.messageId.toString());
return createError(string `Failed to complete message with ID: ${message?.messageId.toString()}`);
}

# Abandon message from queue or subscription based on messageLockToken. Abandon processing of the message for
Expand All @@ -131,9 +131,9 @@ public isolated client class MessageReceiver {
@display {label: "Abandon Message"}
isolated remote function abandon(@display {label: "Message"} Message message) returns Error? {
if message?.lockToken.toString() != DEFAULT_MESSAGE_LOCK_TOKEN {
return abandon(self, message?.lockToken.toString());
return abandon(self, message);
}
return createError("Failed to abandon message with ID " + message?.messageId.toString());
return createError(string `Failed to abandon message with ID: ${message?.messageId.toString()}`);
}

# Dead-Letter the message & moves the message to the Dead-Letter Queue based on messageLockToken. Transfer
Expand All @@ -149,10 +149,9 @@ public isolated client class MessageReceiver {
@display {label: "Dead Letter Description"}
string? deadLetterErrorDescription = ()) returns Error? {
if message?.lockToken.toString() != DEFAULT_MESSAGE_LOCK_TOKEN {
return deadLetter(self, message?.lockToken.toString(), deadLetterReason,
deadLetterErrorDescription);
return deadLetter(self, message, deadLetterReason, deadLetterErrorDescription);
}
return createError("Failed to deadletter message with ID " + message?.messageId.toString());
return createError(string `Failed to deadletter message with ID: ${message?.messageId.toString()}`);
}

# Defer the message in a Queue or Subscription based on messageLockToken. It prevents the message from being
Expand All @@ -163,7 +162,7 @@ public isolated client class MessageReceiver {
@display {label: "Defer Message"}
isolated remote function defer(@display {label: "Message"} Message message)
returns @display {label: "Deferred Msg Seq Num"} int|Error {
check defer(self, message?.lockToken.toString());
check defer(self, message);
return <int>message?.sequenceNumber;
}

Expand All @@ -188,9 +187,9 @@ public isolated client class MessageReceiver {
@display {label: "Renew Lock On Message"}
isolated remote function renewLock(@display {label: "Message"} Message message) returns Error? {
if message?.lockToken.toString() != DEFAULT_MESSAGE_LOCK_TOKEN {
return renewLock(self, message?.lockToken.toString());
return renewLock(self, message);
}
return createError("Failed to renew lock on message with ID " + message?.messageId.toString());
return createError(string `Failed to renew lock on message with ID: ${message?.messageId.toString()}`);
}

# Closes the ASB sender connection.
Expand All @@ -213,27 +212,27 @@ isolated function receiveBatch(MessageReceiver endpointClient, int? maxMessageCo
'class: "org.ballerinax.asb.receiver.MessageReceiver"
} external;

isolated function complete(MessageReceiver endpointClient, string lockToken) returns Error? = @java:Method {
isolated function complete(MessageReceiver endpointClient, Message message) returns Error? = @java:Method {
'class: "org.ballerinax.asb.receiver.MessageReceiver"
} external;

isolated function abandon(MessageReceiver endpointClient, string lockToken) returns Error? = @java:Method {
isolated function abandon(MessageReceiver endpointClient, Message message) returns Error? = @java:Method {
'class: "org.ballerinax.asb.receiver.MessageReceiver"
} external;

isolated function deadLetter(MessageReceiver endpointClient, string lockToken, string? deadLetterReason, string? deadLetterErrorDescription) returns
isolated function deadLetter(MessageReceiver endpointClient, Message message, string? deadLetterReason, string? deadLetterErrorDescription) returns
Error? = @java:Method {
'class: "org.ballerinax.asb.receiver.MessageReceiver"
} external;

isolated function defer(MessageReceiver endpointClient, string lockToken) returns Error? = @java:Method {
isolated function defer(MessageReceiver endpointClient, Message message) returns Error? = @java:Method {
'class: "org.ballerinax.asb.receiver.MessageReceiver"
} external;

isolated function receiveDeferred(MessageReceiver endpointClient, int sequenceNumber) returns Message|Error? = @java:Method {
'class: "org.ballerinax.asb.receiver.MessageReceiver"
} external;

isolated function renewLock(MessageReceiver endpointClient, string lockToken) returns Error? = @java:Method {
isolated function renewLock(MessageReceiver endpointClient, Message message) returns Error? = @java:Method {
'class: "org.ballerinax.asb.receiver.MessageReceiver"
} external;
83 changes: 83 additions & 0 deletions ballerina/tests/asb_sender_receiver_negative_tests.bal
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

import ballerina/log;
import ballerina/test;
import ballerina/regex;

string invalidCompleteError = "^Failed to complete message with ID:.*$";
string invalidAbandonError = "^Failed to abandon message with ID:.*$";
@test:Config {
groups: ["asb_sender_receiver_negative"],
enable: true,
Expand Down Expand Up @@ -54,6 +57,86 @@ function testReceivePayloadWithIncorrectExpectedType() returns error? {
enable: true,
dependsOn: [testReceivePayloadWithIncorrectExpectedType]
}
function testInvalidComplete() returns error? {
log:printInfo("[[testInvalidComplete]");

log:printInfo("Initializing Asb sender client.");
MessageSender messageSender = check new (senderConfig);

log:printInfo("Initializing Asb receiver client.");
receiverConfig.receiveMode = RECEIVE_AND_DELETE;

MessageReceiver messageReceiver = check new (receiverConfig);

log:printInfo("Sending via Asb sender.");
check messageSender->send(message1);

log:printInfo("Receiving from Asb receiver client.");
Message|error? receivedMessage = messageReceiver->receive(serverWaitTime);

if receivedMessage is Message {
log:printInfo("messgae" + receivedMessage.toString());
Error? result = messageReceiver->complete(receivedMessage);
test:assertTrue(result is error, msg = "Unexpected Complete for Messages in Receive and Delete Mode");
test:assertTrue(regex:matches((<Error>result).message(),invalidCompleteError), msg = "Invalid Complete for " +
" Messages in Receive and Delete Mode");
} else if receivedMessage is () {
test:assertFail("No message in the queue.");
} else {
test:assertFail("Receiving message via Asb receiver connection failed.");
}

log:printInfo("Closing Asb sender client.");
check messageSender->close();

log:printInfo("Closing Asb receiver client.");
check messageReceiver->close();
}

@test:Config {
groups: ["asb_sender_receiver_negative"],
dependsOn: [testInvalidComplete]
}
function testInvalidAbandon() returns error? {
log:printInfo("[[testInvalidAbandon]");

log:printInfo("Initializing Asb sender client.");
MessageSender messageSender = check new (senderConfig);

log:printInfo("Initializing Asb receiver client.");
receiverConfig.receiveMode = RECEIVE_AND_DELETE;

MessageReceiver messageReceiver = check new (receiverConfig);

log:printInfo("Sending via Asb sender.");
check messageSender->send(message1);

log:printInfo("Receiving from Asb receiver client.");
Message|error? receivedMessage = messageReceiver->receive(serverWaitTime);

if receivedMessage is Message {
log:printInfo("messgae" + receivedMessage.toString());
Error? result = messageReceiver->abandon(receivedMessage);
test:assertTrue(result is error, msg = "Unexpected Abandon for Messages in Receive and Delete Mode");
test:assertTrue(regex:matches((<Error>result).message(),invalidAbandonError), msg = "Invalid Abandon for " +
" Messages in Receive and Delete Mode");
} else if receivedMessage is () {
test:assertFail("No message in the queue.");
} else {
test:assertFail("Receiving message via Asb receiver connection failed.");
}

log:printInfo("Closing Asb sender client.");
check messageSender->close();

log:printInfo("Closing Asb receiver client.");
check messageReceiver->close();
}

@test:Config {
groups: ["asb_sender_receiver_negative"],
dependsOn: [testInvalidAbandon]
}
function testReceivePayloadWithUnsupportedUnionExpectedType() returns error? {
log:printInfo("[[testReceivePayloadWithUnsupportedUnionExpectedType]]");
log:printInfo("Creating Asb message sender.");
Expand Down
Loading

0 comments on commit 4e6007d

Please sign in to comment.