mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
TextOfFile expansion for full file; http fixes
This commit is contained in:
parent
e5472fe324
commit
82b52acbf3
1
.gitignore
vendored
1
.gitignore
vendored
@ -19,4 +19,5 @@ bin/**
|
||||
**/.DS_Store
|
||||
**/generated/**
|
||||
**/.flattened-pom.xml
|
||||
**/stargate-token.txt
|
||||
/deptree.txt
|
||||
|
@ -21,7 +21,7 @@ bindings:
|
||||
weighted_hosts: WeightedStrings('<<restapi_host:stargate>>')
|
||||
|
||||
request_id: ToHashedUUID(); ToString();
|
||||
request_token: ToString(); TextOfFile(TEMPLATE(stargate_tokenfile,'data/stargate_token.txt')));
|
||||
request_token: ToString(); TextOfFile(TEMPLATE(stargate_tokenfile,'data/stargate_token.txt'));
|
||||
|
||||
seq_key: Mod(<<keycount:10000000>>); ToString() -> String
|
||||
seq_value: Hash(); Mod(<<valuecount:1000000000>>); ToString() -> String
|
||||
|
@ -27,8 +27,7 @@ bindings:
|
||||
|
||||
seq_key: Mod(<<docscount:10000000>>); ToString() -> String
|
||||
random_key: Uniform(0,<<docscount:10000000>>); ToString() -> String
|
||||
# TODO - this needs a dataset_file to be used from data/* preferably
|
||||
document_json: ModuloLineToString('<<dataset_file>>');
|
||||
document_json: Discard(); TextOfFile('data/docsapi-dataset.json', false));
|
||||
|
||||
blocks:
|
||||
schema:
|
||||
|
46
adapter-http/src/main/resources/data/docsapi-dataset.json
Normal file
46
adapter-http/src/main/resources/data/docsapi-dataset.json
Normal file
@ -0,0 +1,46 @@
|
||||
{
|
||||
message: "success",
|
||||
people: [
|
||||
{
|
||||
name: "Sergey Prokopyev",
|
||||
craft: "ISS"
|
||||
},
|
||||
{
|
||||
name: "Dmitry Petelin",
|
||||
craft: "ISS"
|
||||
},
|
||||
{
|
||||
name: "Frank Rubio",
|
||||
craft: "ISS"
|
||||
},
|
||||
{
|
||||
name: "Nicole Mann",
|
||||
craft: "ISS"
|
||||
},
|
||||
{
|
||||
name: "Josh Cassada",
|
||||
craft: "ISS"
|
||||
},
|
||||
{
|
||||
name: "Koichi Wakata",
|
||||
craft: "ISS"
|
||||
},
|
||||
{
|
||||
name: "Anna Kikina",
|
||||
craft: "ISS"
|
||||
},
|
||||
{
|
||||
name: "Fei Junlong",
|
||||
craft: "Shenzhou 15"
|
||||
},
|
||||
{
|
||||
name: "Deng Qingming",
|
||||
craft: "Shenzhou 15"
|
||||
},
|
||||
{
|
||||
name: "Zhang Lu",
|
||||
craft: "Shenzhou 15"
|
||||
}
|
||||
],
|
||||
number: 10
|
||||
}
|
@ -1 +1 @@
|
||||
37f580cc-0015-4fa1-b4dd-32f5874f0330
|
||||
<<your-token-here>>
|
@ -35,22 +35,36 @@ import java.util.function.Function;
|
||||
@Categories({Category.general})
|
||||
public class TextOfFile implements Function<Object, String> {
|
||||
private static final Logger logger = LogManager.getLogger(TextOfFile.class);
|
||||
private final String text;
|
||||
private String text;
|
||||
|
||||
public String toString() {
|
||||
return getClass().getSimpleName();
|
||||
}
|
||||
|
||||
@Example({"TextOfFile()", "Provides the first line of text in the specified file."})
|
||||
@Example({"TextOfFile('path-to-file')", "Provides the first line of text in the specified file."})
|
||||
public TextOfFile(String targetFile) {
|
||||
readFile(targetFile, true);
|
||||
}
|
||||
|
||||
@Example({"TextOfFile('path-to-file', isFirstLineOnly)", "Provides the text in the specified file as specified for first-line or entire file."})
|
||||
public TextOfFile(String targetFile, boolean isFirstLineOnly) {
|
||||
readFile(targetFile, isFirstLineOnly);
|
||||
}
|
||||
|
||||
private void readFile(String targetFile, boolean isFirstLineOnly) {
|
||||
try {
|
||||
final List<String> lines = NBIO.readLines(targetFile);
|
||||
logger.info("TextOfFile() reading: {}", targetFile);
|
||||
if (lines.isEmpty()) {
|
||||
throw new BasicError(String.format("Unable to locate content for %s", this));
|
||||
}
|
||||
text = lines.get(0);
|
||||
if (isFirstLineOnly) {
|
||||
this.text = lines.get(0);
|
||||
} else {
|
||||
StringBuilder content = new StringBuilder();
|
||||
lines.forEach(content::append);
|
||||
this.text = content.toString();
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
throw new BasicError(String.format("Unable to locate file %s: ", targetFile), ex);
|
||||
}
|
||||
@ -58,7 +72,7 @@ public class TextOfFile implements Function<Object, String> {
|
||||
|
||||
@Override
|
||||
public String apply(Object obj) {
|
||||
return text;
|
||||
return this.text;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ import static org.assertj.core.api.Assertions.assertThatException;
|
||||
class TextOfFileTest {
|
||||
|
||||
private static final String EXPECTED_CONTENTS = "test-data-entry";
|
||||
private static final String EXPECTED_MULTILINE_CONTENTS = "additional information";
|
||||
private static final String NOT_EXPECTED_CONTENTS = "foozy-content";
|
||||
private static final String VALID_PATH = "text-provider-sample.txt";
|
||||
private static final String INVALID_PATH = "not-good.txt";
|
||||
@ -32,14 +33,26 @@ class TextOfFileTest {
|
||||
@Test
|
||||
void testValidPathAndContents() {
|
||||
final TextOfFile TextOfFile = new TextOfFile(VALID_PATH);
|
||||
assertThat(TextOfFile.apply(PLACEHOLDER_APPLY_INPUT)).isEqualTo(EXPECTED_CONTENTS);
|
||||
assertThat(TextOfFile.apply(PLACEHOLDER_APPLY_INPUT).trim()).isEqualTo(EXPECTED_CONTENTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInvalidPathAndContents() {
|
||||
void testInvalidPathAndSingleLineContents() {
|
||||
final TextOfFile textOfFileValid = new TextOfFile(VALID_PATH);
|
||||
assertThatException().isThrownBy(() -> new TextOfFile(INVALID_PATH));
|
||||
assertThat(textOfFileValid.apply(PLACEHOLDER_APPLY_INPUT)).isNotEqualTo(NOT_EXPECTED_CONTENTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFullContentsAndSingleLine() {
|
||||
|
||||
boolean isFirstLineOnly = false;
|
||||
final TextOfFile textOfEntireFile = new TextOfFile(VALID_PATH, isFirstLineOnly);
|
||||
assertThat(textOfEntireFile.apply(PLACEHOLDER_APPLY_INPUT)).contains(EXPECTED_MULTILINE_CONTENTS);
|
||||
|
||||
isFirstLineOnly = true;
|
||||
final TextOfFile textOfSingleLine = new TextOfFile(VALID_PATH, isFirstLineOnly);
|
||||
assertThat(textOfSingleLine.apply(PLACEHOLDER_APPLY_INPUT).trim()).isEqualTo(EXPECTED_CONTENTS);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1 +1,3 @@
|
||||
test-data-entry
|
||||
test-data-entry
|
||||
additional information
|
||||
is here
|
Loading…
Reference in New Issue
Block a user