|
18 | 18 |
|
19 | 19 | import static com.google.cloud.datastore.telemetry.TraceUtil.SPAN_NAME_COMMIT;
|
20 | 20 | import static com.google.cloud.datastore.telemetry.TraceUtil.SPAN_NAME_LOOKUP;
|
| 21 | +import static com.google.cloud.datastore.telemetry.TraceUtil.SPAN_NAME_RUN_QUERY; |
21 | 22 | import static io.opentelemetry.semconv.resource.attributes.ResourceAttributes.SERVICE_NAME;
|
22 | 23 | import static org.junit.Assert.assertEquals;
|
23 | 24 | import static org.junit.Assert.assertFalse;
|
|
30 | 31 | import com.google.cloud.datastore.DatastoreOptions;
|
31 | 32 | import com.google.cloud.datastore.Entity;
|
32 | 33 | import com.google.cloud.datastore.Key;
|
| 34 | +import com.google.cloud.datastore.Query; |
| 35 | +import com.google.cloud.datastore.QueryResults; |
| 36 | +import com.google.cloud.datastore.StructuredQuery.PropertyFilter; |
33 | 37 | import com.google.cloud.datastore.testing.RemoteDatastoreHelper;
|
34 | 38 | import com.google.cloud.opentelemetry.trace.TraceConfiguration;
|
35 | 39 | import com.google.cloud.opentelemetry.trace.TraceExporter;
|
@@ -301,11 +305,11 @@ public void before() throws Exception {
|
301 | 305 | String projectId = options.getProjectId();
|
302 | 306 | String kind1 = "kind1";
|
303 | 307 | KEY1 =
|
304 |
| - Key.newBuilder(projectId, kind1, "name1", options.getDatabaseId()) |
| 308 | + Key.newBuilder(projectId, kind1, "key1", options.getDatabaseId()) |
305 | 309 | .setNamespace(options.getNamespace())
|
306 | 310 | .build();
|
307 | 311 | KEY2 =
|
308 |
| - Key.newBuilder(projectId, kind1, "name2", options.getDatabaseId()) |
| 312 | + Key.newBuilder(projectId, kind1, "key2", options.getDatabaseId()) |
309 | 313 | .setNamespace(options.getNamespace())
|
310 | 314 | .build();
|
311 | 315 |
|
@@ -594,7 +598,6 @@ public void updateTraceTest() throws Exception {
|
594 | 598 | assertEquals(entityList, response);
|
595 | 599 |
|
596 | 600 | Span rootSpan = getNewRootSpanWithContext();
|
597 |
| - |
598 | 601 | try (Scope ignored = rootSpan.makeCurrent()) {
|
599 | 602 | Entity entity1_update =
|
600 | 603 | Entity.newBuilder(entity1).set("test_field", "new_test_value1").build();
|
@@ -625,7 +628,34 @@ public void deleteTraceTest() throws Exception {
|
625 | 628 | rootSpan.end();
|
626 | 629 | }
|
627 | 630 | waitForTracesToComplete();
|
628 |
| - |
629 | 631 | fetchAndValidateTrace(customSpanContext.getTraceId(), SPAN_NAME_COMMIT);
|
630 | 632 | }
|
| 633 | + |
| 634 | + @Test |
| 635 | + public void runQueryTraceTest() throws Exception { |
| 636 | + Entity entity1 = Entity.newBuilder(KEY1).set("test_field", "test_value1").build(); |
| 637 | + Entity entity2 = Entity.newBuilder(KEY2).set("test_field", "test_value2").build(); |
| 638 | + List<Entity> entityList = new ArrayList<>(); |
| 639 | + entityList.add(entity1); |
| 640 | + entityList.add(entity2); |
| 641 | + |
| 642 | + List<Entity> response = datastore.add(entity1, entity2); |
| 643 | + assertEquals(entityList, response); |
| 644 | + |
| 645 | + Span rootSpan = getNewRootSpanWithContext(); |
| 646 | + try (Scope ignored = rootSpan.makeCurrent()) { |
| 647 | + PropertyFilter filter = PropertyFilter.eq("test_field", entity1.getValue("test_field")); |
| 648 | + Query<Entity> query = |
| 649 | + Query.newEntityQueryBuilder().setKind(KEY1.getKind()).setFilter(filter).build(); |
| 650 | + QueryResults<Entity> queryResults = datastore.run(query); |
| 651 | + assertTrue(queryResults.hasNext()); |
| 652 | + assertEquals(entity1, queryResults.next()); |
| 653 | + assertFalse(queryResults.hasNext()); |
| 654 | + } finally { |
| 655 | + rootSpan.end(); |
| 656 | + } |
| 657 | + waitForTracesToComplete(); |
| 658 | + |
| 659 | + fetchAndValidateTrace(customSpanContext.getTraceId(), SPAN_NAME_RUN_QUERY); |
| 660 | + } |
631 | 661 | }
|
0 commit comments