|
|
@ -21,12 +21,16 @@ public class Bench { |
|
|
|
|
|
|
|
|
|
|
|
protected final String json; |
|
|
|
protected final String json; |
|
|
|
protected final String path; |
|
|
|
protected final String path; |
|
|
|
private final boolean value; |
|
|
|
private final boolean optionAsValues; |
|
|
|
|
|
|
|
private final boolean optionAllwaysReturnList; |
|
|
|
|
|
|
|
private final boolean optionMergeMultiProps; |
|
|
|
|
|
|
|
|
|
|
|
public Bench(String json, String path, boolean value) { |
|
|
|
public Bench(String json, String path, boolean optionAsValues, boolean optionAllwaysReturnList, boolean optionMergeMultiProps) { |
|
|
|
this.json = json; |
|
|
|
this.json = json; |
|
|
|
this.path = path; |
|
|
|
this.path = path; |
|
|
|
this.value = value; |
|
|
|
this.optionAsValues = optionAsValues; |
|
|
|
|
|
|
|
this.optionAllwaysReturnList = optionAllwaysReturnList; |
|
|
|
|
|
|
|
this.optionMergeMultiProps = optionMergeMultiProps; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Result runJayway() { |
|
|
|
public Result runJayway() { |
|
|
@ -35,33 +39,31 @@ public class Bench { |
|
|
|
long time; |
|
|
|
long time; |
|
|
|
Object res = null; |
|
|
|
Object res = null; |
|
|
|
|
|
|
|
|
|
|
|
//Configuration configuration = Configuration.defaultConfiguration();
|
|
|
|
|
|
|
|
Configuration configuration = Configuration.defaultConfiguration().options(Option.ALWAYS_RETURN_LIST); |
|
|
|
Configuration configuration = Configuration.defaultConfiguration(); |
|
|
|
if(!value){ |
|
|
|
if(optionAllwaysReturnList){ |
|
|
|
configuration = configuration.options(Option.AS_PATH_LIST); |
|
|
|
configuration = configuration.addOptions(Option.ALWAYS_RETURN_LIST); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(optionMergeMultiProps){ |
|
|
|
|
|
|
|
configuration = configuration.addOptions(Option.MERGE_MULTI_PROPS); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!optionAsValues) { |
|
|
|
|
|
|
|
configuration = configuration.addOptions(Option.AS_PATH_LIST); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
long now = System.currentTimeMillis(); |
|
|
|
long now = System.currentTimeMillis(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
res = JsonPath.using(configuration).parse(json).read(path); |
|
|
|
res = JsonPath.using(configuration).parse(json).read(path); |
|
|
|
/* |
|
|
|
} catch (Exception e) { |
|
|
|
if(value) { |
|
|
|
|
|
|
|
res = JsonPath.parse(json).read(path); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
res = JsonPath.parse(json).readPathList(path); |
|
|
|
|
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e){ |
|
|
|
|
|
|
|
error = getError(e); |
|
|
|
error = getError(e); |
|
|
|
} finally { |
|
|
|
} finally { |
|
|
|
time = System.currentTimeMillis() - now; |
|
|
|
time = System.currentTimeMillis() - now; |
|
|
|
|
|
|
|
|
|
|
|
if(res instanceof String) { |
|
|
|
if (res instanceof String) { |
|
|
|
result = "\"" + res + "\""; |
|
|
|
result = "\"" + res + "\""; |
|
|
|
} else if(res instanceof Number) { |
|
|
|
} else if (res instanceof Number) { |
|
|
|
result = res.toString(); |
|
|
|
result = res.toString(); |
|
|
|
} else if(res instanceof Boolean){ |
|
|
|
} else if (res instanceof Boolean) { |
|
|
|
result = res.toString(); |
|
|
|
result = res.toString(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
result = res != null ? JsonProviderFactory.createProvider().toJson(res) : "null"; |
|
|
|
result = res != null ? JsonProviderFactory.createProvider().toJson(res) : "null"; |
|
|
@ -78,7 +80,7 @@ public class Bench { |
|
|
|
Iterator<Object> query = null; |
|
|
|
Iterator<Object> query = null; |
|
|
|
long now = System.currentTimeMillis(); |
|
|
|
long now = System.currentTimeMillis(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
if(!value){ |
|
|
|
if (!optionAsValues) { |
|
|
|
throw new UnsupportedOperationException("Not supported!"); |
|
|
|
throw new UnsupportedOperationException("Not supported!"); |
|
|
|
} |
|
|
|
} |
|
|
|
io.gatling.jsonpath.JsonPath jsonPath = JsonPath$.MODULE$.compile(path).right().get(); |
|
|
|
io.gatling.jsonpath.JsonPath jsonPath = JsonPath$.MODULE$.compile(path).right().get(); |
|
|
@ -87,12 +89,12 @@ public class Bench { |
|
|
|
Object jsonModel = jsonParser.parse(json); |
|
|
|
Object jsonModel = jsonParser.parse(json); |
|
|
|
query = jsonPath.query(jsonModel); |
|
|
|
query = jsonPath.query(jsonModel); |
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e){ |
|
|
|
} catch (Exception e) { |
|
|
|
error = getError(e); |
|
|
|
error = getError(e); |
|
|
|
} finally { |
|
|
|
} finally { |
|
|
|
time = System.currentTimeMillis() - now; |
|
|
|
time = System.currentTimeMillis() - now; |
|
|
|
|
|
|
|
|
|
|
|
if(query != null) { |
|
|
|
if (query != null) { |
|
|
|
List<Object> res = new ArrayList<Object>(); |
|
|
|
List<Object> res = new ArrayList<Object>(); |
|
|
|
while (query.hasNext()) { |
|
|
|
while (query.hasNext()) { |
|
|
|
res.add(query.next()); |
|
|
|
res.add(query.next()); |
|
|
@ -113,27 +115,27 @@ public class Bench { |
|
|
|
|
|
|
|
|
|
|
|
long now = System.currentTimeMillis(); |
|
|
|
long now = System.currentTimeMillis(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
if(!value){ |
|
|
|
if (!optionAsValues) { |
|
|
|
throw new UnsupportedOperationException("Not supported!"); |
|
|
|
throw new UnsupportedOperationException("Not supported!"); |
|
|
|
} |
|
|
|
} |
|
|
|
com.nebhale.jsonpath.JsonPath compiled = com.nebhale.jsonpath.JsonPath.compile(path); |
|
|
|
com.nebhale.jsonpath.JsonPath compiled = com.nebhale.jsonpath.JsonPath.compile(path); |
|
|
|
res = compiled.read(json, Object.class); |
|
|
|
res = compiled.read(json, Object.class); |
|
|
|
} catch (Exception e){ |
|
|
|
} catch (Exception e) { |
|
|
|
error = getError(e); |
|
|
|
error = getError(e); |
|
|
|
} finally { |
|
|
|
} finally { |
|
|
|
time = System.currentTimeMillis() - now; |
|
|
|
time = System.currentTimeMillis() - now; |
|
|
|
result = res!=null? jacksonProvider.toJson(res):null; |
|
|
|
result = res != null ? jacksonProvider.toJson(res) : null; |
|
|
|
return new Result("nebhale", time, result, error); |
|
|
|
return new Result("nebhale", time, result, error); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public List<Result> runAll(){ |
|
|
|
public List<Result> runAll() { |
|
|
|
return asList(runJayway(), runBoon(), runNebhale()); |
|
|
|
return asList(runJayway(), runBoon(), runNebhale()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private String getError(Exception e){ |
|
|
|
private String getError(Exception e) { |
|
|
|
String ex = e.getMessage(); |
|
|
|
String ex = e.getMessage(); |
|
|
|
if(ex == null || ex.trim().isEmpty()){ |
|
|
|
if (ex == null || ex.trim().isEmpty()) { |
|
|
|
ex = "Undefined error"; |
|
|
|
ex = "Undefined error"; |
|
|
|
} |
|
|
|
} |
|
|
|
return ex; |
|
|
|
return ex; |
|
|
|