Skip to content

Commit 32cd624

Browse files
committed
HPCC4J-618 WIP Add WsECL testsuite
- Adds WsECL test suite - Adds published query setup logic - Adds simple ECL query file - Adds wsdl, xsd, req, resp request logic - Changes Utils.connection to allow post init changs of conn Signed-off-by: Rodrigo Pastrana <[email protected]>
1 parent 09a4e20 commit 32cd624

File tree

5 files changed

+231
-13
lines changed

5 files changed

+231
-13
lines changed

wsclient/src/main/java/org/hpccsystems/ws/client/utils/Connection.java

+18-3
Original file line numberDiff line numberDiff line change
@@ -486,12 +486,27 @@ private void setProtocol(String protocol_)
486486
* @param port_
487487
* the new port
488488
*/
489-
private void setPort(String port_)
489+
public void setPort(String port_)
490490
{
491-
if (port_ != null && port_.length() > 0)
491+
boolean hasChanged = false;
492+
493+
if (port_ != null && !port_.isEmpty())
494+
{
495+
if (port != null && !port.equals(port_))
496+
hasChanged = true;
497+
492498
port = port_;
499+
}
493500
else
501+
{
502+
if (port != null && !port.isEmpty())
503+
hasChanged = true;
504+
494505
port = "";
506+
}
507+
508+
if(baseUrl != null && !baseUrl.isEmpty() && hasChanged)
509+
constructUrl();
495510
}
496511

497512
/**
@@ -516,7 +531,7 @@ private void setURIPath(String path)
516531
/**
517532
* Construct url.
518533
*/
519-
private void constructUrl()
534+
public void constructUrl()
520535
{
521536
baseUrl = new StringBuffer();
522537
baseUrl.append(protocol).append(protDelimiter);

wsclient/src/test/java/org/hpccsystems/ws/client/BaseRemoteTest.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public abstract class BaseRemoteTest
6161
protected static String roxieClusterGroup = System.getProperty("roxiegroupname");
6262
protected final static String roxieclustername = System.getProperty("roxieclustername", "roxie");
6363

64-
protected final static String defaultUserName = "JunitUser";
64+
protected final static String defaultUserName = "Junit@User";
6565
protected static Connection connection = null;
6666

6767
protected final static String hpccUser = System.getProperty("hpccuser", defaultUserName);
@@ -269,15 +269,15 @@ public boolean verify(String hostname,javax.net.ssl.SSLSession sslSession)
269269
throw new Exception("Could not acquire wsclient object");
270270

271271
// Run the generate-datasets.ecl script if present in the project resources
272-
try
273-
{
274-
executeECLScript("generate-datasets.ecl");
275-
}
276-
catch (Exception e)
277-
{
278-
e.printStackTrace();
279-
throw new Exception("Error executing test data generation scripts with error: " + e.getMessage());
280-
}
272+
//try
273+
//{
274+
// executeECLScript("generate-datasets.ecl");
275+
//}
276+
//catch (Exception e)
277+
//{
278+
// e.printStackTrace();
279+
// throw new Exception("Error executing test data generation scripts with error: " + e.getMessage());
280+
//}
281281
}
282282

