示例#1
0
 /// <summary>
 /// Polls until this table contains at least the given number of rows. This should be used carefully, only where we know the table won't be huge.
 /// </summary>
 /// <remarks>
 /// <para>
 /// This method is designed to make integration tests more reliable: after an insert, data fetching (with queries or ListRows)
 /// may not see the new data.
 /// </para>
 /// <para>
 /// We've tried using the data in BigQueryTable.Resource.NumRows and BigQueryTable.Resource.StreamingBuffer, but they're not as reliable as
 /// just reading the rows.
 /// </para>
 /// </remarks>
 /// <param name="expectedRows">The number of rows expected.</param>
 /// <param name="pollSettings">The poll settings to use, or null to use the defaults (poll once every 2 seconds, 30 second timeout)</param>
 /// <returns>The actual number of rows in the table.</returns>
 /// <exception cref="TimeoutException">The timeout specified in the poll settings elapsed before the streaming buffer became empty.</exception>
 public static int PollUntilRowCountIsAtLeast(this BigQueryTable table, int expectedRows, PollSettings pollSettings = null) =>
 Polling.PollRepeatedly(
     ignoredDeadline => table.ListRows().Count(),
     count => count >= expectedRows,
     SystemClock.Instance,
     SystemScheduler.Instance,
     pollSettings ?? s_defaultStreamingBufferPollSettings,
     CancellationToken.None);
 internal void InsertAndWait(BigQueryTable table, Action insertAction, int expectedRowCountChange)
 {
     var countBefore = table.ListRows().Count();
     var expectedCount = countBefore + expectedRowCountChange;
     insertAction();
     // Wait until there are *at least* enough rows
     int actualCount = table.PollUntilRowCountIsAtLeast(expectedCount);
     // Now check it's *exactly* the right number of rows.
     Assert.Equal(expectedCount, actualCount);
 }
示例#3
0
        public void ListRows()
        {
            string projectId = _fixture.ProjectId;
            string datasetId = _fixture.GameDatasetId;
            string tableId   = _fixture.HistoryTableId;

            // Snippet: ListRows
            BigQueryClient client = BigQueryClient.Create(projectId);
            BigQueryTable  table  = client.GetTable(datasetId, tableId);
            PagedEnumerable <TableDataList, BigQueryRow> result = table.ListRows();

            foreach (BigQueryRow row in result)
            {
                DateTime timestamp = (DateTime)row["game_started"];
                long     level     = (long)row["level"];
                long     score     = (long)row["score"];
                string   player    = (string)row["player"];
                Console.WriteLine($"{player}: {level}/{score} ({timestamp:yyyy-MM-dd HH:mm:ss})");
            }
            // End snippet

            // We set up 7 results in the fixture. Other tests may add more.
            Assert.True(result.Count() >= 7);
        }