|
26 | 26 | import static com.google.cloud.datastore.telemetry.TraceUtil.SPAN_NAME_TRANSACTION_COMMIT; |
27 | 27 | import static com.google.cloud.datastore.telemetry.TraceUtil.SPAN_NAME_TRANSACTION_LOOKUP; |
28 | 28 | import static com.google.cloud.datastore.telemetry.TraceUtil.SPAN_NAME_TRANSACTION_RUN; |
| 29 | +import static com.google.cloud.datastore.telemetry.TraceUtil.SPAN_NAME_TRANSACTION_RUN_QUERY; |
29 | 30 | import static com.google.common.truth.Truth.assertThat; |
30 | 31 | import static io.opentelemetry.semconv.resource.attributes.ResourceAttributes.SERVICE_NAME; |
31 | 32 | import static org.junit.Assert.assertEquals; |
@@ -795,8 +796,49 @@ public void transactionalLookupTest() throws Exception { |
795 | 796 | Collections.singletonList(SPAN_NAME_TRANSACTION_COMMIT))); |
796 | 797 | } |
797 | 798 |
|
| 799 | + @Test |
| 800 | + public void transactionQueryTest() throws Exception { |
| 801 | + // Set up |
| 802 | + Entity entity1 = Entity.newBuilder(KEY1).set("test_field", "test_value1").build(); |
| 803 | + Entity entity2 = Entity.newBuilder(KEY2).set("test_field", "test_value2").build(); |
| 804 | + List<Entity> entityList = new ArrayList<>(); |
| 805 | + entityList.add(entity1); |
| 806 | + entityList.add(entity2); |
| 807 | + |
| 808 | + List<Entity> response = datastore.add(entity1, entity2); |
| 809 | + assertEquals(entityList, response); |
| 810 | + |
| 811 | + assertNotNull(customSpanContext); |
| 812 | + |
| 813 | + // Test |
| 814 | + Span rootSpan = getNewRootSpanWithContext(); |
| 815 | + try (Scope ignored = rootSpan.makeCurrent()) { |
| 816 | + Transaction transaction = datastore.newTransaction(); |
| 817 | + PropertyFilter filter = PropertyFilter.eq("test_field", entity1.getValue("test_field")); |
| 818 | + Query<Entity> query = |
| 819 | + Query.newEntityQueryBuilder().setKind(KEY1.getKind()).setFilter(filter).build(); |
| 820 | + QueryResults<Entity> queryResults = transaction.run(query); |
| 821 | + transaction.commit(); |
| 822 | + assertTrue(queryResults.hasNext()); |
| 823 | + assertEquals(entity1, queryResults.next()); |
| 824 | + assertFalse(queryResults.hasNext()); |
| 825 | + } finally { |
| 826 | + rootSpan.end(); |
| 827 | + } |
| 828 | + waitForTracesToComplete(); |
| 829 | + |
| 830 | + fetchAndValidateTrace( |
| 831 | + customSpanContext.getTraceId(), |
| 832 | + /*numExpectedSpans=*/ 3, |
| 833 | + Arrays.asList( |
| 834 | + Collections.singletonList(SPAN_NAME_BEGIN_TRANSACTION), |
| 835 | + Collections.singletonList(SPAN_NAME_TRANSACTION_RUN_QUERY), |
| 836 | + Collections.singletonList(SPAN_NAME_TRANSACTION_COMMIT))); |
| 837 | + } |
| 838 | + |
798 | 839 | @Test |
799 | 840 | public void runInTransactionQueryTest() throws Exception { |
| 841 | + // Set up |
800 | 842 | Entity entity1 = Entity.newBuilder(KEY1).set("test_field", "test_value1").build(); |
801 | 843 | Entity entity2 = Entity.newBuilder(KEY2).set("test_field", "test_value2").build(); |
802 | 844 | List<Entity> entityList = new ArrayList<>(); |
@@ -837,7 +879,7 @@ public void runInTransactionQueryTest() throws Exception { |
837 | 879 | } |
838 | 880 |
|
839 | 881 | @Test |
840 | | - public void runInTransactionAggregationQueryTest() throws Exception {} |
| 882 | + public void transactionRunQueryTest() throws Exception {} |
841 | 883 |
|
842 | 884 | @Test |
843 | 885 | public void readWriteTransactionTraceTest() throws Exception {} |
|
0 commit comments