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