283283
public static String executeECLScript(String eclFile) throws Exception
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
/*##############################################################################
2+
3+
HPCC SYSTEMS software Copyright (C) 2024 HPCC Systems®.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
############################################################################## */
17+
18+
package org.hpccsystems.ws.client;
19+
20+
import static org.junit.Assume.assumeTrue;
21+
22+
import java.io.ByteArrayOutputStream;
23+
import java.io.InputStream;
24+
import java.util.List;
25+
26+
import org.hpccsystems.ws.client.utils.Connection;
27+
import org.hpccsystems.ws.client.wrappers.gen.wsworkunits.WUPublishWorkunitResponseWrapper;
28+
import org.hpccsystems.ws.client.wrappers.wsworkunits.QueryResultWrapper;
29+
import org.hpccsystems.ws.client.wrappers.wsworkunits.WorkunitWrapper;
30+
import org.junit.Assert;
31+
import org.junit.BeforeClass;
32+
import org.junit.FixMethodOrder;
33+
import org.junit.Test;
34+
import org.junit.runners.MethodSorters;
35+
36+
public class WSECLTests extends BaseRemoteTest
37+
{
38+
private static HPCCWsWorkUnitsClient wswuclient = null;
39+
private static boolean hasPublishedQuery = false;
40+
private final static String wsECLPort = System.getProperty("wseclport", "8002");
41+
private final static String eclScriptName = "SimpleFunction.ecl";
42+
private static Connection wseclConn = null;
43+
44+
@BeforeClass
45+
public static void setup() throws Exception
46+
{
47+
wswuclient = wsclient.getWsWorkunitsClient(); //for publishing queries
48+
Assert.assertNotNull(wswuclient);
49+
50+
try
51+
{
52+
InputStream resourceStream = BaseRemoteTest.class.getClassLoader().getResourceAsStream(eclScriptName);
53+
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
54+
55+
byte[] buffer = new byte[4096];
56+
int bytesRead = resourceStream.read(buffer);
57+
while (bytesRead > -1) {
58+
byteArrayOutputStream.write(buffer, 0, bytesRead);
59+
bytesRead = resourceStream.read(buffer);
60+
}
61+
62+
byte[] eclData = byteArrayOutputStream.toByteArray();
63+
String ecl = new String(eclData, "UTF-8");
64+
65+
WorkunitWrapper wu = new WorkunitWrapper();
66+
wu.setECL(ecl);
67+
wu.setJobname(eclScriptName);
68+
wu.setCluster(thorclustername);
69+
70+
//wswuclient.createAndRunWUFromECLAndGetResults(wu);
71+
WUPublishWorkunitResponseWrapper resp = wswuclient.publishWUFromEclWrapped(wu);
72+
System.out.println("Finished publishing query" + resp.toString());
73+
List<QueryResultWrapper> queries = wswuclient.listQueries(wu.getWuid(), wu.getJobname(), wu.getCluster(), null, null, null, null, null, null);
74+
for (QueryResultWrapper query : queries)
75+
{
76+
if (query.getName().equalsIgnoreCase(eclScriptName))
77+
{
78+
hasPublishedQuery = true;
79+
return;
80+
}
81+
}
82+
}
83+
catch (Exception e)
84+
{
85+
System.out.println("Could not publish ECL query: " + e.getLocalizedMessage());
86+
}
87+
88+
wseclConn = wsclient.getConnection();
89+
wseclConn.setPort(wsECLPort);
90+
wseclConn.setSocketTimeoutMilli(15000);
91+
wseclConn.setWriteTimeoutMilli(15000);
92+
}
93+
94+
@Test
95+
public void testWsECLGetWSDL()
96+
{
97+
assumeTrue("WsECL connection not available", wseclConn != null);
98+
assumeTrue("WsECL connection port appears invalid", wseclConn.getPort().equals(wsECLPort));
99+
assumeTrue("Cannot test WsECL published query WSDL feature without published queries!", hasPublishedQuery);
100+
101+
try
102+
{
103+
String wsdlURI = "/WsEcl/definitions/query/" + thorclustername + "/" + eclScriptName + "/main/" + eclScriptName + ".wsdl";
104+
105+
String wsdlResponse = wseclConn.sendGetRequest(wsdlURI);
106+
Assert.assertNotNull("Unexpected Null response", wsdlResponse);
107+
//TODO determine good way to confirm success/failure
108+
//Assert.assertArrayEquals(expectedWsdlResponse, wsdlResponse)
109+
}
110+
catch (Exception e)
111+
{
112+
Assert.fail("Could not fetch WsECL query wsdl: " + e.getLocalizedMessage());
113+
}
114+
}
115+
116+
@Test
117+
public void testWsECLGetSampleReq()
118+
{
119+
assumeTrue("WsECL connection not available", wseclConn != null);
120+
assumeTrue("WsECL connection port appears invalid", wseclConn.getPort().equals(wsECLPort));
121+
assumeTrue("Cannot test WsECL published query WSDL feature without published queries!", hasPublishedQuery);
122+
123+
try
124+
{
125+
//http://127.0.0.1:8002/WsEcl/example/request/query/<roxie>/<query>
126+
String sampleReqURI = "/WsEcl/example/request/query" + thorclustername + "/" + eclScriptName;
127+
String sampleReqResponse = wseclConn.sendGetRequest(sampleReqURI);
128+
Assert.assertNotNull("Unexpected Null response", sampleReqResponse);
129+
//TODO determine good way to confirm success/failure
130+
//Assert.assertArrayEquals(expectedWsdlResponse, wsdlResponse)
131+
}
132+
catch (Exception e)
133+
{
134+
Assert.fail("Could not fetch WsECL query wsdl: " + e.getLocalizedMessage());
135+
}
136+
}
137+
138+
@Test
139+
public void testWsECLGetSampleResp()
140+
{
141+
assumeTrue("WsECL connection not available", wseclConn != null);
142+
assumeTrue("WsECL connection port appears invalid", wseclConn.getPort().equals(wsECLPort));
143+
assumeTrue("Cannot test WsECL published query WSDL feature without published queries!", hasPublishedQuery);
144+
145+
try
146+
{
147+
//http://127.0.0.1:8002/WsEcl/example/response/query/<roxie>/<query>
148+
String sampleRespURI = "/WsEcl/example/response/query" + thorclustername + "/" + eclScriptName;
149+
String sampleRespResponse = wseclConn.sendGetRequest(sampleRespURI);
150+
Assert.assertNotNull("Unexpected Null response", sampleRespResponse);
151+
//TODO determine good way to confirm success/failure
152+
//Assert.assertArrayEquals(expectedWsdlResponse, wsdlResponse)
153+
}
154+
catch (Exception e)
155+
{
156+
Assert.fail("Could not fetch WsECL query wsdl: " + e.getLocalizedMessage());
157+
}
158+
}
159+
160+
@Test
161+
public void testWsECLGetSchema()
162+
{
163+
assumeTrue("WsECL connection not available", wseclConn != null);
164+
assumeTrue("WsECL connection port appears invalid", wseclConn.getPort().equals(wsECLPort));
165+
assumeTrue("Cannot test WsECL published query WSDL feature without published queries!", hasPublishedQuery);
166+
167+
try
168+
{
169+
String xsdURI = "/WsEcl/definitions/query/" + thorclustername + "/" + eclScriptName + "/main/" + eclScriptName + ".xsd";
170+
String xsdResponse = wseclConn.sendGetRequest(xsdURI);
171+
Assert.assertNotNull("Unexpected Null response", xsdResponse);
172+
//TODO determine good way to confirm success/failure
173+
//Assert.assertArrayEquals(expectedWsdlResponse, wsdlResponse)
174+
}
175+
catch (Exception e)
176+
{
177+
Assert.fail("Could not fetch WsECL query xsd: " + e.getLocalizedMessage());
178+
}
179+
}
180+
181+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import $.esdl_example;
2+
request := dataset([], esdl_example.t_RoxieEchoPersonInfoRequest) : stored('RoxieEchoPersonInfoRequest', few);
3+
output(request, named('RoxieEchoPersonInfoResponse'));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
MyFunc(STRING DataIn, STRING1 SearchChar) := FUNCTION
2+
3+
StrLen := LENGTH(TRIM(dataIn));
4+
ds := DATASET([{DataIn}], {STRING chars});
5+
6+
OutRec := RECORD
7+
UNSIGNED1 flag;
8+
END;
9+
10+
OutRec Xform(ds L, INTEGER C) := TRANSFORM
11+
SELF.flag := IF(L.chars[C] = SearchChar, 1, 0);
12+
END;
13+
14+
n := NORMALIZE(ds, StrLen, Xform(LEFT, COUNTER));
15+
16+
RETURN COUNT(n(flag=1));
17+
END;
18+
19+
OUTPUT(MyFunc('abc~xyz~def~fred', '~'));

0 commit comments

Comments
 (0)