From ce6860af3b1f05239fd6f2e973d9e835c37d2b12 Mon Sep 17 00:00:00 2001 From: MohamedSabthar Date: Tue, 10 Dec 2024 11:19:43 +0530 Subject: [PATCH 1/4] Revert "Disable subscription tests" This reverts commit 59971474317ff4e0033b256e459eebcac7a073bc. --- .../tests/01_dataloader_tests.bal | 5 ++--- .../modules/five/tests/01_subscription_five_tests.bal | 2 -- .../modules/five/tests/02_subscription_with_context.bal | 2 -- .../five/tests/03_subscription_with_constraint.bal | 2 -- .../modules/four/tests/01_subscription_four_tests.bal | 7 ------- .../modules/one/tests/01_subscription_tests.bal | 8 -------- .../modules/six/tests/01_subscription_six_tests.bal | 1 - .../six/tests/01_subscription_with_interceptors.bal | 8 -------- .../modules/three/tests/01_subscription_three_tests.bal | 8 -------- .../modules/two/tests/01_subscription_two_tests.bal | 7 ------- ballerina/tests/03_subscriptions.bal | 1 - 11 files changed, 2 insertions(+), 49 deletions(-) diff --git a/ballerina-tests/graphql-dataloader-test-suite/tests/01_dataloader_tests.bal b/ballerina-tests/graphql-dataloader-test-suite/tests/01_dataloader_tests.bal index 3dad5e9dc..8739a7c95 100644 --- a/ballerina-tests/graphql-dataloader-test-suite/tests/01_dataloader_tests.bal +++ b/ballerina-tests/graphql-dataloader-test-suite/tests/01_dataloader_tests.bal @@ -49,7 +49,6 @@ isolated function testDataLoaderWithDifferentAliasForSameField() returns error? } @test:Config { - enable: false, groups: ["subscriptions", "dataloader"], after: resetDispatchCounters } @@ -70,8 +69,8 @@ isolated function testDataLoaderWithSubscription() returns error? { @test:Config { groups: ["dataloader", "mutation"], dependsOn: [ - testDataLoaderWithQuery - // ,testDataLoaderWithSubscription + testDataLoaderWithQuery, + testDataLoaderWithSubscription ], after: resetDispatchCounters } diff --git a/ballerina-tests/graphql-subscription-test-suite/modules/five/tests/01_subscription_five_tests.bal b/ballerina-tests/graphql-subscription-test-suite/modules/five/tests/01_subscription_five_tests.bal index e7237caa2..e8b26a43a 100644 --- a/ballerina-tests/graphql-subscription-test-suite/modules/five/tests/01_subscription_five_tests.bal +++ b/ballerina-tests/graphql-subscription-test-suite/modules/five/tests/01_subscription_five_tests.bal @@ -20,7 +20,6 @@ import ballerina/test; import ballerina/websocket; @test:Config { - enable: false, groups: ["listener", "subscriptions"] } function testAttachServiceWithSubscriptionToHttp2BasedListener() returns error? { @@ -33,7 +32,6 @@ function testAttachServiceWithSubscriptionToHttp2BasedListener() returns error? } @test:Config { - enable: false, groups: ["listener", "subscriptions"] } function testAttachServiceWithSubscriptionToHttp1BasedListener() returns error? { diff --git a/ballerina-tests/graphql-subscription-test-suite/modules/five/tests/02_subscription_with_context.bal b/ballerina-tests/graphql-subscription-test-suite/modules/five/tests/02_subscription_with_context.bal index 308bd271a..76b55fcc6 100644 --- a/ballerina-tests/graphql-subscription-test-suite/modules/five/tests/02_subscription_with_context.bal +++ b/ballerina-tests/graphql-subscription-test-suite/modules/five/tests/02_subscription_with_context.bal @@ -19,7 +19,6 @@ import ballerina/test; import ballerina/websocket; @test:Config { - enable: false, groups: ["context", "subscriptions"] } isolated function testContextWithSubscriptions() returns error? { @@ -41,7 +40,6 @@ isolated function testContextWithSubscriptions() returns error? { } @test:Config { - enable: false, groups: ["context", "subscriptions"] } isolated function testContextWithInvalidScopeInSubscriptions() returns error? { diff --git a/ballerina-tests/graphql-subscription-test-suite/modules/five/tests/03_subscription_with_constraint.bal b/ballerina-tests/graphql-subscription-test-suite/modules/five/tests/03_subscription_with_constraint.bal index 93210863a..752b0a158 100644 --- a/ballerina-tests/graphql-subscription-test-suite/modules/five/tests/03_subscription_with_constraint.bal +++ b/ballerina-tests/graphql-subscription-test-suite/modules/five/tests/03_subscription_with_constraint.bal @@ -19,7 +19,6 @@ import ballerina/test; import ballerina/websocket; @test:Config { - enable: false, groups: ["constraints", "subscriptions"] } isolated function testSubscriptionWithConstraints() returns error? { @@ -34,7 +33,6 @@ isolated function testSubscriptionWithConstraints() returns error? { } @test:Config { - enable: false, groups: ["constraints", "subscriptions"] } isolated function testMultipleSubscriptionClientsWithConstraints() returns error? { diff --git a/ballerina-tests/graphql-subscription-test-suite/modules/four/tests/01_subscription_four_tests.bal b/ballerina-tests/graphql-subscription-test-suite/modules/four/tests/01_subscription_four_tests.bal index 210c99cbb..64590962d 100644 --- a/ballerina-tests/graphql-subscription-test-suite/modules/four/tests/01_subscription_four_tests.bal +++ b/ballerina-tests/graphql-subscription-test-suite/modules/four/tests/01_subscription_four_tests.bal @@ -20,7 +20,6 @@ import ballerina/test; import ballerina/websocket; @test:Config { - enable: false, groups: ["subscriptions", "multiplexing"] } isolated function testSubscriptionMultiplexing() returns error? { @@ -56,7 +55,6 @@ isolated function testSubscriptionMultiplexing() returns error? { } @test:Config { - enable: false, groups: ["request_validation", "websocket", "subscriptions"] } isolated function testInvalidWebSocketRequestWithEmptyQuery() returns error? { @@ -71,7 +69,6 @@ isolated function testInvalidWebSocketRequestWithEmptyQuery() returns error? { } @test:Config { - enable: false, groups: ["request_validation", "websocket", "subscriptions"] } isolated function testInvalidWebSocketRequestWithInvalidQuery() returns error? { @@ -87,7 +84,6 @@ isolated function testInvalidWebSocketRequestWithInvalidQuery() returns error? { } @test:Config { - enable: false, groups: ["request_validation", "websocket", "subscriptions"] } isolated function testInvalidWebSocketRequestWithoutQuery() returns error? { @@ -102,7 +98,6 @@ isolated function testInvalidWebSocketRequestWithoutQuery() returns error? { } @test:Config { - enable: false, groups: ["request_validation", "websocket", "subscriptions"] } isolated function testInvalidVariableInWebSocketPayload() returns error? { @@ -119,7 +114,6 @@ isolated function testInvalidVariableInWebSocketPayload() returns error? { } @test:Config { - enable: false, groups: ["request_validation", "websocket", "subscriptions"] } isolated function testEmptyWebSocketPayload() returns error? { @@ -134,7 +128,6 @@ isolated function testEmptyWebSocketPayload() returns error? { } @test:Config { - enable: false, groups: ["request_validation", "websocket", "subscriptions"] } isolated function testInvalidWebSocketPayload() returns error? { diff --git a/ballerina-tests/graphql-subscription-test-suite/modules/one/tests/01_subscription_tests.bal b/ballerina-tests/graphql-subscription-test-suite/modules/one/tests/01_subscription_tests.bal index ba6dd2046..8cf319786 100644 --- a/ballerina-tests/graphql-subscription-test-suite/modules/one/tests/01_subscription_tests.bal +++ b/ballerina-tests/graphql-subscription-test-suite/modules/one/tests/01_subscription_tests.bal @@ -19,7 +19,6 @@ import ballerina/test; import ballerina/websocket; @test:Config { - enable: false, groups: ["subscriptions"] } isolated function testSubscription() returns error? { @@ -37,7 +36,6 @@ isolated function testSubscription() returns error? { } @test:Config { - enable: false, groups: ["subscriptions"] } isolated function testSubscriptionWithoutSubProtocol() returns error? { @@ -49,7 +47,6 @@ isolated function testSubscriptionWithoutSubProtocol() returns error? { } @test:Config { - enable: false, groups: ["subscriptions"] } isolated function testSubscriptionsWithMultipleOperations() returns error? { @@ -79,7 +76,6 @@ isolated function testSubscriptionsWithMultipleOperations() returns error? { } @test:Config { - enable: false, groups: ["records", "subscriptions"] } isolated function testSubscriptionWithRecords() returns error? { @@ -97,7 +93,6 @@ isolated function testSubscriptionWithRecords() returns error? { } @test:Config { - enable: false, groups: ["subscriptions"] } isolated function testQueryWithSameSubscriptionFieldName() returns error? { @@ -109,7 +104,6 @@ isolated function testQueryWithSameSubscriptionFieldName() returns error? { } @test:Config { - enable: false, groups: ["fragments", "subscriptions"] } isolated function testSubscriptionWithFragments() returns error? { @@ -127,7 +121,6 @@ isolated function testSubscriptionWithFragments() returns error? { } @test:Config { - enable: false, groups: ["union", "subscriptions"] } isolated function testSubscriptionWithUnionType() returns error? { @@ -145,7 +138,6 @@ isolated function testSubscriptionWithUnionType() returns error? { } @test:Config { - enable: false, groups: ["variables", "subscriptions"] } isolated function testSubscriptionWithVariables() returns error? { diff --git a/ballerina-tests/graphql-subscription-test-suite/modules/six/tests/01_subscription_six_tests.bal b/ballerina-tests/graphql-subscription-test-suite/modules/six/tests/01_subscription_six_tests.bal index 750fe54bb..a75f2be7f 100644 --- a/ballerina-tests/graphql-subscription-test-suite/modules/six/tests/01_subscription_six_tests.bal +++ b/ballerina-tests/graphql-subscription-test-suite/modules/six/tests/01_subscription_six_tests.bal @@ -19,7 +19,6 @@ import ballerina/test; import ballerina/websocket; @test:Config { - enable: false, groups: ["subscriptions", "service"] } isolated function testConnectionClousureWhenPongNotRecived() returns error? { diff --git a/ballerina-tests/graphql-subscription-test-suite/modules/six/tests/01_subscription_with_interceptors.bal b/ballerina-tests/graphql-subscription-test-suite/modules/six/tests/01_subscription_with_interceptors.bal index d46809d56..f61e6575e 100644 --- a/ballerina-tests/graphql-subscription-test-suite/modules/six/tests/01_subscription_with_interceptors.bal +++ b/ballerina-tests/graphql-subscription-test-suite/modules/six/tests/01_subscription_with_interceptors.bal @@ -19,7 +19,6 @@ import ballerina/test; import ballerina/websocket; @test:Config { - enable: false, groups: ["interceptors", "subscriptions"] } isolated function testInterceptorsWithSubscriptionReturningScalar() returns error? { @@ -42,7 +41,6 @@ isolated function testInterceptorsWithSubscriptionReturningScalar() returns erro } @test:Config { - enable: false, groups: ["interceptors", "subscriptions", "records"] } isolated function testInterceptorsWithSubscriptionReturningRecord() returns error? { @@ -65,7 +63,6 @@ isolated function testInterceptorsWithSubscriptionReturningRecord() returns erro } @test:Config { - enable: false, groups: ["interceptors", "fragments", "subscriptions"] } isolated function testInterceptorsWithSubscriptionAndFragments() returns error? { @@ -88,7 +85,6 @@ isolated function testInterceptorsWithSubscriptionAndFragments() returns error? } @test:Config { - enable: false, groups: ["interceptors", "union", "subscriptions"] } isolated function testInterceptorsWithUnionTypeSubscription() returns error? { @@ -132,7 +128,6 @@ isolated function testInterceptorsWithUnionTypeSubscription() returns error? { } @test:Config { - enable: false, groups: ["interceptors", "subscriptions"] } isolated function testInterceptorsReturnBeforeResolverWithSubscription() returns error? { @@ -155,7 +150,6 @@ isolated function testInterceptorsReturnBeforeResolverWithSubscription() returns } @test:Config { - enable: false, groups: ["interceptors", "subscriptions"] } isolated function testInterceptorsDestructiveModificationWithSubscription() returns error? { @@ -204,7 +198,6 @@ isolated function testInterceptorsDestructiveModificationWithSubscription() retu } @test:Config { - enable: false, groups: ["interceptors", "subscriptions"] } isolated function testInterceptorsWithSubscribersRunSimultaniously1() returns error? { @@ -244,7 +237,6 @@ isolated function testInterceptorsWithSubscribersRunSimultaniously1() returns er } @test:Config { - enable: false, groups: ["interceptors", "union", "subscriptions"] } isolated function testInterceptorsWithSubscribersRunSimultaniously2() returns error? { diff --git a/ballerina-tests/graphql-subscription-test-suite/modules/three/tests/01_subscription_three_tests.bal b/ballerina-tests/graphql-subscription-test-suite/modules/three/tests/01_subscription_three_tests.bal index b205db3cf..ecade6828 100644 --- a/ballerina-tests/graphql-subscription-test-suite/modules/three/tests/01_subscription_three_tests.bal +++ b/ballerina-tests/graphql-subscription-test-suite/modules/three/tests/01_subscription_three_tests.bal @@ -19,7 +19,6 @@ import ballerina/test; import ballerina/websocket; @test:Config { - enable: false, groups: ["subscriptions"] } function testAlreadyExistingSubscriber() returns error? { @@ -52,7 +51,6 @@ function testAlreadyExistingSubscriber() returns error? { } @test:Config { - enable: false, groups: ["subscriptions"] } isolated function testOnPing() returns error? { @@ -65,7 +63,6 @@ isolated function testOnPing() returns error? { } @test:Config { - enable: false, groups: ["subscriptions"] } isolated function testInvalidSubProtocolInSubscriptions() returns error? { @@ -80,7 +77,6 @@ isolated function testInvalidSubProtocolInSubscriptions() returns error? { } @test:Config { - enable: false, groups: ["subscriptions", "runtime_errors"] } isolated function testErrorsInStreams() returns error? { @@ -100,7 +96,6 @@ isolated function testErrorsInStreams() returns error? { } @test:Config { - enable: false, groups: ["subscriptions"] } isolated function testMultipleSubscriptionUsingSingleClient() returns error? { @@ -126,7 +121,6 @@ isolated function testMultipleSubscriptionUsingSingleClient() returns error? { } @test:Config { - enable: false, groups: ["subscriptions"] } isolated function testSubscriptionWithInvalidPayload() returns error? { @@ -143,7 +137,6 @@ isolated function testSubscriptionWithInvalidPayload() returns error? { } @test:Config { - enable: false, groups: ["subscriptions", "recrods", "service"] } isolated function testResolverReturingStreamOfRecordsWithServiceObjects() returns error? { @@ -159,7 +152,6 @@ isolated function testResolverReturingStreamOfRecordsWithServiceObjects() return } @test:Config { - enable: false, groups: ["subscriptions", "recrods", "service", "maps"] } isolated function testResolverReturingStreamOfRecordsWithMapOfServiceObjects() returns error? { diff --git a/ballerina-tests/graphql-subscription-test-suite/modules/two/tests/01_subscription_two_tests.bal b/ballerina-tests/graphql-subscription-test-suite/modules/two/tests/01_subscription_two_tests.bal index 62dd04d7c..b812b29fb 100644 --- a/ballerina-tests/graphql-subscription-test-suite/modules/two/tests/01_subscription_two_tests.bal +++ b/ballerina-tests/graphql-subscription-test-suite/modules/two/tests/01_subscription_two_tests.bal @@ -19,7 +19,6 @@ import ballerina/test; import ballerina/websocket; @test:Config { - enable: false, groups: ["introspection", "typename", "subscriptions"] } isolated function testSubscriptionWithIntrospectionInFields() returns error? { @@ -35,7 +34,6 @@ isolated function testSubscriptionWithIntrospectionInFields() returns error? { } @test:Config { - enable: false, groups: ["subscriptions"] } isolated function testInvalidSubscription() returns error? { @@ -51,7 +49,6 @@ isolated function testInvalidSubscription() returns error? { } @test:Config { - enable: false, groups: ["subscriptions"] } isolated function testSubscriptionFunctionWithErrors() returns error? { @@ -73,7 +70,6 @@ isolated function testSubscriptionFunctionWithErrors() returns error? { } @test:Config { - enable: false, groups: ["service", "subscriptions"] } isolated function testSubscriptionWithServiceObjects() returns error? { @@ -92,7 +88,6 @@ isolated function testSubscriptionWithServiceObjects() returns error? { } @test:Config { - enable: false, groups: ["subscriptions"] } isolated function testSubscriptionWithMultipleClients() returns error? { @@ -130,7 +125,6 @@ isolated function testConnectionInitMessage() returns error? { } @test:Config { - enable: false, groups: ["subscriptions"] } isolated function testInvalidMultipleConnectionInitMessages() returns error? { @@ -145,7 +139,6 @@ isolated function testInvalidMultipleConnectionInitMessages() returns error? { } @test:Config { - enable: false, groups: ["subscriptions"] } isolated function testUnauthorizedAccess() returns error? { diff --git a/ballerina/tests/03_subscriptions.bal b/ballerina/tests/03_subscriptions.bal index 844acede6..ec55bef6b 100644 --- a/ballerina/tests/03_subscriptions.bal +++ b/ballerina/tests/03_subscriptions.bal @@ -18,7 +18,6 @@ import ballerina/test; import graphql.parser; @test:Config { - enable: false, groups: ["subscriptions", "validation"], dataProvider: dataProviderSubscriptionValidation } From 06fd31d0e7bf6e04998a831a554f7f8a127b8573 Mon Sep 17 00:00:00 2001 From: MohamedSabthar Date: Tue, 10 Dec 2024 11:20:08 +0530 Subject: [PATCH 2/4] Revert "Disable test testDataLoaderWithDifferentAliasForSameField" This reverts commit 39adcc88645df4c1fa960b30ee39620a5220a891. --- .../tests/01_dataloader_tests.bal | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ballerina-tests/graphql-dataloader-test-suite/tests/01_dataloader_tests.bal b/ballerina-tests/graphql-dataloader-test-suite/tests/01_dataloader_tests.bal index 8739a7c95..17bc71db8 100644 --- a/ballerina-tests/graphql-dataloader-test-suite/tests/01_dataloader_tests.bal +++ b/ballerina-tests/graphql-dataloader-test-suite/tests/01_dataloader_tests.bal @@ -35,8 +35,7 @@ isolated function testDataLoaderWithQuery() returns error? { @test:Config { groups: ["dataloader", "query"], - after: resetDispatchCounters, - enable: false + after: resetDispatchCounters } isolated function testDataLoaderWithDifferentAliasForSameField() returns error? { graphql:Client graphqlClient = check new ("localhost:9090/dataloader"); From b8ffe8a952c9c9cf2fb624463aa6c3015fac46a2 Mon Sep 17 00:00:00 2001 From: warunalakshitha Date: Tue, 10 Dec 2024 23:34:11 +0530 Subject: [PATCH 3/4] Remove unwanted completable futures --- gradle.properties | 2 +- .../graphql/runtime/client/QueryExecutor.java | 12 +---- .../runtime/client/QueryExecutorCallback.java | 42 ----------------- .../runtime/engine/ArgumentHandler.java | 15 +++--- .../graphql/runtime/engine/DataLoader.java | 19 ++++---- .../stdlib/graphql/runtime/engine/Engine.java | 44 +++++++++--------- .../runtime/engine/ExecutionCallback.java | 46 ------------------- spotbugs-exclude.xml | 12 ++--- 8 files changed, 47 insertions(+), 145 deletions(-) delete mode 100644 native/src/main/java/io/ballerina/stdlib/graphql/runtime/client/QueryExecutorCallback.java delete mode 100644 native/src/main/java/io/ballerina/stdlib/graphql/runtime/engine/ExecutionCallback.java diff --git a/gradle.properties b/gradle.properties index 25f2895bc..ed36abb1b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -29,7 +29,7 @@ stdlibTaskVersion=2.6.0-20241122-124800-cb84357 # Level 03 stdlibCacheVersion=3.9.0-20241122-182900-c956a97 stdlibFileVersion=1.11.0-20241122-180900-dff344c -stdlibMimeVersion=2.11.0-20241125-094600-bbddf94 +stdlibMimeVersion=2.11.0-20241204-145000-6cef6a1 stdlibUuidVersion=1.9.0-20241125-110300-5eb185d # Level 04 diff --git a/native/src/main/java/io/ballerina/stdlib/graphql/runtime/client/QueryExecutor.java b/native/src/main/java/io/ballerina/stdlib/graphql/runtime/client/QueryExecutor.java index fa0d1f888..b46b3d863 100644 --- a/native/src/main/java/io/ballerina/stdlib/graphql/runtime/client/QueryExecutor.java +++ b/native/src/main/java/io/ballerina/stdlib/graphql/runtime/client/QueryExecutor.java @@ -24,10 +24,6 @@ import io.ballerina.runtime.api.values.BString; import io.ballerina.runtime.api.values.BTypedesc; -import java.util.concurrent.CompletableFuture; - -import static io.ballerina.stdlib.graphql.runtime.utils.ModuleUtils.getResult; - /** * This class is used to execute a GraphQL document using the Ballerina GraphQL client. */ @@ -67,15 +63,11 @@ private static Object invokeClientMethod(Environment env, BObject client, BStrin private static Object invokeClientMethod(Environment env, BObject client, String methodName, Object[] paramFeed) { return env.yieldAndRun(() -> { - CompletableFuture balFuture = new CompletableFuture<>(); - QueryExecutorCallback executorCallback = new QueryExecutorCallback(balFuture); try { - Object result = env.getRuntime().callMethod(client, methodName, null, paramFeed); - executorCallback.notifySuccess(result); + return env.getRuntime().callMethod(client, methodName, null, paramFeed); } catch (BError bError) { - executorCallback.notifyFailure(bError); + return bError; } - return getResult(balFuture); }); } } diff --git a/native/src/main/java/io/ballerina/stdlib/graphql/runtime/client/QueryExecutorCallback.java b/native/src/main/java/io/ballerina/stdlib/graphql/runtime/client/QueryExecutorCallback.java deleted file mode 100644 index 8aacaf047..000000000 --- a/native/src/main/java/io/ballerina/stdlib/graphql/runtime/client/QueryExecutorCallback.java +++ /dev/null @@ -1,42 +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. - */ - -package io.ballerina.stdlib.graphql.runtime.client; - -import io.ballerina.runtime.api.values.BError; - -import java.util.concurrent.CompletableFuture; - -/** - * This class implements async callback methods of {@link QueryExecutor}. - */ -public class QueryExecutorCallback { - private final CompletableFuture balFuture; - - public QueryExecutorCallback(CompletableFuture balFuture) { - this.balFuture = balFuture; - } - - public void notifySuccess(Object result) { - balFuture.complete(result); - } - - public void notifyFailure(BError bError) { - balFuture.complete(bError); - } -} diff --git a/native/src/main/java/io/ballerina/stdlib/graphql/runtime/engine/ArgumentHandler.java b/native/src/main/java/io/ballerina/stdlib/graphql/runtime/engine/ArgumentHandler.java index 9b8c2eaf6..730bb7252 100644 --- a/native/src/main/java/io/ballerina/stdlib/graphql/runtime/engine/ArgumentHandler.java +++ b/native/src/main/java/io/ballerina/stdlib/graphql/runtime/engine/ArgumentHandler.java @@ -51,7 +51,6 @@ import java.util.Arrays; import java.util.List; import java.util.Objects; -import java.util.concurrent.CompletableFuture; import static io.ballerina.runtime.api.types.TypeTags.INTERSECTION_TAG; import static io.ballerina.stdlib.graphql.runtime.engine.EngineUtils.ARGUMENTS_FIELD; @@ -540,16 +539,18 @@ private boolean isRepresentationArgument(Type type) { private void addConstraintValidationErrors(Environment environment, BArray errors) { environment.yieldAndRun(() -> { - CompletableFuture future = new CompletableFuture<>(); - ExecutionCallback executionCallback = new ExecutionCallback(future); BObject fieldNode = this.field.getObjectValue(INTERNAL_NODE); Object[] arguments = {errors, fieldNode}; try { - Object result = environment.getRuntime() - .callMethod(this.responseGenerator, ADD_CONSTRAINT_ERRORS_METHOD, null, arguments); - executionCallback.notifySuccess(result); + environment.getRuntime().callMethod(this.responseGenerator, ADD_CONSTRAINT_ERRORS_METHOD, null, + arguments); } catch (BError bError) { - executionCallback.notifyFailure(bError); + bError.printStackTrace(); + // Service level `panic` is captured in this method. + // Since, `panic` is due to a critical application bug or resource exhaustion we need to exit the + // application. + // Please refer: https://github.com/ballerina-platform/ballerina-standard-library/issues/2714 + System.exit(1); } return null; }); diff --git a/native/src/main/java/io/ballerina/stdlib/graphql/runtime/engine/DataLoader.java b/native/src/main/java/io/ballerina/stdlib/graphql/runtime/engine/DataLoader.java index b9dfd9764..d8449fe8c 100644 --- a/native/src/main/java/io/ballerina/stdlib/graphql/runtime/engine/DataLoader.java +++ b/native/src/main/java/io/ballerina/stdlib/graphql/runtime/engine/DataLoader.java @@ -23,10 +23,6 @@ import io.ballerina.runtime.api.values.BObject; import io.ballerina.runtime.api.values.BTypedesc; -import java.util.concurrent.CompletableFuture; - -import static io.ballerina.stdlib.graphql.runtime.utils.ModuleUtils.getResult; - /** * This class provides native implementations of the Ballerina DataLoader class. */ @@ -38,17 +34,18 @@ private DataLoader() { public static Object get(Environment env, BObject dataLoader, Object key, BTypedesc typedesc) { return env.yieldAndRun(() -> { - CompletableFuture balFuture = new CompletableFuture<>(); Object[] paramFeed = getProcessGetMethodParams(key, typedesc); - ExecutionCallback executionCallback = new ExecutionCallback(balFuture); try { - Object result = env.getRuntime().callMethod(dataLoader, DATA_LOADER_PROCESSES_GET_METHOD_NAME, null, - paramFeed); - executionCallback.notifySuccess(result); + return env.getRuntime().callMethod(dataLoader, DATA_LOADER_PROCESSES_GET_METHOD_NAME, null, paramFeed); } catch (BError bError) { - executionCallback.notifyFailure(bError); + bError.printStackTrace(); + // Service level `panic` is captured in this method. + // Since, `panic` is due to a critical application bug or resource exhaustion we need to exit the + // application. + // Please refer: https://github.com/ballerina-platform/ballerina-standard-library/issues/2714 + System.exit(1); } - return getResult(balFuture); + return null; }); } diff --git a/native/src/main/java/io/ballerina/stdlib/graphql/runtime/engine/Engine.java b/native/src/main/java/io/ballerina/stdlib/graphql/runtime/engine/Engine.java index a3873458f..91825245c 100644 --- a/native/src/main/java/io/ballerina/stdlib/graphql/runtime/engine/Engine.java +++ b/native/src/main/java/io/ballerina/stdlib/graphql/runtime/engine/Engine.java @@ -49,7 +49,6 @@ import java.util.Base64; import java.util.HashMap; import java.util.List; -import java.util.concurrent.CompletableFuture; import static io.ballerina.runtime.observability.ObservabilityConstants.KEY_OBSERVER_CONTEXT; import static io.ballerina.stdlib.graphql.commons.utils.TypeUtils.removeEscapeCharacter; @@ -64,7 +63,6 @@ import static io.ballerina.stdlib.graphql.runtime.engine.EngineUtils.SUBSCRIBE_ACCESSOR; import static io.ballerina.stdlib.graphql.runtime.engine.EngineUtils.isPathsMatching; import static io.ballerina.stdlib.graphql.runtime.utils.ModuleUtils.getModule; -import static io.ballerina.stdlib.graphql.runtime.utils.ModuleUtils.getResult; import static io.ballerina.stdlib.graphql.runtime.utils.Utils.ERROR_TYPE; import static io.ballerina.stdlib.graphql.runtime.utils.Utils.INTERNAL_NODE; import static io.ballerina.stdlib.graphql.runtime.utils.Utils.createError; @@ -133,16 +131,18 @@ private static Object getResultObject(Environment environment, BObject context, return null; } return environment.yieldAndRun(() -> { - CompletableFuture subscriptionFutureResult = new CompletableFuture<>(); - ExecutionCallback executionCallback = new ExecutionCallback(subscriptionFutureResult); Object[] args = argumentHandler.getArguments(); try { - Object result = callResourceMethod(environment.getRuntime(), service, methodName, args); - executionCallback.notifySuccess(result); + return callResourceMethod(environment.getRuntime(), service, methodName, args); } catch (BError bError) { - executionCallback.notifyFailure(bError); + bError.printStackTrace(); + // Service level `panic` is captured in this method. + // Since, `panic` is due to a critical application bug or resource exhaustion we need to exit the + // application. + // Please refer: https://github.com/ballerina-platform/ballerina-standard-library/issues/2714 + System.exit(1); } - return getResult(subscriptionFutureResult); + return null; }); } @@ -183,17 +183,18 @@ public static Object executeInterceptor(Environment environment, BObject interce return null; } return environment.yieldAndRun(() -> { - CompletableFuture future = new CompletableFuture<>(); - ExecutionCallback executionCallback = new ExecutionCallback(future); Object[] arguments = getInterceptorArguments(context, field); try { - Object result = callResourceMethod(environment.getRuntime(), interceptor, remoteMethod.getName(), - arguments); - executionCallback.notifySuccess(result); + return callResourceMethod(environment.getRuntime(), interceptor, remoteMethod.getName(), arguments); } catch (BError bError) { - executionCallback.notifyFailure(bError); + bError.printStackTrace(); + // Service level `panic` is captured in this method. + // Since, `panic` is due to a critical application bug or resource exhaustion we need to exit the + // application. + // Please refer: https://github.com/ballerina-platform/ballerina-standard-library/issues/2714 + System.exit(1); } - return getResult(future); + return null; }); } @@ -283,16 +284,17 @@ public static boolean hasPrefetchMethod(BObject serviceObject, BString prefetchM public static void executePrefetchMethod(Environment environment, BObject context, BObject service, MethodType resourceMethod, BObject fieldObject) { environment.yieldAndRun(() -> { - CompletableFuture future = new CompletableFuture<>(); - ExecutionCallback executionCallback = new ExecutionCallback(future); ArgumentHandler argumentHandler = new ArgumentHandler(resourceMethod, context, fieldObject, null, false); Object[] arguments = argumentHandler.getArguments(); try { - Object result = callResourceMethod(environment.getRuntime(), service, resourceMethod.getName(), - arguments); - executionCallback.notifySuccess(result); + return callResourceMethod(environment.getRuntime(), service, resourceMethod.getName(), arguments); } catch (BError bError) { - executionCallback.notifyFailure(bError); + bError.printStackTrace(); + // Service level `panic` is captured in this method. + // Since, `panic` is due to a critical application bug or resource exhaustion we need to exit the + // application. + // Please refer: https://github.com/ballerina-platform/ballerina-standard-library/issues/2714 + System.exit(1); } return null; }); diff --git a/native/src/main/java/io/ballerina/stdlib/graphql/runtime/engine/ExecutionCallback.java b/native/src/main/java/io/ballerina/stdlib/graphql/runtime/engine/ExecutionCallback.java deleted file mode 100644 index e71082abc..000000000 --- a/native/src/main/java/io/ballerina/stdlib/graphql/runtime/engine/ExecutionCallback.java +++ /dev/null @@ -1,46 +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. - */ - -package io.ballerina.stdlib.graphql.runtime.engine; - -import io.ballerina.runtime.api.values.BError; - -import java.util.concurrent.CompletableFuture; - -/** - * Callback class for executing Ballerina dependently type methods. - */ -public class ExecutionCallback { - private final CompletableFuture future; - - ExecutionCallback(CompletableFuture future) { - this.future = future; - } - - public void notifySuccess(Object o) { - this.future.complete(o); - } - - public void notifyFailure(BError bError) { - bError.printStackTrace(); - // Service level `panic` is captured in this method. - // Since, `panic` is due to a critical application bug or resource exhaustion we need to exit the application. - // Please refer: https://github.com/ballerina-platform/ballerina-standard-library/issues/2714 - System.exit(1); - } -} diff --git a/spotbugs-exclude.xml b/spotbugs-exclude.xml index df23d34d2..a1cdb9c35 100644 --- a/spotbugs-exclude.xml +++ b/spotbugs-exclude.xml @@ -20,13 +20,6 @@ - - - - - - - @@ -53,4 +46,9 @@ + + + + + From 539e3960e997bede930345073baad4b5043ca525 Mon Sep 17 00:00:00 2001 From: warunalakshitha Date: Tue, 10 Dec 2024 23:47:28 +0530 Subject: [PATCH 4/4] Add utils method for handle system exit --- .../runtime/engine/ArgumentHandler.java | 8 ++----- .../graphql/runtime/engine/DataLoader.java | 9 +++----- .../stdlib/graphql/runtime/engine/Engine.java | 22 ++++--------------- .../stdlib/graphql/runtime/utils/Utils.java | 9 ++++++++ spotbugs-exclude.xml | 2 ++ 5 files changed, 20 insertions(+), 30 deletions(-) diff --git a/native/src/main/java/io/ballerina/stdlib/graphql/runtime/engine/ArgumentHandler.java b/native/src/main/java/io/ballerina/stdlib/graphql/runtime/engine/ArgumentHandler.java index 730bb7252..492eb6af6 100644 --- a/native/src/main/java/io/ballerina/stdlib/graphql/runtime/engine/ArgumentHandler.java +++ b/native/src/main/java/io/ballerina/stdlib/graphql/runtime/engine/ArgumentHandler.java @@ -63,6 +63,7 @@ import static io.ballerina.stdlib.graphql.runtime.engine.EngineUtils.isEnum; import static io.ballerina.stdlib.graphql.runtime.engine.EngineUtils.isIgnoreType; import static io.ballerina.stdlib.graphql.runtime.utils.Utils.INTERNAL_NODE; +import static io.ballerina.stdlib.graphql.runtime.utils.Utils.handleBErrorAndExit; import static io.ballerina.stdlib.graphql.runtime.utils.Utils.isContext; import static io.ballerina.stdlib.graphql.runtime.utils.Utils.isField; import static io.ballerina.stdlib.graphql.runtime.utils.Utils.isFileUpload; @@ -545,12 +546,7 @@ private void addConstraintValidationErrors(Environment environment, BArray error environment.getRuntime().callMethod(this.responseGenerator, ADD_CONSTRAINT_ERRORS_METHOD, null, arguments); } catch (BError bError) { - bError.printStackTrace(); - // Service level `panic` is captured in this method. - // Since, `panic` is due to a critical application bug or resource exhaustion we need to exit the - // application. - // Please refer: https://github.com/ballerina-platform/ballerina-standard-library/issues/2714 - System.exit(1); + handleBErrorAndExit(bError); } return null; }); diff --git a/native/src/main/java/io/ballerina/stdlib/graphql/runtime/engine/DataLoader.java b/native/src/main/java/io/ballerina/stdlib/graphql/runtime/engine/DataLoader.java index d8449fe8c..44dcd9cd9 100644 --- a/native/src/main/java/io/ballerina/stdlib/graphql/runtime/engine/DataLoader.java +++ b/native/src/main/java/io/ballerina/stdlib/graphql/runtime/engine/DataLoader.java @@ -23,6 +23,8 @@ import io.ballerina.runtime.api.values.BObject; import io.ballerina.runtime.api.values.BTypedesc; +import static io.ballerina.stdlib.graphql.runtime.utils.Utils.handleBErrorAndExit; + /** * This class provides native implementations of the Ballerina DataLoader class. */ @@ -38,12 +40,7 @@ public static Object get(Environment env, BObject dataLoader, Object key, BTyped try { return env.getRuntime().callMethod(dataLoader, DATA_LOADER_PROCESSES_GET_METHOD_NAME, null, paramFeed); } catch (BError bError) { - bError.printStackTrace(); - // Service level `panic` is captured in this method. - // Since, `panic` is due to a critical application bug or resource exhaustion we need to exit the - // application. - // Please refer: https://github.com/ballerina-platform/ballerina-standard-library/issues/2714 - System.exit(1); + handleBErrorAndExit(bError); } return null; }); diff --git a/native/src/main/java/io/ballerina/stdlib/graphql/runtime/engine/Engine.java b/native/src/main/java/io/ballerina/stdlib/graphql/runtime/engine/Engine.java index 91825245c..b3684ac88 100644 --- a/native/src/main/java/io/ballerina/stdlib/graphql/runtime/engine/Engine.java +++ b/native/src/main/java/io/ballerina/stdlib/graphql/runtime/engine/Engine.java @@ -66,6 +66,7 @@ import static io.ballerina.stdlib.graphql.runtime.utils.Utils.ERROR_TYPE; import static io.ballerina.stdlib.graphql.runtime.utils.Utils.INTERNAL_NODE; import static io.ballerina.stdlib.graphql.runtime.utils.Utils.createError; +import static io.ballerina.stdlib.graphql.runtime.utils.Utils.handleBErrorAndExit; /** * This handles Ballerina GraphQL Engine. @@ -135,12 +136,7 @@ private static Object getResultObject(Environment environment, BObject context, try { return callResourceMethod(environment.getRuntime(), service, methodName, args); } catch (BError bError) { - bError.printStackTrace(); - // Service level `panic` is captured in this method. - // Since, `panic` is due to a critical application bug or resource exhaustion we need to exit the - // application. - // Please refer: https://github.com/ballerina-platform/ballerina-standard-library/issues/2714 - System.exit(1); + handleBErrorAndExit(bError); } return null; }); @@ -187,12 +183,7 @@ public static Object executeInterceptor(Environment environment, BObject interce try { return callResourceMethod(environment.getRuntime(), interceptor, remoteMethod.getName(), arguments); } catch (BError bError) { - bError.printStackTrace(); - // Service level `panic` is captured in this method. - // Since, `panic` is due to a critical application bug or resource exhaustion we need to exit the - // application. - // Please refer: https://github.com/ballerina-platform/ballerina-standard-library/issues/2714 - System.exit(1); + handleBErrorAndExit(bError); } return null; }); @@ -289,12 +280,7 @@ public static void executePrefetchMethod(Environment environment, BObject contex try { return callResourceMethod(environment.getRuntime(), service, resourceMethod.getName(), arguments); } catch (BError bError) { - bError.printStackTrace(); - // Service level `panic` is captured in this method. - // Since, `panic` is due to a critical application bug or resource exhaustion we need to exit the - // application. - // Please refer: https://github.com/ballerina-platform/ballerina-standard-library/issues/2714 - System.exit(1); + handleBErrorAndExit(bError); } return null; }); diff --git a/native/src/main/java/io/ballerina/stdlib/graphql/runtime/utils/Utils.java b/native/src/main/java/io/ballerina/stdlib/graphql/runtime/utils/Utils.java index fd368186d..c080c8a43 100644 --- a/native/src/main/java/io/ballerina/stdlib/graphql/runtime/utils/Utils.java +++ b/native/src/main/java/io/ballerina/stdlib/graphql/runtime/utils/Utils.java @@ -96,4 +96,13 @@ private static boolean hasExpectedModuleName(Type type, String expectedModuleNam public static BString getHashCode(BObject object) { return StringUtils.fromString(Integer.toString(object.hashCode())); } + + public static void handleBErrorAndExit(BError bError) { + bError.printStackTrace(); + // Service level `panic` is captured in this method. + // Since, `panic` is due to a critical application bug or resource exhaustion we need to exit the + // application. + // Please refer: https://github.com/ballerina-platform/ballerina-standard-library/issues/2714 + System.exit(1); + } } diff --git a/spotbugs-exclude.xml b/spotbugs-exclude.xml index a1cdb9c35..b04f5a9de 100644 --- a/spotbugs-exclude.xml +++ b/spotbugs-exclude.xml @@ -48,6 +48,8 @@ + +