Skip to content

Commit

Permalink
Added tests for
Browse files Browse the repository at this point in the history
  • Loading branch information
tomuben committed Jul 25, 2024
1 parent 8108f71 commit deeab99
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 1 deletion.
57 changes: 57 additions & 0 deletions exaudfclient/base/exaudflib/test/script_option_lines_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,60 @@ TEST(ScriptOptionLinesTest, ignores_any_other_option) {
EXPECT_EQ(code, original_code);
}


TEST(ScriptOptionLinesTest, test_all_in_one_line_does_second_option_does_not_work) {
/**
Verify the wrong behavior and assumptions as described in https://github.com/exasol/script-languages-release/issues/652.
Here we call `extractOptionLine()` with the keys in the order of the new implementation (first for key 'jvmoption').
This is supposed to not work.
*/
size_t pos;
const std::string original_code = "%jar /buckets/bucketfs1/jars/exajdbc.jar; %jvmoption -Xms4m; class JAVA_UDF_3 {static void run(ExaMetadata exa, ExaIterator ctx) throws Exception {String host_name = ctx.getString(\"col1\");}}\n/\n;";
std::string code = original_code;
const std::string res = extractOptionLine(code, "%jvmoption", whitespace, lineEnd, pos, throwException);
EXPECT_TRUE(res.empty());
EXPECT_EQ(code, original_code);
}

TEST(ScriptOptionLinesTest, test_all_in_one_line_does_first_option_does_work) {
/**
Verify the wrong behavior and assumptions as described in https://github.com/exasol/script-languages-release/issues/652.
Here we call `extractOptionLine()` with the keys in the order of the old implementation (first for key '%jar', then for key 'jvmoption').
This is supposed to work.
*/
size_t pos;
const std::string original_code = "%jar /buckets/bucketfs1/jars/exajdbc.jar; %jvmoption -Xms4m; class JAVA_UDF_3 {static void run(ExaMetadata exa, ExaIterator ctx) throws Exception {String host_name = ctx.getString(\"col1\");}}\n/\n;";
std::string code = original_code;
std::string res = extractOptionLine(code, "%jar", whitespace, lineEnd, pos, throwException);
EXPECT_EQ(res, "/buckets/bucketfs1/jars/exajdbc.jar");
EXPECT_EQ(code, " %jvmoption -Xms4m; class JAVA_UDF_3 {static void run(ExaMetadata exa, ExaIterator ctx) throws Exception {String host_name = ctx.getString(\"col1\");}}\n/\n;");
res = extractOptionLine(code, "%jvmoption", whitespace, lineEnd, pos, throwException);
EXPECT_EQ(code, " class JAVA_UDF_3 {static void run(ExaMetadata exa, ExaIterator ctx) throws Exception {String host_name = ctx.getString(\"col1\");}}\n/\n;");
}

TEST(ScriptOptionLinesTest, test_values_must_not_contain_spaces) {
/**
Verify the wrong behavior and assumptions as described in https://github.com/exasol/script-languages-release/issues/878
The parser is actually correct, but the client code incorrectly parses the result (see javacontainer_test.cc - quoted_jvm_option)
*/
size_t pos;
const std::string original_code =
"%jvmoption -Dhttp.agent=\"ABC DEF\";\n\n"
"class JVMOPTION_TEST_WITH_SPACE {\n"
"static void run(ExaMetadata exa, ExaIterator ctx) throws Exception {\n\n"
" ctx.emit(\"Success!\");\n"
" }\n"
"}\n";
std::string code = original_code;
std::string res = extractOptionLine(code, "%jvmoption", whitespace, lineEnd, pos, throwException);
EXPECT_EQ(res, "-Dhttp.agent=\"ABC DEF\"");
const std::string expected_result_code =
"\n\n"
"class JVMOPTION_TEST_WITH_SPACE {\n"
"static void run(ExaMetadata exa, ExaIterator ctx) throws Exception {\n\n"
" ctx.emit(\"Success!\");\n"
" }\n"
"}\n";
EXPECT_EQ(code, expected_result_code);
}

30 changes: 29 additions & 1 deletion exaudfclient/base/javacontainer/test/cpp/javacontainer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,32 @@ TEST(JavaContainer, combined_inline_jar) {
}



TEST(JavaContainer, quoted_jvm_option) {
const std::string script_code =
"%jvmoption -Dhttp.agent=\"ABC DEF\";\n\n"
"class JVMOPTION_TEST_WITH_SPACE {\n"
"static void run(ExaMetadata exa, ExaIterator ctx) throws Exception {\n\n"
" ctx.emit(\"Success!\");\n"
" }\n"
"}\n";
JavaVMTest vm(script_code);
EXPECT_EQ(vm.getJavaVMInternalStatus().m_exaJavaPath, "/exaudf/javacontainer");
EXPECT_EQ(vm.getJavaVMInternalStatus().m_localClasspath, "/tmp");
const std::string expected_script_code =
"package com.exasol;\r\n\n\n"
"class JVMOPTION_TEST_WITH_SPACE {\n"
"static void run(ExaMetadata exa, ExaIterator ctx) throws Exception {\n\n"
"\tctx.emit(\"Success!\");\n"
" }\n}\n";
EXPECT_EQ(vm.getJavaVMInternalStatus().m_scriptCode, expected_script_code);
EXPECT_EQ(vm.getJavaVMInternalStatus().m_exaJarPath, "/exaudf/javacontainer/libexaudf.jar");
EXPECT_EQ(vm.getJavaVMInternalStatus().m_classpath, "/tmp:/exaudf/javacontainer/libexaudf.jar");
const std::vector<std::string> expectedJarPaths = {};
EXPECT_EQ(vm.getJavaVMInternalStatus().m_jarPaths, expectedJarPaths);
EXPECT_TRUE(vm.getJavaVMInternalStatus().m_needsCompilation);
const std::vector<std::string> expectedJVMOptions = { "-Dhttp.agent=\"ABC", "DEF\"", "-Xms128m", "-Xmx128m", "-Xss512k",
"-XX:ErrorFile=/tmp/hs_err_pid%p.log",
"-Djava.class.path=/tmp:/exaudf/javacontainer/libexaudf.jar",
"-XX:+UseSerialGC" };
EXPECT_EQ(vm.getJavaVMInternalStatus().m_jvmOptions, expectedJVMOptions);
}

0 comments on commit deeab99

Please sign in to comment.