Skip to content

Commit

Permalink
Merge pull request #135 from ayeshLK/master
Browse files Browse the repository at this point in the history
Add test case for failover scenario with ActiveMQ
  • Loading branch information
ayeshLK authored Nov 21, 2024
2 parents 2ebdfde + 362a29e commit f591879
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-timestamped-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ jobs:
call_workflow:
name: Run Build Workflow
if: ${{ github.repository_owner == 'ballerina-platform' }}
uses: ballerina-platform/ballerina-library/.github/workflows/build-timestamp-master-template.yml@main
uses: ballerina-platform/ballerina-library/.github/workflows/build-timestamp-master-template.yml@2201.10.x
secrets: inherit
2 changes: 1 addition & 1 deletion .github/workflows/build-with-bal-test-graalvm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
call_stdlib_workflow:
name: Run StdLib Workflow
if: ${{ github.event_name != 'schedule' || (github.event_name == 'schedule' && github.repository_owner == 'ballerina-platform') }}
uses: ballerina-platform/ballerina-library/.github/workflows/build-with-bal-test-graalvm-template.yml@main
uses: ballerina-platform/ballerina-library/.github/workflows/build-with-bal-test-graalvm-template.yml@2201.10.x
with:
lang_tag: ${{ inputs.lang_tag }}
lang_version: ${{ inputs.lang_version }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/central-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
call_workflow:
name: Run Central Publish Workflow
if: ${{ github.repository_owner == 'ballerina-platform' }}
uses: ballerina-platform/ballerina-library/.github/workflows/central-publish-template.yml@main
uses: ballerina-platform/ballerina-library/.github/workflows/central-publish-template.yml@2201.10.x
secrets: inherit
with:
environment: ${{ github.event.inputs.environment }}
2 changes: 1 addition & 1 deletion .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
call_workflow:
name: Run Release Workflow
if: ${{ github.repository_owner == 'ballerina-platform' }}
uses: ballerina-platform/ballerina-library/.github/workflows/release-package-template.yml@main
uses: ballerina-platform/ballerina-library/.github/workflows/release-package-template.yml@2201.10.x
secrets: inherit
with:
package-name: java.jms
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
call_workflow:
name: Run PR Build Workflow
if: ${{ github.repository_owner == 'ballerina-platform' }}
uses: ballerina-platform/ballerina-library/.github/workflows/pull-request-build-template.yml@main
uses: ballerina-platform/ballerina-library/.github/workflows/pull-request-build-template.yml@2201.10.x
with:
additional-windows-test-flags: "-x test"
secrets: inherit
2 changes: 1 addition & 1 deletion .github/workflows/trigger-load-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
call_stdlib_trigger_load_test_workflow:
name: Run StdLib Load Test Workflow
if: ${{ github.event_name != 'schedule' || (github.event_name == 'schedule' && github.repository_owner == 'ballerina-platform') }}
uses: ballerina-platform/ballerina-library/.github/workflows/trigger-load-tests-template.yml@main
uses: ballerina-platform/ballerina-library/.github/workflows/trigger-load-tests-template.yml@2201.10.x
with:
repo_name: 'module-ballerina-java.jms'
runtime_artifacts_url: 'https://api.github.com/repos/ballerina-platform/module-ballerina-java.jms/actions/artifacts'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/trivy-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ jobs:
call_workflow:
name: Run Trivy Scan Workflow
if: ${{ github.repository_owner == 'ballerina-platform' }}
uses: ballerina-platform/ballerina-library/.github/workflows/trivy-scan-template.yml@main
uses: ballerina-platform/ballerina-library/.github/workflows/trivy-scan-template.yml@2201.10.x
secrets: inherit
2 changes: 1 addition & 1 deletion ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ modules = [
[[package]]
org = "ballerinax"
name = "activemq.driver"
version = "1.0.1"
version = "1.0.2"
scope = "testOnly"
modules = [
{org = "ballerinax", packageName = "activemq.driver", moduleName = "activemq.driver"}
Expand Down
86 changes: 86 additions & 0 deletions ballerina/tests/failover_connection_tests.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org).
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import ballerina/test;
import ballerinax/activemq.driver as _;

final Connection TEST_FAILOVER_CONNECTION = check new (
initialContextFactory = "org.apache.activemq.jndi.ActiveMQInitialContextFactory",
providerUrl = "failover:(tcp://localhost:61616)"
);

final Session FAILOVER_AUTO_ACK_SESSION = check createSession(AUTO_ACKNOWLEDGE);

isolated function createFailoverSession(AcknowledgementMode acknowledgementMode) returns Session|error {
return TEST_FAILOVER_CONNECTION->createSession(acknowledgementMode);
}

@test:Config {
groups: ["failover"]
}
isolated function testQueueWithTextMessageWithFailover() returns error? {
MessageProducer failoverQueueProducer = check createProducer(FAILOVER_AUTO_ACK_SESSION, {
'type: QUEUE,
name: "test-failover-queue"
});
final MessageConsumer failoverQueueConsumer = check createConsumer(FAILOVER_AUTO_ACK_SESSION, destination = {
'type: QUEUE,
name: "test-failover-queue"
});

string content = "This is a sample message";
TextMessage message = {
content: content
};
check failoverQueueProducer->send(message);
Message? response = check failoverQueueConsumer->receive(5000);
test:assertTrue(response is TextMessage, "Invalid message type received");
if response is TextMessage {
test:assertEquals(response.content, content, "Invalid payload");
}

check failoverQueueProducer->close();
check failoverQueueConsumer->close();
}

@test:Config {
groups: ["failover"]
}
isolated function testTopicWithTextMessageWithFailover() returns error? {
MessageProducer failoverTopicProducer = check createProducer(AUTO_ACK_SESSION, {
'type: TOPIC,
name: "test-failover-topic"
});
MessageConsumer failoverTopicConsumer = check createConsumer(AUTO_ACK_SESSION, destination = {
'type: TOPIC,
name: "test-failover-topic"
});

string content = "This is a sample message";
TextMessage message = {
content: content
};
check failoverTopicProducer->send(message);
Message? response = check failoverTopicConsumer->receive(5000);
test:assertTrue(response is TextMessage, "Invalid message type received");
if response is TextMessage {
test:assertEquals(response.content, content, "Invalid payload");
}

check failoverTopicProducer->close();
check failoverTopicConsumer->close();
}

2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ javaxJmsVersion=2.0.1
slf4jVersion=2.0.7

# Test dependenices
activeMQDriverVersion=1.0.1
activeMQDriverVersion=1.0.2-20241121-153900-bfb39bd

#stdlib dependencies

Expand Down

0 comments on commit f591879

Please sign in to comment.