Example #1
0
        public void Paged_enumerable_should_return_correct_enumerables_for_pages()
        {
            // Arrange
            int         capacity = 250;
            IList <int> list     = new List <int>(capacity);

            for (int i = 0; i < capacity; i++)
            {
                list.Add(i);
            }

            // Act
            var pagedList  = new PagedEnumerable <int>(list, 10, 10);
            var pagedList2 = new PagedEnumerable <int>(list, 10, 10);
            var pagedList3 = list.ToPaged(13, 25);
            var pagedList4 = list.ToPaged(20, 13);

            // Assert
            Assert.Equal(25, pagedList.TotalPages);
            Assert.Equal(10, pagedList2.Count());
            Assert.Equal(10, pagedList3.TotalPages);
            Assert.Equal(13, pagedList3.Page);
            Assert.Equal(20, pagedList4.TotalPages);
            Assert.Equal(3, pagedList4.Count());
        }
Example #2
0
        public double ReadBucketSize(string bucketName)
        {
            // Initialize request argument(s)
            string metricType = "storage.googleapis.com/storage/total_bytes";
            string filter     = $"metric.type=\"{metricType}\"";

            filter += $" AND resource.labels.bucket_name =\"{bucketName}\"";
            ListTimeSeriesRequest request = new ListTimeSeriesRequest
            {
                ProjectName = new ProjectName(Config.ProjectId),
                Filter      = filter,
                Interval    = new TimeInterval(),
                View        = ListTimeSeriesRequest.Types.TimeSeriesView.Full,
            };
            // Create timestamp for current time formatted in seconds.
            long      timeStamp      = (long)(DateTime.UtcNow - s_unixEpoch).TotalSeconds;
            Timestamp startTimeStamp = new Timestamp();

            // Set startTime to limit results to the last 8*60 minutes.
            // Gcs bucket size will be caculated every 24 hours.
            startTimeStamp.Seconds = timeStamp - (1 * 60 * 60);
            Timestamp endTimeStamp = new Timestamp();

            // Set endTime to current time.
            endTimeStamp.Seconds = timeStamp;
            TimeInterval interval = new TimeInterval();

            interval.StartTime = startTimeStamp;
            interval.EndTime   = endTimeStamp;
            request.Interval   = interval;
            // Make the request.
            PagedEnumerable <ListTimeSeriesResponse, TimeSeries> response =
                this.metric.ListTimeSeries(request);

            // Iterate over all response items, lazily performing RPCs as required.
            if (response.Count() == 0)
            {
                throw new Exception(string.Format("failed to get bucket: {0} size", bucketName));
            }
            TimeSeries item   = response.First();
            var        points = item.Points;
            double     size   = points[0].Value.DoubleValue;

            return(size);
        }
Example #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);
        }
Example #4
0
        public void Paged_enumerable_should_return_correct_enumerables_for_pages()
        {
            int capacity = 250;
            IList<int> list = new List<int>(capacity);
            for (int i = 0; i < capacity; i++)
            {
                list.Add(i);
            }
            var pagedList = new PagedEnumerable<int>(list, 10, 10);
            Assert.That(pagedList.TotalPages, Is.EqualTo(25));

            var pagedList2 = new PagedEnumerable<int>(list, 10, 10);
            Assert.That(pagedList2.Count(), Is.EqualTo(10));

            var pagedList3 = list.GetPaged(13, 25);
            Assert.That(pagedList3.TotalPages, Is.EqualTo(10));
            Assert.That(pagedList3.CurrentPage, Is.EqualTo(13));

            var pagedList4 = list.GetPaged(20, 13);
            Assert.That(pagedList4.TotalPages, Is.EqualTo(20));
            Assert.That(pagedList4.Count(), Is.EqualTo(3));
        }