@Test public void negativePrefetchChunksNotAllowed() { expectedException.expect(IllegalArgumentException.class); Options.prefetchChunks(-1); }
@Test public void zeroPrefetchChunksNotAllowed() { expectedException.expect(IllegalArgumentException.class); Options.prefetchChunks(0); }
@Test public void queryOptTest() { int chunks = 3; Options opts = Options.fromQueryOptions(Options.prefetchChunks(chunks)); assertThat(opts.toString()).isEqualTo("prefetchChunks: " + Integer.toString(chunks) + " "); assertThat(opts.prefetchChunks()).isEqualTo(chunks); assertThat(opts.hashCode()).isEqualTo(964); }
@Override // Since Options mandates checking hasXX() before XX() is called, the equals & hashCode look more // complicated than usual. public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } Options that = (Options) o; return (!hasLimit() && !that.hasLimit() || hasLimit() && that.hasLimit() && Objects.equals(limit(), that.limit())) && (!hasPrefetchChunks() && !that.hasPrefetchChunks() || hasPrefetchChunks() && that.hasPrefetchChunks() && Objects.equals(prefetchChunks(), that.prefetchChunks())) && (!hasPageSize() && !that.hasPageSize() || hasPageSize() && that.hasPageSize() && Objects.equals(pageSize(), that.pageSize())) && Objects.equals(pageToken(), that.pageToken()) && Objects.equals(filter(), that.filter()); }
@Test public void allOptionsPresent() { Options options = Options.fromReadOptions(Options.limit(10), Options.prefetchChunks(1)); assertThat(options.hasLimit()).isTrue(); assertThat(options.limit()).isEqualTo(10); assertThat(options.hasPrefetchChunks()).isTrue(); assertThat(options.prefetchChunks()).isEqualTo(1); }
ResultSet executeQueryInternalWithOptions( Statement statement, com.google.spanner.v1.ExecuteSqlRequest.QueryMode queryMode, Options readOptions, ByteString partitionToken) { beforeReadOrQuery(); final ExecuteSqlRequest.Builder request = getExecuteSqlRequestBuilder(statement, queryMode); if (partitionToken != null) { request.setPartitionToken(partitionToken); } final int prefetchChunks = readOptions.hasPrefetchChunks() ? readOptions.prefetchChunks() : defaultPrefetchChunks; ResumableStreamIterator stream = new ResumableStreamIterator(MAX_BUFFERED_CHUNKS, QUERY, span) { @Override CloseableIterator<PartialResultSet> startStream(@Nullable ByteString resumeToken) { GrpcStreamIterator stream = new GrpcStreamIterator(prefetchChunks); if (resumeToken != null) { request.setResumeToken(resumeToken); } SpannerRpc.StreamingCall call = rpc.executeQuery(request.build(), stream.consumer(), session.options); call.request(prefetchChunks); stream.setCall(call); return stream; } }; return new GrpcResultSet(stream, this, queryMode); }
@Test public void readWithSmallPrefetchChunks() { try (ResultSet resultSet = client .singleUse() .read( TABLE_NAME, KeySet.all(), Arrays.asList("Key", "Data", "Fingerprint", "Size"), Options.prefetchChunks(1))) { validate(resultSet); } }
@Test public void queryEquality() { Options o1; Options o2; Options o3; o1 = Options.fromQueryOptions(); o2 = Options.fromQueryOptions(); assertThat(o1.equals(o2)).isTrue(); o2 = Options.fromReadOptions(Options.prefetchChunks(1)); assertThat(o1.equals(o2)).isFalse(); assertThat(o2.equals(o1)).isFalse(); o3 = Options.fromReadOptions(Options.prefetchChunks(1)); assertThat(o2.equals(o3)).isTrue(); o3 = Options.fromReadOptions(Options.prefetchChunks(2)); assertThat(o2.equals(o3)).isFalse(); } }
@Test public void queryWithSmallPrefetchChunks() { try (ResultSet resultSet = client .singleUse() .executeQuery( Statement.of( "SELECT Key, Data, Fingerprint, Size FROM " + TABLE_NAME + " ORDER BY Key"), Options.prefetchChunks(1))) { validate(resultSet); } }
readOptions.hasPrefetchChunks() ? readOptions.prefetchChunks() : defaultPrefetchChunks; ResumableStreamIterator stream = new ResumableStreamIterator(MAX_BUFFERED_CHUNKS, READ, span) {
@Test public void statementInstance() { Partition p = Partition.createQueryPartition(partitionToken, partitionOptions, stmt, queryOptions); assertThat(p.getPartitionToken()).isEqualTo(partitionToken); assertThat(p.getStatement()).isEqualTo(stmt); assertThat(p.getQueryOptions().hasPrefetchChunks()).isTrue(); assertThat(p.getQueryOptions().prefetchChunks()).isEqualTo(10); assertNull(p.getTable()); assertNull(p.getColumns()); assertNull(p.getKeys()); assertNull(p.getIndex()); assertNull(p.getReadOptions()); // Test serialization. reserializeAndAssert(p); }
@Override // Since Options mandates checking hasXX() before XX() is called, the equals & hashCode look more // complicated than usual. public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } Options that = (Options) o; return (!hasLimit() && !that.hasLimit() || hasLimit() && that.hasLimit() && Objects.equals(limit(), that.limit())) && (!hasPrefetchChunks() && !that.hasPrefetchChunks() || hasPrefetchChunks() && that.hasPrefetchChunks() && Objects.equals(prefetchChunks(), that.prefetchChunks())) && (!hasPageSize() && !that.hasPageSize() || hasPageSize() && that.hasPageSize() && Objects.equals(pageSize(), that.pageSize())) && Objects.equals(pageToken(), that.pageToken()) && Objects.equals(filter(), that.filter()); }
ResultSet executeQueryInternalWithOptions( Statement statement, com.google.spanner.v1.ExecuteSqlRequest.QueryMode queryMode, Options readOptions, ByteString partitionToken) { beforeReadOrQuery(); final ExecuteSqlRequest.Builder request = getExecuteSqlRequestBuilder(statement, queryMode); if (partitionToken != null) { request.setPartitionToken(partitionToken); } final int prefetchChunks = readOptions.hasPrefetchChunks() ? readOptions.prefetchChunks() : defaultPrefetchChunks; ResumableStreamIterator stream = new ResumableStreamIterator(MAX_BUFFERED_CHUNKS, QUERY, span) { @Override CloseableIterator<PartialResultSet> startStream(@Nullable ByteString resumeToken) { GrpcStreamIterator stream = new GrpcStreamIterator(prefetchChunks); if (resumeToken != null) { request.setResumeToken(resumeToken); } SpannerRpc.StreamingCall call = rpc.executeQuery(request.build(), stream.consumer(), session.options); call.request(prefetchChunks); stream.setCall(call); return stream; } }; return new GrpcResultSet(stream, this, queryMode); }
readOptions.hasPrefetchChunks() ? readOptions.prefetchChunks() : defaultPrefetchChunks; ResumableStreamIterator stream = new ResumableStreamIterator(MAX_BUFFERED_CHUNKS, READ, span) {