diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/RuntimeRegistry.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/RuntimeRegistry.java index 1a3ec5d602ca..9ce89176033f 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/RuntimeRegistry.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/RuntimeRegistry.java @@ -17,6 +17,7 @@ package io.ballerina.runtime.internal.scheduling; import io.ballerina.runtime.api.async.Callback; +import io.ballerina.runtime.api.utils.TypeUtils; import io.ballerina.runtime.api.values.BError; import io.ballerina.runtime.api.values.BFunctionPointer; import io.ballerina.runtime.api.values.BObject; @@ -91,7 +92,8 @@ private synchronized void invokeStopHandlerFunction(Strand strand, Scheduler sch BFunctionPointer bFunctionPointer = stopHandlerStack.pop(); StopHandlerCallback callback = new StopHandlerCallback(strand, scheduler); final FutureValue future = scheduler.createFuture(strand, callback, null, - ((BFunctionType) bFunctionPointer.getType()).retType, null, strand.getMetadata()); + ((BFunctionType) TypeUtils.getImpliedType(bFunctionPointer.getType())).retType, null, + strand.getMetadata()); scheduler.scheduleLocal(new Object[]{strand}, bFunctionPointer, strand, future); } diff --git a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/packaging/ModuleExecutionFlowTests.java b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/packaging/ModuleExecutionFlowTests.java index dd9722b53eb8..e29f1801e14e 100644 --- a/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/packaging/ModuleExecutionFlowTests.java +++ b/tests/jballerina-integration-test/src/test/java/org/ballerinalang/test/packaging/ModuleExecutionFlowTests.java @@ -140,6 +140,8 @@ public void testStopHandlerExecution() throws BallerinaTestException { LogLeecher infoLeecher1 = new LogLeecher("Stopped stopHandlerFunc3"); LogLeecher infoLeecher2 = new LogLeecher("Stopped stopHandlerFunc2"); LogLeecher infoLeecher3 = new LogLeecher("Stopped stopHandlerFunc1"); + LogLeecher infoLeecher4 = new LogLeecher("Stopped inlineStopHandler"); + serverInstance.addLogLeecher(infoLeecher4); serverInstance.addLogLeecher(infoLeecher1); serverInstance.addLogLeecher(infoLeecher2); serverInstance.addLogLeecher(infoLeecher3); diff --git a/tests/jballerina-integration-test/src/test/resources/packaging/stop_handler_execution/main.bal b/tests/jballerina-integration-test/src/test/resources/packaging/stop_handler_execution/main.bal index 41637860fe75..54bd4a2819be 100644 --- a/tests/jballerina-integration-test/src/test/resources/packaging/stop_handler_execution/main.bal +++ b/tests/jballerina-integration-test/src/test/resources/packaging/stop_handler_execution/main.bal @@ -22,19 +22,19 @@ int count = 0; function stopHandlerFunc1() returns error? { incrementCount(); - assertCount(5); + assertCount(6); println("Stopped stopHandlerFunc1"); } function stopHandlerFunc2() returns error? { incrementCount(); - assertCount(4); + assertCount(5); println("Stopped stopHandlerFunc2"); } function stopHandlerFunc3() returns error? { incrementCount(); - assertCount(3); + assertCount(4); println("Stopped stopHandlerFunc3"); } @@ -49,6 +49,12 @@ public function main() { incrementCount(); assertCount(2); runtime:onGracefulStop(stopHandlerFunc3); + runtime:StopHandler inlineStopHandler = function() returns error? { + incrementCount(); + assertCount(3); + println("Stopped inlineStopHandler"); + }; + runtime:onGracefulStop(inlineStopHandler); runtime:sleep(3); } diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/runtime/api/RuntimeAPITest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/runtime/api/RuntimeAPITest.java index 19480a6932ef..7ca9edaca1d8 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/runtime/api/RuntimeAPITest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/runtime/api/RuntimeAPITest.java @@ -45,7 +45,6 @@ public Object[] packageNameProvider() { "invalid_values", "async", "utils", - "stop_handler", "identifier_utils", "environment" }; diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/stop_handler/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/stop_handler/Ballerina.toml deleted file mode 100644 index 1b09d3767f68..000000000000 --- a/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/stop_handler/Ballerina.toml +++ /dev/null @@ -1,4 +0,0 @@ -[package] -org= "testorg" -name="stop_handler" -version= "1.0.0" diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/stop_handler/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/stop_handler/main.bal deleted file mode 100644 index 5660560faa34..000000000000 --- a/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/stop_handler/main.bal +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (c) 2022 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -// -// WSO2 Inc. 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/lang.runtime; -import ballerina/test; - -import stop_handler.moduleA; - -function stopHandlerFunc1() returns error? { - runtime:sleep(1); - moduleA:incrementCount(); - moduleA:assertCount(10); -} - -function stopHandlerFunc2() returns error? { - moduleA:incrementCount(); - moduleA:assertCount(9); -} - -function stopHandlerFunc3() returns error? { - runtime:sleep(0.5); - moduleA:incrementCount(); - moduleA:assertCount(7); -} - -function stopHandlerFunc4() returns error? { - runtime:sleep(1.5); - moduleA:incrementCount(); - moduleA:assertCount(8); -} - -function init() { - moduleA:incrementCount(); - moduleA:assertCount(1); - runtime:onGracefulStop(stopHandlerFunc1); - runtime:onGracefulStop(stopHandlerFunc2); - runtime:onGracefulStop(stopHandlerFunc4); -} - -final moduleA:ListenerObj lo = new moduleA:ListenerObj("ModDyncListener"); - -public function main() { - moduleA:incrementCount(); - moduleA:assertCount(2); - runtime:registerListener(lo); - runtime:onGracefulStop(stopHandlerFunc3); - - checkpanic lo.'start(); - error? v = lo.gracefulStop(); - if (v is error) { - test:assertEquals(v.message(), "listener in main stopped"); - } - runtime:deregisterListener(lo); - moduleA:main(); -} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/stop_handler/modules/moduleA/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/stop_handler/modules/moduleA/main.bal deleted file mode 100644 index 088aca81c2b2..000000000000 --- a/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/stop_handler/modules/moduleA/main.bal +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright (c) 2022 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -// -// WSO2 Inc. 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/lang.runtime; -import ballerina/test; - -int count = 0; - -function stopHandlerFunc1() returns error? { - runtime:sleep(1); - incrementCount(); - assertCount(11); -} - -function stopHandlerFunc2() returns error? { - incrementCount(); - assertCount(6); -} - -function init() { - runtime:onGracefulStop(stopHandlerFunc1); -} - -public class ListenerObj { - - *runtime:DynamicListener; - private string name = ""; - - public function init(string name) { - self.name = name; - } - - public function 'start() returns error? { - if (self.name == "ModDyncListener") { - incrementCount(); - assertCount(3); - } - } - - public function gracefulStop() returns error? { - if (self.name == "ModDyncListener") { - runtime:sleep(1.5); - incrementCount(); - assertCount(4); - return error("listener in main stopped"); - } else if (self.name == "ModDyncListenerA") { - return error("listener in moduleA stopped"); - } - } - - public function immediateStop() { - } - - public function attach(service object {} s, string[]|string? name = ()) returns error? { - } - - public function detach(service object {} s) returns error? { - } -} - -final ListenerObj lo = new ListenerObj("ModDyncListenerA"); - -public function main() { - incrementCount(); - assertCount(5); - runtime:registerListener(lo); - runtime:onGracefulStop(stopHandlerFunc2); - - checkpanic lo.'start(); - error? v = lo.gracefulStop(); - if (v is error) { - test:assertEquals(v.message(), "listener in moduleA stopped"); - } - runtime:deregisterListener(lo); -} - -public function incrementCount() { - count += 1; -} - -public function assertCount(int val) { - test:assertEquals(count, val); -}