From d97e55987314f81c2e8c4b55bd2fd591e1675887 Mon Sep 17 00:00:00 2001
From: Aditya Pareek <119134401+LOGANBLUE1@users.noreply.github.com>
Date: Wed, 18 Feb 2026 09:47:04 +0530
Subject: [PATCH 1/3] fixed the objectMapper bug - #1271
---
.../writer/JsonStringArgumentsWriter.java | 8 +-
.../zingg/spark/client/TestArguments.java | 80 ++++++++++---------
2 files changed, 47 insertions(+), 41 deletions(-)
diff --git a/common/client/src/main/java/zingg/common/client/arguments/writer/JsonStringArgumentsWriter.java b/common/client/src/main/java/zingg/common/client/arguments/writer/JsonStringArgumentsWriter.java
index a135e0631..3f4beb491 100644
--- a/common/client/src/main/java/zingg/common/client/arguments/writer/JsonStringArgumentsWriter.java
+++ b/common/client/src/main/java/zingg/common/client/arguments/writer/JsonStringArgumentsWriter.java
@@ -3,14 +3,16 @@
import zingg.common.client.arguments.model.IZArgs;
import zingg.common.client.ZinggClientException;
+import java.nio.file.Paths;
+
public class JsonStringArgumentsWriter extends ArgumentsWriter {
@Override
- public void write(String sink, IZArgs args) throws ZinggClientException {
+ public void write(String path, IZArgs args) throws ZinggClientException {
try {
- sink = objectMapper.writeValueAsString(args);
+ objectMapper.writeValue(Paths.get(path).toFile(), args);
} catch (Exception exception) {
- throw new ZinggClientException("Error writing config to string", exception);
+ throw new ZinggClientException("Error writing config to jsonfile", exception);
}
}
}
diff --git a/spark/client/src/test/java/zingg/spark/client/TestArguments.java b/spark/client/src/test/java/zingg/spark/client/TestArguments.java
index 57721f64e..be5bdfa85 100644
--- a/spark/client/src/test/java/zingg/spark/client/TestArguments.java
+++ b/spark/client/src/test/java/zingg/spark/client/TestArguments.java
@@ -2,6 +2,8 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
+import java.nio.file.Path;
+import java.rmi.NoSuchObjectException;
import java.util.Arrays;
import java.util.List;
@@ -9,6 +11,7 @@
import org.apache.commons.logging.LogFactory;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
import zingg.common.client.arguments.ArgumentServiceImpl;
import zingg.common.client.arguments.IArgumentService;
import zingg.common.client.arguments.loader.LoaderFactory;
@@ -23,6 +26,8 @@
import zingg.spark.client.pipe.SparkPipe;
public class TestArguments {
+ @TempDir
+ Path tempDir;
public static final Log LOG = LogFactory.getLog(TestArguments.class);
protected final IArgumentService argumentService;
@@ -31,48 +36,47 @@ public TestArguments() {
this.argumentService = new ArgumentServiceImpl<>(Arguments.class, new LoaderFactory<>(),new WriterFactory<>());
}
@Test
- public void testWriteArgumentObjectToJSONFile() {
+ public void testWriteArgumentObjectToJSONFile() throws ZinggClientException, NoSuchObjectException {
IArguments args = new Arguments();
- try {
- FieldDefinition fname = new FieldDefinition();
- fname.setFieldName("fname");
- fname.setDataType("string");
- fname.setMatchType(Arrays.asList(MatchTypes.EXACT, MatchTypes.FUZZY, MatchTypes.PINCODE));
- //fname.setMatchType(Arrays.asList(MatchType.EXACT));
- fname.setFields("fname");
- FieldDefinition lname = new FieldDefinition();
- lname.setFieldName("lname");
- lname.setDataType("string");
- lname.setMatchType(Arrays.asList(MatchTypes.FUZZY));
- lname.setFields("lname");
- args.setFieldDefinition(Arrays.asList(fname, lname));
+ Path path = tempDir.resolve("configFromArgObject.json");
- Pipe inputPipe = new SparkPipe();
- inputPipe.setName("test");
- inputPipe.setFormat(Pipe.FORMAT_CSV);
- inputPipe.setProp("path", "examples/febrl/test.csv");
- args.setData(new Pipe[] {inputPipe});
+ FieldDefinition fname = new FieldDefinition();
+ fname.setFieldName("fname");
+ fname.setDataType("string");
+ fname.setMatchType(Arrays.asList(MatchTypes.EXACT, MatchTypes.FUZZY, MatchTypes.PINCODE));
+ //fname.setMatchType(Arrays.asList(MatchType.EXACT));
+ fname.setFields("fname");
+ FieldDefinition lname = new FieldDefinition();
+ lname.setFieldName("lname");
+ lname.setDataType("string");
+ lname.setMatchType(Arrays.asList(MatchTypes.FUZZY));
+ lname.setFields("lname");
+ args.setFieldDefinition(Arrays.asList(fname, lname));
- Pipe outputPipe = new SparkPipe();
- outputPipe.setName("output");
- outputPipe.setFormat(Pipe.FORMAT_CSV);
- outputPipe.setProp("path", "examples/febrl/output.csv");
- args.setOutput(new Pipe[] {outputPipe});
+ Pipe inputPipe = new SparkPipe();
+ inputPipe.setName("test");
+ inputPipe.setFormat(Pipe.FORMAT_CSV);
+ inputPipe.setProp("path", "examples/febrl/test.csv");
+ args.setData(new Pipe[]{inputPipe});
- args.setBlockSize(400L);
- args.setCollectMetrics(true);
- args.setModelId("500");
- argumentService.loadArguments("/tmp/configFromArgObject.json");
+ Pipe outputPipe = new SparkPipe();
+ outputPipe.setName("output");
+ outputPipe.setFormat(Pipe.FORMAT_CSV);
+ outputPipe.setProp("path", "examples/febrl/output.csv");
+ args.setOutput(new Pipe[]{outputPipe});
- //reload the same config file to check if deserialization is successful
- IArguments newArgs = argumentService.loadArguments("/tmp/configFromArgObject.json");
- assertEquals(newArgs.getModelId(), "500", "Model id is different");
- assertEquals(newArgs.getBlockSize(), 400L, "Block size is different");
- assertEquals(newArgs.getFieldDefinition().get(0).getFieldName(), "fname", "Field Definition[0]'s name is different");
- List expectedMatchType = Arrays.asList(MatchTypes.EXACT, MatchTypes.FUZZY, MatchTypes.PINCODE);
- assertEquals(newArgs.getFieldDefinition().get(0).getMatchType(), expectedMatchType);
- } catch (Exception | ZinggClientException e) {
- e.printStackTrace();
- }
+ args.setBlockSize(400L);
+ args.setCollectMetrics(true);
+ args.setModelId("500");
+
+ argumentService.writeArguments(path.toString(), args);
+
+ //reload the same config file to check if deserialization is successful
+ IArguments newArgs = argumentService.loadArguments(path.toString());
+ assertEquals(newArgs.getModelId(), "500", "Model id is different");
+ assertEquals(newArgs.getBlockSize(), 400L, "Block size is different");
+ assertEquals(newArgs.getFieldDefinition().get(0).getFieldName(), "fname", "Field Definition[0]'s name is different");
+ List expectedMatchType = Arrays.asList(MatchTypes.EXACT, MatchTypes.FUZZY, MatchTypes.PINCODE);
+ assertEquals(newArgs.getFieldDefinition().get(0).getMatchType(), expectedMatchType);
}
}
From db7f50ec23e2d1423c7c68b4ba7268a8f5a5ff44 Mon Sep 17 00:00:00 2001
From: Aditya Pareek <119134401+LOGANBLUE1@users.noreply.github.com>
Date: Wed, 18 Feb 2026 17:07:35 +0530
Subject: [PATCH 2/3] removed try-catch from the junits
---
.../zingg/common/client/TestArguments.java | 364 ++++++++----------
.../java/zingg/common/client/TestClient.java | 19 +-
.../zingg/common/client/TestClientOption.java | 49 +--
.../zingg/common/client/TestFieldDefUtil.java | 27 +-
.../common/client/TestFieldDefinition.java | 28 +-
.../documenter/TestDataDocumenterBase.java | 16 +-
.../documenter/TestModelDocumenterBase.java | 30 +-
.../core/executor/TestExecutorsGeneric.java | 17 +-
.../TestStopWordsRecommenderBase.java | 24 +-
.../java/zingg/spark/core/TestDocumenter.java | 41 --
.../java/zingg/spark/core/TestImageType.java | 115 ++----
11 files changed, 284 insertions(+), 446 deletions(-)
delete mode 100644 spark/core/src/test/java/zingg/spark/core/TestDocumenter.java
diff --git a/common/client/src/test/java/zingg/common/client/TestArguments.java b/common/client/src/test/java/zingg/common/client/TestArguments.java
index 353bd2a2b..3b537383e 100644
--- a/common/client/src/test/java/zingg/common/client/TestArguments.java
+++ b/common/client/src/test/java/zingg/common/client/TestArguments.java
@@ -1,8 +1,5 @@
package zingg.common.client;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
-
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
@@ -21,6 +18,8 @@
import zingg.common.client.arguments.model.IArguments;
import zingg.common.client.arguments.loader.template.EnvironmentVariableSubstitutor;
+import static org.junit.jupiter.api.Assertions.*;
+
public class TestArguments {
@@ -37,238 +36,203 @@ public TestArguments() {
}
@Test
- public void testSubstituteVariablesWithAllEnvVarSet() {
- try {
- Map env = new HashMap();
- env.put(KEY_HEADER, "true");
- env.put(KEY_FORMAT, "csv");
- env.put(KEY_MODEL_ID, "400");
-
- byte[] encoded = Files
- .readAllBytes(Paths.get(getClass().getResource("../../../testArguments/testConfigTemplate.json.env").getFile()));
- String template = new String(encoded, StandardCharsets.UTF_8);
- String substitutedJsonString = environmentVariableSubstitutor.substitute(template, env);
- IArguments arguments = argumentService.loadArguments(substitutedJsonString);
- assertEquals(arguments.getData()[0].getProps().get(KEY_HEADER), env.get(KEY_HEADER));
- assertEquals(arguments.getData()[0].getFormat(), env.get(KEY_FORMAT));
- assertEquals(arguments.getModelId(), env.get(KEY_MODEL_ID));
- } catch (IOException | ZinggClientException e) {
- fail("Unexpected exception " + e.getMessage());
- }
+ public void testSubstituteVariablesWithAllEnvVarSet() throws IOException, ZinggClientException {
+ Map env = new HashMap<>();
+ env.put(KEY_HEADER, "true");
+ env.put(KEY_FORMAT, "csv");
+ env.put(KEY_MODEL_ID, "400");
+
+ byte[] encoded = Files
+ .readAllBytes(Paths.get(getClass().getResource("../../../testArguments/testConfigTemplate.json.env").getFile()));
+ String template = new String(encoded, StandardCharsets.UTF_8);
+ String substitutedJsonString = environmentVariableSubstitutor.substitute(template, env);
+ IArguments arguments = argumentService.loadArguments(substitutedJsonString);
+ assertEquals(arguments.getData()[0].getProps().get(KEY_HEADER), env.get(KEY_HEADER));
+ assertEquals(arguments.getData()[0].getFormat(), env.get(KEY_FORMAT));
+ assertEquals(arguments.getModelId(), env.get(KEY_MODEL_ID));
}
@Test
- public void testSubstituteVariablesWithMissingEnvVar() {
- try {
- Map env = new HashMap();
- env.put(KEY_HEADER, "true");
- env.put(KEY_MODEL_ID, "400");
-
- byte[] encoded = Files
- .readAllBytes(Paths.get(getClass().getResource("../../../testArguments/testConfigTemplate.json.env").getFile()));
-
- String template = new String(encoded, StandardCharsets.UTF_8);
- String substitutedJsonString = environmentVariableSubstitutor.substitute(template, env);
- IArguments args = argumentService.loadArguments(substitutedJsonString);
- fail("Exception was expected due to missing environment variable");
- } catch (IOException | ZinggClientException e) {
- LOG.warn("Expected exception received due to missing environment variable");
- }
+ public void testSubstituteVariablesWithMissingEnvVar() throws IOException {
+
+ Map env = new HashMap<>();
+ env.put(KEY_HEADER, "true");
+ env.put(KEY_MODEL_ID, "400");
+
+ byte[] encoded = Files.readAllBytes(
+ Paths.get(getClass()
+ .getResource("../../../testArguments/testConfigTemplate.json.env")
+ .getFile())
+ );
+
+ String template = new String(encoded, StandardCharsets.UTF_8);
+
+ assertThrows(ZinggClientException.class, () -> {
+ String substitutedJsonString =
+ environmentVariableSubstitutor.substitute(template, env);
+
+ argumentService.loadArguments(substitutedJsonString);
+ });
}
+
@Test
- public void testSubstituteVariablesWithBlankEnvVar() {
- try {
- Map env = new HashMap();
- env.put(KEY_HEADER, "true");
- env.put(KEY_FORMAT, "");
- env.put(KEY_MODEL_ID, "400");
-
- byte[] encoded = Files
- .readAllBytes(Paths.get(getClass().getResource("../../../testArguments/testConfigTemplate.json.env").getFile()));
-
- String template = new String(encoded, StandardCharsets.UTF_8);
- String substitutedJsonString = environmentVariableSubstitutor.substitute(template, env);
- IArguments args = argumentService.loadArguments(substitutedJsonString);
-
- fail("Exception was expected for blank value for an environment variable");
- } catch (IOException | ZinggClientException e) {
- LOG.warn("Expected exception received due to blank value for an environment variable");
- }
+ public void testSubstituteVariablesWithBlankEnvVar() throws IOException {
+ Map env = new HashMap<>();
+ env.put(KEY_HEADER, "true");
+ env.put(KEY_FORMAT, "");
+ env.put(KEY_MODEL_ID, "400");
+
+ byte[] encoded = Files.readAllBytes(
+ Paths.get(getClass()
+ .getResource("../../../testArguments/testConfigTemplate.json.env")
+ .getFile()));
+
+ String template = new String(encoded, StandardCharsets.UTF_8);
+
+ assertThrows(ZinggClientException.class, () -> {
+ String substitutedJsonString =
+ environmentVariableSubstitutor.substitute(template, env);
+
+ argumentService.loadArguments(substitutedJsonString);
+ });
}
@Test
- public void testInvalidEnvVarBooleanType() {
- try {
-
- Map env = new HashMap();
- env.put(KEY_HEADER, "someValue");
- env.put(KEY_FORMAT, "csv");
- env.put(KEY_MODEL_ID, "400");
-
- byte[] encoded = Files
- .readAllBytes(Paths.get(getClass().getResource("../../../testArguments/testConfigTemplate.json.env").getFile()));
-
- String template = new String(encoded, StandardCharsets.UTF_8);
- String substitutedJsonString = environmentVariableSubstitutor.substitute(template, env);
- IArguments args = argumentService.loadArguments(substitutedJsonString);
-
- fail("Exception was expected for invalid value for a Boolean variable");
- } catch (IOException | ZinggClientException e) {
- LOG.warn("Expected exception received due to invalid value for a Boolean variable");
- }
+ public void testInvalidEnvVarBooleanType() throws IOException {
+// try {
+
+ Map env = new HashMap<>();
+ env.put(KEY_HEADER, "someValue");
+ env.put(KEY_FORMAT, "csv");
+ env.put(KEY_MODEL_ID, "400");
+
+ byte[] encoded = Files.readAllBytes(
+ Paths.get(getClass()
+ .getResource("../../../testArguments/testConfigTemplate.json.env")
+ .getFile()));
+
+ String template = new String(encoded, StandardCharsets.UTF_8);
+ assertThrows(ZinggClientException.class, () -> {
+ String substitutedJsonString =
+ environmentVariableSubstitutor.substitute(template, env);
+
+ argumentService.loadArguments(substitutedJsonString);
+ });
}
@Test
- public void testBooleanType() {
- try {
- Map env = new HashMap();
- env.put(KEY_HEADER, "true");
- env.put(KEY_FORMAT, "csv");
- env.put(KEY_MODEL_ID, "400");
-
- byte[] encoded = Files
- .readAllBytes(Paths.get(getClass().getResource("../../../testArguments/testConfigTemplate.json.env").getFile()));
-
- String template = new String(encoded, StandardCharsets.UTF_8);
- String substitutedJsonString = environmentVariableSubstitutor.substitute(template, env);
- IArguments args = argumentService.loadArguments(substitutedJsonString);
-
- assertEquals(args.getOutput()[0].getProps().get(KEY_HEADER), env.get(KEY_HEADER));
- } catch (IOException | ZinggClientException e) {
- fail("Exception was not expected for valid value for a Boolean variable within quotes");
-
- }
+ public void testBooleanType() throws IOException, ZinggClientException {
+ Map env = new HashMap<>();
+ env.put(KEY_HEADER, "true");
+ env.put(KEY_FORMAT, "csv");
+ env.put(KEY_MODEL_ID, "400");
+
+ byte[] encoded = Files
+ .readAllBytes(Paths.get(getClass().getResource("../../../testArguments/testConfigTemplate.json.env").getFile()));
+
+ String template = new String(encoded, StandardCharsets.UTF_8);
+ String substitutedJsonString = environmentVariableSubstitutor.substitute(template, env);
+ IArguments args = argumentService.loadArguments(substitutedJsonString);
+
+ assertEquals(args.getOutput()[0].getProps().get(KEY_HEADER), env.get(KEY_HEADER));
}
@Test
- public void testInvalidEnvVarNumericType() {
- try {
- Map env = new HashMap();
- env.put(KEY_HEADER, "true");
- env.put(KEY_FORMAT, "csv");
- env.put(KEY_MODEL_ID, "ONEHUNDRED");
-
- byte[] encoded = Files
- .readAllBytes(Paths.get(getClass().getResource("../../../testArguments/testConfigTemplate.json.env").getFile()));
-
- String template = new String(encoded, StandardCharsets.UTF_8);
- String substitutedJsonString = environmentVariableSubstitutor.substitute(template, env);
- IArguments args = argumentService.loadArguments(substitutedJsonString);
-
- fail("Exception was expected for invalid value for a Numeric variable");
- } catch (IOException | ZinggClientException e) {
- LOG.warn("Expected exception received due to invalid value for a Numeric variable");
- }
+ public void testInvalidEnvVarNumericType() throws IOException {
+ Map env = new HashMap<>();
+ env.put(KEY_HEADER, "true");
+ env.put(KEY_FORMAT, "csv");
+ env.put(KEY_MODEL_ID, "ONEHUNDRED");
+
+ byte[] encoded = Files.readAllBytes(
+ Paths.get(getClass()
+ .getResource("../../../testArguments/testConfigTemplate.json.env")
+ .getFile()));
+
+ String template = new String(encoded, StandardCharsets.UTF_8);
+ assertThrows(ZinggClientException.class, () -> {
+ String substitutedJsonString =
+ environmentVariableSubstitutor.substitute(template, env);
+
+ argumentService.loadArguments(substitutedJsonString);
+ });
}
@Test
- public void testNumericWithinQuotes() {
- try {
-
- Map env = new HashMap();
- env.put(KEY_HEADER, "true");
- env.put(KEY_FORMAT, "csv");
- env.put(KEY_MODEL_ID, "500");
-
- byte[] encoded = Files.readAllBytes(
- Paths.get(getClass().getResource("../../../testArguments/testNumericWithinQuotesTemplate.json.env").getFile()));
-
- String template = new String(encoded, StandardCharsets.UTF_8);
- String substitutedJsonString = environmentVariableSubstitutor.substitute(template, env);
- IArguments args = argumentService.loadArguments(substitutedJsonString);
- //Numeric within quotes are allowed
- assertEquals(args.getModelId(), env.get(KEY_MODEL_ID));
- } catch (IOException | ZinggClientException e) {
- fail("Unexpected exception in testNumericWithinQuotes()" + e.getMessage());
- }
+ public void testNumericWithinQuotes() throws IOException, ZinggClientException {
+ Map env = new HashMap<>();
+ env.put(KEY_HEADER, "true");
+ env.put(KEY_FORMAT, "csv");
+ env.put(KEY_MODEL_ID, "500");
+
+ byte[] encoded = Files.readAllBytes(
+ Paths.get(getClass().getResource("../../../testArguments/testNumericWithinQuotesTemplate.json.env").getFile()));
+
+ String template = new String(encoded, StandardCharsets.UTF_8);
+ String substitutedJsonString = environmentVariableSubstitutor.substitute(template, env);
+ IArguments args = argumentService.loadArguments(substitutedJsonString);
+ //Numeric within quotes are allowed
+ assertEquals(args.getModelId(), env.get(KEY_MODEL_ID));
}
@Test
- public void testMalformedVariable() {
- try {
-
- Map env = new HashMap();
- env.put(KEY_HEADER, "true");
- env.put(KEY_FORMAT, "csv");
- env.put(KEY_MODEL_ID, "500");
-
- byte[] encoded = Files.readAllBytes(
- Paths.get(getClass().getResource("../../../testArguments/testMalformedConfigTemplate.json.env").getFile()));
-
- String template = new String(encoded, StandardCharsets.UTF_8);
- String substitutedJsonString = environmentVariableSubstitutor.substitute(template, env);
- IArguments args = argumentService.loadArguments(substitutedJsonString);
-
- fail("Exception was expected for malformed variable in json");
- } catch (IOException | ZinggClientException e) {
- LOG.warn("Expected exception received due to malformed variable in json");
- }
+ public void testMalformedVariable() throws IOException {
+ Map env = new HashMap<>();
+ env.put(KEY_HEADER, "true");
+ env.put(KEY_FORMAT, "csv");
+ env.put(KEY_MODEL_ID, "500");
+
+ byte[] encoded = Files.readAllBytes(
+ Paths.get(getClass().getResource("../../../testArguments/testMalformedConfigTemplate.json.env").getFile()));
+
+ String template = new String(encoded, StandardCharsets.UTF_8);
+ assertThrows(ZinggClientException.class, () -> {
+ String substitutedJsonString =
+ environmentVariableSubstitutor.substitute(template, env);
+
+ argumentService.loadArguments(substitutedJsonString);
+ });
}
@Test
public void testInvalidFilePath() {
String filePath = "../dummyFilename";
- try {
+
+ assertThrows(ZinggClientException.class, () -> {
argumentService.loadArguments(filePath);
- fail("Exception was expected for invalid filepath or name");
- } catch (ZinggClientException e) {
- LOG.warn("Expected exception received: NoSuchFileException");
- } catch (NoSuchObjectException e) {
- throw new RuntimeException(e);
- }
- }
+ });
+ }
+
@Test
- public void testMatchTypeMultiple() {
- IArguments args;
- try {
- args = argumentService.loadArguments(getClass().getResource("../../../testArguments/configWithMultipleMatchTypes.json").getFile());
- List extends IMatchType> fNameMatchType = args.getFieldDefinition().get(0).getMatchType();
- assertEquals(2, fNameMatchType.size());
- assertEquals(MatchTypes.FUZZY, fNameMatchType.get(0));
- assertEquals(MatchTypes.NULL_OR_BLANK, fNameMatchType.get(1));
-
-
- } catch (Exception | ZinggClientException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- fail("Could not read config");
- }
-
+ public void testMatchTypeMultiple() throws ZinggClientException, NoSuchObjectException {
+ IArguments args = argumentService.loadArguments(getClass().getResource("../../../testArguments/configWithMultipleMatchTypes.json").getFile());
+ List extends IMatchType> fNameMatchType = args.getFieldDefinition().get(0).getMatchType();
+ assertEquals(2, fNameMatchType.size());
+ assertEquals(MatchTypes.FUZZY, fNameMatchType.get(0));
+ assertEquals(MatchTypes.NULL_OR_BLANK, fNameMatchType.get(1));
}
@Test
- public void testMatchTypeWrong() {
- IArguments args;
- try {
- args = argumentService.loadArguments(getClass().getResource("../../../testArguments/configWithMultipleMatchTypesUnsupported.json").getFile());
- } catch (Exception | ZinggClientException e) {
- LOG.info("config had error, should have flagged");
- }
+ public void testMatchTypeWrong() throws NoSuchObjectException, ZinggClientException {
+ IArguments args = argumentService.loadArguments(getClass().getResource("../../../testArguments/configWithMultipleMatchTypesUnsupported.json").getFile());
}
@Test
- public void testJsonStringify(){
- IArguments argsFromJsonFile;
- try{
- argsFromJsonFile = argumentService.loadArguments(getClass().getResource("../../../testArguments/configWithMultipleMatchTypes.json").getFile());
- String strFromJsonFile = argsFromJsonFile.toString();
-
- IArguments argsFullCycle = argumentService.loadArguments(strFromJsonFile);
-
- assertEquals(argsFullCycle.getFieldDefinition().get(0).getName(), argsFromJsonFile.getFieldDefinition().get(0).getName());
- assertEquals(argsFullCycle.getFieldDefinition().get(2).getName(), argsFromJsonFile.getFieldDefinition().get(2).getName());
- assertEquals(argsFullCycle.getModelId(), argsFromJsonFile.getModelId());
- assertEquals(argsFullCycle.getNumPartitions(), argsFromJsonFile.getNumPartitions());
- assertEquals(argsFullCycle.getLabelDataSampleSize() ,argsFromJsonFile.getLabelDataSampleSize());
- assertEquals(argsFullCycle.getZinggDir(),argsFromJsonFile.getZinggDir());
- assertEquals(argsFullCycle.getJobId(),argsFromJsonFile.getJobId());
-
- } catch (Exception | ZinggClientException e) {
- LOG.error("Error occurred while running tests " + e.getMessage());
- }
-
+ public void testJsonStringify() throws NoSuchObjectException, ZinggClientException {
+ IArguments argsFromJsonFile = argumentService.loadArguments(getClass().getResource("../../../testArguments/configWithMultipleMatchTypes.json").getFile());
+ String strFromJsonFile = argsFromJsonFile.toString();
+
+ IArguments argsFullCycle = argumentService.loadArguments(strFromJsonFile);
+
+ assertEquals(argsFullCycle.getFieldDefinition().get(0).getName(), argsFromJsonFile.getFieldDefinition().get(0).getName());
+ assertEquals(argsFullCycle.getFieldDefinition().get(2).getName(), argsFromJsonFile.getFieldDefinition().get(2).getName());
+ assertEquals(argsFullCycle.getModelId(), argsFromJsonFile.getModelId());
+ assertEquals(argsFullCycle.getNumPartitions(), argsFromJsonFile.getNumPartitions());
+ assertEquals(argsFullCycle.getLabelDataSampleSize() ,argsFromJsonFile.getLabelDataSampleSize());
+ assertEquals(argsFullCycle.getZinggDir(),argsFromJsonFile.getZinggDir());
+ assertEquals(argsFullCycle.getJobId(),argsFromJsonFile.getJobId());
}
}
diff --git a/common/client/src/test/java/zingg/common/client/TestClient.java b/common/client/src/test/java/zingg/common/client/TestClient.java
index 5a3befd85..5b6553da5 100644
--- a/common/client/src/test/java/zingg/common/client/TestClient.java
+++ b/common/client/src/test/java/zingg/common/client/TestClient.java
@@ -1,5 +1,6 @@
package zingg.common.client;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;
import org.apache.commons.logging.Log;
@@ -12,25 +13,19 @@ public class TestClient {
public static final Log LOG = LogFactory.getLog(TestClient.class);
@Test
- public void testValidPhase() {
+ public void testValidPhase() throws ZinggClientException {
String phase = "train";
- try {
- ZinggOptions.verifyPhase(phase);
- } catch (ZinggClientException e1) {
- fail("No exception was expected as it is a valid phase: " + phase);
- }
+ ZinggOptions.verifyPhase(phase);
}
@Test
public void testInvalidPhase() {
String phase = "tain";
- try {
+
+ assertThrows(ZinggClientException.class, () -> {
ZinggOptions.verifyPhase(phase);
- fail("An exception should have been thrown for an invalid phase");
- } catch (ZinggClientException e1) {
- LOG.info("Expected exception as it is an invalid phase: " + phase);
- }
+ });
}
-
+
}
\ No newline at end of file
diff --git a/common/client/src/test/java/zingg/common/client/TestClientOption.java b/common/client/src/test/java/zingg/common/client/TestClientOption.java
index afe48176d..bc974e6a1 100644
--- a/common/client/src/test/java/zingg/common/client/TestClientOption.java
+++ b/common/client/src/test/java/zingg/common/client/TestClientOption.java
@@ -1,12 +1,9 @@
package zingg.common.client;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
-
import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.*;
+
public class TestClientOption {
@@ -27,34 +24,28 @@ public void testParseArguments() {
@Test
public void testParseUnsupportedArgumentsConf() {
- try {
- String[] args = {"--phase", "train",
- "--conf1", "conf.json",
- "--zinggDir", "/tmp/z_main",
- "--email", "zingg@zingg.ai",
- "--license", "zinggLicense.txt"};
-
- ClientOptions co = new ClientOptions(args);
- fail("exception should have been raised due to invalid conf option");
- } catch (Exception e) {
- assertTrue(true);
- }
+ String[] args = {"--phase", "train",
+ "--conf1", "conf.json",
+ "--zinggDir", "/tmp/z_main",
+ "--email", "zingg@zingg.ai",
+ "--license", "zinggLicense.txt"};
+
+ assertThrows(UnsupportedOperationException.class, () -> {
+ new ClientOptions(args);
+ });
}
@Test
public void testParseUnsupportedArgumentsPhase() {
- try {
- String[] args = {"--phase1", "train",
- "--conf1", "conf.json",
- "--zinggDir", "/tmp/z_main",
- "--email", "zingg@zingg.ai",
- "--license", "zinggLicense.txt"};
-
- ClientOptions co = new ClientOptions(args);
- fail("exception should have been raised due to invalid phase option");
- } catch (Exception e) {
- assertTrue(true);
- }
+ String[] args = {"--phase1", "train",
+ "--conf1", "conf.json",
+ "--zinggDir", "/tmp/z_main",
+ "--email", "zingg@zingg.ai",
+ "--license", "zinggLicense.txt"};
+
+ assertThrows(UnsupportedOperationException.class, () -> {
+ new ClientOptions(args);
+ });
}
diff --git a/common/client/src/test/java/zingg/common/client/TestFieldDefUtil.java b/common/client/src/test/java/zingg/common/client/TestFieldDefUtil.java
index 43fa691e2..94959d028 100644
--- a/common/client/src/test/java/zingg/common/client/TestFieldDefUtil.java
+++ b/common/client/src/test/java/zingg/common/client/TestFieldDefUtil.java
@@ -3,6 +3,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
+import java.rmi.NoSuchObjectException;
import java.util.List;
import org.apache.commons.logging.Log;
@@ -27,23 +28,13 @@ public TestFieldDefUtil() {
@Test
- public void testMatchTypeFilter() {
- IArguments args;
- try {
- args = argumentService.loadArguments(getClass().getResource("../../../testArguments/configTestDontUse.json").getFile());
- List extends FieldDefinition> dontUseList = fieldDefUtil.getFieldDefinitionDontUse(args.getFieldDefinition());
- assertEquals(dontUseList.size(), 3);
-
- List extends FieldDefinition> matchList = fieldDefUtil.getFieldDefinitionToUse(args.getFieldDefinition());
- assertEquals(matchList.size(), 4);
-
- } catch (Exception | ZinggClientException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- fail("Could not read config");
- }
-
+ public void testMatchTypeFilter() throws NoSuchObjectException, ZinggClientException {
+ IArguments args = argumentService.loadArguments(getClass().getResource("../../../testArguments/configTestDontUse.json").getFile());
+ List extends FieldDefinition> dontUseList = fieldDefUtil.getFieldDefinitionDontUse(args.getFieldDefinition());
+ assertEquals(dontUseList.size(), 3);
+
+ List extends FieldDefinition> matchList = fieldDefUtil.getFieldDefinitionToUse(args.getFieldDefinition());
+ assertEquals(matchList.size(), 4);
}
-
-
+
}
diff --git a/common/client/src/test/java/zingg/common/client/TestFieldDefinition.java b/common/client/src/test/java/zingg/common/client/TestFieldDefinition.java
index fa009097e..d2bc7935a 100644
--- a/common/client/src/test/java/zingg/common/client/TestFieldDefinition.java
+++ b/common/client/src/test/java/zingg/common/client/TestFieldDefinition.java
@@ -13,26 +13,18 @@ public class TestFieldDefinition {
public static final Log LOG = LogFactory.getLog(TestFieldDefinition.class);
@Test
- public void testConvertAListOFMatchTypesIntoString() {
- try {
- List matchType = Arrays.asList(MatchTypes.EMAIL, MatchTypes.FUZZY, MatchTypes.NULL_OR_BLANK);
- String expectedString = "EMAIL,FUZZY,NULL_OR_BLANK";
- String strMatchType = FieldDefinition.MatchTypeSerializer.getStringFromMatchType(matchType);
- assertEquals(expectedString, strMatchType);
- } catch (Exception | ZinggClientException e) {
- e.printStackTrace();
- }
+ public void testConvertAListOFMatchTypesIntoString() throws ZinggClientException {
+ List matchType = Arrays.asList(MatchTypes.EMAIL, MatchTypes.FUZZY, MatchTypes.NULL_OR_BLANK);
+ String expectedString = "EMAIL,FUZZY,NULL_OR_BLANK";
+ String strMatchType = FieldDefinition.MatchTypeSerializer.getStringFromMatchType(matchType);
+ assertEquals(expectedString, strMatchType);
}
@Test
- public void testConvertAListOFStringIntoMatchTypes() {
- try{
- String mtString = "FUZZY,NULL_OR_BLANK";
- List expectedString = Arrays.asList(MatchTypes.FUZZY, MatchTypes.NULL_OR_BLANK);
- List matchTypeString = FieldDefinition.MatchTypeDeserializer.getMatchTypeFromString(mtString);
- assertEquals(expectedString, matchTypeString);
- } catch (Exception | ZinggClientException e) {
- e.printStackTrace();
- }
+ public void testConvertAListOFStringIntoMatchTypes() throws ZinggClientException, Exception {
+ String mtString = "FUZZY,NULL_OR_BLANK";
+ List expectedString = Arrays.asList(MatchTypes.FUZZY, MatchTypes.NULL_OR_BLANK);
+ List matchTypeString = FieldDefinition.MatchTypeDeserializer.getMatchTypeFromString(mtString);
+ assertEquals(expectedString, matchTypeString);
}
}
diff --git a/common/core/src/test/java/zingg/common/core/documenter/TestDataDocumenterBase.java b/common/core/src/test/java/zingg/common/core/documenter/TestDataDocumenterBase.java
index cfd722597..9b5ec97ec 100644
--- a/common/core/src/test/java/zingg/common/core/documenter/TestDataDocumenterBase.java
+++ b/common/core/src/test/java/zingg/common/core/documenter/TestDataDocumenterBase.java
@@ -2,8 +2,8 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
+import java.rmi.NoSuchObjectException;
import java.util.Map;
import org.apache.commons.logging.Log;
@@ -38,16 +38,10 @@ public void initialize(Context context) throws ZinggClientExcepti
protected abstract DataDocumenter getDataDocumenter(IContext context, IArguments args, ClientOptions options);
@BeforeEach
- public void setUp(){
- try {
- String configPath = getClass().getResource("../../../../documenter/config.json").getFile();
- IArgumentService argsUtil = new ArgumentServiceImpl<>(Arguments.class);
- docArguments = argsUtil.loadArguments(configPath);
- } catch (Throwable e) {
- e.printStackTrace();
- LOG.info("Unexpected exception received " + e.getMessage());
- fail(e.getMessage());
- }
+ public void setUp() throws NoSuchObjectException, ZinggClientException {
+ String configPath = getClass().getResource("../../../../documenter/config.json").getFile();
+ IArgumentService argsUtil = new ArgumentServiceImpl<>(Arguments.class);
+ docArguments = argsUtil.loadArguments(configPath);
}
@Test
diff --git a/common/core/src/test/java/zingg/common/core/documenter/TestModelDocumenterBase.java b/common/core/src/test/java/zingg/common/core/documenter/TestModelDocumenterBase.java
index c443ba299..8a7ccba55 100644
--- a/common/core/src/test/java/zingg/common/core/documenter/TestModelDocumenterBase.java
+++ b/common/core/src/test/java/zingg/common/core/documenter/TestModelDocumenterBase.java
@@ -7,6 +7,7 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
+import java.rmi.NoSuchObjectException;
import java.util.Collections;
import java.util.Map;
@@ -41,30 +42,21 @@ public void initialize(Context context) throws ZinggClientExcepti
}
@BeforeEach
- public void setUp(){
-
- try {
- String configPath = getClass().getResource("../../../../documenter/config.json").getFile();
- IArgumentService argsUtil = new ArgumentServiceImpl<>(Arguments.class);
- docArguments = argsUtil.loadArguments(configPath);
- String zinggDirPath = getClass().getResource("../../../../"+docArguments.getZinggDir()).getFile();
- docArguments.setZinggDir(zinggDirPath);
- } catch (Throwable e) {
- e.printStackTrace();
- LOG.info("Unexpected exception received " + e.getMessage());
- fail(e.getMessage());
- }
+ public void setUp() throws NoSuchObjectException, ZinggClientException {
+ String configPath = getClass().getResource("../../../../documenter/config.json").getFile();
+ IArgumentService argsUtil = new ArgumentServiceImpl<>(Arguments.class);
+ docArguments = argsUtil.loadArguments(configPath);
+ String zinggDirPath = getClass().getResource("../../../../"+docArguments.getZinggDir()).getFile();
+ docArguments.setZinggDir(zinggDirPath);
}
@Test
- public void testIfModelDocumenterGeneratedDocFile() throws Throwable {
+ public void testIfModelDocumenterGeneratedDocFile() throws IOException, ZinggClientException {
ModelDocumenter modelDoc = getModelDocumenter(context, docArguments, new ClientOptions());
- try {
- Files.deleteIfExists(Paths.get(modelDoc.getModelHelper().getZinggModelDocFile(docArguments)));
- } catch (IOException e) {
- e.printStackTrace();
- }
+
+ Files.deleteIfExists(Paths.get(modelDoc.getModelHelper().getZinggModelDocFile(docArguments)));
+
modelDoc.createModelDocument();
assertTrue(Files.exists(Paths.get(modelDoc.getModelHelper().getZinggModelDocFile(docArguments))), "Model documentation file is not generated");
diff --git a/common/core/src/test/java/zingg/common/core/executor/TestExecutorsGeneric.java b/common/core/src/test/java/zingg/common/core/executor/TestExecutorsGeneric.java
index f11619fc0..430d40146 100644
--- a/common/core/src/test/java/zingg/common/core/executor/TestExecutorsGeneric.java
+++ b/common/core/src/test/java/zingg/common/core/executor/TestExecutorsGeneric.java
@@ -38,18 +38,13 @@ public void init(S s) throws ZinggClientException, IOException {
//public abstract void tearDown();
@Test
- public void testExecutors() throws ZinggClientException {
- try {
- List> executorTesterList = getExecutors();
- for (ExecutorTester executorTester : executorTesterList) {
- executorTester.setupArgs();
- executorTester.initAndExecute(session);
- executorTester.validateResults();
- }
- } catch (Exception e) {
- throw new ZinggClientException("Exception occurred while running one or more test executors, ", e);
+ public void testExecutors() throws ZinggClientException, IOException, NoSuchMethodException {
+ List> executorTesterList = getExecutors();
+ for (ExecutorTester executorTester : executorTesterList) {
+ executorTester.setupArgs();
+ executorTester.initAndExecute(session);
+ executorTester.validateResults();
}
-
}
//model id getter
diff --git a/common/core/src/test/java/zingg/common/core/recommender/TestStopWordsRecommenderBase.java b/common/core/src/test/java/zingg/common/core/recommender/TestStopWordsRecommenderBase.java
index 41799dc14..f7cc3a97e 100644
--- a/common/core/src/test/java/zingg/common/core/recommender/TestStopWordsRecommenderBase.java
+++ b/common/core/src/test/java/zingg/common/core/recommender/TestStopWordsRecommenderBase.java
@@ -1,9 +1,5 @@
package zingg.common.core.recommender;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
-
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -22,6 +18,8 @@
import zingg.common.core.recommender.model.Records;
import zingg.common.core.recommender.model.WordByCount;
+import static org.junit.jupiter.api.Assertions.*;
+
public abstract class TestStopWordsRecommenderBase {
public static final Log LOG = LogFactory.getLog(TestStopWordsRecommenderBase.class);
@@ -43,17 +41,15 @@ public void initialize(DFObjectUtil dfObjectUtil, Context
this.recommender = getRecommender(context,arguments);
}
- @Test
- public void testWithNegativefCuttoff() throws Throwable{
- try {
- LOG.info("Test with stopCutoff = -1");
- stopwordList = getStopWordList(-1.0f);
- fail("Exception should not have been thrown when stopCutoff is negative");
- }
- catch(ZinggClientException e) {
- }
+ @Test
+ public void testWithNegativeCutoff() {
+
+ LOG.info("Test with stopCutoff = -1");
- }
+ assertThrows(ZinggClientException.class, () -> {
+ getStopWordList(-1.0f);
+ });
+ }
@Test
public void testWithCuttoffOne() throws Throwable {
diff --git a/spark/core/src/test/java/zingg/spark/core/TestDocumenter.java b/spark/core/src/test/java/zingg/spark/core/TestDocumenter.java
deleted file mode 100644
index f07b26945..000000000
--- a/spark/core/src/test/java/zingg/spark/core/TestDocumenter.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package zingg.spark.core;
-import static org.junit.jupiter.api.Assertions.fail;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.junit.jupiter.api.BeforeEach;
-
-import zingg.common.client.arguments.ArgumentServiceImpl;
-import zingg.common.client.arguments.IArgumentService;
-import zingg.common.client.arguments.model.IArguments;
-import zingg.common.client.arguments.model.Arguments;
-
-public class TestDocumenter {
-
- public static final Log LOG = LogFactory.getLog(TestDocumenter.class);
-
- @BeforeEach
- public void setUp(){
- try {
- IArgumentService argumentService = new ArgumentServiceImpl<>(Arguments.class);
- IArguments args = argumentService.loadArguments(getClass().getResource("/testDocumenter/config.json").getFile());
- //fail("Exception was expected for missing config file");
- } catch (Throwable e) {
- if(LOG.isDebugEnabled()) {
- e.printStackTrace();
- }
- LOG.info("Unexpected exception received " + e.getMessage());
- fail(e.getMessage());
- }
- }
-
- /*
- @Test
- public void testOutput() throws Throwable{
- Documenter doc = new Documenter();
- doc.init(args, "");
- doc.setArgs(args);
- doc.execute();
- }
- */
-}
diff --git a/spark/core/src/test/java/zingg/spark/core/TestImageType.java b/spark/core/src/test/java/zingg/spark/core/TestImageType.java
index 140a43288..f60faf0fd 100644
--- a/spark/core/src/test/java/zingg/spark/core/TestImageType.java
+++ b/spark/core/src/test/java/zingg/spark/core/TestImageType.java
@@ -1,12 +1,12 @@
package zingg.spark.core;
import static org.apache.spark.sql.functions.callUDF;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.*;
import java.util.Arrays;
+import org.apache.spark.SparkException;
+import org.apache.spark.SparkException$;
import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.RowFactory;
@@ -89,85 +89,59 @@ public void testCosine() {
@Test
public void testUDFArray() {
-
- try {
- // create a DF with double array as a column
- Dataset df = createSampleDataset();
- df.show();
- // check the schema of DF
- df.printSchema();
- // register ArrayDoubleSimilarityFunction as a UDF
- TestUDFDoubleArr testUDFDoubleArr = new TestUDFDoubleArr();
- SparkFnRegistrar.registerUDF2(sparkSession, "testUDFDoubleArr", testUDFDoubleArr, DataTypes.DoubleType);
- // call the UDF from select clause of DF
- df = df.withColumn("cosine",
- callUDF("testUDFDoubleArr", df.col("image_embedding"), df.col("image_embedding")));
- // see if error is reproduced
- df.show();
- fail("exception expected");
- } catch (Exception e) {
- //e.printStackTrace();
- }
-
-
+ // create a DF with double array as a column
+ Dataset df = createSampleDataset();
+ df.show();
+ // check the schema of DF
+ df.printSchema();
+ // register ArrayDoubleSimilarityFunction as a UDF
+ TestUDFDoubleArr testUDFDoubleArr = new TestUDFDoubleArr();
+ SparkFnRegistrar.registerUDF2(sparkSession, "testUDFDoubleArr", testUDFDoubleArr, DataTypes.DoubleType);
+ // call the UDF from select clause of DF
+ df = df.withColumn("cosine",
+ callUDF("testUDFDoubleArr", df.col("image_embedding"), df.col("image_embedding")));
+ // see if error is reproduced
+ assertThrows(SparkException.class, df::show);
}
@Test
public void testUDFList() {
-
- try {
- // create a DF with double array as a column
- Dataset df = createSampleDataset();
- df.show();
- // check the schema of DF
- df.printSchema();
-
- // register ArrayDoubleSimilarityFunction as a UDF
- TestUDFDoubleList testUDFDoubleList = new TestUDFDoubleList();
- SparkFnRegistrar.registerUDF2(sparkSession, "testUDFDoubleList", testUDFDoubleList, DataTypes.DoubleType);
+ // create a DF with double array as a column
+ Dataset df = createSampleDataset();
+ df.show();
+ // check the schema of DF
+ df.printSchema();
- // call the UDF from select clause of DF
- df = df.withColumn("cosine", callUDF("testUDFDoubleList",df.col("image_embedding"),df.col("image_embedding")));
- // see if error is reproduced
- df.show();
- fail("exception expected");
- } catch (Exception e) {
- //e.printStackTrace();
- }
-
-
+ // register ArrayDoubleSimilarityFunction as a UDF
+ TestUDFDoubleList testUDFDoubleList = new TestUDFDoubleList();
+ SparkFnRegistrar.registerUDF2(sparkSession, "testUDFDoubleList", testUDFDoubleList, DataTypes.DoubleType);
+
+ // call the UDF from select clause of DF
+ df = df.withColumn("cosine", callUDF("testUDFDoubleList",df.col("image_embedding"),df.col("image_embedding")));
+ // see if error is reproduced
+ assertThrows(SparkException.class, df::show);
}
@Test
public void testUDFSeq() {
-
- try {
- // create a DF with double array as a column
- Dataset df = createSampleDataset();
- df.show();
- // check the schema of DF
- df.printSchema();
-
- // register ArrayDoubleSimilarityFunction as a UDF
- TestUDFDoubleSeq testUDFDoubleSeq = new TestUDFDoubleSeq();
- SparkFnRegistrar.registerUDF2(sparkSession, "testUDFDoubleSeq", testUDFDoubleSeq, DataTypes.DoubleType);
+ // create a DF with double array as a column
+ Dataset df = createSampleDataset();
+ df.show();
+ // check the schema of DF
+ df.printSchema();
- // call the UDF from select clause of DF
- df = df.withColumn("cosine", callUDF("testUDFDoubleSeq",df.col("image_embedding"),df.col("image_embedding")));
- // see if error is reproduced
- df.show();
- fail("exception expected");
- } catch (Exception e) {
- //e.printStackTrace();
- }
-
-
-
+ // register ArrayDoubleSimilarityFunction as a UDF
+ TestUDFDoubleSeq testUDFDoubleSeq = new TestUDFDoubleSeq();
+ SparkFnRegistrar.registerUDF2(sparkSession, "testUDFDoubleSeq", testUDFDoubleSeq, DataTypes.DoubleType);
+
+ // call the UDF from select clause of DF
+ df = df.withColumn("cosine", callUDF("testUDFDoubleSeq",df.col("image_embedding"),df.col("image_embedding")));
+ // see if error is reproduced
+ assertThrows(SparkException.class, df::show);
}
@Test
public void testUDFWrappedArr() {
-
// create a DF with double array as a column
Dataset df = createSampleDataset();
df.show();
@@ -190,13 +164,10 @@ public void testUDFWrappedArr() {
System.out.println("cos diff "+diff+ " "+cos.getClass());
assertTrue(Math.abs(diff) df = createSampleDataset();
df.show();
@@ -217,8 +188,6 @@ public void testUDFObj() {
Double cos = (Double)r.getAs("cosine");
assertEquals(0.3, cos);
System.out.println(""+cos+ " "+cos.getClass());
-
-
}
From 5338d43dfe68610521138e69c5070104b3d57fe5 Mon Sep 17 00:00:00 2001
From: Aditya Pareek <119134401+LOGANBLUE1@users.noreply.github.com>
Date: Wed, 18 Feb 2026 17:12:08 +0530
Subject: [PATCH 3/3] reverted changes
---
.../writer/JsonStringArgumentsWriter.java | 8 +-
.../zingg/spark/client/TestArguments.java | 80 +++++++++----------
2 files changed, 41 insertions(+), 47 deletions(-)
diff --git a/common/client/src/main/java/zingg/common/client/arguments/writer/JsonStringArgumentsWriter.java b/common/client/src/main/java/zingg/common/client/arguments/writer/JsonStringArgumentsWriter.java
index 3f4beb491..a135e0631 100644
--- a/common/client/src/main/java/zingg/common/client/arguments/writer/JsonStringArgumentsWriter.java
+++ b/common/client/src/main/java/zingg/common/client/arguments/writer/JsonStringArgumentsWriter.java
@@ -3,16 +3,14 @@
import zingg.common.client.arguments.model.IZArgs;
import zingg.common.client.ZinggClientException;
-import java.nio.file.Paths;
-
public class JsonStringArgumentsWriter extends ArgumentsWriter {
@Override
- public void write(String path, IZArgs args) throws ZinggClientException {
+ public void write(String sink, IZArgs args) throws ZinggClientException {
try {
- objectMapper.writeValue(Paths.get(path).toFile(), args);
+ sink = objectMapper.writeValueAsString(args);
} catch (Exception exception) {
- throw new ZinggClientException("Error writing config to jsonfile", exception);
+ throw new ZinggClientException("Error writing config to string", exception);
}
}
}
diff --git a/spark/client/src/test/java/zingg/spark/client/TestArguments.java b/spark/client/src/test/java/zingg/spark/client/TestArguments.java
index be5bdfa85..57721f64e 100644
--- a/spark/client/src/test/java/zingg/spark/client/TestArguments.java
+++ b/spark/client/src/test/java/zingg/spark/client/TestArguments.java
@@ -2,8 +2,6 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
-import java.nio.file.Path;
-import java.rmi.NoSuchObjectException;
import java.util.Arrays;
import java.util.List;
@@ -11,7 +9,6 @@
import org.apache.commons.logging.LogFactory;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.io.TempDir;
import zingg.common.client.arguments.ArgumentServiceImpl;
import zingg.common.client.arguments.IArgumentService;
import zingg.common.client.arguments.loader.LoaderFactory;
@@ -26,8 +23,6 @@
import zingg.spark.client.pipe.SparkPipe;
public class TestArguments {
- @TempDir
- Path tempDir;
public static final Log LOG = LogFactory.getLog(TestArguments.class);
protected final IArgumentService argumentService;
@@ -36,47 +31,48 @@ public TestArguments() {
this.argumentService = new ArgumentServiceImpl<>(Arguments.class, new LoaderFactory<>(),new WriterFactory<>());
}
@Test
- public void testWriteArgumentObjectToJSONFile() throws ZinggClientException, NoSuchObjectException {
+ public void testWriteArgumentObjectToJSONFile() {
IArguments args = new Arguments();
- Path path = tempDir.resolve("configFromArgObject.json");
+ try {
+ FieldDefinition fname = new FieldDefinition();
+ fname.setFieldName("fname");
+ fname.setDataType("string");
+ fname.setMatchType(Arrays.asList(MatchTypes.EXACT, MatchTypes.FUZZY, MatchTypes.PINCODE));
+ //fname.setMatchType(Arrays.asList(MatchType.EXACT));
+ fname.setFields("fname");
+ FieldDefinition lname = new FieldDefinition();
+ lname.setFieldName("lname");
+ lname.setDataType("string");
+ lname.setMatchType(Arrays.asList(MatchTypes.FUZZY));
+ lname.setFields("lname");
+ args.setFieldDefinition(Arrays.asList(fname, lname));
- FieldDefinition fname = new FieldDefinition();
- fname.setFieldName("fname");
- fname.setDataType("string");
- fname.setMatchType(Arrays.asList(MatchTypes.EXACT, MatchTypes.FUZZY, MatchTypes.PINCODE));
- //fname.setMatchType(Arrays.asList(MatchType.EXACT));
- fname.setFields("fname");
- FieldDefinition lname = new FieldDefinition();
- lname.setFieldName("lname");
- lname.setDataType("string");
- lname.setMatchType(Arrays.asList(MatchTypes.FUZZY));
- lname.setFields("lname");
- args.setFieldDefinition(Arrays.asList(fname, lname));
+ Pipe inputPipe = new SparkPipe();
+ inputPipe.setName("test");
+ inputPipe.setFormat(Pipe.FORMAT_CSV);
+ inputPipe.setProp("path", "examples/febrl/test.csv");
+ args.setData(new Pipe[] {inputPipe});
- Pipe inputPipe = new SparkPipe();
- inputPipe.setName("test");
- inputPipe.setFormat(Pipe.FORMAT_CSV);
- inputPipe.setProp("path", "examples/febrl/test.csv");
- args.setData(new Pipe[]{inputPipe});
+ Pipe outputPipe = new SparkPipe();
+ outputPipe.setName("output");
+ outputPipe.setFormat(Pipe.FORMAT_CSV);
+ outputPipe.setProp("path", "examples/febrl/output.csv");
+ args.setOutput(new Pipe[] {outputPipe});
- Pipe outputPipe = new SparkPipe();
- outputPipe.setName("output");
- outputPipe.setFormat(Pipe.FORMAT_CSV);
- outputPipe.setProp("path", "examples/febrl/output.csv");
- args.setOutput(new Pipe[]{outputPipe});
+ args.setBlockSize(400L);
+ args.setCollectMetrics(true);
+ args.setModelId("500");
+ argumentService.loadArguments("/tmp/configFromArgObject.json");
- args.setBlockSize(400L);
- args.setCollectMetrics(true);
- args.setModelId("500");
-
- argumentService.writeArguments(path.toString(), args);
-
- //reload the same config file to check if deserialization is successful
- IArguments newArgs = argumentService.loadArguments(path.toString());
- assertEquals(newArgs.getModelId(), "500", "Model id is different");
- assertEquals(newArgs.getBlockSize(), 400L, "Block size is different");
- assertEquals(newArgs.getFieldDefinition().get(0).getFieldName(), "fname", "Field Definition[0]'s name is different");
- List expectedMatchType = Arrays.asList(MatchTypes.EXACT, MatchTypes.FUZZY, MatchTypes.PINCODE);
- assertEquals(newArgs.getFieldDefinition().get(0).getMatchType(), expectedMatchType);
+ //reload the same config file to check if deserialization is successful
+ IArguments newArgs = argumentService.loadArguments("/tmp/configFromArgObject.json");
+ assertEquals(newArgs.getModelId(), "500", "Model id is different");
+ assertEquals(newArgs.getBlockSize(), 400L, "Block size is different");
+ assertEquals(newArgs.getFieldDefinition().get(0).getFieldName(), "fname", "Field Definition[0]'s name is different");
+ List expectedMatchType = Arrays.asList(MatchTypes.EXACT, MatchTypes.FUZZY, MatchTypes.PINCODE);
+ assertEquals(newArgs.getFieldDefinition().get(0).getMatchType(), expectedMatchType);
+ } catch (Exception | ZinggClientException e) {
+ e.printStackTrace();
+ }
}
}