Skip to content

Commit

Permalink
Merge pull request #656 from ayeshLK/master
Browse files Browse the repository at this point in the history
Use offset ports for test cases
  • Loading branch information
ayeshLK authored Aug 7, 2024
2 parents d267dea + 4dfbdc8 commit 30e0d23
Show file tree
Hide file tree
Showing 22 changed files with 89 additions and 54 deletions.
4 changes: 2 additions & 2 deletions ballerina-tests/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[package]
org = "ballerina"
name = "websub_tests"
version = "2.11.0"
version = "2.11.1"

[platform.java17]
graalvmCompatible = true

[[platform.java17.dependency]]
path = "../native/build/libs/websub-native-2.11.0.jar"
path = "../native/build/libs/websub-native-2.11.1-SNAPSHOT.jar"
8 changes: 4 additions & 4 deletions ballerina-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ distribution-version = "2201.9.0"
[[package]]
org = "ballerina"
name = "auth"
version = "2.11.0"
version = "2.11.1"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "crypto"},
Expand Down Expand Up @@ -44,7 +44,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "crypto"
version = "2.7.0"
version = "2.7.2"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
Expand All @@ -66,7 +66,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "http"
version = "2.11.0"
version = "2.11.3"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "auth"},
Expand Down Expand Up @@ -337,7 +337,7 @@ modules = [
[[package]]
org = "ballerina"
name = "websub_tests"
version = "2.11.0"
version = "2.11.1"
dependencies = [
{org = "ballerina", name = "test"},
{org = "ballerina", name = "websub"}
Expand Down
6 changes: 3 additions & 3 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
org = "ballerina"
name = "websub"
version = "2.11.0"
version = "2.11.1"
authors = ["Ballerina"]
keywords = ["websub", "subscriber", "service", "listener"]
repository = "https://github.com/ballerina-platform/module-ballerina-websub"
Expand All @@ -15,5 +15,5 @@ graalvmCompatible = true
[[platform.java17.dependency]]
groupId = "io.ballerina.stdlib"
artifactId = "websub-native"
version = "2.11.0"
path = "../native/build/libs/websub-native-2.11.0.jar"
version = "2.11.1"
path = "../native/build/libs/websub-native-2.11.1-SNAPSHOT.jar"
2 changes: 1 addition & 1 deletion ballerina/CompilerPlugin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ id = "websub-compiler-plugin"
class = "io.ballerina.stdlib.websub.WebSubCompilerPlugin"

[[dependency]]
path = "../compiler-plugin/build/libs/websub-compiler-plugin-2.11.0.jar"
path = "../compiler-plugin/build/libs/websub-compiler-plugin-2.11.1-SNAPSHOT.jar"
8 changes: 4 additions & 4 deletions ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ distribution-version = "2201.9.0"
[[package]]
org = "ballerina"
name = "auth"
version = "2.11.0"
version = "2.11.1"
dependencies = [
{org = "ballerina", name = "crypto"},
{org = "ballerina", name = "jballerina.java"},
Expand Down Expand Up @@ -41,7 +41,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "crypto"
version = "2.7.0"
version = "2.7.2"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "time"}
Expand All @@ -64,7 +64,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "http"
version = "2.11.0"
version = "2.11.3"
dependencies = [
{org = "ballerina", name = "auth"},
{org = "ballerina", name = "cache"},
Expand Down Expand Up @@ -336,7 +336,7 @@ modules = [
[[package]]
org = "ballerina"
name = "websub"
version = "2.11.0"
version = "2.11.1"
dependencies = [
{org = "ballerina", name = "crypto"},
{org = "ballerina", name = "http"},
Expand Down
9 changes: 4 additions & 5 deletions ballerina/tests/additional_external_error_data_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@
// under the License.

import ballerina/log;
import ballerina/http;
// import ballerina/io;
import ballerina/http;
import ballerina/test;

listener Listener additionalErrorDetailsListener = new (9093);
listener Listener additionalErrorDetailsListener = new (SUB_WITH_ADDITIONAL_ERRDETAILS_PORT);

SubscriberService serviceWithAdditionalErrorDetails = @SubscriberServiceConfig {
target: "http://0.0.0.0:9191/common/discovery",
target: string `http://0.0.0.0:${COMMON_HUB_SVC_PORT}/common/discovery`,
leaseSeconds: 36000,
unsubscribeOnShutdown: false
}
Expand Down Expand Up @@ -61,7 +60,7 @@ function afterAdditionalErrorDetailsService() returns error? {
check additionalErrorDetailsListener.gracefulStop();
}

http:Client subscriberServiceErrorDetailsClientEp = check new ("http://localhost:9093/subscriber");
http:Client subscriberServiceErrorDetailsClientEp = check new (string `http://localhost:${SUB_WITH_ADDITIONAL_ERRDETAILS_PORT}/subscriber`);

@test:Config {
groups: ["service-with-additional-details"]
Expand Down
6 changes: 3 additions & 3 deletions ballerina/tests/basic_subscriber_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import ballerina/test;
import ballerina/http;
import ballerina/mime;

listener Listener basicSubscriberListener = new (9090);
listener Listener basicSubscriberListener = new (BASIC_SUB_PORT);

SubscriberService simpleSubscriberService = @SubscriberServiceConfig { target: "http://0.0.0.0:9191/common/discovery", leaseSeconds: 36000, unsubscribeOnShutdown: false }
SubscriberService simpleSubscriberService = @SubscriberServiceConfig { target: string `http://0.0.0.0:${COMMON_HUB_SVC_PORT}/common/discovery`, leaseSeconds: 36000, unsubscribeOnShutdown: false }
service object {
isolated remote function onSubscriptionValidationDenied(SubscriptionDeniedError msg) returns Acknowledgement? {
log:printDebug("onSubscriptionValidationDenied invoked");
Expand Down Expand Up @@ -64,7 +64,7 @@ function afterSimpleSubscriberTest() returns error? {
check basicSubscriberListener.gracefulStop();
}

http:Client httpClient = check new ("http://localhost:9090/subscriber");
http:Client httpClient = check new (string `http://localhost:${BASIC_SUB_PORT}/subscriber`);

@test:Config {
groups: ["simpleSubscriber"]
Expand Down
4 changes: 2 additions & 2 deletions ballerina/tests/content_verification_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ isolated function isUrlEncodedContentVerified() returns boolean {
secret: hashKey,
unsubscribeOnShutdown: false
}
service /subscriber on new Listener(9098) {
service /subscriber on new Listener(CONTENT_VERIFY_SUB_PORT) {
remote function onEventNotification(ContentDistributionMessage event)
returns Acknowledgement|SubscriptionDeletedError? {
log:printInfo("[VERIFICATION] onEventNotification invoked ", contentDistributionMessage = event);
Expand All @@ -86,7 +86,7 @@ service /subscriber on new Listener(9098) {
}
}

final http:Client contentVerificationClient = check new("http://localhost:9098/subscriber");
final http:Client contentVerificationClient = check new(string `http://localhost:${CONTENT_VERIFY_SUB_PORT}/subscriber`);

@test:Config {
groups: ["contentVerification"]
Expand Down
6 changes: 3 additions & 3 deletions ballerina/tests/default_method_impl_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import ballerina/log;
import ballerina/test;
import ballerina/http;

listener Listener serviceWithDefaultImplListener = new (9091);
listener Listener serviceWithDefaultImplListener = new (SUB_WITH_DFLT_METHODS_PORT);

SubscriberService serviceWithDefaultImpl = @SubscriberServiceConfig { target: "http://0.0.0.0:9191/common/discovery", leaseSeconds: 36000, secret: "Kslk30SNF2AChs2", unsubscribeOnShutdown: false }
SubscriberService serviceWithDefaultImpl = @SubscriberServiceConfig { target: string `http://0.0.0.0:${COMMON_HUB_SVC_PORT}/common/discovery`, leaseSeconds: 36000, secret: "Kslk30SNF2AChs2", unsubscribeOnShutdown: false }
service object {
isolated remote function onEventNotification(ContentDistributionMessage event)
returns Acknowledgement|SubscriptionDeletedError? {
Expand All @@ -45,7 +45,7 @@ function afterGroupTwo() returns error? {
check serviceWithDefaultImplListener.gracefulStop();
}

http:Client serviceWithDefaultImplClientEp = check new("http://localhost:9091/subscriber");
http:Client serviceWithDefaultImplClientEp = check new(string `http://localhost:${SUB_WITH_DFLT_METHODS_PORT}/subscriber`);

@test:Config {
groups: ["defaultMethodImpl"]
Expand Down
4 changes: 2 additions & 2 deletions ballerina/tests/isolated_subscriber_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import ballerina/mime;
string[] receivedMsgs = [];

@SubscriberServiceConfig {}
service /subscriber on new Listener(9103) {
service /subscriber on new Listener(ISOLATED_SUB_PORT) {
remote function onSubscriptionVerification(SubscriptionVerification msg) returns SubscriptionVerificationSuccess|SubscriptionVerificationError {
if (msg.hubTopic == "test1") {
return SUBSCRIPTION_VERIFICATION_ERROR;
Expand All @@ -46,7 +46,7 @@ service /subscriber on new Listener(9103) {
}
}

http:Client isolatedSubTestClient = check new ("http://localhost:9103/subscriber");
http:Client isolatedSubTestClient = check new (string `http://localhost:${ISOLATED_SUB_PORT}/subscriber`);

@test:Config {
groups: ["isolatedSubscriber"]
Expand Down
6 changes: 3 additions & 3 deletions ballerina/tests/multi_service_listener_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import ballerina/test;
import ballerina/http;
import ballerina/mime;

listener Listener multiServiceListener = new(9096);
listener Listener multiServiceListener = new(MULTIPLE_SUB_ATTACH_PORT);

@SubscriberServiceConfig {
unsubscribeOnShutdown: false
Expand Down Expand Up @@ -73,8 +73,8 @@ service /subscriberTwo on multiServiceListener {
}
}

http:Client clientForServiceOne = check new ("http://localhost:9096/subscriberOne");
http:Client clientForServiceTwo = check new ("http://localhost:9096/subscriberTwo");
http:Client clientForServiceOne = check new (string `http://localhost:${MULTIPLE_SUB_ATTACH_PORT}/subscriberOne`);
http:Client clientForServiceTwo = check new (string `http://localhost:${MULTIPLE_SUB_ATTACH_PORT}/subscriberTwo`);

@test:Config {
groups: ["multiServiceListener"]
Expand Down
2 changes: 1 addition & 1 deletion ballerina/tests/optional_subscriber_target_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import ballerina/log;
import ballerina/test;

listener Listener optionalTargetListener = new (9094);
listener Listener optionalTargetListener = new (SUB_WITH_OPT_TARGET_PORT);

SubscriberService optionalSubscriberTarget = @SubscriberServiceConfig { leaseSeconds: 36000, secret: "Kslk30SNF2AChs2", unsubscribeOnShutdown: false }
service object {
Expand Down
Empty file.
4 changes: 2 additions & 2 deletions ballerina/tests/ssl_enabled_subscriber_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ListenerConfiguration listenerConfigs = {
}
};

listener Listener sslEnabledListener = new(9095, listenerConfigs);
listener Listener sslEnabledListener = new(SSL_ENABLED_SUB_PORT, listenerConfigs);

@SubscriberServiceConfig {
unsubscribeOnShutdown: false
Expand Down Expand Up @@ -64,7 +64,7 @@ http:ClientConfiguration httpsConfig = {
}
}
};
http:Client sslEnabledClient = check new("https://localhost:9095/subscriber", httpsConfig);
http:Client sslEnabledClient = check new(string `https://localhost:${SSL_ENABLED_SUB_PORT}/subscriber`, httpsConfig);

@test:Config {
groups: ["sslEnabledSubscriber"]
Expand Down
6 changes: 3 additions & 3 deletions ballerina/tests/subscriber_with_error_return_types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import ballerina/test;
import ballerina/http;
import ballerina/mime;

listener Listener errorReturnsSubscriberListener = new (9099);
listener Listener errorReturnsSubscriberListener = new (SUB_WITH_ERROR_RTRN_PORT);

SubscriberService subscriberWithErrorReturns = @SubscriberServiceConfig { target: "http://0.0.0.0:9191/common/discovery", leaseSeconds: 36000, unsubscribeOnShutdown: false }
SubscriberService subscriberWithErrorReturns = @SubscriberServiceConfig { target: string `http://0.0.0.0:${COMMON_HUB_SVC_PORT}/common/discovery`, leaseSeconds: 36000, unsubscribeOnShutdown: false }
service object {
isolated remote function onSubscriptionValidationDenied(SubscriptionDeniedError msg) returns error? {
return error ("Error occured while processing request");
Expand All @@ -45,7 +45,7 @@ function afterSubscriberWithErrorReturnsTest() returns error? {
check errorReturnsSubscriberListener.gracefulStop();
}

http:Client SubscriberWithErrorReturnsClientEp = check new("http://localhost:9099/subscriber");
http:Client SubscriberWithErrorReturnsClientEp = check new(string `http://localhost:${SUB_WITH_ERROR_RTRN_PORT}/subscriber`);

@test:Config {
groups: ["subscriberWithErrorReturns"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import ballerina/mime;
import ballerina/http;

@SubscriberServiceConfig {}
service /subscriber on new Listener(9104) {
service /subscriber on new Listener(SUB_WITH_RO_PARAMS_PORT) {
isolated remote function onSubscriptionValidationDenied(readonly & SubscriptionDeniedError msg) returns Acknowledgement? {
test:assertTrue(msg is readonly);
return ACKNOWLEDGEMENT;
Expand Down Expand Up @@ -63,7 +63,7 @@ service /subscriber on new Listener(9104) {
}
}

http:Client readonlyParamTestClient = check new ("http://localhost:9104/subscriber");
http:Client readonlyParamTestClient = check new (string `http://localhost:${SUB_WITH_RO_PARAMS_PORT}/subscriber`);

@test:Config {
groups: ["subscriberWithReadonlyParams"]
Expand Down
4 changes: 2 additions & 2 deletions ballerina/tests/subscription_initiation_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ isolated function testUnSubscriptionInitiationSuccessWithAdditionalParams() retu
groups: ["subscriptionInitiation"]
}
function testSubInitFailedWithListenerForResourceDiscoveryFailure() returns error? {
Listener ls = check new (9500);
Listener ls = check new (SUB_INIT_RCS_DISCOVERY_PORT);
var res = ls.attachWithConfig(websubServiceObj, getServiceAnnotationConfig(DISCOVERY_FAILURE_URL), "sub");
if res is error {
log:printError("[testSubInitFailedWithListenerForResourceDiscoveryFailure] error occurred ", 'error = res);
Expand All @@ -267,7 +267,7 @@ function testSubInitFailedWithListenerForResourceDiscoveryFailure() returns erro
groups: ["subscriptionInitiation"]
}
function testSubInitFailedWithListenerForSubFailure() returns error? {
Listener ls = check new (9501);
Listener ls = check new (SUB_INIT_FAILURE_PORT);
var res = ls.attachWithConfig(websubServiceObj, getServiceAnnotationConfig([ HUB_FAILURE_URL, COMMON_TOPIC ]), "sub");
test:assertFalse(res is error);
var startDetails = ls.'start();
Expand Down
4 changes: 2 additions & 2 deletions ballerina/tests/test_init.bal
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
import ballerina/test;
import ballerina/http;

listener http:Listener simpleHttpServiceListener = new (9191);
listener http:Listener simpleHttpServiceListener = new (COMMON_HUB_SVC_PORT);

http:Service simpleHttpService = service object {
isolated resource function get discovery(http:Caller caller, http:Request request) returns error? {
http:Response response = new;
response.addHeader("Link", "<http://127.0.0.1:9191/common/hub>; rel=\"hub\"");
response.addHeader("Link", string `<http://127.0.0.1:${COMMON_HUB_SVC_PORT}/common/hub>; rel=\"hub\"`);
response.addHeader("Link", "<https://sample.topic.com>; rel=\"self\"");
check caller->respond(response);
}
Expand Down
36 changes: 36 additions & 0 deletions ballerina/tests/test_ports.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com).
//
// 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.

// Ports related to subscriber services
const int BASE_PORT = 9400;
const int BASIC_SUB_PORT = BASE_PORT + 1;
const int SUB_WITH_DFLT_METHODS_PORT = BASE_PORT + 2;
const int SUB_WITH_ADDITIONAL_ERRDETAILS_PORT = BASE_PORT + 3;
const int SUB_WITH_OPT_TARGET_PORT = BASE_PORT + 4;
const int SSL_ENABLED_SUB_PORT = BASE_PORT + 5;
const int MULTIPLE_SUB_ATTACH_PORT = BASE_PORT + 6;
const int MANUAL_SUB_ATTACH_PORT = BASE_PORT + 7;
const int CONTENT_VERIFY_SUB_PORT = BASE_PORT + 8;
const int SUB_WITH_ERROR_RTRN_PORT = BASE_PORT + 9;
const int SUB_UTILS_PORT = BASE_PORT + 10;
const int UNSUB_SUB_PORT = BASE_PORT + 11;
const int ISOLATED_SUB_PORT = BASE_PORT + 12;
const int SUB_WITH_RO_PARAMS_PORT = BASE_PORT + 13;
const int SUB_INIT_RCS_DISCOVERY_PORT = BASE_PORT + 14;
const int SUB_INIT_FAILURE_PORT = BASE_PORT + 15;

// Ports related to hub services
const int COMMON_HUB_SVC_PORT = 9500;
6 changes: 3 additions & 3 deletions ballerina/tests/unsubscription_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ isolated function getHubMode(http:Request request) returns string|error {
return queryParams[HUB_MODE] ?: "";
}

final http:Client notificationClientEp = check new("http://127.0.0.1:9102/sub");
final http:Client verificationClientEp = check new(string `http://127.0.0.1:${UNSUB_SUB_PORT}/sub`);

isolated function notifySubscriber(string mode) returns error? {
string challenge = uuid:createType4AsString();
string queryParams = string`?${HUB_MODE}=${mode}&${HUB_TOPIC}=test&${HUB_CHALLENGE}=${challenge}&${HUB_LEASE_SECONDS}=100000`;
log:printInfo("[UNSUB_VER] Sending verification: ", params = challenge);
string response = check notificationClientEp->get(queryParams);
string response = check verificationClientEp->get(queryParams);
log:printInfo("[UNSUB_VER] Received verification", response = response);
if challenge == response {
log:printInfo("[UNSUB_VER] Updating verification status");
Expand Down Expand Up @@ -85,7 +85,7 @@ service object {
groups: ["unsubscriptionViaGracefulstop"]
}
function testUnsubscriptionOnGracefulStop() returns error? {
Listener ls = check new (9102);
Listener ls = check new (UNSUB_SUB_PORT);
check ls.attach(unsubscriptionTestSubscriber, "sub");
check ls.'start();
log:printInfo("[UNSUB_VER] Starting Subscriber");
Expand Down
Loading

0 comments on commit 30e0d23

Please sign in to comment.