Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
yirutang committed Dec 9, 2020
1 parent adafeb7 commit 0b31552
Showing 1 changed file with 0 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -569,63 +569,4 @@ public void testStreamReconnect() throws IOException, InterruptedException, Exec
// assertEquals(1L, response.get().getOffset());
}
}

@Test
public void testFlushRows() throws IOException, InterruptedException, ExecutionException {
String tableName = "BufferTable";
TableInfo tableInfo =
TableInfo.newBuilder(
TableId.of(DATASET, tableName),
StandardTableDefinition.of(
Schema.of(
com.google.cloud.bigquery.Field.newBuilder("foo", LegacySQLTypeName.STRING)
.build())))
.build();
bigquery.create(tableInfo);
TableName parent = TableName.of(ServiceOptions.getDefaultProjectId(), DATASET, tableName);
WriteStream writeStream =
client.createWriteStream(
CreateWriteStreamRequest.newBuilder()
.setParent(parent.toString())
.setWriteStream(WriteStream.newBuilder().setType(WriteStream.Type.BUFFERED).build())
.build());
try (StreamWriter streamWriter = StreamWriter.newBuilder(writeStream.getName()).build()) {
ApiFuture<AppendRowsResponse> response =
streamWriter.append(
createAppendRequest(writeStream.getName(), new String[] {"aaa"})
.setOffset(Int64Value.of(0L))
.build());
response.get();
// Waiting for API breaking change to be generated in new client.
// assertEquals(0L, response.get().getOffset());
FlushRowsRequest flushRequest =
FlushRowsRequest.newBuilder()
.setWriteStream(writeStream.getName())
.setOffset(Int64Value.of(0))
.build();
client.flushRows(flushRequest);
try {
flushRequest = flushRequest.toBuilder().setOffset(Int64Value.of(1)).build();
client.flushRows(flushRequest);
fail("Expected Out Of Range exception");
} catch (com.google.api.gax.rpc.OutOfRangeException ex) {
assertThat(ex.getMessage())
.contains("OUT_OF_RANGE: Offset 1 is beyond the end of the stream");
}
}
String query = "SELECT * from " + DATASET + "." + tableName;
LOG.info("Querying: " + query);
TableResult queryResult = bigquery.query(QueryJobConfiguration.newBuilder(query).build());
Iterator<FieldValueList> iter = queryResult.getValues().iterator();

// We cannot read from tabledata.list yet.
// TableResult result =
// bigquery.listTableData(tableInfo.getTableId(),
// BigQuery.TableDataListOption.startIndex(0L));
// Iterator<FieldValueList> iter = result.getValues().iterator();
// Why I cannot get result?
assertFalse(iter.hasNext());
// assertEquals("aaa", iter.next().get(0).getStringValue());
// assertEquals(false, iter.hasNext());
}
}

0 comments on commit 0b31552

Please sign in to comment.