From 67e1d945423219261e3b205d4f9332762ef83d4e Mon Sep 17 00:00:00 2001 From: darshanime-d11 Date: Wed, 12 Feb 2025 15:17:17 +0530 Subject: [PATCH] use non-zero exit code on exception --- README.md | 3 +- pom.xml | 22 +- .../com/aerospike/load/AerospikeLoad.java | 275 +++++++++--------- .../java/com/aerospike/load/DataTypeTest.java | 155 +++++++--- 4 files changed, 273 insertions(+), 182 deletions(-) diff --git a/README.md b/README.md index 0ae1054..308017c 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,8 @@ Following dependencies are downloaded automatically: * Aerospike Java client 7.2.2 or greater * Apache commons cli 1.7.0 * Log4j 2.22.1 -* Junit 4.13.1 +* Junit 5.11.4 +* system-lambda 1.2.1 * Json-simple 1.1.1 diff --git a/pom.xml b/pom.xml index 2f69d97..c1ec965 100644 --- a/pom.xml +++ b/pom.xml @@ -51,13 +51,29 @@ log4j-core 2.22.1 + - junit - junit - 4.13.1 + org.junit.jupiter + junit-jupiter-api + 5.11.4 + test + + + + org.junit.jupiter + junit-jupiter-engine + 5.11.4 test + + + com.github.stefanbirkner + system-lambda + 1.2.1 + test + + com.googlecode.json-simple diff --git a/src/main/java/com/aerospike/load/AerospikeLoad.java b/src/main/java/com/aerospike/load/AerospikeLoad.java index 0f0728a..cef0d78 100644 --- a/src/main/java/com/aerospike/load/AerospikeLoad.java +++ b/src/main/java/com/aerospike/load/AerospikeLoad.java @@ -41,6 +41,7 @@ import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; import org.apache.commons.cli.PosixParser; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; @@ -104,143 +105,145 @@ private static void printVersion() } } - public static void main(String[] args) throws IOException { - long processStart = System.currentTimeMillis(); + public static void main(String[] args) throws IOException { + int exitCode = -1; + try { + CommandLine cl = parseArgs(args); + exitCode = launch(cl); + } catch (Exception e) { + if (log.isDebugEnabled()) { + e.printStackTrace(); + } + } + System.exit(exitCode); + } + + public static int launch(CommandLine cl) throws Exception { + long processStart = System.currentTimeMillis(); + + AerospikeClient client = null; + statPrinter = new Thread(new PrintStat(counters)); + // Create Abstract derived params from provided commandline params. + params = Utils.parseParameters(cl); + if (params.verbose) { + Configurator.setAllLevels(LogManager.getRootLogger().getName(), Level.DEBUG); + } + + initReadWriteThreadCnt(cl); + + // Get and validate user roles for client. + client = getAerospikeClient(cl); + if (client == null) { + return -1; + } + + List dataFileNames = new ArrayList(); + initDataFileNameList(cl, dataFileNames); + if (dataFileNames.size() == 0) { + return -1; + } + + // Remove column definition file from list. if directory containing config file is passed. + String columnDefinitionFileName = cl.getOptionValue("c", ""); + dataFileNames.remove(columnDefinitionFileName); + log.info("Number of data files:" + dataFileNames.size()); + + initBytesToRead(dataFileNames); + + log.info("Aerospike loader started"); + // Perform main Read Write job. + runLoader(client, columnDefinitionFileName, dataFileNames); + + // Stop statistic printer thread. + statPrinter.interrupt(); + log.info("Aerospike loader completed"); + if (client != null) { + client.close(); + } + + long processStop = System.currentTimeMillis(); + log.info(String.format("Loader completed in %.3fsec", (float) (processStop - processStart) / 1000)); + return 0; + } + + public static CommandLine parseArgs(String[] args) throws ParseException { + counters = new Counter(); + CommandLine cl; + + Options options = new Options(); + options.addOption("h", "hosts", true, + "List of seed hosts in format:\n" + + "hostname1[:tlsname][:port1],...\n" + + "The tlsname is only used when connecting with a secure TLS enabled server. " + + "If the port is not specified, the default port is used.\n" + + "IPv6 addresses must be enclosed in square brackets.\n" + + "Default: localhost\n" + + "Examples:\n" + + "host1\n" + + "host1:3000,host2:3000\n" + + "192.168.1.10:cert1:3000,[2001::1111]:cert2:3000\n" + ); + options.addOption("V", "version", false, "Aerospike Loader Version"); + options.addOption("p", "port", true, "Server port (default: 3000)"); + options.addOption("U", "user", true, "User name"); + options.addOption("P", "password", true, "Password"); + options.addOption("n", "namespace", true, "Namespace (default: test)"); + options.addOption("c", "config", true, "Column definition file name"); + options.addOption("g", "max-throughput", true, "It limit numer of writes/sec in aerospike."); + options.addOption("T", "transaction-timeout", true, "write transaction timeout in milliseconds(default: No timeout)"); + options.addOption("e", "expirationTime", true, + "Set expiration time of each record in seconds." + + " -1: Never expire, " + + " 0: Default to namespace," + + " >0: Actual given expiration time" + ); + options.addOption("tz", "timezone", true, "Timezone of source where data dump is taken (default: local timezone)"); + options.addOption("ec", "abort-error-count", true, "Error count to abort (default: 0)"); + options.addOption("wa", "write-action", true, "Write action if key already exists (default: update)"); + options.addOption("sa", "services_alternate", false, "Enable alternate services."); + options.addOption("tls", "tls-enable", false, "Use TLS/SSL sockets"); + options.addOption("tp", "tls-protocols", true, + "Allow TLS protocols\n" + + "Values: TLSv1,TLSv1.1,TLSv1.2 separated by comma\n" + + "Default: TLSv1.2" + ); + options.addOption("tlsCiphers", "tls-cipher-suite", true, + "Allow TLS cipher suites\n" + + "Values: cipher names defined by JVM separated by comma\n" + + "Default: null (default cipher list provided by JVM)" + ); + options.addOption("tr", "tlsRevoke", true, + "Revoke certificates identified by their serial number\n" + + "Values: serial numbers separated by comma\n" + + "Default: null (Do not revoke certificates)" + ); + + options.addOption("tlsLoginOnly", false, "Use TLS/SSL sockets on node login only"); + options.addOption("auth", true, "Authentication mode. Values: " + Arrays.toString(AuthMode.values())); + + options.addOption("uk", "send-user-key", false, + "Send user defined key in addition to hash digest to store on the server. (default: userKey is not sent to reduce meta-data overhead)" + ); + options.addOption("v", "verbose", false, "Logging all"); + options.addOption("um", "unorderdMaps", false, "Write all maps as unorderd maps"); + options.addOption("u", "usage", false, "Print usage."); + + CommandLineParser parser = new PosixParser(); + cl = parser.parse(options, args, false); + + if (args.length == 0 || cl.hasOption("u")) { + printUsage(options); + return cl; + } + + if (cl.hasOption("V")) { + printVersion(); + return cl; + } + + return cl; + } - AerospikeClient client = null; - counters = new Counter(); - CommandLine cl; - - try { - Options options = new Options(); - options.addOption("h", "hosts", true, - "List of seed hosts in format:\n" + - "hostname1[:tlsname][:port1],...\n" + - "The tlsname is only used when connecting with a secure TLS enabled server. " + - "If the port is not specified, the default port is used.\n" + - "IPv6 addresses must be enclosed in square brackets.\n" + - "Default: localhost\n" + - "Examples:\n" + - "host1\n" + - "host1:3000,host2:3000\n" + - "192.168.1.10:cert1:3000,[2001::1111]:cert2:3000\n" - ); - options.addOption("V", "version", false, "Aerospike Loader Version"); - options.addOption("p", "port", true, "Server port (default: 3000)"); - options.addOption("U", "user", true, "User name"); - options.addOption("P", "password", true, "Password"); - options.addOption("n", "namespace", true, "Namespace (default: test)"); - options.addOption("c", "config", true, "Column definition file name"); - options.addOption("g", "max-throughput", true, "It limit numer of writes/sec in aerospike."); - options.addOption("T", "transaction-timeout", true, "write transaction timeout in milliseconds(default: No timeout)"); - options.addOption("e", "expirationTime", true, - "Set expiration time of each record in seconds." + - " -1: Never expire, " + - " 0: Default to namespace," + - " >0: Actual given expiration time" - ); - options.addOption("tz", "timezone", true, "Timezone of source where data dump is taken (default: local timezone)"); - options.addOption("ec", "abort-error-count", true, "Error count to abort (default: 0)"); - options.addOption("wa", "write-action", true, "Write action if key already exists (default: update)"); - options.addOption("sa", "services_alternate", false, "Enable alternate services."); - options.addOption("tls", "tls-enable", false, "Use TLS/SSL sockets"); - options.addOption("tp", "tls-protocols", true, - "Allow TLS protocols\n" + - "Values: TLSv1,TLSv1.1,TLSv1.2 separated by comma\n" + - "Default: TLSv1.2" - ); - options.addOption("tlsCiphers", "tls-cipher-suite", true, - "Allow TLS cipher suites\n" + - "Values: cipher names defined by JVM separated by comma\n" + - "Default: null (default cipher list provided by JVM)" - ); - options.addOption("tr", "tlsRevoke", true, - "Revoke certificates identified by their serial number\n" + - "Values: serial numbers separated by comma\n" + - "Default: null (Do not revoke certificates)" - ); - - options.addOption("tlsLoginOnly", false, "Use TLS/SSL sockets on node login only"); - options.addOption("auth", true, "Authentication mode. Values: " + Arrays.toString(AuthMode.values())); - - options.addOption("uk", "send-user-key", false, - "Send user defined key in addition to hash digest to store on the server. (default: userKey is not sent to reduce meta-data overhead)" - ); - options.addOption("v", "verbose", false, "Logging all"); - options.addOption("um", "unorderdMaps", false, "Write all maps as unorderd maps"); - options.addOption("u", "usage", false, "Print usage."); - - CommandLineParser parser = new PosixParser(); - cl = parser.parse(options, args, false); - - if (args.length == 0 || cl.hasOption("u")) { - printUsage(options); - return; - } - - if (cl.hasOption("V")) { - printVersion(); - return; - } - } catch (Exception e) { - log.error(e); - if (log.isDebugEnabled()) { - e.printStackTrace(); - } - return; - } - - try { - statPrinter = new Thread(new PrintStat(counters)); - // Create Abstract derived params from provided commandline params. - params = Utils.parseParameters(cl); - if (params.verbose) { - Configurator.setAllLevels(LogManager.getRootLogger().getName(), Level.DEBUG); - } - - initReadWriteThreadCnt(cl); - - // Get and validate user roles for client. - client = getAerospikeClient(cl); - if (client == null) { - return; - } - - List dataFileNames = new ArrayList(); - initDataFileNameList(cl, dataFileNames); - if (dataFileNames.size() == 0) { - return; - } - - // Remove column definition file from list. if directory containing config file is passed. - String columnDefinitionFileName = cl.getOptionValue("c", ""); - dataFileNames.remove(columnDefinitionFileName); - log.info("Number of data files:" + dataFileNames.size()); - - initBytesToRead(dataFileNames); - - log.info("Aerospike loader started"); - // Perform main Read Write job. - runLoader(client, columnDefinitionFileName, dataFileNames); - - } catch (Exception e) { - log.error(e); - if (log.isDebugEnabled()) { - e.printStackTrace(); - } - } finally { - // Stop statistic printer thread. - statPrinter.interrupt(); - log.info("Aerospike loader completed"); - if (client != null) { - client.close(); - } - } - - long processStop = System.currentTimeMillis(); - log.info(String.format("Loader completed in %.3fsec", (float) (processStop - processStart) / 1000)); - } - private static AerospikeClient getAerospikeClient(CommandLine cl) { ClientPolicy clientPolicy = new ClientPolicy(); diff --git a/src/test/java/com/aerospike/load/DataTypeTest.java b/src/test/java/com/aerospike/load/DataTypeTest.java index dd2eb3c..c38e373 100644 --- a/src/test/java/com/aerospike/load/DataTypeTest.java +++ b/src/test/java/com/aerospike/load/DataTypeTest.java @@ -1,6 +1,7 @@ package com.aerospike.load; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -29,6 +30,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import com.github.stefanbirkner.systemlambda.SystemLambda; import com.aerospike.client.AerospikeClient; import com.aerospike.client.AerospikeException; @@ -118,9 +120,41 @@ public JSONObject parseConfigFile(String configFile) { } return jsonObject; } - + + @Test + public void testInvalidConfig() throws Exception { + System.out.println("TestInvalidConfig: start"); + if(!client.isConnected()) { + System.out.println("Client is not able to connect:" + host + ":" + port); + return; + } + // Create datafile + + HashMap binMap = (HashMap) testSchema.get("test_string"); + + int setMod = 5, range = 100, seed = 10, nrecords = 10; + dataFile = rootDir + "dataString.dsv"; + writeDataMap(dataFile, nrecords, setMod, range, seed, binMap); + + // Run Aerospike loader + int exitCode = SystemLambda.catchSystemExit(() -> { + AerospikeLoad.main(new String[]{"-h", host,"-p", port,"-n", ns, "-ec", error_count,"-wa", write_action,"-c", "/non/existing/config.json", dataFile}); + }); + + // Validate loaded data + String dstType = null; + boolean dataValid = validateMap(client, dataFile, nrecords, setMod, range, seed, binMap, dstType); + boolean error = getError(log); + + assertTrue(dataValid); + assertTrue(!error); + assertEquals(-1, exitCode, "Unexpected exit code"); + + System.out.println("TestInvalidConfig: Complete"); + } + // String type data validation - //@Test + @Test public void testValidateString() throws Exception { System.out.println("TestValidateString: start"); if(!client.isConnected()) { @@ -131,14 +165,15 @@ public void testValidateString() throws Exception { HashMap binMap = (HashMap) testSchema.get("test_string"); - int setMod = 5, range = 100, seed = 10, nrecords = 10; dataFile = rootDir + "dataString.dsv"; - writeDataMap(dataFile, nrecords, setMod, range, seed, binMap); - - // Run Aerospike loader - AerospikeLoad.main(new String[]{"-h", host,"-p", port,"-n", ns, "-ec", error_count,"-wa", write_action,"-c", "src/test/resources/configString.json", dataFile}); - + writeDataMap(dataFile, nrecords, setMod, range, seed, binMap); + + // Run Aerospike loader + int exitCode = SystemLambda.catchSystemExit(() -> { + AerospikeLoad.main(new String[]{"-h", host,"-p", port,"-n", ns, "-ec", error_count,"-wa", write_action,"-c", "src/test/resources/configString.json", dataFile}); + }); + // Validate loaded data String dstType = null; boolean dataValid = validateMap(client, dataFile, nrecords, setMod, range, seed, binMap, dstType); @@ -146,7 +181,8 @@ public void testValidateString() throws Exception { assertTrue(dataValid); assertTrue(!error); - + assertEquals(0, exitCode, "Unexpected exit code"); + System.out.println("TestValidateString: Complete"); } @@ -166,11 +202,13 @@ public void testValidateInteger() throws Exception { int setMod = 5, range = 100, seed = 10, nrecords = 10; dataFile = rootDir + "dataInt.dsv"; - writeDataMap(dataFile, nrecords, setMod, range, seed, binMap); + writeDataMap(dataFile, nrecords, setMod, range, seed, binMap); // Run Aerospike loader - AerospikeLoad.main(new String[]{"-h", host,"-p", port,"-n", ns, "-ec", error_count,"-wa", write_action,"-c", "src/test/resources/configInt.json", dataFile}); - + int exitCode = SystemLambda.catchSystemExit(() -> { + AerospikeLoad.main(new String[]{"-h", host,"-p", port,"-n", ns, "-ec", error_count,"-wa", write_action,"-c", "src/test/resources/configInt.json", dataFile}); + }); + // Validate loaded data String dstType = null; boolean dataValid = validateMap(client, dataFile, nrecords, setMod, range, seed, binMap, dstType); @@ -178,7 +216,8 @@ public void testValidateInteger() throws Exception { assertTrue(dataValid); assertTrue(!error); - + assertEquals(0, exitCode, "Unexpected exit code"); + System.out.println("TestValidateInteger: Complete"); } @@ -201,8 +240,10 @@ public void testValidateStringUtf8() throws Exception { writeDataMap(dataFile, nrecords, setMod, range, seed, binMap); // Run Aerospike loader - AerospikeLoad.main(new String[]{"-h", host,"-p", port,"-n", ns, "-ec", error_count,"-wa", write_action,"-c", "src/test/resources/configUtf8.json", dataFile}); - + int exitCode = SystemLambda.catchSystemExit(() -> { + AerospikeLoad.main(new String[]{"-h", host,"-p", port,"-n", ns, "-ec", error_count,"-wa", write_action,"-c", "src/test/resources/configUtf8.json", dataFile}); + }); + // Validate loaded data String dstType = null; boolean dataValid = validateMap(client, dataFile, nrecords, setMod, range, seed, binMap, dstType); @@ -210,7 +251,8 @@ public void testValidateStringUtf8() throws Exception { assertTrue(dataValid); assertTrue(!error); - + assertEquals(0, exitCode, "Unexpected exit code"); + System.out.println("TestValidateStringutf8: Complete"); } @@ -232,8 +274,10 @@ public void testValidateTimestampInteger() throws Exception { writeDataMap(dataFile, nrecords, setMod, range, seed, binMap); // Run Aerospike loader - AerospikeLoad.main(new String[]{"-h", host,"-p", port,"-n", ns, "-ec", error_count,"-wa", write_action,"-c", "src/test/resources/configDate.json", dataFile}); - + int exitCode = SystemLambda.catchSystemExit(() -> { + AerospikeLoad.main(new String[]{"-h", host,"-p", port,"-n", ns, "-ec", error_count,"-wa", write_action,"-c", "src/test/resources/configDate.json", dataFile}); + }); + // Validate loaded data String dst_type = "integer"; boolean dataValid = validateMap(client, dataFile, nrecords, setMod, range, seed, binMap, dst_type); @@ -241,7 +285,8 @@ public void testValidateTimestampInteger() throws Exception { assertTrue(dataValid); assertTrue(!error); - + assertEquals(0, exitCode, "Unexpected exit code"); + System.out.println("TestValidateTimestampInteger: Complete"); } @@ -261,10 +306,12 @@ public void testValidateBlob() throws Exception { int setMod = 5, range = 100, seed = 10, nrecords = 10; dataFile = rootDir + "dataBlob.dsv"; writeDataMap(dataFile, nrecords, setMod, range, seed, binMap); - - // Run Aerospike loader - AerospikeLoad.main(new String[]{"-h", host,"-p", port,"-n", ns, "-ec", error_count,"-wa", write_action,"-c", "src/test/resources/configBlob.json", dataFile}); - + + // Run Aerospike loader + int exitCode = SystemLambda.catchSystemExit(() -> { + AerospikeLoad.main(new String[]{"-h", host,"-p", port,"-n", ns, "-ec", error_count,"-wa", write_action,"-c", "src/test/resources/configBlob.json", dataFile}); + }); + // Validate loaded data String dstType = "blob"; boolean dataValid = validateMap(client, dataFile, nrecords, setMod, range, seed, binMap, dstType); @@ -272,7 +319,8 @@ public void testValidateBlob() throws Exception { assertTrue(dataValid); assertTrue(!error); - + assertEquals(0, exitCode, "Unexpected exit code"); + System.out.println("TestValidateBlob: Complete"); } @@ -294,8 +342,10 @@ public void testValidateList() throws Exception { writeDataMap(dataFile, nrecords, setMod, range, seed, binMap); // Run Aerospike loader - AerospikeLoad.main(new String[]{"-h", host,"-p", port,"-n", ns, "-ec", error_count,"-wa", write_action,"-c", "src/test/resources/configList.json", dataFile}); - + int exitCode = SystemLambda.catchSystemExit(() -> { + AerospikeLoad.main(new String[]{"-h", host,"-p", port,"-n", ns, "-ec", error_count,"-wa", write_action,"-c", "src/test/resources/configList.json", dataFile}); + }); + // Validate loaded data String dstType = "list"; boolean dataValid = validateMap(client, dataFile, nrecords, setMod, range, seed, binMap, dstType); @@ -303,6 +353,7 @@ public void testValidateList() throws Exception { assertTrue(dataValid); assertTrue(!error); + assertEquals(0, exitCode, "Unexpected exit code"); System.out.println("TestValidateList: Complete"); } @@ -326,8 +377,10 @@ public void testValidateMap() throws Exception { writeDataMap(dataFile, nrecords, setMod, range, seed, binMap); // Run Aerospike loader - AerospikeLoad.main(new String[]{"-h", host,"-p", port,"-n", ns, "-ec", error_count,"-wa", write_action,"-c", "src/test/resources/configMap.json", dataFile}); - + int exitCode = SystemLambda.catchSystemExit(() -> { + AerospikeLoad.main(new String[]{"-h", host,"-p", port,"-n", ns, "-ec", error_count,"-wa", write_action,"-c", "src/test/resources/configMap.json", dataFile}); + }); + // Validate loaded data String dstType = "map"; boolean dataValid = validateMap(client, dataFile, nrecords, setMod, range, seed, binMap, dstType); @@ -335,6 +388,7 @@ public void testValidateMap() throws Exception { assertTrue(dataValid); assertTrue(!error); + assertEquals(0, exitCode, "Unexpected exit code"); System.out.println("TestValidateMap: Complete"); } @@ -358,8 +412,10 @@ public void testValidateJSON() throws Exception { writeDataMap(dataFile, nrecords, setMod, range, seed, binMap); // Run Aerospike loader - AerospikeLoad.main(new String[]{"-h", host,"-p", port,"-n", ns, "-v", "-ec", error_count,"-wa", write_action,"-c", "src/test/resources/configJson.json", dataFile}); - + int exitCode = SystemLambda.catchSystemExit(() -> { + AerospikeLoad.main(new String[]{"-h", host,"-p", port,"-n", ns, "-v", "-ec", error_count,"-wa", write_action,"-c", "src/test/resources/configJson.json", dataFile}); + }); + // Validate loaded data String dstType = "json"; boolean dataValid = validateMap(client, dataFile, nrecords, setMod, range, seed, binMap, dstType); @@ -367,6 +423,7 @@ public void testValidateJSON() throws Exception { assertTrue(dataValid); assertTrue(!error); + assertEquals(0, exitCode, "Unexpected exit code"); System.out.println("TestValidateJSON: Complete"); } @@ -390,12 +447,15 @@ public void testAllDatatype() throws Exception { writeDataMap(dataFile, nrecords, setMod, range, seed, binMap); // Run Aerospike loader - AerospikeLoad.main(new String[]{"-h", host,"-p", port,"-n", ns, "-ec", error_count,"-wa", write_action,"-c", "src/test/resources/configAllDataType.json", dataFile}); - + int exitCode = SystemLambda.catchSystemExit(() -> { + AerospikeLoad.main(new String[]{"-h", host,"-p", port,"-n", ns, "-ec", error_count,"-wa", write_action,"-c", "src/test/resources/configAllDataType.json", dataFile}); + }); + boolean error = getError(log); assertTrue(!error); - + assertEquals(0, exitCode, "Unexpected exit code"); + System.out.println("TestAllDatatype: Complete"); } @@ -407,13 +467,17 @@ public void testDynamicBinName() throws Exception { System.out.println("Client is not able to connect:" + host + ":" + port); return; } - - AerospikeLoad.main(new String[]{"-h", host,"-p", port,"-n", ns, "-ec", error_count,"-wa", write_action,"-c", "src/test/resources/configDynamicBinName.json", "src/test/resources/dataDynamicBin.csv"}); + + int exitCode = SystemLambda.catchSystemExit(() -> { + AerospikeLoad.main(new String[]{"-h", host,"-p", port,"-n", ns, "-ec", error_count,"-wa", write_action,"-c", "src/test/resources/configDynamicBinName.json", "src/test/resources/dataDynamicBin.csv"}); + }); + boolean error = getError(log); assertTrue(!error); - + assertEquals(0, exitCode, "Unexpected exit code"); + System.out.println("Test Dynamic BinName: Complete"); } @@ -425,13 +489,17 @@ public void testStaticBinName() throws Exception { System.out.println("Client is not able to connect:" + host + ":" + port); return; } - - AerospikeLoad.main(new String[]{"-h", host,"-p", port,"-n", ns, "-ec", error_count,"-wa", write_action,"-c", "src/test/resources/configStaticBinName.json", "src/test/resources/dataStaticBin.csv"}); + + int exitCode = SystemLambda.catchSystemExit(() -> { + AerospikeLoad.main(new String[]{"-h", host,"-p", port,"-n", ns, "-ec", error_count,"-wa", write_action,"-c", "src/test/resources/configStaticBinName.json", "src/test/resources/dataStaticBin.csv"}); + }); + boolean error = getError(log); assertTrue(!error); - + assertEquals(0, exitCode, "Unexpected exit code"); + System.out.println("Test static BinName: Complete"); } @@ -455,8 +523,10 @@ public void testValidateMapOrder() throws Exception { // Run Aerospike loader this.expectedMapOrder = MapOrder.UNORDERED; - AerospikeLoad.main(new String[]{"-h", host,"-p", port,"-n", ns, "-ec", error_count,"-wa", write_action, "-um", "-c", "src/test/resources/configMap.json", dataFile}); - + int exitCode = SystemLambda.catchSystemExit(() -> { + AerospikeLoad.main(new String[]{"-h", host,"-p", port,"-n", ns, "-ec", error_count,"-wa", write_action, "-um", "-c", "src/test/resources/configMap.json", dataFile}); + }); + // Validate loaded data String dstType = "map"; boolean dataValid = validateMap(client, dataFile, nrecords, setMod, range, seed, binMap, dstType); @@ -464,6 +534,7 @@ public void testValidateMapOrder() throws Exception { assertTrue(dataValid); assertTrue(!error); + assertEquals(0, exitCode, "Unexpected exit code"); this.expectedMapOrder = MapOrder.KEY_ORDERED; System.out.println("TestValidateMap: Complete");