diff --git a/src/org/gcube/informationsystem/collector/stubs/testsuite/ParallelXQueryExecuteTester.java b/src/org/gcube/informationsystem/collector/stubs/testsuite/ParallelXQueryExecuteTester.java new file mode 100644 index 0000000..bb4b0f9 --- /dev/null +++ b/src/org/gcube/informationsystem/collector/stubs/testsuite/ParallelXQueryExecuteTester.java @@ -0,0 +1,114 @@ +package org.gcube.informationsystem.collector.stubs.testsuite; + + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.net.URL; +import java.rmi.RemoteException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.gcube.common.core.contexts.GCUBERemotePortTypeContext; +import org.gcube.common.core.scope.GCUBEScope; +import org.gcube.common.core.utils.logging.GCUBEClientLog; +import org.gcube.informationsystem.collector.stubs.XQueryAccessPortType; +import org.gcube.informationsystem.collector.stubs.XQueryExecuteRequest; +import org.gcube.informationsystem.collector.stubs.XQueryExecuteResponse; +import org.gcube.informationsystem.collector.stubs.XQueryFaultType; +import org.gcube.informationsystem.collector.stubs.service.XQueryAccessServiceLocator; + +/** + * Tester for XQueryExecute operation of the gcube/informationsystem/collector/XQueryAccess portType + * + * @author Manuele Simi (ISTI-CNR) + * + */ +public class ParallelXQueryExecuteTester { + + + private static GCUBEClientLog logger = new GCUBEClientLog(ParallelXQueryExecuteTester.class); + /** + * @param args + *
    + *
  1. IC host + *
  2. IC port + *
  3. Caller Scope + *
  4. File including the XQuery to submit + *
+ */ + public static void main(String[] args) { + + if (args.length != 5) { + logger.fatal("Usage: XQueryExecuteTester " ); + return; + } + String portTypeURI = "http://"+args[0]+":"+ args[1]+"/wsrf/services/gcube/informationsystem/collector/XQueryAccess"; + + XQueryAccessPortType tempPort = null; + try { + tempPort = new XQueryAccessServiceLocator().getXQueryAccessPortTypePort(new URL(portTypeURI)); + tempPort = GCUBERemotePortTypeContext.getProxy(tempPort, GCUBEScope.getScope(args[2])); + } catch (Exception e) { + logger.error("",e); + } + final XQueryAccessPortType port = tempPort; + final String queryFile = args[3]; + final String scopeName = args[2]; + for (int i=1; i <= Integer.valueOf(args[4]); i++) { + new Thread() { + + /* (non-Javadoc) + * @see java.lang.Thread#run() + */ + @Override + public void run() { + XQueryExecuteRequest request = new XQueryExecuteRequest(); + request.setXQueryExpression(readQuery(queryFile)); + try { + logger.info(this.getId() + ": Submitting query in scope " + GCUBEScope.getScope(scopeName).getName() + "...."); + XQueryExecuteResponse response = port.XQueryExecute(request); + logger.info(this.getId() + ": Number of returned records: " + response.getSize()); + logger.info(this.getId() + ": Received dataset: \n" + response.getDataset()); + + Pattern p = Pattern.compile("(.*?)", Pattern.DOTALL); + Matcher m = p.matcher(response.getDataset()); + while (m.find()) { + logger.debug(m.group(1)); + } + + } catch (XQueryFaultType e) { + logger.error("XQuery Fault Error received", e); + } catch (RemoteException e) { + logger.error(e); + } + } + + }.start(); + + } + } + + private static String readQuery(final String filename) { + String queryString = null; + try { + BufferedReader input = new BufferedReader(new FileReader(filename)); + StringBuilder contents = new StringBuilder(); + String line; + while (( line = input.readLine()) != null){ + contents.append(line); + contents.append(System.getProperty("line.separator")); + } + input.close(); + queryString = contents.toString(); + } catch (FileNotFoundException e1) { + logger.fatal("invalid file: " + filename); + } catch (IOException e) { + logger.fatal("an error occurred when reading " + filename); + } + return queryString; + + } + +} diff --git a/test-suite/executeParallelQuery.sh b/test-suite/executeParallelQuery.sh new file mode 100644 index 0000000..845230e --- /dev/null +++ b/test-suite/executeParallelQuery.sh @@ -0,0 +1 @@ +java -cp .:./lib/org.gcube.informationsystem.collector.testsuite.jar:$CLASSPATH org/gcube/informationsystem/collector/stubs/testsuite/ParallelXQueryExecuteTester $1 $2 $3 $4 $5 diff --git a/test-suite/executeQuery.sh b/test-suite/executeQuery.sh new file mode 100755 index 0000000..7e2b050 --- /dev/null +++ b/test-suite/executeQuery.sh @@ -0,0 +1 @@ +java -cp .:./lib/org.gcube.informationsystem.collector.testsuite.jar:$CLASSPATH org/gcube/informationsystem/collector/stubs/testsuite/XQueryExecuteTester $1 $2 $3 $4 diff --git a/test-suite/samples/xquery.xml b/test-suite/samples/xquery.xml new file mode 100644 index 0000000..09043fc --- /dev/null +++ b/test-suite/samples/xquery.xml @@ -0,0 +1,6 @@ +declare namespace is = 'http://gcube-system.org/namespaces/informationsystem/registry'; +declare namespace gc = 'http://gcube-system.org/namespaces/common/core/porttypes/GCUBEProvider'; + for $entry0ValueAuth in collection("/db/Profiles/GHN")//Document/Data/is:Profile/Resource/Scopes/Scope + let $result := $entry0ValueAuth/../.. where ($entry0ValueAuth/string() eq '/d4science.research-infrastructures.eu/Ecosystem/gMan' or $entry0ValueAuth/string() eq +'/d4science.research-infrastructures.eu/Ecosystem') + return $result diff --git a/test-suite/samples/xquery2.xml b/test-suite/samples/xquery2.xml new file mode 100644 index 0000000..6ff1374 --- /dev/null +++ b/test-suite/samples/xquery2.xml @@ -0,0 +1,6 @@ +declare namespace is = 'http://gcube-system.org/namespaces/informationsystem/registry'; + for $entry0ValueAuth in collection("/db/Profiles/Service")//Document/Data/is:Profile/Resource/Scopes/Scope + let $result := $entry0ValueAuth/../.. + +return $result + diff --git a/test-suite/samples/xquery3.xml b/test-suite/samples/xquery3.xml new file mode 100644 index 0000000..99894ff --- /dev/null +++ b/test-suite/samples/xquery3.xml @@ -0,0 +1,5 @@ +declare namespace is = 'http://gcube-system.org/namespaces/informationsystem/registry'; +declare namespace gc = 'http://gcube-system.org/namespaces/common/core/porttypes/GCUBEProvider'; + for $entry0ValueAuth in collection("/db/Profiles/GHN")//Document/Data/is:Profile/Resource/Scopes/Scope + let $result := $entry0ValueAuth/../.. where ($result/ghnID/text()/string() eq "ad9cad70-3379-11df-b053-8612d6b1a894") + return $result