|
32 | 32 | import com.google.cloud.bigquery.storage.test.Test.FooType; |
33 | 33 | import com.google.cloud.bigquery.storage.test.Test.InnerType; |
34 | 34 | import com.google.cloud.bigquery.storage.v1.ConnectionWorker.Load; |
| 35 | +import com.google.common.collect.Iterables; |
35 | 36 | import com.google.protobuf.ByteString; |
36 | 37 | import com.google.protobuf.DescriptorProtos; |
37 | 38 | import com.google.protobuf.Int64Value; |
@@ -1722,6 +1723,61 @@ void testEarliestSendTime_retryScenario() throws Exception { |
1722 | 1723 |
|
1723 | 1724 | // Once exhausted, state should be null |
1724 | 1725 | assertThat(connectionWorker.getEarliestSendTime()).isNull(); |
| 1726 | + |
| 1727 | + AppendRowsRequest initialRequest = testBigQueryWrite.getAppendRequests().get(0); |
| 1728 | + AppendRowsRequest retryRequest = testBigQueryWrite.getAppendRequests().get(1); |
| 1729 | + assertThat(retryRequest.getClientStats().getRequestStats().getSendTimeMillis()) |
| 1730 | + .isAtLeast(initialRequest.getClientStats().getRequestStats().getSendTimeMillis()); |
| 1731 | + } |
| 1732 | + } |
| 1733 | + |
| 1734 | + @Test |
| 1735 | + void testClientStats_sendTimeMillisPopulated() throws Exception { |
| 1736 | + // Arrange |
| 1737 | + ProtoSchema schema1 = createProtoSchema("foo"); |
| 1738 | + try (StreamWriter sw1 = |
| 1739 | + StreamWriter.newBuilder(TEST_STREAM_1, client) |
| 1740 | + .setLocation("us") |
| 1741 | + .setWriterSchema(schema1) |
| 1742 | + .build(); |
| 1743 | + ConnectionWorker connectionWorker = createConnectionWorker()) { |
| 1744 | + testBigQueryWrite.addResponse(createAppendResponse(0)); |
| 1745 | + |
| 1746 | + // Act |
| 1747 | + long beforeSendMillis = Instant.now().toEpochMilli(); |
| 1748 | + ApiFuture<AppendRowsResponse> future = |
| 1749 | + sendTestMessage(connectionWorker, sw1, createFooProtoRows(new String[] {"0"}), 0); |
| 1750 | + future.get(); |
| 1751 | + long afterSendMillis = Instant.now().toEpochMilli(); |
| 1752 | + |
| 1753 | + // Assert |
| 1754 | + AppendRowsRequest sentRequest = |
| 1755 | + Iterables.getOnlyElement(testBigQueryWrite.getAppendRequests()); |
| 1756 | + assertThat(sentRequest.hasClientStats()).isTrue(); |
| 1757 | + assertThat(sentRequest.getClientStats().hasRequestStats()).isTrue(); |
| 1758 | + assertThat(sentRequest.getClientStats().getRequestStats().hasSendTimeMillis()).isTrue(); |
| 1759 | + long sendTimeMillis = sentRequest.getClientStats().getRequestStats().getSendTimeMillis(); |
| 1760 | + assertThat(sendTimeMillis).isAtLeast(beforeSendMillis); |
| 1761 | + assertThat(sendTimeMillis).isAtMost(afterSendMillis); |
| 1762 | + |
| 1763 | + // Arrange retry scenario |
| 1764 | + testBigQueryWrite.addResponse( |
| 1765 | + new DummyResponseSupplierWillFailThenSucceed( |
| 1766 | + new FakeBigQueryWriteImpl.Response(createAppendResponse(1)), |
| 1767 | + /* totalFailCount= */ 1, |
| 1768 | + com.google.rpc.Status.newBuilder().setCode(Code.INTERNAL.ordinal()).build())); |
| 1769 | + |
| 1770 | + // Act |
| 1771 | + ApiFuture<AppendRowsResponse> retryFuture = |
| 1772 | + sendTestMessage(connectionWorker, sw1, createFooProtoRows(new String[] {"1"}), 1); |
| 1773 | + retryFuture.get(); |
| 1774 | + |
| 1775 | + // Assert |
| 1776 | + assertThat(testBigQueryWrite.getAppendRequests()).hasSize(3); |
| 1777 | + AppendRowsRequest initialRequest = testBigQueryWrite.getAppendRequests().get(1); |
| 1778 | + AppendRowsRequest retryRequest = testBigQueryWrite.getAppendRequests().get(2); |
| 1779 | + assertThat(retryRequest.getClientStats().getRequestStats().getSendTimeMillis()) |
| 1780 | + .isAtLeast(initialRequest.getClientStats().getRequestStats().getSendTimeMillis()); |
1725 | 1781 | } |
1726 | 1782 | } |
1727 | 1783 | } |
0 commit comments