tyge68 commented on code in PR #48:
URL: 
https://github.com/apache/sling-org-apache-sling-graphql-core/pull/48#discussion_r4181909294


##########
src/test/java/org/apache/sling/graphql/core/engine/MissingFetcherFallbackTest.java:
##########
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF 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 org.apache.sling.graphql.core.engine;
+
+import org.apache.sling.graphql.core.mocks.EchoDataFetcher;
+import org.apache.sling.graphql.core.mocks.TestUtil;
+import org.junit.Test;
+
+import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+
+/**
+ * A field annotated with a fetcher that is not registered must still read the
+ * matching source property, as graphql-java did when no DataFetcher was wired.
+ */
+public class MissingFetcherFallbackTest extends ResourceQueryTestBase {
+
+    @Override
+    protected String getTestSchemaName() {
+        return "missing-fetcher-schema";
+    }
+
+    @Override
+    protected void setupAdditionalServices() {
+        TestUtil.registerSlingDataFetcher(context.bundleContext(), 
"echoNS/echo", new EchoDataFetcher(null));
+    }
+
+    @Test
+    public void missingFetcherFallsBackToResourceProperty() throws Exception {
+        final String json = queryJSON("{ currentResource { path resourceType } 
}");

Review Comment:
   **Non-blocking: explicitly cover the cache-disabled fallback path.** This 
class inherits `ResourceQueryTestBase.getQueryExecutorProperties()`, which 
returns `null`, so activation uses the new `executableSchemaCacheEnabled=true` 
default. Consequently, this test and `MissingFetcherFallbackCachedTest` both 
exercise the enabled path rather than providing enabled/disabled counterparts. 
Consider overriding the properties here to set 
`executableSchemaCacheEnabled=false`; the cached subclass already overrides 
them to `true`. That would directly protect the documented opt-out behavior as 
well as the cached fallback.



##########
src/test/java/org/apache/sling/graphql/core/engine/ExecutableSchemaCacheExecuteTest.java:
##########
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF 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 org.apache.sling.graphql.core.engine;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.graphql.api.engine.QueryExecutor;
+import org.apache.sling.graphql.core.mocks.EchoDataFetcher;
+import org.apache.sling.graphql.core.mocks.TestUtil;
+import org.junit.Test;
+
+import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.not;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/**
+ * End-to-end execute() coverage with the executable schema cache enabled,
+ * verifying GraphQLContext Resource isolation across distinct request 
resources.
+ */
+public class ExecutableSchemaCacheExecuteTest extends ResourceQueryTestBase {
+
+    @Override
+    protected Map<String, Object> getQueryExecutorProperties() {
+        Map<String, Object> props = new HashMap<>();
+        props.put("executableSchemaCacheEnabled", true);
+        props.put("schemaCacheSize", 32);
+        return props;
+    }
+
+    @Override
+    protected void setupAdditionalServices() {
+        TestUtil.registerSlingDataFetcher(context.bundleContext(), 
"echoNS/echo", new EchoDataFetcher(null));
+    }
+
+    @Test
+    public void cachedSchemaUsesPerRequestResource() {
+        final QueryExecutor queryExecutor = 
context.getService(QueryExecutor.class);
+        assertNotNull(queryExecutor);
+
+        Resource resourceA = mockResource("/content/a-" + UUID.randomUUID(), 
"type/a");
+        Resource resourceB = mockResource("/content/b-" + UUID.randomUUID(), 
"type/b");
+
+        final String query = "{ currentResource { path resourceType } }";
+        Map<String, Object> resultA =
+                queryExecutor.execute(query, java.util.Collections.emptyMap(), 
resourceA, new String[] {});
+        Map<String, Object> resultB =
+                queryExecutor.execute(query, java.util.Collections.emptyMap(), 
resourceB, new String[] {});

Review Comment:
   **Non-blocking: add an overlapping-request isolation case.** These 
executions are sequential, while the contention test exercises schema 
construction rather than `execute()` with different Resources. A 
latch/barrier-backed fetcher could keep A and B in flight simultaneously after 
warming the shared schema, then assert that each fetcher's 
`getCurrentResource()` still refers to its own request. Including a resolver in 
that scenario would cover the other wrapper changed here. This would guard 
against request state accidentally becoming shared later; I did not observe 
such leakage in the current implementation.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to