public void FromRowKeys_Valid() { var set = RowSet.FromRowKeys("a", "z"); Assert.Equal(new[] { ByteString.CopyFromUtf8("a"), ByteString.CopyFromUtf8("z") }, set.RowKeys); Assert.Equal(0, set.RowRanges.Count); }
public async Task ErrorAtVeryEndDoesntCauseRetry() { var request = new ReadRowsRequest { Rows = RowSet.FromRowKeys("a") }; var client = Utilities.CreateReadRowsMockClient( request, initialStreamResponse: new[] { new ReadRowsResponse { Chunks = { CreateChunk("a", "cf1", "column1", "value1", commitRow: true) } } }, errorAtEndOfLastStream: true); var rows = await client.ReadRows(request).ToList(); Assert.Equal(1, rows.Count); var row = rows[0]; Assert.Equal("a", row.Key.ToStringUtf8()); Assert.Equal("cf1", row.Families[0].Name); Assert.Equal("column1", row.Families[0].Columns[0].Qualifier.ToStringUtf8()); Assert.Equal("value1", row.Families[0].Columns[0].Cells[0].Value.ToStringUtf8()); }
public async Task RetryingBeforeTotalExpiration() { var request = new ReadRowsRequest { Rows = RowSet.FromRowKeys("a", "b", "c") }; var client = Utilities.CreateReadRowsMockClient( request, initialStreamResponse: new[] { new ReadRowsResponse { Chunks = { CreateChunk("a", "cf1", "column1", "value1", commitRow: true) } } }, responsesForRetryStreams: new[] { null, // A null entry will throw an Unavailable RpcException new [] { new ReadRowsResponse { Chunks = { CreateChunk("b", "cf1", "column2", "value2", commitRow: true) } } } }); await client.ReadRows(request).ToListAsync(); }
public void TestFilterRowsRowRangesKeyInMiddle() { BigtableByteString key1 = "row1"; BigtableByteString key2 = "row2"; BigtableByteString key3 = "row3"; BigtableByteString lastFoundKey = "row1a"; RowSet fullRowSet = RowSet.FromRowKeys(key1, key2, key3); fullRowSet.RowRanges.Add(new[] { RowRange.OpenClosed(null, key1), // should be filtered out RowRange.Open(null, key1), // should be filtered out RowRange.Open(key1, key2), // should be converted (lastFoundKey, key2) RowRange.ClosedOpen(key1, key2), // should be converted (lastFoundKey, key2) RowRange.Closed(key1, key2), // should be converted (lastFoundKey, key2] RowRange.Open(key2, key3), // should stay RowRange.ClosedOpen(key2, key3) // should stay }); RowSet filteredRowSet = RowSet.FromRowKeys(key2, key3); filteredRowSet.RowRanges.Add(new[] { RowRange.Open(lastFoundKey, key2), // should be converted (lastFoundKey, key2) RowRange.Open(lastFoundKey, key2), // should be converted (lastFoundKey, key2) RowRange.OpenClosed(lastFoundKey, key2), // should be converted (lastFoundKey, key2] RowRange.Open(key2, key3), // should stay RowRange.ClosedOpen(key2, key3) // should stay }); ReadRowsRequest originalRequest = new ReadRowsRequest { Rows = fullRowSet }; ReadRowsRequest filteredRequest = new ReadRowsRequest { Rows = filteredRowSet }; BigtableReadRowsRequestManager underTest = new BigtableReadRowsRequestManager(originalRequest); Assert.Equal(originalRequest, underTest.BuildUpdatedRequest()); underTest.LastFoundKey = lastFoundKey; ReadRowsRequest originalRequestClone = originalRequest.Clone(); // Assert that originalRequest and originalRequestClone are different objects. Assert.False(ReferenceEquals(originalRequest, originalRequestClone)); // Assert that originalRequest and originalRequestClone have same value before calling BuildUpdatedRequest. Assert.Equal(originalRequest, originalRequestClone); Assert.Equal(filteredRequest, underTest.BuildUpdatedRequest()); // Assert that BuildUpdatedRequest did not modify the original RowSet. Assert.Equal(originalRequest, originalRequestClone); }
// [END bigtable_reads_row_partial] // [START bigtable_reads_rows] /// <summary> /// /// Reads multiple rows from an existing table. ///</summary> /// <param name="projectId">Your Google Cloud Project ID.</param> /// <param name="instanceId">Your Google Cloud Bigtable Instance ID.</param> /// <param name="tableId">Your Google Cloud Bigtable table ID.</param> public string readRows(string projectId = "YOUR-PROJECT-ID", string instanceId = "YOUR-INSTANCE-ID", string tableId = "YOUR-TABLE-ID") { BigtableClient bigtableClient = BigtableClient.Create(); TableName tableName = new TableName(projectId, instanceId, tableId); RowSet rowSet = RowSet.FromRowKeys("phone#4c410523#20190501", "phone#4c410523#20190502"); ReadRowsStream readRowsStream = bigtableClient.ReadRows(tableName, rowSet); string result = ""; readRowsStream.ForEach(row => result += printRow(row)); return(result); }
public async Task SimpleRetryWithKeys() { var request = new ReadRowsRequest { Rows = RowSet.FromRowKeys("a", "b", "c") }; var client = Utilities.CreateReadRowsMockClient( request, initialStreamResponse: new[] { new ReadRowsResponse { Chunks = { CreateChunk("a", "cf1", "column1", "value1", commitRow: true) } } }, responsesForRetryStreams: new[] { new [] { new ReadRowsResponse { Chunks = { CreateChunk("b", "cf1", "column2", "value2", commitRow: true) } } } }); var rows = await client.ReadRows(request).ToList(); Assert.Equal(2, rows.Count); var row = rows[0]; Assert.Equal("a", row.Key.ToStringUtf8()); Assert.Equal("cf1", row.Families[0].Name); Assert.Equal("column1", row.Families[0].Columns[0].Qualifier.ToStringUtf8()); Assert.Equal("value1", row.Families[0].Columns[0].Cells[0].Value.ToStringUtf8()); row = rows[1]; Assert.Equal("b", row.Key.ToStringUtf8()); Assert.Equal("cf1", row.Families[0].Name); Assert.Equal("column2", row.Families[0].Columns[0].Qualifier.ToStringUtf8()); Assert.Equal("value2", row.Families[0].Columns[0].Cells[0].Value.ToStringUtf8()); }
public async Task RetryingAfterTotalExpiration() { var settings = new BigtableServiceApiSettings(); // Don't allow for any time to retry. settings.ReadRowsRetrySettings = settings.ReadRowsRetrySettings.WithTotalExpiration( Expiration.FromTimeout(TimeSpan.Zero)); var request = new ReadRowsRequest { Rows = RowSet.FromRowKeys("a", "b", "c") }; var client = Utilities.CreateReadRowsMockClient( request, initialStreamResponse: new[] { new ReadRowsResponse { Chunks = { CreateChunk("a", "cf1", "column1", "value1", commitRow: true) } } }, responsesForRetryStreams: new[] { null, // A null entry will throw an Unavailable RpcException new [] { new ReadRowsResponse { Chunks = { CreateChunk("b", "cf1", "column2", "value2", commitRow: true) } } } }, settings: settings); var exception = await Assert.ThrowsAsync <RpcException>(() => client.ReadRows(request).ToList()); Assert.Equal(StatusCode.Unavailable, exception.StatusCode); }
public void FromRowKeys_Invalid() { Assert.Throws <ArgumentNullException>(() => RowSet.FromRowKeys(null)); }
private static ReadRowsRequest CreateRowKeysRequest(params BigtableByteString[] keys) => new ReadRowsRequest { Rows = RowSet.FromRowKeys(keys) };