Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added a test for best effort queries #182

Merged
merged 2 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/test/java/io/dgraph/AclTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@ private void verifyOperation(boolean shouldFail, String operation, Runnable runn
return;
}

assertFalse(shouldFail, "the " + operation + " should have failed");
// assertFalse(shouldFail, );
if (shouldFail != false) {
throw new RuntimeException("the " + operation + " should have failed");
}
}

private void resetUser() throws Exception {
Expand Down
35 changes: 35 additions & 0 deletions src/test/java/io/dgraph/DgraphAsyncClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,39 @@ public void testCheckVersion() {
assertTrue(v.getTag().length() > 0);
// assertEquals(v.getTag().charAt(0), 'v');
}

@Test
public void testBestEffortQueries() throws InterruptedException {
Operation op = Operation.newBuilder().setSchema("name: string @index(exact) .").build();
dgraphAsyncClient.alter(op).join();

// Add data
JsonObject json = new JsonObject();
json.addProperty("name", "Alice");

Mutation mu =
Mutation.newBuilder()
.setCommitNow(true)
.setSetJson(ByteString.copyFromUtf8(json.toString()))
.build();
Response mutationResp = dgraphAsyncClient.newTransaction().mutate(mu).join();
System.out.println("mutation response:" + mutationResp);

// sleep for 5 seconds for the max assigned ts to be propagated
Thread.sleep(5000);

// create a new transaction to verify the best effort read
AsyncTransaction readTxn = dgraphAsyncClient.newReadOnlyTransaction();
readTxn.setBestEffort(true);
String query = "query me($a: string) { me(func: eq(name, $a)) { name }}";
Map<String, String> vars = Collections.singletonMap("$a", "Alice");
Response res = readTxn.queryWithVars(query, vars).join();

// Verify data as expected
JsonParser parser = new JsonParser();
json = parser.parse(res.getJson().toStringUtf8()).getAsJsonObject();
assertTrue(json.has("me"));
String name = json.getAsJsonArray("me").get(0).getAsJsonObject().get("name").getAsString();
assertEquals(name, "Alice");
}
}
Loading