-
Notifications
You must be signed in to change notification settings - Fork 831
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e6dd8d
commit 23fa285
Showing
8 changed files
with
186 additions
and
16 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
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
21 changes: 21 additions & 0 deletions
21
incubating/wrappers/java/src/test/java/io/seldon/wrapper/api/TestMessages.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,21 @@ | ||
package io.seldon.wrapper.api; | ||
|
||
import static io.seldon.wrapper.util.TestUtils.readFileFromAbsolutePathOrResources; | ||
|
||
final public class TestMessages { | ||
|
||
/** | ||
* All possible fields based on the SeldonMessage Proto: | ||
* https://docs.seldon.io/projects/seldon-core/en/v1.6.0/reference/apis/prediction.html | ||
*/ | ||
public static final String TF_DATA = readFile("requests/defaultData.json"); | ||
public static final String DEFAULT_DATA = TF_DATA; | ||
public static final String JSON_DATA = readFile("requests/jsonData.json"); | ||
// TODO: add binData | ||
// TODO: add strData | ||
// TODO: add customData | ||
|
||
private static String readFile(String file) { | ||
return readFileFromAbsolutePathOrResources(file); | ||
} | ||
} |
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
39 changes: 38 additions & 1 deletion
39
incubating/wrappers/java/src/test/java/io/seldon/wrapper/util/TestUtils.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,14 +1,51 @@ | ||
package io.seldon.wrapper.util; | ||
|
||
import java.io.IOException; | ||
import java.io.*; | ||
import java.nio.charset.Charset; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
|
||
public class TestUtils { | ||
|
||
private static final ClassLoader classLoader = TestUtils.class.getClassLoader(); | ||
|
||
public static String readFile(String path, Charset encoding) throws IOException { | ||
byte[] encoded = Files.readAllBytes(Paths.get(path)); | ||
return new String(encoded, encoding); | ||
} | ||
|
||
/** | ||
* Will load file from either an absolute path of a relative path from "target/test-classes" | ||
* @param file file path (ex: "requests/jsonData.json", "/dev/null") | ||
* @return | ||
*/ | ||
public static String readFileFromAbsolutePathOrResources(String file) { | ||
try { | ||
InputStream is = getInputStreamFromAbsolutePathOrResources(file, classLoader); | ||
byte[] bytes = is.readAllBytes(); | ||
return new String(bytes, StandardCharsets.UTF_8); | ||
} catch(Throwable t) { | ||
System.out.println(t); | ||
t.printStackTrace(); | ||
// nothing | ||
} | ||
return null; | ||
} | ||
|
||
public static InputStream getInputStreamFromAbsolutePathOrResources(String file, ClassLoader classLoader) { | ||
InputStream is = null; | ||
|
||
// try loading assuming an absolute path | ||
try { | ||
is = new FileInputStream(file); | ||
} catch ( FileNotFoundException fne ) { | ||
// Nothing | ||
} | ||
if( is == null ) { | ||
is = classLoader.getResourceAsStream(file); | ||
} | ||
|
||
return is; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
incubating/wrappers/java/src/test/resources/requests/defaultData.json
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,10 @@ | ||
{ | ||
"data": { | ||
"ndarray": [ | ||
[ | ||
1, | ||
2 | ||
] | ||
] | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
incubating/wrappers/java/src/test/resources/requests/jsonData.json
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,9 @@ | ||
{ | ||
"jsonData": { | ||
"data": { | ||
"subject": "helpful message", | ||
"body": "nothing strange, good, rewarding" | ||
}, | ||
"foo": "bar" | ||
} | ||
} |