Skip to content

Commit

Permalink
HPCC4J-599 Halt all JUnits on init failure (#708)
Browse files Browse the repository at this point in the history
- Updated init logic in BaseRemoteTest to automatically fail tests if init fails

Signed-off-by: James McMullan James.McMullan@lexisnexis.com

Signed-off-by: James McMullan James.McMullan@lexisnexis.com
  • Loading branch information
jpmcmu authored May 15, 2024
1 parent b333af9 commit b9ce161
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 17 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/JAPIPRBuildAction.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ jobs:
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Rebase
run: |
git config user.email 'hpccsystems@lexisnexisrisk.com'
git config user.name 'hpccsystems development'
git rebase origin/${{ github.event.pull_request.base.ref }}
git log --pretty=one -n 15

- name: Set up JDK 11
uses: actions/setup-java@v1
Expand All @@ -34,3 +28,7 @@ jobs:

- name: Build with Maven
run: mvn -B package --file pom.xml

# Expect a failure here, verifying that the test suite fails early on init issues
- name: Test Suite Verification
run: "! mvn test --activate-profiles jenkins-on-demand -Dhpccconn=https://bad_host:8010"
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*##############################################################################
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 org.junit.Assert;
import org.junit.Test;
import org.junit.experimental.categories.Category;

@Category(org.hpccsystems.commons.annotations.RemoteTests.class)
public class BaseRemoteInitTest
{
@Test
public void initTest() throws Exception
{
String exceptionMessage = "";
if (BaseRemoteTest.initializationException != null)
{
exceptionMessage = BaseRemoteTest.initializationException.getMessage();
}

Assert.assertTrue("Error initializing test suite: " + exceptionMessage, BaseRemoteTest.initializationException == null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ HPCC SYSTEMS software Copyright (C) 2019 HPCC Systems®.

package org.hpccsystems.ws.client;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.InetAddress;
Expand All @@ -40,7 +37,9 @@ HPCC SYSTEMS software Copyright (C) 2019 HPCC Systems®.
import org.hpccsystems.ws.client.platform.Platform;
import org.hpccsystems.ws.client.utils.Connection;
import org.hpccsystems.ws.client.wrappers.gen.wstopology.TpGroupWrapper;
import org.junit.Assume;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.experimental.categories.Category;

import java.net.URL;
Expand All @@ -52,6 +51,7 @@ HPCC SYSTEMS software Copyright (C) 2019 HPCC Systems®.
@Category(org.hpccsystems.commons.annotations.RemoteTests.class)
public abstract class BaseRemoteTest
{
public static Exception initializationException = null;
protected static Platform platform;
protected static HPCCWsClient wsclient;

Expand Down Expand Up @@ -85,6 +85,31 @@ public abstract class BaseRemoteTest
public static final String DEFAULTHPCCSUPERFILENAME = "benchmark::all_types::superfile";

static
{
try
{
initialize();
}
catch (Exception e)
{
initializationException = e;
}
}

@BeforeClass
public static void initCheck()
{
String exceptionMessage = "";
if (initializationException != null)
{
exceptionMessage = initializationException.getLocalizedMessage();
initializationException.printStackTrace();
}

Assume.assumeTrue("Error initializing test suite: " + exceptionMessage, initializationException == null);
}

public static void initialize() throws Exception
{
// This allows testing against locally created self signed certs to work.
// In production certs will need to be created valid hostnames
Expand Down Expand Up @@ -146,10 +171,14 @@ public boolean verify(String hostname,javax.net.ssl.SSLSession sslSession)
}
catch (MalformedURLException e)
{
fail("Could not acquire connection object based on: '" + connString + "' - " + e.getLocalizedMessage());
throw new Exception("Could not acquire connection object based on: '" + connString + "' - " + e.getLocalizedMessage());
}

if (connection == null)
{
throw new Exception("Could not acquire connection object based on: '" + connString + "'");
}

Assert.assertNotNull("Could not acquire connection object", connection);
connection.setCredentials(hpccUser, hpccPass);

if (connTO != null)
Expand All @@ -159,8 +188,10 @@ public boolean verify(String hostname,javax.net.ssl.SSLSession sslSession)
connection.setSocketTimeoutMilli(Integer.valueOf(sockTO));

platform = Platform.get(connection);

Assert.assertNotNull("Could not acquire platform object", platform);
if (platform == null)
{
throw new Exception("Could not acquire platform object");
}
}

try
Expand Down Expand Up @@ -200,10 +231,11 @@ public boolean verify(String hostname,javax.net.ssl.SSLSession sslSession)
}
catch (Exception e)
{
fail("Could not acquire wsclient object: " + e.getMessage() );
throw new Exception("Could not acquire wsclient object: " + e.getMessage() );
}

Assert.assertNotNull("Could not acquire wsclient object", wsclient);
if (wsclient == null)
throw new Exception("Could not acquire wsclient object");

// Run the generate-datasets.ecl script if present in the project resources
try
Expand All @@ -212,7 +244,7 @@ public boolean verify(String hostname,javax.net.ssl.SSLSession sslSession)
}
catch (Exception e)
{
Assert.fail("Error executing test data generation scripts with error: " + e.getMessage());
throw new Exception("Error executing test data generation scripts with error: " + e.getMessage());
}
}

Expand Down Expand Up @@ -255,7 +287,7 @@ static public void executeMultiThreadedTask(Callable<String> callableTask, int t
{
try
{
assertTrue(futures.get(threadIndex).get().isEmpty());
Assert.assertTrue(futures.get(threadIndex).get().isEmpty());
}
catch (InterruptedException | ExecutionException e)
{
Expand Down

0 comments on commit b9ce161

Please sign in to comment.