Skip to content

Commit b35304e

Browse files
authored
fix: Remove Guava ImmutableList from API surface (#411)
Replace com.google.common.collect.ImmutableList with java.util.List BREAKING CHANGE
1 parent 7c150cc commit b35304e

11 files changed

+55
-44
lines changed

google-cloud-spanner/clirr-ignored-differences.xml

+15-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,21 @@
227227
<className>com/google/cloud/spanner/connection/Connection</className>
228228
<method>* executeQueryAsync(*)</method>
229229
</difference>
230-
230+
231+
<!-- Use List interface in Async API (compared to 1.60.0)-->
232+
<difference>
233+
<differenceType>7006</differenceType>
234+
<className>com/google/cloud/spanner/AsyncResultSet</className>
235+
<method>com.google.common.collect.ImmutableList toList(com.google.common.base.Function)</method>
236+
<to>java.util.List</to>
237+
</difference>
238+
<difference>
239+
<differenceType>7006</differenceType>
240+
<className>com/google/cloud/spanner/ForwardingAsyncResultSet</className>
241+
<method>com.google.common.collect.ImmutableList toList(com.google.common.base.Function)</method>
242+
<to>java.util.List</to>
243+
</difference>
244+
231245
<!-- Adding operation RPCs to InstanceAdminClient. -->
232246
<difference>
233247
<differenceType>7012</differenceType>

google-cloud-spanner/src/main/java/com/google/cloud/spanner/AsyncResultSet.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import com.google.api.core.ApiFuture;
2020
import com.google.common.base.Function;
21-
import com.google.common.collect.ImmutableList;
21+
import java.util.List;
2222
import java.util.concurrent.ExecutionException;
2323
import java.util.concurrent.Executor;
2424

@@ -203,8 +203,7 @@ interface ReadyCallback {
203203
* inline executor such as {@code MoreExecutors.directExecutor()}; using such an executor may
204204
* degrade the performance of the Spanner library.
205205
*/
206-
<T> ApiFuture<ImmutableList<T>> toListAsync(
207-
Function<StructReader, T> transformer, Executor executor);
206+
<T> ApiFuture<List<T>> toListAsync(Function<StructReader, T> transformer, Executor executor);
208207

209208
/**
210209
* Transforms the row cursor into an immutable list using the given transformer function. {@code
@@ -222,5 +221,5 @@ <T> ApiFuture<ImmutableList<T>> toListAsync(
222221
*
223222
* @param transformer function which will be used to transform the row. It should not return null.
224223
*/
225-
<T> ImmutableList<T> toList(Function<StructReader, T> transformer) throws SpannerException;
224+
<T> List<T> toList(Function<StructReader, T> transformer) throws SpannerException;
226225
}

google-cloud-spanner/src/main/java/com/google/cloud/spanner/AsyncResultSetImpl.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.google.spanner.v1.ResultSetStats;
3232
import java.util.Collection;
3333
import java.util.LinkedList;
34+
import java.util.List;
3435
import java.util.concurrent.BlockingDeque;
3536
import java.util.concurrent.Callable;
3637
import java.util.concurrent.CountDownLatch;
@@ -483,12 +484,12 @@ public void resume() {
483484
}
484485

485486
private static class CreateListCallback<T> implements ReadyCallback {
486-
private final SettableApiFuture<ImmutableList<T>> future;
487+
private final SettableApiFuture<List<T>> future;
487488
private final Function<StructReader, T> transformer;
488489
private final ImmutableList.Builder<T> builder = ImmutableList.builder();
489490

490491
private CreateListCallback(
491-
SettableApiFuture<ImmutableList<T>> future, Function<StructReader, T> transformer) {
492+
SettableApiFuture<List<T>> future, Function<StructReader, T> transformer) {
492493
this.future = future;
493494
this.transformer = transformer;
494495
}
@@ -516,20 +517,20 @@ public CallbackResponse cursorReady(AsyncResultSet resultSet) {
516517
}
517518

518519
@Override
519-
public <T> ApiFuture<ImmutableList<T>> toListAsync(
520+
public <T> ApiFuture<List<T>> toListAsync(
520521
Function<StructReader, T> transformer, Executor executor) {
521522
synchronized (monitor) {
522523
Preconditions.checkState(!closed, "This AsyncResultSet has been closed");
523524
Preconditions.checkState(
524525
this.state == State.INITIALIZED, "This AsyncResultSet has already been used.");
525-
final SettableApiFuture<ImmutableList<T>> res = SettableApiFuture.<ImmutableList<T>>create();
526+
final SettableApiFuture<List<T>> res = SettableApiFuture.<List<T>>create();
526527
CreateListCallback<T> callback = new CreateListCallback<T>(res, transformer);
527528
ApiFuture<Void> finished = setCallback(executor, callback);
528529
return ApiFutures.transformAsync(
529530
finished,
530-
new ApiAsyncFunction<Void, ImmutableList<T>>() {
531+
new ApiAsyncFunction<Void, List<T>>() {
531532
@Override
532-
public ApiFuture<ImmutableList<T>> apply(Void input) throws Exception {
533+
public ApiFuture<List<T>> apply(Void input) throws Exception {
533534
return res;
534535
}
535536
},
@@ -538,9 +539,8 @@ public ApiFuture<ImmutableList<T>> apply(Void input) throws Exception {
538539
}
539540

540541
@Override
541-
public <T> ImmutableList<T> toList(Function<StructReader, T> transformer)
542-
throws SpannerException {
543-
ApiFuture<ImmutableList<T>> future = toListAsync(transformer, MoreExecutors.directExecutor());
542+
public <T> List<T> toList(Function<StructReader, T> transformer) throws SpannerException {
543+
ApiFuture<List<T>> future = toListAsync(transformer, MoreExecutors.directExecutor());
544544
try {
545545
return future.get();
546546
} catch (ExecutionException e) {

google-cloud-spanner/src/main/java/com/google/cloud/spanner/ForwardingAsyncResultSet.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import com.google.api.core.ApiFuture;
2020
import com.google.common.base.Function;
2121
import com.google.common.base.Preconditions;
22-
import com.google.common.collect.ImmutableList;
22+
import java.util.List;
2323
import java.util.concurrent.Executor;
2424

2525
/** Forwarding implementation of {@link AsyncResultSet} that forwards all calls to a delegate. */
@@ -52,14 +52,13 @@ public void resume() {
5252
}
5353

5454
@Override
55-
public <T> ApiFuture<ImmutableList<T>> toListAsync(
55+
public <T> ApiFuture<List<T>> toListAsync(
5656
Function<StructReader, T> transformer, Executor executor) {
5757
return delegate.toListAsync(transformer, executor);
5858
}
5959

6060
@Override
61-
public <T> ImmutableList<T> toList(Function<StructReader, T> transformer)
62-
throws SpannerException {
61+
public <T> List<T> toList(Function<StructReader, T> transformer) throws SpannerException {
6362
return delegate.toList(transformer);
6463
}
6564
}

google-cloud-spanner/src/test/java/com/google/cloud/spanner/AsyncResultSetImplStressTest.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public void toList() throws Exception {
176176
for (int i = 0; i < TEST_RUNS; i++) {
177177
try (AsyncResultSetImpl impl =
178178
new AsyncResultSetImpl(executorProvider, createResultSet(), bufferSize)) {
179-
ImmutableList<Row> list =
179+
List<Row> list =
180180
impl.toList(
181181
new Function<StructReader, Row>() {
182182
@Override
@@ -198,7 +198,7 @@ public void toListWithErrors() throws Exception {
198198
try (AsyncResultSetImpl impl =
199199
new AsyncResultSetImpl(
200200
executorProvider, createResultSetWithErrors(1.0 / resultSetSize), bufferSize)) {
201-
ImmutableList<Row> list =
201+
List<Row> list =
202202
impl.toList(
203203
new Function<StructReader, Row>() {
204204
@Override
@@ -219,7 +219,7 @@ public Row apply(StructReader input) {
219219
public void asyncToList() throws Exception {
220220
ExecutorProvider executorProvider = SpannerOptions.createDefaultAsyncExecutorProvider();
221221
for (int bufferSize = 1; bufferSize < resultSetSize * 2; bufferSize *= 2) {
222-
List<ApiFuture<ImmutableList<Row>>> futures = new ArrayList<>(TEST_RUNS);
222+
List<ApiFuture<List<Row>>> futures = new ArrayList<>(TEST_RUNS);
223223
ExecutorService executor = createExecService(32);
224224
for (int i = 0; i < TEST_RUNS; i++) {
225225
try (AsyncResultSet impl =
@@ -235,8 +235,8 @@ public Row apply(StructReader input) {
235235
executor));
236236
}
237237
}
238-
List<ImmutableList<Row>> lists = ApiFutures.allAsList(futures).get();
239-
for (ImmutableList<Row> list : lists) {
238+
List<List<Row>> lists = ApiFutures.allAsList(futures).get();
239+
for (List<Row> list : lists) {
240240
assertThat(list).containsExactlyElementsIn(createExpectedRows());
241241
}
242242
executor.shutdown();

google-cloud-spanner/src/test/java/com/google/cloud/spanner/AsyncResultSetImplTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
import com.google.cloud.spanner.AsyncResultSet.CursorState;
2828
import com.google.cloud.spanner.AsyncResultSet.ReadyCallback;
2929
import com.google.common.base.Function;
30-
import com.google.common.collect.ImmutableList;
3130
import com.google.common.collect.Range;
31+
import java.util.List;
3232
import java.util.concurrent.BlockingDeque;
3333
import java.util.concurrent.CountDownLatch;
3434
import java.util.concurrent.ExecutionException;
@@ -117,7 +117,7 @@ public void toList() {
117117
when(delegate.getCurrentRowAsStruct()).thenReturn(mock(Struct.class));
118118
try (AsyncResultSetImpl rs =
119119
new AsyncResultSetImpl(simpleProvider, delegate, AsyncResultSetImpl.DEFAULT_BUFFER_SIZE)) {
120-
ImmutableList<Object> list =
120+
List<Object> list =
121121
rs.toList(
122122
new Function<StructReader, Object>() {
123123
@Override
@@ -160,7 +160,7 @@ public void toListAsync() throws InterruptedException, ExecutionException {
160160
when(delegate.getCurrentRowAsStruct()).thenReturn(mock(Struct.class));
161161
try (AsyncResultSetImpl rs =
162162
new AsyncResultSetImpl(simpleProvider, delegate, AsyncResultSetImpl.DEFAULT_BUFFER_SIZE)) {
163-
ApiFuture<ImmutableList<Object>> future =
163+
ApiFuture<List<Object>> future =
164164
rs.toListAsync(
165165
new Function<StructReader, Object>() {
166166
@Override

google-cloud-spanner/src/test/java/com/google/cloud/spanner/AsyncRunnerTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -596,11 +596,11 @@ public String apply(Struct input) {
596596
@Test
597597
public void asyncRunnerRead() throws Exception {
598598
AsyncRunner runner = client().runAsync();
599-
ApiFuture<ImmutableList<String>> val =
599+
ApiFuture<List<String>> val =
600600
runner.runAsync(
601-
new AsyncWork<ImmutableList<String>>() {
601+
new AsyncWork<List<String>>() {
602602
@Override
603-
public ApiFuture<ImmutableList<String>> doWorkAsync(TransactionContext txn) {
603+
public ApiFuture<List<String>> doWorkAsync(TransactionContext txn) {
604604
return txn.readAsync(READ_TABLE_NAME, KeySet.all(), READ_COLUMN_NAMES)
605605
.toListAsync(
606606
new Function<StructReader, String>() {

google-cloud-spanner/src/test/java/com/google/cloud/spanner/AsyncTransactionManagerTest.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import java.util.Arrays;
5252
import java.util.Collection;
5353
import java.util.Collections;
54+
import java.util.List;
5455
import java.util.concurrent.ExecutionException;
5556
import java.util.concurrent.Executor;
5657
import java.util.concurrent.Executors;
@@ -960,17 +961,17 @@ public ApiFuture<String> apply(TransactionContext txn, Struct input)
960961

961962
@Test
962963
public void asyncTransactionManagerRead() throws Exception {
963-
AsyncTransactionStep<Void, ImmutableList<String>> res;
964+
AsyncTransactionStep<Void, List<String>> res;
964965
try (AsyncTransactionManager mgr = client().transactionManagerAsync()) {
965966
TransactionContextFuture txn = mgr.beginAsync();
966967
while (true) {
967968
try {
968969
res =
969970
txn.then(
970-
new AsyncTransactionFunction<Void, ImmutableList<String>>() {
971+
new AsyncTransactionFunction<Void, List<String>>() {
971972
@Override
972-
public ApiFuture<ImmutableList<String>> apply(
973-
TransactionContext txn, Void input) throws Exception {
973+
public ApiFuture<List<String>> apply(TransactionContext txn, Void input)
974+
throws Exception {
974975
return txn.readAsync(READ_TABLE_NAME, KeySet.all(), READ_COLUMN_NAMES)
975976
.toListAsync(
976977
new Function<StructReader, String>() {

google-cloud-spanner/src/test/java/com/google/cloud/spanner/ReadAsyncTest.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import com.google.cloud.spanner.MockSpannerServiceImpl.StatementResult;
3333
import com.google.common.base.Function;
3434
import com.google.common.collect.ContiguousSet;
35-
import com.google.common.collect.ImmutableList;
3635
import com.google.common.collect.ImmutableSet;
3736
import com.google.common.collect.Iterables;
3837
import io.grpc.Server;
@@ -317,8 +316,8 @@ public void readOnlyTransaction() throws Exception {
317316
mockSpanner.putStatementResult(
318317
StatementResult.query(statement2, generateKeyValueResultSet(ContiguousSet.closed(1, 3))));
319318

320-
ApiFuture<ImmutableList<String>> values1;
321-
ApiFuture<ImmutableList<String>> values2;
319+
ApiFuture<List<String>> values1;
320+
ApiFuture<List<String>> values2;
322321
try (ReadOnlyTransaction tx = client.readOnlyTransaction()) {
323322
try (AsyncResultSet rs = tx.executeQueryAsync(statement1)) {
324323
values1 =
@@ -346,9 +345,9 @@ public String apply(StructReader input) {
346345
ApiFuture<Iterable<String>> allValues =
347346
ApiFutures.transform(
348347
ApiFutures.allAsList(Arrays.asList(values1, values2)),
349-
new ApiFunction<List<ImmutableList<String>>, Iterable<String>>() {
348+
new ApiFunction<List<List<String>>, Iterable<String>>() {
350349
@Override
351-
public Iterable<String> apply(List<ImmutableList<String>> input) {
350+
public Iterable<String> apply(List<List<String>> input) {
352351
return Iterables.mergeSorted(
353352
input,
354353
new Comparator<String>() {

google-cloud-spanner/src/test/java/com/google/cloud/spanner/RetryOnInvalidatedSessionTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import com.google.cloud.spanner.v1.SpannerSettings;
3232
import com.google.common.base.Function;
3333
import com.google.common.base.Stopwatch;
34-
import com.google.common.collect.ImmutableList;
3534
import com.google.protobuf.ListValue;
3635
import com.google.spanner.v1.ResultSetMetadata;
3736
import com.google.spanner.v1.StructType;
@@ -275,7 +274,7 @@ public void singleUseSelect() throws InterruptedException {
275274
@Test
276275
public void singleUseSelectAsync() throws Exception {
277276
invalidateSessionPool();
278-
ApiFuture<ImmutableList<Long>> list;
277+
ApiFuture<List<Long>> list;
279278
try (AsyncResultSet rs = client.singleUse().executeQueryAsync(SELECT1AND2)) {
280279
list = rs.toListAsync(TO_LONG, executor);
281280
assertThat(list.get()).containsExactly(1L, 2L);

google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITAsyncExamplesTest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,8 @@ public ApiFuture<long[]> doWorkAsync(TransactionContext txn) {
343343
public void readOnlyTransaction() throws Exception {
344344
ImmutableList<String> keys1 = ImmutableList.of("k10", "k11", "k12");
345345
ImmutableList<String> keys2 = ImmutableList.of("k1", "k2", "k3");
346-
ApiFuture<ImmutableList<String>> values1;
347-
ApiFuture<ImmutableList<String>> values2;
346+
ApiFuture<List<String>> values1;
347+
ApiFuture<List<String>> values2;
348348
try (ReadOnlyTransaction tx = client.readOnlyTransaction()) {
349349
try (AsyncResultSet rs =
350350
tx.executeQueryAsync(
@@ -382,9 +382,9 @@ public String apply(StructReader input) {
382382
ApiFuture<Iterable<String>> allValues =
383383
ApiFutures.transform(
384384
ApiFutures.allAsList(Arrays.asList(values1, values2)),
385-
new ApiFunction<List<ImmutableList<String>>, Iterable<String>>() {
385+
new ApiFunction<List<List<String>>, Iterable<String>>() {
386386
@Override
387-
public Iterable<String> apply(List<ImmutableList<String>> input) {
387+
public Iterable<String> apply(List<List<String>> input) {
388388
return Iterables.mergeSorted(
389389
input,
390390
new Comparator<String>() {

0 commit comments

Comments
 (0)