forked from unicode-org/conformance
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ICU4J executor impl for collator (unicode-org#137)
* Doc updates * Add high level behavior of ICU4J executor * Add interfaces to describe generic behavior per test type * Add Collator specific concrete tester impl files * Update Python Subprocess.run to run command string rather than array of command split parts
- Loading branch information
Showing
16 changed files
with
658 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
executors/icu4j/73/executor-icu4j/src/main/java/org/unicode/conformance/ExecutorUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.unicode.conformance; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.reflect.TypeToken; | ||
import io.lacuna.bifurcan.IEntry; | ||
import java.util.HashMap; | ||
import java.util.Iterator; | ||
import java.util.Map; | ||
|
||
public class ExecutorUtils { | ||
|
||
public static Gson GSON = new Gson(); | ||
|
||
public static void printResponseString(String responseString) { | ||
System.out.println(responseString); | ||
} | ||
|
||
public static io.lacuna.bifurcan.Map<String,String> parseInputLine(String inputLine) { | ||
TypeToken<Map<String, String>> mapType = new TypeToken<Map<String, String>>(){}; | ||
Map<String,String> parsedInputJavaMap = ExecutorUtils.GSON.fromJson(inputLine, mapType); | ||
|
||
io.lacuna.bifurcan.Map<String,String> parsedInputPersistentMap = | ||
io.lacuna.bifurcan.Map.from(parsedInputJavaMap); | ||
|
||
return parsedInputPersistentMap; | ||
} | ||
|
||
public static String formatAsJson(io.lacuna.bifurcan.IMap<String,String> mapData) { | ||
java.util.Map<String,String> jMap = new HashMap<>(); | ||
for (Iterator<IEntry<String, String>> it = mapData.stream().iterator(); it.hasNext(); ) { | ||
IEntry<String, String> entry = it.next(); | ||
jMap.put(entry.key(), entry.value()); | ||
} | ||
return GSON.toJson(jMap); | ||
} | ||
|
||
} |
142 changes: 137 additions & 5 deletions
142
executors/icu4j/73/executor-icu4j/src/main/java/org/unicode/conformance/Icu4jExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,145 @@ | ||
package org.unicode.conformance; | ||
|
||
import com.google.gson.reflect.TypeToken; | ||
import com.ibm.icu.impl.locale.XCldrStub.ImmutableMap; | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import org.unicode.conformance.testtype.ITestType; | ||
import org.unicode.conformance.testtype.collator.CollatorTester; | ||
|
||
/** | ||
* Hello world! | ||
* | ||
*/ | ||
public class Icu4jExecutor | ||
{ | ||
public static void main( String[] args ) | ||
{ | ||
System.out.println( "Hello World!" ); | ||
public class Icu4jExecutor { | ||
|
||
public static final String PLATFORM = "ICU4J"; | ||
public static final String PLATFORM_VERSION = "73.2"; | ||
public static final String ICU_VERSION = "73"; | ||
|
||
public static final String CLDR_VERSION = "43"; | ||
|
||
/** | ||
* Entry point for the executor. | ||
* | ||
* Run on an infinite loop until the input "#EXIT" is received. | ||
*/ | ||
public static void main(String[] args) throws IOException { | ||
try (InputStreamReader isr = new InputStreamReader(System.in); | ||
BufferedReader br = new BufferedReader(isr)) { | ||
while (true) { | ||
computeAndHandleResponse(br); | ||
} | ||
} catch (IOException ioe) { | ||
String javaSetupErrorMsg = ioe.getMessage(); | ||
String executorErrorMsg = "! " + javaSetupErrorMsg; | ||
ExecutorUtils.printResponseString(executorErrorMsg); | ||
|
||
// exit with non-zero return code | ||
throw ioe; | ||
} | ||
} | ||
|
||
public static void computeAndHandleResponse(BufferedReader br) { | ||
try { | ||
String line = br.readLine(); | ||
String response = computeResponseString(line); | ||
handleResponseString(response); | ||
} catch (Exception e) { | ||
// At this level, we assume the IOException is coming from BufferedReader. | ||
// Any test case execution errors should be handled higher in the call stack (deeper in | ||
// the code) | ||
String javaErrorMsg = e.getMessage(); | ||
String executorErrorMsg = "! " + javaErrorMsg; | ||
ExecutorUtils.printResponseString(executorErrorMsg); | ||
} | ||
} | ||
|
||
/** | ||
* Returns the string to be sent back to the testdriver caller, with the following cases: | ||
* | ||
* <ul> | ||
* <li>For a test case input that was executed, return the JSON string of the result</li> | ||
* <li>For empty input lines, return the empty string</li> | ||
* <li>For end-of-input when <pre>#EXIT</pre> is sent in as input, return null</li> | ||
* <li>For errors during test execution, return the error output string prefixed with | ||
* <pre>#</pre></li> | ||
* </ul> | ||
*/ | ||
public static String computeResponseString(String inputLine) throws Exception { | ||
if (inputLine.equals("#EXIT")) { | ||
return null; | ||
} else if (inputLine.trim().equals("")) { | ||
return ""; | ||
} else if (inputLine.equals("#VERSION")) { | ||
return getVersionResponse(); | ||
} else { | ||
return getTestCaseResponse(inputLine); | ||
} | ||
} | ||
|
||
public static String getVersionResponse() { | ||
Map<String,String> versionMap = new HashMap<>(); | ||
versionMap.put("platform", PLATFORM); | ||
versionMap.put("cldrVersion", CLDR_VERSION); | ||
versionMap.put("icuVersion", ICU_VERSION); | ||
versionMap.put("platformVersion", PLATFORM_VERSION); | ||
|
||
String result = ExecutorUtils.GSON.toJson(versionMap); | ||
return result; | ||
} | ||
|
||
public static String getTestCaseResponse(String inputLine) throws Exception { | ||
|
||
io.lacuna.bifurcan.Map<String,String> parsedInputPersistentMap = | ||
ExecutorUtils.parseInputLine(inputLine); | ||
|
||
Optional<String> testTypeOpt = parsedInputPersistentMap.get("test_type"); | ||
|
||
if (!testTypeOpt.isPresent()) { | ||
io.lacuna.bifurcan.IMap<String,String> response = | ||
parsedInputPersistentMap | ||
.put("error", "Error in input") | ||
.put("error_msg", "Error in input found in executor before execution"); | ||
|
||
return ExecutorUtils.formatAsJson(response); | ||
} else { | ||
String testTypeStr = testTypeOpt.get(); | ||
ITestType testType; | ||
if (testTypeStr.equals("collation_short")) { | ||
testType = new CollatorTester(); | ||
} else { | ||
io.lacuna.bifurcan.IMap<String,String> response = | ||
parsedInputPersistentMap | ||
.put("error", "Error in input") | ||
.put("error_msg", "Error in input found in executor before execution"); | ||
|
||
return ExecutorUtils.formatAsJson(response); | ||
} | ||
|
||
return testType.getFinalOutputFromInput(parsedInputPersistentMap); | ||
} | ||
} | ||
|
||
/** | ||
* Perform behavior according to the executor spec at <code>REPO/executors/README.md</code> | ||
* based on the output and associated semantics of <code>computeResponseString()</code>. | ||
* @param responseString | ||
*/ | ||
public static void handleResponseString(String responseString) { | ||
if (responseString == null) { | ||
System.exit(0); | ||
} | ||
if (responseString.equals("")) { | ||
return; // empty input line, do nothing | ||
} | ||
|
||
// otherwise, response string carries test result | ||
ExecutorUtils.printResponseString(responseString); | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
...ors/icu4j/73/executor-icu4j/src/main/java/org/unicode/conformance/testtype/ITestType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.unicode.conformance.testtype; | ||
|
||
import org.unicode.conformance.ExecutorUtils; | ||
|
||
public interface ITestType { | ||
|
||
default io.lacuna.bifurcan.Map<String,String> parseInput(String inputLine) { | ||
return ExecutorUtils.parseInputLine(inputLine); | ||
} | ||
|
||
ITestTypeInputJson inputMapToJson(io.lacuna.bifurcan.Map<String,String> inputMapData); | ||
|
||
default ITestTypeInputJson parseInputJson(String inputLine) { | ||
io.lacuna.bifurcan.Map<String,String> inputMapData = | ||
parseInput(inputLine); | ||
ITestTypeInputJson inputJson = inputMapToJson(inputMapData); | ||
|
||
return inputJson; | ||
} | ||
|
||
ITestTypeOutputJson execute(ITestTypeInputJson inputJson); | ||
|
||
String formatOutputJson(ITestTypeOutputJson outputJson); | ||
|
||
default ITestTypeOutputJson getStructuredOutputFromInputStr(String inputLine) { | ||
io.lacuna.bifurcan.Map<String,String> inputMapData = parseInput(inputLine); | ||
return getStructuredOutputFromInput(inputMapData); | ||
} | ||
|
||
default ITestTypeOutputJson getStructuredOutputFromInput(io.lacuna.bifurcan.Map<String,String> inputMapData) { | ||
ITestTypeInputJson inputJson = inputMapToJson(inputMapData); | ||
ITestTypeOutputJson outputJson = execute(inputJson); | ||
return outputJson; | ||
} | ||
|
||
default String getFinalOutputFromInput(io.lacuna.bifurcan.Map<String,String> inputMapData) throws Exception { | ||
ITestTypeOutputJson outputJson = getStructuredOutputFromInput(inputMapData); | ||
String formattedOutput = formatOutputJson(outputJson); | ||
return formattedOutput; | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
.../73/executor-icu4j/src/main/java/org/unicode/conformance/testtype/ITestTypeInputJson.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.unicode.conformance.testtype; | ||
|
||
public interface ITestTypeInputJson { | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
...73/executor-icu4j/src/main/java/org/unicode/conformance/testtype/ITestTypeOutputJson.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.unicode.conformance.testtype; | ||
|
||
public interface ITestTypeOutputJson { | ||
|
||
} |
Oops, something went wrong.