-
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.
Moving the dependency io.opencensus.* into a test dependency only,
to avoid excessive CPU usage reported in census-instrumentation/opencensus-java#1599
- Loading branch information
Lucas Wang
committed
Jun 28, 2019
1 parent
1e35cb2
commit 04ecb54
Showing
2 changed files
with
98 additions
and
93 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 |
---|---|---|
@@ -1,97 +1,102 @@ | ||
package io.dgraph; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
|
||
import com.google.gson.JsonArray; | ||
import com.google.gson.JsonObject; | ||
import com.google.protobuf.ByteString; | ||
import org.testng.annotations.Test; | ||
import io.dgraph.DgraphProto.*; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.assertTrue; | ||
import org.testng.annotations.Test; | ||
|
||
public class UpsertBlockTest extends DgraphIntegrationTest { | ||
@Test | ||
public void upsertBlockTest() throws Exception { | ||
DgraphProto.Operation op = | ||
DgraphProto.Operation.newBuilder() | ||
.setSchema("email: string @index(exact) @upsert .").build(); | ||
dgraphClient.alter(op); | ||
|
||
String query = "" + | ||
"{\n" + | ||
" me(func: eq(email, \"ashish@dgraph.io\")) {\n" + | ||
" v as uid\n" + | ||
" }\n" + | ||
"}\n"; | ||
|
||
JsonArray jA = new JsonArray(); | ||
JsonObject p1 = new JsonObject(); | ||
p1.addProperty("uid", "uid(v)"); | ||
p1.addProperty("name", "wrong"); | ||
jA.add(p1); | ||
|
||
JsonObject p2 = new JsonObject(); | ||
p2.addProperty("email", "ashish@dgraph.io"); | ||
p2.addProperty("uid", "uid(v)"); | ||
jA.add(p2); | ||
|
||
Mutation mu = Mutation.newBuilder() | ||
.setQuery(query) | ||
.setSetJson(ByteString.copyFromUtf8(jA.toString())) | ||
.build(); | ||
|
||
Transaction txn = dgraphClient.newTransaction(); | ||
txn.mutate(mu); | ||
txn.commit(); | ||
|
||
String query2 = "" + | ||
"{\n" + | ||
" me(func: eq(email, \"ashish@dgraph.io\")) {\n" + | ||
" name\n" + | ||
" email\n" + | ||
" }\n" + | ||
"}\n"; | ||
|
||
txn = dgraphClient.newTransaction(); | ||
Response response = txn.query(query2); | ||
String res = response.getJson().toStringUtf8(); | ||
String exp1 = "{\"me\":[{\"name\":\"wrong\",\"email\":\"ashish@dgraph.io\"}]}"; | ||
assertEquals(res, exp1); | ||
|
||
jA = new JsonArray(); | ||
p1 = new JsonObject(); | ||
p1.addProperty("uid", "uid(v)"); | ||
p1.addProperty("name", "ashish"); | ||
jA.add(p1); | ||
|
||
mu = Mutation.newBuilder() | ||
.setQuery(query) | ||
.setSetJson(ByteString.copyFromUtf8(jA.toString())) | ||
.build(); | ||
|
||
txn = dgraphClient.newTransaction(); | ||
txn.mutate(mu); | ||
txn.commit(); | ||
|
||
txn = dgraphClient.newTransaction(); | ||
response = txn.query(query2); | ||
res = response.getJson().toStringUtf8(); | ||
String exp2 = "{\"me\":[{\"name\":\"ashish\",\"email\":\"ashish@dgraph.io\"}]}"; | ||
assertEquals(res, exp2); | ||
|
||
mu = Mutation.newBuilder() | ||
.setQuery(query) | ||
.setDelNquads(ByteString.copyFromUtf8("uid(v) <name> * .\nuid(v) <email> * .")) | ||
.build(); | ||
|
||
txn = dgraphClient.newTransaction(); | ||
txn.mutate(mu); | ||
txn.commit(); | ||
|
||
txn = dgraphClient.newTransaction(); | ||
response = txn.query(query2); | ||
res = response.getJson().toStringUtf8(); | ||
String exp3 = "{\"me\":[]}"; | ||
assertEquals(res, exp3); | ||
} | ||
@Test | ||
public void upsertBlockTest() throws Exception { | ||
DgraphProto.Operation op = | ||
DgraphProto.Operation.newBuilder() | ||
.setSchema("email: string @index(exact) @upsert .") | ||
.build(); | ||
dgraphClient.alter(op); | ||
|
||
String query = | ||
"" | ||
+ "{\n" | ||
+ " me(func: eq(email, \"ashish@dgraph.io\")) {\n" | ||
+ " v as uid\n" | ||
+ " }\n" | ||
+ "}\n"; | ||
|
||
JsonArray jA = new JsonArray(); | ||
JsonObject p1 = new JsonObject(); | ||
p1.addProperty("uid", "uid(v)"); | ||
p1.addProperty("name", "wrong"); | ||
jA.add(p1); | ||
|
||
JsonObject p2 = new JsonObject(); | ||
p2.addProperty("email", "ashish@dgraph.io"); | ||
p2.addProperty("uid", "uid(v)"); | ||
jA.add(p2); | ||
|
||
Mutation mu = | ||
Mutation.newBuilder() | ||
.setQuery(query) | ||
.setSetJson(ByteString.copyFromUtf8(jA.toString())) | ||
.build(); | ||
|
||
Transaction txn = dgraphClient.newTransaction(); | ||
txn.mutate(mu); | ||
txn.commit(); | ||
|
||
String query2 = | ||
"" | ||
+ "{\n" | ||
+ " me(func: eq(email, \"ashish@dgraph.io\")) {\n" | ||
+ " name\n" | ||
+ " email\n" | ||
+ " }\n" | ||
+ "}\n"; | ||
|
||
txn = dgraphClient.newTransaction(); | ||
Response response = txn.query(query2); | ||
String res = response.getJson().toStringUtf8(); | ||
String exp1 = "{\"me\":[{\"name\":\"wrong\",\"email\":\"ashish@dgraph.io\"}]}"; | ||
assertEquals(res, exp1); | ||
|
||
jA = new JsonArray(); | ||
p1 = new JsonObject(); | ||
p1.addProperty("uid", "uid(v)"); | ||
p1.addProperty("name", "ashish"); | ||
jA.add(p1); | ||
|
||
mu = | ||
Mutation.newBuilder() | ||
.setQuery(query) | ||
.setSetJson(ByteString.copyFromUtf8(jA.toString())) | ||
.build(); | ||
|
||
txn = dgraphClient.newTransaction(); | ||
txn.mutate(mu); | ||
txn.commit(); | ||
|
||
txn = dgraphClient.newTransaction(); | ||
response = txn.query(query2); | ||
res = response.getJson().toStringUtf8(); | ||
String exp2 = "{\"me\":[{\"name\":\"ashish\",\"email\":\"ashish@dgraph.io\"}]}"; | ||
assertEquals(res, exp2); | ||
|
||
mu = | ||
Mutation.newBuilder() | ||
.setQuery(query) | ||
.setDelNquads(ByteString.copyFromUtf8("uid(v) <name> * .\nuid(v) <email> * .")) | ||
.build(); | ||
|
||
txn = dgraphClient.newTransaction(); | ||
txn.mutate(mu); | ||
txn.commit(); | ||
|
||
txn = dgraphClient.newTransaction(); | ||
response = txn.query(query2); | ||
res = response.getJson().toStringUtf8(); | ||
String exp3 = "{\"me\":[]}"; | ||
assertEquals(res, exp3); | ||
} | ||
} |