Skip to content

Commit

Permalink
HPCC4J-618 WIP Add WsECL testsuite
Browse files Browse the repository at this point in the history
- 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]>
  • Loading branch information
rpastrana committed Jun 28, 2024
1 parent 09a4e20 commit 32cd624
Show file tree
Hide file tree
Showing 5 changed files with 231 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -486,12 +486,27 @@ private void setProtocol(String protocol_)
* @param port_
* the new port
*/
private void setPort(String port_)
public void setPort(String port_)
{
if (port_ != null && port_.length() > 0)
boolean hasChanged = false;

if (port_ != null && !port_.isEmpty())
{
if (port != null && !port.equals(port_))
hasChanged = true;

port = port_;
}
else
{
if (port != null && !port.isEmpty())
hasChanged = true;

port = "";
}

if(baseUrl != null && !baseUrl.isEmpty() && hasChanged)
constructUrl();
}

/**
Expand All @@ -516,7 +531,7 @@ private void setURIPath(String path)
/**
* Construct url.
*/
private void constructUrl()
public void constructUrl()
{
baseUrl = new StringBuffer();
baseUrl.append(protocol).append(protDelimiter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public abstract class BaseRemoteTest
protected static String roxieClusterGroup = System.getProperty("roxiegroupname");
protected final static String roxieclustername = System.getProperty("roxieclustername", "roxie");

protected final static String defaultUserName = "JunitUser";
protected final static String defaultUserName = "Junit@User";
protected static Connection connection = null;

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

// Run the generate-datasets.ecl script if present in the project resources
try
{
executeECLScript("generate-datasets.ecl");
}
catch (Exception e)
{
e.printStackTrace();
throw new Exception("Error executing test data generation scripts with error: " + e.getMessage());
}
//try
//{
// executeECLScript("generate-datasets.ecl");
//}
//catch (Exception e)
//{
// e.printStackTrace();
// throw new Exception("Error executing test data generation scripts with error: " + e.getMessage());
//}
}

public static String executeECLScript(String eclFile) throws Exception
Expand Down
181 changes: 181 additions & 0 deletions wsclient/src/test/java/org/hpccsystems/ws/client/WSECLTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
/*##############################################################################
HPCC SYSTEMS software Copyright (C) 2024 HPCC Systems®.
Licensed 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.hpccsystems.ws.client;

import static org.junit.Assume.assumeTrue;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.List;

import org.hpccsystems.ws.client.utils.Connection;
import org.hpccsystems.ws.client.wrappers.gen.wsworkunits.WUPublishWorkunitResponseWrapper;
import org.hpccsystems.ws.client.wrappers.wsworkunits.QueryResultWrapper;
import org.hpccsystems.ws.client.wrappers.wsworkunits.WorkunitWrapper;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;

public class WSECLTests extends BaseRemoteTest
{
private static HPCCWsWorkUnitsClient wswuclient = null;
private static boolean hasPublishedQuery = false;
private final static String wsECLPort = System.getProperty("wseclport", "8002");
private final static String eclScriptName = "SimpleFunction.ecl";
private static Connection wseclConn = null;

@BeforeClass
public static void setup() throws Exception
{
wswuclient = wsclient.getWsWorkunitsClient(); //for publishing queries
Assert.assertNotNull(wswuclient);

try
{
InputStream resourceStream = BaseRemoteTest.class.getClassLoader().getResourceAsStream(eclScriptName);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

byte[] buffer = new byte[4096];
int bytesRead = resourceStream.read(buffer);
while (bytesRead > -1) {
byteArrayOutputStream.write(buffer, 0, bytesRead);
bytesRead = resourceStream.read(buffer);
}

byte[] eclData = byteArrayOutputStream.toByteArray();
String ecl = new String(eclData, "UTF-8");

WorkunitWrapper wu = new WorkunitWrapper();
wu.setECL(ecl);
wu.setJobname(eclScriptName);
wu.setCluster(thorclustername);

//wswuclient.createAndRunWUFromECLAndGetResults(wu);
WUPublishWorkunitResponseWrapper resp = wswuclient.publishWUFromEclWrapped(wu);
System.out.println("Finished publishing query" + resp.toString());
List<QueryResultWrapper> queries = wswuclient.listQueries(wu.getWuid(), wu.getJobname(), wu.getCluster(), null, null, null, null, null, null);
for (QueryResultWrapper query : queries)
{
if (query.getName().equalsIgnoreCase(eclScriptName))
{
hasPublishedQuery = true;
return;
}
}
}
catch (Exception e)
{
System.out.println("Could not publish ECL query: " + e.getLocalizedMessage());
}

wseclConn = wsclient.getConnection();
wseclConn.setPort(wsECLPort);
wseclConn.setSocketTimeoutMilli(15000);
wseclConn.setWriteTimeoutMilli(15000);
}

@Test
public void testWsECLGetWSDL()
{
assumeTrue("WsECL connection not available", wseclConn != null);
assumeTrue("WsECL connection port appears invalid", wseclConn.getPort().equals(wsECLPort));
assumeTrue("Cannot test WsECL published query WSDL feature without published queries!", hasPublishedQuery);

try
{
String wsdlURI = "/WsEcl/definitions/query/" + thorclustername + "/" + eclScriptName + "/main/" + eclScriptName + ".wsdl";

String wsdlResponse = wseclConn.sendGetRequest(wsdlURI);
Assert.assertNotNull("Unexpected Null response", wsdlResponse);
//TODO determine good way to confirm success/failure
//Assert.assertArrayEquals(expectedWsdlResponse, wsdlResponse)
}
catch (Exception e)
{
Assert.fail("Could not fetch WsECL query wsdl: " + e.getLocalizedMessage());
}
}

@Test
public void testWsECLGetSampleReq()
{
assumeTrue("WsECL connection not available", wseclConn != null);
assumeTrue("WsECL connection port appears invalid", wseclConn.getPort().equals(wsECLPort));
assumeTrue("Cannot test WsECL published query WSDL feature without published queries!", hasPublishedQuery);

try
{
//http://127.0.0.1:8002/WsEcl/example/request/query/<roxie>/<query>
String sampleReqURI = "/WsEcl/example/request/query" + thorclustername + "/" + eclScriptName;
String sampleReqResponse = wseclConn.sendGetRequest(sampleReqURI);
Assert.assertNotNull("Unexpected Null response", sampleReqResponse);
//TODO determine good way to confirm success/failure
//Assert.assertArrayEquals(expectedWsdlResponse, wsdlResponse)
}
catch (Exception e)
{
Assert.fail("Could not fetch WsECL query wsdl: " + e.getLocalizedMessage());
}
}

@Test
public void testWsECLGetSampleResp()
{
assumeTrue("WsECL connection not available", wseclConn != null);
assumeTrue("WsECL connection port appears invalid", wseclConn.getPort().equals(wsECLPort));
assumeTrue("Cannot test WsECL published query WSDL feature without published queries!", hasPublishedQuery);

try
{
//http://127.0.0.1:8002/WsEcl/example/response/query/<roxie>/<query>
String sampleRespURI = "/WsEcl/example/response/query" + thorclustername + "/" + eclScriptName;
String sampleRespResponse = wseclConn.sendGetRequest(sampleRespURI);
Assert.assertNotNull("Unexpected Null response", sampleRespResponse);
//TODO determine good way to confirm success/failure
//Assert.assertArrayEquals(expectedWsdlResponse, wsdlResponse)
}
catch (Exception e)
{
Assert.fail("Could not fetch WsECL query wsdl: " + e.getLocalizedMessage());
}
}

@Test
public void testWsECLGetSchema()
{
assumeTrue("WsECL connection not available", wseclConn != null);
assumeTrue("WsECL connection port appears invalid", wseclConn.getPort().equals(wsECLPort));
assumeTrue("Cannot test WsECL published query WSDL feature without published queries!", hasPublishedQuery);

try
{
String xsdURI = "/WsEcl/definitions/query/" + thorclustername + "/" + eclScriptName + "/main/" + eclScriptName + ".xsd";
String xsdResponse = wseclConn.sendGetRequest(xsdURI);
Assert.assertNotNull("Unexpected Null response", xsdResponse);
//TODO determine good way to confirm success/failure
//Assert.assertArrayEquals(expectedWsdlResponse, wsdlResponse)
}
catch (Exception e)
{
Assert.fail("Could not fetch WsECL query xsd: " + e.getLocalizedMessage());
}
}

}
3 changes: 3 additions & 0 deletions wsclient/src/test/resources/RoxieEchoPersonInfo.ecl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import $.esdl_example;
request := dataset([], esdl_example.t_RoxieEchoPersonInfoRequest) : stored('RoxieEchoPersonInfoRequest', few);
output(request, named('RoxieEchoPersonInfoResponse'));
19 changes: 19 additions & 0 deletions wsclient/src/test/resources/SimpleFunction.ecl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
MyFunc(STRING DataIn, STRING1 SearchChar) := FUNCTION

StrLen := LENGTH(TRIM(dataIn));
ds := DATASET([{DataIn}], {STRING chars});

OutRec := RECORD
UNSIGNED1 flag;
END;

OutRec Xform(ds L, INTEGER C) := TRANSFORM
SELF.flag := IF(L.chars[C] = SearchChar, 1, 0);
END;

n := NORMALIZE(ds, StrLen, Xform(LEFT, COUNTER));

RETURN COUNT(n(flag=1));
END;

OUTPUT(MyFunc('abc~xyz~def~fred', '~'));

0 comments on commit 32cd624

Please sign in to comment.