From b35304ede5c980c3c042b89247058cc5a4ab1488 Mon Sep 17 00:00:00 2001 From: Niel Markwick Date: Thu, 10 Sep 2020 03:01:33 +0200 Subject: [PATCH] fix: Remove Guava ImmutableList from API surface (#411) Replace com.google.common.collect.ImmutableList with java.util.List BREAKING CHANGE --- .../clirr-ignored-differences.xml | 16 +++++++++++++++- .../google/cloud/spanner/AsyncResultSet.java | 7 +++---- .../cloud/spanner/AsyncResultSetImpl.java | 18 +++++++++--------- .../spanner/ForwardingAsyncResultSet.java | 7 +++---- .../spanner/AsyncResultSetImplStressTest.java | 10 +++++----- .../cloud/spanner/AsyncResultSetImplTest.java | 6 +++--- .../google/cloud/spanner/AsyncRunnerTest.java | 6 +++--- .../spanner/AsyncTransactionManagerTest.java | 9 +++++---- .../google/cloud/spanner/ReadAsyncTest.java | 9 ++++----- .../spanner/RetryOnInvalidatedSessionTest.java | 3 +-- .../cloud/spanner/it/ITAsyncExamplesTest.java | 8 ++++---- 11 files changed, 55 insertions(+), 44 deletions(-) diff --git a/google-cloud-spanner/clirr-ignored-differences.xml b/google-cloud-spanner/clirr-ignored-differences.xml index ca6ae666a2..bc33de3bbb 100644 --- a/google-cloud-spanner/clirr-ignored-differences.xml +++ b/google-cloud-spanner/clirr-ignored-differences.xml @@ -227,7 +227,21 @@ com/google/cloud/spanner/connection/Connection * executeQueryAsync(*) - + + + + 7006 + com/google/cloud/spanner/AsyncResultSet + com.google.common.collect.ImmutableList toList(com.google.common.base.Function) + java.util.List + + + 7006 + com/google/cloud/spanner/ForwardingAsyncResultSet + com.google.common.collect.ImmutableList toList(com.google.common.base.Function) + java.util.List + + 7012 diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AsyncResultSet.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AsyncResultSet.java index c44a42994e..1ae353c002 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AsyncResultSet.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AsyncResultSet.java @@ -18,7 +18,7 @@ import com.google.api.core.ApiFuture; import com.google.common.base.Function; -import com.google.common.collect.ImmutableList; +import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executor; @@ -203,8 +203,7 @@ interface ReadyCallback { * inline executor such as {@code MoreExecutors.directExecutor()}; using such an executor may * degrade the performance of the Spanner library. */ - ApiFuture> toListAsync( - Function transformer, Executor executor); + ApiFuture> toListAsync(Function transformer, Executor executor); /** * Transforms the row cursor into an immutable list using the given transformer function. {@code @@ -222,5 +221,5 @@ ApiFuture> toListAsync( * * @param transformer function which will be used to transform the row. It should not return null. */ - ImmutableList toList(Function transformer) throws SpannerException; + List toList(Function transformer) throws SpannerException; } diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AsyncResultSetImpl.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AsyncResultSetImpl.java index 981bd45d39..442556b56d 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AsyncResultSetImpl.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/AsyncResultSetImpl.java @@ -31,6 +31,7 @@ import com.google.spanner.v1.ResultSetStats; import java.util.Collection; import java.util.LinkedList; +import java.util.List; import java.util.concurrent.BlockingDeque; import java.util.concurrent.Callable; import java.util.concurrent.CountDownLatch; @@ -483,12 +484,12 @@ public void resume() { } private static class CreateListCallback implements ReadyCallback { - private final SettableApiFuture> future; + private final SettableApiFuture> future; private final Function transformer; private final ImmutableList.Builder builder = ImmutableList.builder(); private CreateListCallback( - SettableApiFuture> future, Function transformer) { + SettableApiFuture> future, Function transformer) { this.future = future; this.transformer = transformer; } @@ -516,20 +517,20 @@ public CallbackResponse cursorReady(AsyncResultSet resultSet) { } @Override - public ApiFuture> toListAsync( + public ApiFuture> toListAsync( Function transformer, Executor executor) { synchronized (monitor) { Preconditions.checkState(!closed, "This AsyncResultSet has been closed"); Preconditions.checkState( this.state == State.INITIALIZED, "This AsyncResultSet has already been used."); - final SettableApiFuture> res = SettableApiFuture.>create(); + final SettableApiFuture> res = SettableApiFuture.>create(); CreateListCallback callback = new CreateListCallback(res, transformer); ApiFuture finished = setCallback(executor, callback); return ApiFutures.transformAsync( finished, - new ApiAsyncFunction>() { + new ApiAsyncFunction>() { @Override - public ApiFuture> apply(Void input) throws Exception { + public ApiFuture> apply(Void input) throws Exception { return res; } }, @@ -538,9 +539,8 @@ public ApiFuture> apply(Void input) throws Exception { } @Override - public ImmutableList toList(Function transformer) - throws SpannerException { - ApiFuture> future = toListAsync(transformer, MoreExecutors.directExecutor()); + public List toList(Function transformer) throws SpannerException { + ApiFuture> future = toListAsync(transformer, MoreExecutors.directExecutor()); try { return future.get(); } catch (ExecutionException e) { diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/ForwardingAsyncResultSet.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/ForwardingAsyncResultSet.java index 78e3505998..e94590bd09 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/ForwardingAsyncResultSet.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/ForwardingAsyncResultSet.java @@ -19,7 +19,7 @@ import com.google.api.core.ApiFuture; import com.google.common.base.Function; import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableList; +import java.util.List; import java.util.concurrent.Executor; /** Forwarding implementation of {@link AsyncResultSet} that forwards all calls to a delegate. */ @@ -52,14 +52,13 @@ public void resume() { } @Override - public ApiFuture> toListAsync( + public ApiFuture> toListAsync( Function transformer, Executor executor) { return delegate.toListAsync(transformer, executor); } @Override - public ImmutableList toList(Function transformer) - throws SpannerException { + public List toList(Function transformer) throws SpannerException { return delegate.toList(transformer); } } diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/AsyncResultSetImplStressTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/AsyncResultSetImplStressTest.java index c3383cadda..44a0571259 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/AsyncResultSetImplStressTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/AsyncResultSetImplStressTest.java @@ -176,7 +176,7 @@ public void toList() throws Exception { for (int i = 0; i < TEST_RUNS; i++) { try (AsyncResultSetImpl impl = new AsyncResultSetImpl(executorProvider, createResultSet(), bufferSize)) { - ImmutableList list = + List list = impl.toList( new Function() { @Override @@ -198,7 +198,7 @@ public void toListWithErrors() throws Exception { try (AsyncResultSetImpl impl = new AsyncResultSetImpl( executorProvider, createResultSetWithErrors(1.0 / resultSetSize), bufferSize)) { - ImmutableList list = + List list = impl.toList( new Function() { @Override @@ -219,7 +219,7 @@ public Row apply(StructReader input) { public void asyncToList() throws Exception { ExecutorProvider executorProvider = SpannerOptions.createDefaultAsyncExecutorProvider(); for (int bufferSize = 1; bufferSize < resultSetSize * 2; bufferSize *= 2) { - List>> futures = new ArrayList<>(TEST_RUNS); + List>> futures = new ArrayList<>(TEST_RUNS); ExecutorService executor = createExecService(32); for (int i = 0; i < TEST_RUNS; i++) { try (AsyncResultSet impl = @@ -235,8 +235,8 @@ public Row apply(StructReader input) { executor)); } } - List> lists = ApiFutures.allAsList(futures).get(); - for (ImmutableList list : lists) { + List> lists = ApiFutures.allAsList(futures).get(); + for (List list : lists) { assertThat(list).containsExactlyElementsIn(createExpectedRows()); } executor.shutdown(); diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/AsyncResultSetImplTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/AsyncResultSetImplTest.java index 9359dc6694..78da23ca43 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/AsyncResultSetImplTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/AsyncResultSetImplTest.java @@ -27,8 +27,8 @@ import com.google.cloud.spanner.AsyncResultSet.CursorState; import com.google.cloud.spanner.AsyncResultSet.ReadyCallback; import com.google.common.base.Function; -import com.google.common.collect.ImmutableList; import com.google.common.collect.Range; +import java.util.List; import java.util.concurrent.BlockingDeque; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; @@ -117,7 +117,7 @@ public void toList() { when(delegate.getCurrentRowAsStruct()).thenReturn(mock(Struct.class)); try (AsyncResultSetImpl rs = new AsyncResultSetImpl(simpleProvider, delegate, AsyncResultSetImpl.DEFAULT_BUFFER_SIZE)) { - ImmutableList list = + List list = rs.toList( new Function() { @Override @@ -160,7 +160,7 @@ public void toListAsync() throws InterruptedException, ExecutionException { when(delegate.getCurrentRowAsStruct()).thenReturn(mock(Struct.class)); try (AsyncResultSetImpl rs = new AsyncResultSetImpl(simpleProvider, delegate, AsyncResultSetImpl.DEFAULT_BUFFER_SIZE)) { - ApiFuture> future = + ApiFuture> future = rs.toListAsync( new Function() { @Override diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/AsyncRunnerTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/AsyncRunnerTest.java index eb00047ca4..3869dbdfcf 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/AsyncRunnerTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/AsyncRunnerTest.java @@ -596,11 +596,11 @@ public String apply(Struct input) { @Test public void asyncRunnerRead() throws Exception { AsyncRunner runner = client().runAsync(); - ApiFuture> val = + ApiFuture> val = runner.runAsync( - new AsyncWork>() { + new AsyncWork>() { @Override - public ApiFuture> doWorkAsync(TransactionContext txn) { + public ApiFuture> doWorkAsync(TransactionContext txn) { return txn.readAsync(READ_TABLE_NAME, KeySet.all(), READ_COLUMN_NAMES) .toListAsync( new Function() { diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/AsyncTransactionManagerTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/AsyncTransactionManagerTest.java index e2299f3615..70b3fd3f92 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/AsyncTransactionManagerTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/AsyncTransactionManagerTest.java @@ -51,6 +51,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executor; import java.util.concurrent.Executors; @@ -960,17 +961,17 @@ public ApiFuture apply(TransactionContext txn, Struct input) @Test public void asyncTransactionManagerRead() throws Exception { - AsyncTransactionStep> res; + AsyncTransactionStep> res; try (AsyncTransactionManager mgr = client().transactionManagerAsync()) { TransactionContextFuture txn = mgr.beginAsync(); while (true) { try { res = txn.then( - new AsyncTransactionFunction>() { + new AsyncTransactionFunction>() { @Override - public ApiFuture> apply( - TransactionContext txn, Void input) throws Exception { + public ApiFuture> apply(TransactionContext txn, Void input) + throws Exception { return txn.readAsync(READ_TABLE_NAME, KeySet.all(), READ_COLUMN_NAMES) .toListAsync( new Function() { diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/ReadAsyncTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/ReadAsyncTest.java index 13e4c47d08..ec5524170d 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/ReadAsyncTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/ReadAsyncTest.java @@ -32,7 +32,6 @@ import com.google.cloud.spanner.MockSpannerServiceImpl.StatementResult; import com.google.common.base.Function; import com.google.common.collect.ContiguousSet; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import io.grpc.Server; @@ -317,8 +316,8 @@ public void readOnlyTransaction() throws Exception { mockSpanner.putStatementResult( StatementResult.query(statement2, generateKeyValueResultSet(ContiguousSet.closed(1, 3)))); - ApiFuture> values1; - ApiFuture> values2; + ApiFuture> values1; + ApiFuture> values2; try (ReadOnlyTransaction tx = client.readOnlyTransaction()) { try (AsyncResultSet rs = tx.executeQueryAsync(statement1)) { values1 = @@ -346,9 +345,9 @@ public String apply(StructReader input) { ApiFuture> allValues = ApiFutures.transform( ApiFutures.allAsList(Arrays.asList(values1, values2)), - new ApiFunction>, Iterable>() { + new ApiFunction>, Iterable>() { @Override - public Iterable apply(List> input) { + public Iterable apply(List> input) { return Iterables.mergeSorted( input, new Comparator() { diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/RetryOnInvalidatedSessionTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/RetryOnInvalidatedSessionTest.java index 7380791eed..fcf1c6e35b 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/RetryOnInvalidatedSessionTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/RetryOnInvalidatedSessionTest.java @@ -31,7 +31,6 @@ import com.google.cloud.spanner.v1.SpannerSettings; import com.google.common.base.Function; import com.google.common.base.Stopwatch; -import com.google.common.collect.ImmutableList; import com.google.protobuf.ListValue; import com.google.spanner.v1.ResultSetMetadata; import com.google.spanner.v1.StructType; @@ -275,7 +274,7 @@ public void singleUseSelect() throws InterruptedException { @Test public void singleUseSelectAsync() throws Exception { invalidateSessionPool(); - ApiFuture> list; + ApiFuture> list; try (AsyncResultSet rs = client.singleUse().executeQueryAsync(SELECT1AND2)) { list = rs.toListAsync(TO_LONG, executor); assertThat(list.get()).containsExactly(1L, 2L); diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITAsyncExamplesTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITAsyncExamplesTest.java index c5e2419ba6..5849176bbb 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITAsyncExamplesTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITAsyncExamplesTest.java @@ -343,8 +343,8 @@ public ApiFuture doWorkAsync(TransactionContext txn) { public void readOnlyTransaction() throws Exception { ImmutableList keys1 = ImmutableList.of("k10", "k11", "k12"); ImmutableList keys2 = ImmutableList.of("k1", "k2", "k3"); - ApiFuture> values1; - ApiFuture> values2; + ApiFuture> values1; + ApiFuture> values2; try (ReadOnlyTransaction tx = client.readOnlyTransaction()) { try (AsyncResultSet rs = tx.executeQueryAsync( @@ -382,9 +382,9 @@ public String apply(StructReader input) { ApiFuture> allValues = ApiFutures.transform( ApiFutures.allAsList(Arrays.asList(values1, values2)), - new ApiFunction>, Iterable>() { + new ApiFunction>, Iterable>() { @Override - public Iterable apply(List> input) { + public Iterable apply(List> input) { return Iterables.mergeSorted( input, new Comparator() {