From 69829a5db65f44a8365357573ae13c8d46550258 Mon Sep 17 00:00:00 2001 From: James McMullan Date: Mon, 13 May 2024 09:23:22 -0400 Subject: [PATCH] HPCC4J-599 Halt all JUnits on init failure - Updated init logic in BaseRemoteTest to automatically fail tests if init fails Signed-off-by: James McMullan James.McMullan@lexisnexis.com --- .../hpccsystems/ws/client/BaseRemoteTest.java | 49 ++++++++++++++----- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/wsclient/src/test/java/org/hpccsystems/ws/client/BaseRemoteTest.java b/wsclient/src/test/java/org/hpccsystems/ws/client/BaseRemoteTest.java index 402e2782d..55036186b 100644 --- a/wsclient/src/test/java/org/hpccsystems/ws/client/BaseRemoteTest.java +++ b/wsclient/src/test/java/org/hpccsystems/ws/client/BaseRemoteTest.java @@ -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; @@ -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; @@ -52,6 +51,8 @@ HPCC SYSTEMS software Copyright (C) 2019 HPCC Systems®. @Category(org.hpccsystems.commons.annotations.RemoteTests.class) public abstract class BaseRemoteTest { + protected static boolean initialized = false; + protected static Exception initializationException = null; protected static Platform platform; protected static HPCCWsClient wsclient; @@ -85,6 +86,25 @@ public abstract class BaseRemoteTest public static final String DEFAULTHPCCSUPERFILENAME = "benchmark::all_types::superfile"; static + { + try + { + initialize(); + initialized = true; + } + catch (Exception e) + { + initializationException = e; + } + } + + @BeforeClass + public static void initCheck() + { + Assert.assertTrue("Error initializing test suite: " + initializationException.getLocalizedMessage(), initialized); + } + + 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 @@ -146,10 +166,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) @@ -159,8 +183,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 @@ -200,10 +226,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 @@ -212,7 +239,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()); } } @@ -255,7 +282,7 @@ static public void executeMultiThreadedTask(Callable callableTask, int t { try { - assertTrue(futures.get(threadIndex).get().isEmpty()); + Assert.assertTrue(futures.get(threadIndex).get().isEmpty()); } catch (InterruptedException | ExecutionException e) {