anicolaspp / ojai-testing Goto Github PK
View Code? Open in Web Editor NEWEmbeded In-Memory Implementation of OJAI Driver to be used in testing
License: MIT License
Embeded In-Memory Implementation of OJAI Driver to be used in testing
License: MIT License
We are using ojai-testing for unit testing our application. Additionally we want to use ojai-testing during development on the developer notebooks. With ojai-testing we don't need to connect to a cluster.
In our webservice applications, we are creating and closing the Ojai Store on each http request. That means that a document that was inserted first, can not be read by our api (using ojai-testing), because the store will be cleared after each http call.
Is there any way to not clear the store after calling close?
Maybe there would be a way to pass an option (like clearStoreOnClosing
) while registering the InMemoryDriver (which passes this option to InMemoryConnection and this one to the InMemoryStore).
What do you think about this? Should I send you a PR with this approach?
I'm using ojai-testing in a Java and Maven based application. Running my test i get the following error:
java.lang.BootstrapMethodError: java.lang.NoClassDefFoundError: javafx/util/Pair
at com.mapr.db.impl.InMemoryStore.find(InMemoryStore.java:179)
at de.mycompany.mapr.sample.FootballPlayersController.get(FootballPlayersController.java:64)
at de.mycompany.mapr.sample.FootballPlayersControllerTests.get_databaseContainsOneElement_shouldReturnArrayWithOneDocument(FootballPlayersControllerTests.java:25)
Here is my test class:
String json = "{\"_id\": \"111\", \"Name\": \"Cláudio André Mergen Taffarel\", \"Club\": \"Brasilien\"}, \"Wage\": \"?\"";
Document dummyFootballer = connection().newDocument(json);
documentStore(TABLE_PATH).insert(dummyFootballer);
FootballPlayersController target = new FootballPlayersController(connection());
ResponseEntity<String> response = target.get();
The class under test:
List<String> documents = new ArrayList<>();
try (DocumentStore store = connection.getStore(tablePath)) {
Query query = connection.newQuery()
.select("_id", "Name", "Age", "Club", "Wage")
.limit(10)
.build();
try (DocumentStream stream = store.find(query)) {
for (Document document : stream) {
documents.add(document.asJsonString());
}
}
}
The exception is thrown in store.find()
. I am not sure why this Exception is thrown. When I run the Java Decompiler in IntelliJ i can see the following implementation of find()
where return new Pair() is used:
OjaiQuery var2 = (OjaiQuery)var1;
ConditionImpl var3 = var2.getCondition();
long var4 = var2.getLimit();
String[] var6 = (String[])var2.getProjectedFieldSet().stream().map(FieldPath::asJsonString).toArray((var0) -> {
return new String[var0];
});
List var7 = (List)var2.getOrderByFields().stream().map((var1x) -> {
return new Pair(var1x, var2.getFieldOrdering(var1x));
}).collect(Collectors.toList());
Stream var8 = this.withCondition(this.documents.stream(), var3).map((var2x) -> {
return this.project(var2x, var6);
});
return new ResultDocumentStream(this.withLimit(var8, var4), this.connection);
At the top I can see import javafx.util.Pair;
But in your implementation is nothing about javafx or a Pair-class. I have absoluteley no idea what is happening here...
Currently ojai-testing does not support to specify a query with .select("*")
. Is there any easy way to support this?
Hi and thanks for this implementation of an OJAI in-memory document store.
I found an issue with a container field path query:
Given two documents:
{
"_id": "001",
"tasks": [
{"_id": "t001"},
{"_id": "t002"}
]
}
{
"_id": "002",
"tasks": [
{"_id": "t003"}
]
}
When I execute the following query from a Java application:
QueryCondition containsTaskCondition =
connection.newCondition().is("tasks[]._id", QueryCondition.Op.EQUAL, "t002").build();
Query query = connection.newQuery().where(containsTaskCondition).build();
DocumentStream docStream = store.find(query);
Document doc = docStream.iterator().next();
Then the object doc
should contain document 001
.
Currently an exception is thrown:
java.lang.IllegalArgumentException: [] cannot be used to get/set/delete a value in a Document
at com.mapr.db.rowcol.DBDocumentImpl.checkForArrayNotation(DBDocumentImpl.java:183)
at com.mapr.db.rowcol.DBDocumentImpl.getKeyValue(DBDocumentImpl.java:826)
at com.mapr.db.rowcol.DBDocumentImpl.getValue(DBDocumentImpl.java:837)
at com.mapr.db.impl.InMemoryStore.evalCondition(InMemoryStore.java:889)
at com.mapr.db.impl.InMemoryStore.lambda$withCondition$8(InMemoryStore.java:198)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:176)
at java.base/java.util.ArrayList$ArrayListSpliterator.tryAdvance(ArrayList.java:1631)
at java.base/java.util.stream.StreamSpliterators$WrappingSpliterator.lambda$initPartialTraversalState$0(StreamSpliterators.java:294)
at java.base/java.util.stream.StreamSpliterators$AbstractWrappingSpliterator.fillBuffer(StreamSpliterators.java:206)
at java.base/java.util.stream.StreamSpliterators$AbstractWrappingSpliterator.doAdvance(StreamSpliterators.java:161)
at java.base/java.util.stream.StreamSpliterators$WrappingSpliterator.tryAdvance(StreamSpliterators.java:300)
at java.base/java.util.Spliterators$1Adapter.hasNext(Spliterators.java:681)
at java.base/java.util.Spliterators$1Adapter.next(Spliterators.java:687)
Any suggestion on how to fix this?
Thanks,
Martin
Can you add a license file to this work? Something permissive enough to give assurance that the code in this repo can be used legally within my project? Without this, I don't think legal will allow me to use this, even if it is just for unit tests.
Hello, I found a problem LinearProjector#getNextSegments. It seems to concatenate the path segments without separating them with ".", so subsequent paths don't get split up correctly, and the document can't be further queried.
I'd propose changing
private String getNextSegments(String[] pathSegments) {
return Arrays.stream(pathSegments).skip(1).reduce("", (a, b) -> a + b);
}
to
private String getNextSegments(String[] pathSegments) {
return Arrays.stream(pathSegments).skip(1).collect(Collectors.joining("."));
}
I think that will fix the problem; if I fixed the path being returned from this method in my debugger, my tests succeeded just the same as when I run them with an actual mapr connection. I'd make the change myself, but the project doesn't build for me, and I know nothing about sbt to try to fix it.
When I built the query using the find(query)
method on the DocumentStore
where in the query there was a LESS condition, only the values that were equal to the value got returned.
My query condition: condition.is("expiration", QueryCondition.Op.LESS, 123L)
After some debugging I found that class ConditionEvaluator
seems to only support EQUALS operation.
Can you verify if the comparison in that class is done correctly in the framework?
Is there a way to test conditions other than EQUALS?
Best regards
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.