-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed running multiple upserts within one transaction (#137)
- Loading branch information
Showing
2 changed files
with
46 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.assertTrue; | ||
import static org.testng.Assert.fail; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.JsonArray; | ||
|
@@ -307,6 +308,47 @@ public void upsertZeroMutations() { | |
} | ||
} | ||
|
||
@Test | ||
public void upsertMultipleWithinSingleTransactionTest() { | ||
DgraphProto.Operation op = | ||
DgraphProto.Operation.newBuilder() | ||
.setSchema("email: string @index(exact) @upsert .") | ||
.build(); | ||
dgraphClient.alter(op); | ||
|
||
JsonArray jsonData = new JsonArray(); | ||
JsonObject person = new JsonObject(); | ||
person.addProperty("uid", "uid(v)"); | ||
person.addProperty("name", "wrong"); | ||
jsonData.add(person); | ||
|
||
JsonObject person2 = new JsonObject(); | ||
person2.addProperty("email", "[email protected]"); | ||
person2.addProperty("uid", "uid(v)"); | ||
jsonData.add(person2); | ||
|
||
String query = | ||
"{\n" | ||
+ " me(func: eq(email, \"[email protected]\")) {\n" | ||
+ " v as uid\n" | ||
+ " }\n" | ||
+ "}\n"; | ||
Mutation mu = | ||
Mutation.newBuilder().setSetJson(ByteString.copyFromUtf8(jsonData.toString())).build(); | ||
Request request = Request.newBuilder().addMutations(mu).setQuery(query).build(); | ||
|
||
Transaction transaction = dgraphClient.newTransaction(); | ||
transaction.doRequest(request); | ||
|
||
try { | ||
transaction.doRequest(request); | ||
} catch (RuntimeException e) { | ||
fail(e.getMessage()); | ||
} | ||
|
||
transaction.discard(); | ||
} | ||
|
||
static class User { | ||
String branch; | ||
} | ||
|