You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@jena.apache.org by GitBox <gi...@apache.org> on 2022/06/23 09:56:36 UTC

[GitHub] [jena] afs opened a new pull request, #1402: GH-1400: Allow SERVICE QuerySendMode to be specified by a string

afs opened a new pull request, #1402:
URL: https://github.com/apache/jena/pull/1402

   GitHub issue resolved #1400
   
   Pull request Description:
   
   Let the SERVICE send mode be set using a string.
   
   ----
   
    - [x] Tests are included.
    - [ ] Documentation change and updates are provided for the [Apache Jena website](https://github.com/apache/jena-site/)
    - [x] Commits have been squashed to remove intermediate development commit messages.
    - [x] Key commit messages start with the issue number (GH-xxxx or JENA-xxxx)
   
   By submitting this pull request, I acknowledge that I am making a contribution to the Apache Software Foundation under the terms and conditions of the [Contributor's Agreement](https://www.apache.org/licenses/contributor-agreements.html).
   
   ----
   
   See the [Apache Jena "Contributing" guide](https://github.com/apache/jena/blob/main/CONTRIBUTING.md).
   


-- 
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: pr-unsubscribe@jena.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


[GitHub] [jena] afs commented on pull request #1402: GH-1400: Allow SERVICE QuerySendMode to be specified by a string

Posted by GitBox <gi...@apache.org>.
afs commented on PR #1402:
URL: https://github.com/apache/jena/pull/1402#issuecomment-1164219490

   FYI @Aklakan


-- 
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: pr-unsubscribe@jena.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


[GitHub] [jena] afs commented on pull request #1402: GH-1400: Allow SERVICE QuerySendMode to be specified by a string

Posted by GitBox <gi...@apache.org>.
afs commented on PR #1402:
URL: https://github.com/apache/jena/pull/1402#issuecomment-1165586283

   It reuses an existing context key.
   
   If you use `Service.java` then it will be honoured. If have a different execution code, you may want to implement the additional string value possibilities.


-- 
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: pr-unsubscribe@jena.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


[GitHub] [jena] afs merged pull request #1402: GH-1400: Allow SERVICE QuerySendMode to be specified by a string

Posted by GitBox <gi...@apache.org>.
afs merged PR #1402:
URL: https://github.com/apache/jena/pull/1402


-- 
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: pr-unsubscribe@jena.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


[GitHub] [jena] afs commented on a diff in pull request #1402: GH-1400: Allow SERVICE QuerySendMode to be specified by a string

Posted by GitBox <gi...@apache.org>.
afs commented on code in PR #1402:
URL: https://github.com/apache/jena/pull/1402#discussion_r904836874


##########
jena-integration-tests/src/test/java/org/apache/jena/sparql/exec/http/TestService2.java:
##########
@@ -0,0 +1,142 @@
+/**
+ * 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.jena.sparql.exec.http;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.jena.datatypes.xsd.XSDDatatype;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.NodeFactory ;
+import org.apache.jena.http.HttpEnv;
+import org.apache.jena.http.sys.HttpRequestModifier;
+import org.apache.jena.http.sys.RegistryRequestModifier;
+import org.apache.jena.query.ARQ;
+import org.apache.jena.query.QueryExecException;
+import org.apache.jena.sparql.ARQConstants;
+import org.apache.jena.sparql.core.DatasetGraph;
+import org.apache.jena.sparql.core.DatasetGraphZero;
+import org.apache.jena.sparql.exec.QueryExec;
+import org.apache.jena.sparql.exec.RowSet;
+import org.apache.jena.sparql.util.Context;
+import org.apache.jena.test.conn.EnvTest;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/** Most tests of SERVICE */
+public class TestService2 {
+
+    private static String SERVICE;
+    private static EnvTest env;
+    // Local dataset for execution of SERVICE. Can be used to carry a context.
+    private static final DatasetGraph localDataset() {return DatasetGraphZero.create(); }
+
+    @BeforeClass public static void beforeClass() {
+        // Also edit src/test/resources/log4j2.properties to get logging output.
+        // FusekiLogging.setLogging();
+        env = EnvTest.create("/ds");
+        SERVICE = env.datasetURL();
+    }
+
+    @Before public void before() {
+        env.clear();
+    }
+
+    @AfterClass public static void afterClass() {
+        EnvTest.stop(env);
+    }
+
+    @Test public void service_send_mode_1() { serviceSendMode(QuerySendMode.asGetAlways); }
+    @Test public void service_send_mode_2() {serviceSendMode(QuerySendMode.asGetWithLimitBody); }
+    @Test public void service_send_mode_3() { serviceSendMode(QuerySendMode.asGetWithLimitForm); }
+    @Test public void service_send_mode_4() { serviceSendMode(QuerySendMode.asPost); }
+    @Test public void service_send_mode_5() { serviceSendMode(QuerySendMode.asPostForm); }
+
+    @Test public void service_send_mode_str_1() { serviceSendMode("GET"); }
+    @Test public void service_send_mode_str_2() { serviceSendMode("POST"); }
+
+    @Test(expected=QueryExecException.class)
+    public void service_send_mode_str_3() { serviceSendMode("JUNK"); }
+
+    @Test(expected=QueryExecException.class)
+    public void service_send_mode_str_4() { serviceSendMode(""); }
+
+    @Test public void service_send_mode_str_10() { serviceSendMode(QuerySendMode.asGetAlways.name()); }
+    @Test public void service_send_mode_str_11() { serviceSendMode(QuerySendMode.asGetWithLimitBody.name()); }
+    @Test public void service_send_mode_str_12() { serviceSendMode(QuerySendMode.asGetWithLimitForm.name()); }
+    @Test public void service_send_mode_str_13() { serviceSendMode(QuerySendMode.asPost.name()); }
+    @Test public void service_send_mode_str_14() { serviceSendMode(QuerySendMode.asPostForm.name()); }
+
+    @Test public void service_send_mode_withLimit_1() { serviceSendModeWithLimit(QuerySendMode.asGetAlways, 10); }
+    @Test public void service_send_mode_withLimit_2() { serviceSendModeWithLimit(QuerySendMode.asGetWithLimitBody, 10); }
+    @Test public void service_send_mode_withLimit_3() { serviceSendModeWithLimit(QuerySendMode.asGetWithLimitForm, 10); }
+    @Test public void service_send_mode_withLimit_4() { serviceSendModeWithLimit(QuerySendMode.asPost, 10); }
+    @Test public void service_send_mode_withLimit_5() { serviceSendModeWithLimit(QuerySendMode.asPostForm, 10); }
+
+    private void serviceSendMode(QuerySendMode sendMode) {
+        serviceSendModeWithLimit(sendMode, -1);
+    }
+
+    private void serviceSendMode(String sendMode) {
+        Node expected = NodeFactory.createLiteral("28181", XSDDatatype.XSDinteger);
+        String queryString = "SELECT * { SERVICE <"+SERVICE+"> { VALUES ?x { 28181 } } }";
+
+        Context cxt = new Context();
+        // Until GH-1399 is fixed, theer must be a setting for registryServiceExecutors
+        cxt.set(ARQConstants.registryServiceExecutors, ARQ.getContext().get(ARQConstants.registryServiceExecutors));
+        cxt.set(Service.httpServiceSendMode, sendMode);
+        RowSet rs = QueryExec.dataset(localDataset()).query(queryString).context(cxt).select().materialize();
+        assertTrue(rs.hasNext());
+        Node n = rs.next().get("x");
+        assertEquals(expected, n);
+    }
+
+    private void serviceSendModeWithLimit(QuerySendMode sendMode, int urlLimit) {
+        int systemValue = HttpEnv.urlLimit;
+        try {
+            if ( urlLimit > 0 )
+                HttpEnv.urlLimit = urlLimit;
+            Context cxt = new Context();
+            cxt.set(Service.httpServiceSendMode, sendMode);
+            serviceSendMode_runTest(cxt);
+        } finally {
+            HttpEnv.urlLimit = systemValue;
+        }
+    }
+
+    private void serviceSendMode_runTest(Context cxt) {
+        Node expected = NodeFactory.createLiteral("28181", XSDDatatype.XSDinteger);
+        String queryString = "SELECT * { SERVICE <"+SERVICE+"> { VALUES ?x { 28181 } } }";
+        RowSet rs = QueryExec.dataset(localDataset()).query(queryString).select().materialize();
+        assertTrue(rs.hasNext());
+        Node n = rs.next().get("x");
+        assertEquals(expected, n);
+    }
+
+    private static void runWithModifier(String key, HttpRequestModifier modifier, Runnable action) {
+        RegistryRequestModifier.get().add(SERVICE, modifier);
+        try {
+            action.run();
+        } finally {
+            RegistryRequestModifier.get().remove(SERVICE);
+        }
+    }
+}

Review Comment:
   Done - and the file it was cloned from.



-- 
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: pr-unsubscribe@jena.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


[GitHub] [jena] kinow commented on a diff in pull request #1402: GH-1400: Allow SERVICE QuerySendMode to be specified by a string

Posted by GitBox <gi...@apache.org>.
kinow commented on code in PR #1402:
URL: https://github.com/apache/jena/pull/1402#discussion_r904834110


##########
jena-integration-tests/src/test/java/org/apache/jena/sparql/exec/http/TestService2.java:
##########
@@ -0,0 +1,142 @@
+/**
+ * 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.jena.sparql.exec.http;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.jena.datatypes.xsd.XSDDatatype;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.NodeFactory ;
+import org.apache.jena.http.HttpEnv;
+import org.apache.jena.http.sys.HttpRequestModifier;
+import org.apache.jena.http.sys.RegistryRequestModifier;
+import org.apache.jena.query.ARQ;
+import org.apache.jena.query.QueryExecException;
+import org.apache.jena.sparql.ARQConstants;
+import org.apache.jena.sparql.core.DatasetGraph;
+import org.apache.jena.sparql.core.DatasetGraphZero;
+import org.apache.jena.sparql.exec.QueryExec;
+import org.apache.jena.sparql.exec.RowSet;
+import org.apache.jena.sparql.util.Context;
+import org.apache.jena.test.conn.EnvTest;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/** Most tests of SERVICE */
+public class TestService2 {
+
+    private static String SERVICE;
+    private static EnvTest env;
+    // Local dataset for execution of SERVICE. Can be used to carry a context.
+    private static final DatasetGraph localDataset() {return DatasetGraphZero.create(); }
+
+    @BeforeClass public static void beforeClass() {
+        // Also edit src/test/resources/log4j2.properties to get logging output.
+        // FusekiLogging.setLogging();
+        env = EnvTest.create("/ds");
+        SERVICE = env.datasetURL();
+    }
+
+    @Before public void before() {
+        env.clear();
+    }
+
+    @AfterClass public static void afterClass() {
+        EnvTest.stop(env);
+    }
+
+    @Test public void service_send_mode_1() { serviceSendMode(QuerySendMode.asGetAlways); }
+    @Test public void service_send_mode_2() {serviceSendMode(QuerySendMode.asGetWithLimitBody); }
+    @Test public void service_send_mode_3() { serviceSendMode(QuerySendMode.asGetWithLimitForm); }
+    @Test public void service_send_mode_4() { serviceSendMode(QuerySendMode.asPost); }
+    @Test public void service_send_mode_5() { serviceSendMode(QuerySendMode.asPostForm); }
+
+    @Test public void service_send_mode_str_1() { serviceSendMode("GET"); }
+    @Test public void service_send_mode_str_2() { serviceSendMode("POST"); }
+
+    @Test(expected=QueryExecException.class)
+    public void service_send_mode_str_3() { serviceSendMode("JUNK"); }
+
+    @Test(expected=QueryExecException.class)
+    public void service_send_mode_str_4() { serviceSendMode(""); }
+
+    @Test public void service_send_mode_str_10() { serviceSendMode(QuerySendMode.asGetAlways.name()); }
+    @Test public void service_send_mode_str_11() { serviceSendMode(QuerySendMode.asGetWithLimitBody.name()); }
+    @Test public void service_send_mode_str_12() { serviceSendMode(QuerySendMode.asGetWithLimitForm.name()); }
+    @Test public void service_send_mode_str_13() { serviceSendMode(QuerySendMode.asPost.name()); }
+    @Test public void service_send_mode_str_14() { serviceSendMode(QuerySendMode.asPostForm.name()); }
+
+    @Test public void service_send_mode_withLimit_1() { serviceSendModeWithLimit(QuerySendMode.asGetAlways, 10); }
+    @Test public void service_send_mode_withLimit_2() { serviceSendModeWithLimit(QuerySendMode.asGetWithLimitBody, 10); }
+    @Test public void service_send_mode_withLimit_3() { serviceSendModeWithLimit(QuerySendMode.asGetWithLimitForm, 10); }
+    @Test public void service_send_mode_withLimit_4() { serviceSendModeWithLimit(QuerySendMode.asPost, 10); }
+    @Test public void service_send_mode_withLimit_5() { serviceSendModeWithLimit(QuerySendMode.asPostForm, 10); }
+
+    private void serviceSendMode(QuerySendMode sendMode) {
+        serviceSendModeWithLimit(sendMode, -1);
+    }
+
+    private void serviceSendMode(String sendMode) {
+        Node expected = NodeFactory.createLiteral("28181", XSDDatatype.XSDinteger);
+        String queryString = "SELECT * { SERVICE <"+SERVICE+"> { VALUES ?x { 28181 } } }";
+
+        Context cxt = new Context();
+        // Until GH-1399 is fixed, theer must be a setting for registryServiceExecutors
+        cxt.set(ARQConstants.registryServiceExecutors, ARQ.getContext().get(ARQConstants.registryServiceExecutors));
+        cxt.set(Service.httpServiceSendMode, sendMode);
+        RowSet rs = QueryExec.dataset(localDataset()).query(queryString).context(cxt).select().materialize();
+        assertTrue(rs.hasNext());
+        Node n = rs.next().get("x");
+        assertEquals(expected, n);
+    }
+
+    private void serviceSendModeWithLimit(QuerySendMode sendMode, int urlLimit) {
+        int systemValue = HttpEnv.urlLimit;
+        try {
+            if ( urlLimit > 0 )
+                HttpEnv.urlLimit = urlLimit;
+            Context cxt = new Context();
+            cxt.set(Service.httpServiceSendMode, sendMode);
+            serviceSendMode_runTest(cxt);
+        } finally {
+            HttpEnv.urlLimit = systemValue;
+        }
+    }
+
+    private void serviceSendMode_runTest(Context cxt) {
+        Node expected = NodeFactory.createLiteral("28181", XSDDatatype.XSDinteger);
+        String queryString = "SELECT * { SERVICE <"+SERVICE+"> { VALUES ?x { 28181 } } }";
+        RowSet rs = QueryExec.dataset(localDataset()).query(queryString).select().materialize();
+        assertTrue(rs.hasNext());
+        Node n = rs.next().get("x");
+        assertEquals(expected, n);
+    }
+
+    private static void runWithModifier(String key, HttpRequestModifier modifier, Runnable action) {
+        RegistryRequestModifier.get().add(SERVICE, modifier);
+        try {
+            action.run();
+        } finally {
+            RegistryRequestModifier.get().remove(SERVICE);
+        }
+    }
+}

Review Comment:
   Missing newline :grimacing: 



-- 
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: pr-unsubscribe@jena.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


[GitHub] [jena] Aklakan commented on pull request #1402: GH-1400: Allow SERVICE QuerySendMode to be specified by a string

Posted by GitBox <gi...@apache.org>.
Aklakan commented on PR #1402:
URL: https://github.com/apache/jena/pull/1402#issuecomment-1165485611

   > FYI @Aklakan
   
   At first glance this only adds a context attribute and should thus not conflict with my work as I just pass the context along.


-- 
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: pr-unsubscribe@jena.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org