From 2306f850c60f9184a62965ed75ce77228662fbd7 Mon Sep 17 00:00:00 2001 From: Garrett Jones Date: Tue, 23 Feb 2016 16:57:53 -0800 Subject: [PATCH] Making GAX compatible with Java 1.7 --- build.gradle | 3 ++ .../api/gax/core/ConnectionSettings.java | 4 +-- .../com/google/api/gax/grpc/ApiCallable.java | 2 +- .../grpc/ExceptionTransformingCallable.java | 2 +- .../api/gax/grpc/PageStreamingCallable.java | 2 +- .../api/gax/grpc/ServiceApiSettings.java | 4 +-- .../gax/bundling/ThresholdBundlerTest.java | 8 +++--- .../google/api/gax/grpc/ApiCallableTest.java | 28 +++++++++---------- 8 files changed, 28 insertions(+), 25 deletions(-) diff --git a/build.gradle b/build.gradle index ba0fb1b5abe2..8a2645c81e94 100644 --- a/build.gradle +++ b/build.gradle @@ -9,6 +9,9 @@ group = "com.google.api" archivesBaseName = "gax" version = "0.0.2-SNAPSHOT" +sourceCompatibility = 1.7 +targetCompatibility = 1.7 + // Dependencies // ------------ diff --git a/src/main/java/com/google/api/gax/core/ConnectionSettings.java b/src/main/java/com/google/api/gax/core/ConnectionSettings.java index a34a721f3b06..ae15bb501363 100644 --- a/src/main/java/com/google/api/gax/core/ConnectionSettings.java +++ b/src/main/java/com/google/api/gax/core/ConnectionSettings.java @@ -79,7 +79,7 @@ public abstract static class Builder { /** * Sets the credentials to use in order to call the service. */ - public Builder provideCredentialsWith(Credentials credentials) { + public Builder provideCredentialsWith(final Credentials credentials) { return setCredentialsProvider(new CredentialsProvider() { @Override public Credentials getCredentials() { @@ -91,7 +91,7 @@ public Credentials getCredentials() { /** * Sets the credentials using application default, applying the given scopes if needed. */ - public Builder provideCredentialsWith(List scopes) { + public Builder provideCredentialsWith(final List scopes) { return setCredentialsProvider(new CredentialsProvider() { @Override public Credentials getCredentials() throws IOException { diff --git a/src/main/java/com/google/api/gax/grpc/ApiCallable.java b/src/main/java/com/google/api/gax/grpc/ApiCallable.java index 8366383d81ed..030b80a3d3a4 100644 --- a/src/main/java/com/google/api/gax/grpc/ApiCallable.java +++ b/src/main/java/com/google/api/gax/grpc/ApiCallable.java @@ -114,7 +114,7 @@ public ResponseT call(RequestT request) { * @param context {@link com.google.api.gax.grpc.CallContext} to make the call with * @param observer Observer to interact with the result */ - public void asyncCall(CallContext context, StreamObserver observer) { + public void asyncCall(CallContext context, final StreamObserver observer) { Futures.addCallback( futureCall(context), new FutureCallback() { diff --git a/src/main/java/com/google/api/gax/grpc/ExceptionTransformingCallable.java b/src/main/java/com/google/api/gax/grpc/ExceptionTransformingCallable.java index 7b361c2a29de..f8eb59e87361 100644 --- a/src/main/java/com/google/api/gax/grpc/ExceptionTransformingCallable.java +++ b/src/main/java/com/google/api/gax/grpc/ExceptionTransformingCallable.java @@ -58,7 +58,7 @@ class ExceptionTransformingCallable } public ListenableFuture futureCall(CallContext context) { - SettableFuture result = SettableFuture.create(); + final SettableFuture result = SettableFuture.create(); ListenableFuture innerCall = callable.futureCall(context); Futures.addCallback( innerCall, diff --git a/src/main/java/com/google/api/gax/grpc/PageStreamingCallable.java b/src/main/java/com/google/api/gax/grpc/PageStreamingCallable.java index a8c7d7e455ef..c310927cac70 100644 --- a/src/main/java/com/google/api/gax/grpc/PageStreamingCallable.java +++ b/src/main/java/com/google/api/gax/grpc/PageStreamingCallable.java @@ -62,7 +62,7 @@ public String toString() { } public ListenableFuture> futureCall(CallContext context) { - return Futures.immediateFuture(new StreamingIterable(context)); + return Futures.immediateFuture((Iterable)new StreamingIterable(context)); } private class StreamingIterable implements Iterable { diff --git a/src/main/java/com/google/api/gax/grpc/ServiceApiSettings.java b/src/main/java/com/google/api/gax/grpc/ServiceApiSettings.java index af523a33030f..3046f7b582c5 100644 --- a/src/main/java/com/google/api/gax/grpc/ServiceApiSettings.java +++ b/src/main/java/com/google/api/gax/grpc/ServiceApiSettings.java @@ -128,7 +128,7 @@ public abstract Builder setRetryableCodes( public abstract Builder setRetryParams( ImmutableMap retryParams); - public Builder provideChannelWith(ManagedChannel channel) { + public Builder provideChannelWith(final ManagedChannel channel) { ChannelProvider provider = new ChannelProvider() { @Override public ManagedChannel getChannel(Executor executor) { @@ -138,7 +138,7 @@ public ManagedChannel getChannel(Executor executor) { return setChannelProvider(provider); } - public Builder provideChannelWith(ConnectionSettings settings) { + public Builder provideChannelWith(final ConnectionSettings settings) { ChannelProvider provider = new ChannelProvider() { @Override public ManagedChannel getChannel(Executor executor) throws IOException { diff --git a/src/test/java/com/google/api/gax/bundling/ThresholdBundlerTest.java b/src/test/java/com/google/api/gax/bundling/ThresholdBundlerTest.java index 534dd17c7751..0f3b89e22360 100644 --- a/src/test/java/com/google/api/gax/bundling/ThresholdBundlerTest.java +++ b/src/test/java/com/google/api/gax/bundling/ThresholdBundlerTest.java @@ -45,7 +45,7 @@ public class ThresholdBundlerTest { @Test public void testEmptyAddAndDrain() { ThresholdBundler bundler = - new ThresholdBundler(BundlingThresholds.of(5)); + new ThresholdBundler(BundlingThresholds.of(5)); List resultBundle = new ArrayList<>(); Truth.assertThat(bundler.size()).isEqualTo(0); Truth.assertThat(bundler.toArray()).isEqualTo(new Integer[]{}); @@ -58,7 +58,7 @@ public void testEmptyAddAndDrain() { @Test public void testAddAndDrain() { ThresholdBundler bundler = - new ThresholdBundler(BundlingThresholds.of(5)); + new ThresholdBundler(BundlingThresholds.of(5)); bundler.add(14); Truth.assertThat(bundler.size()).isEqualTo(1); Truth.assertThat(bundler.toArray()).isEqualTo(new Integer[]{14}); @@ -79,7 +79,7 @@ public void testAddAndDrain() { @Test public void testBundling() throws Exception { ThresholdBundler bundler = - new ThresholdBundler(BundlingThresholds.of(2)); + new ThresholdBundler(BundlingThresholds.of(2)); AccumulatingBundleReceiver receiver = new AccumulatingBundleReceiver(); ThresholdBundlingForwarder forwarder = @@ -143,7 +143,7 @@ public void testBundlingWithDelay() throws Exception { @Test public void testFlush() throws Exception { ThresholdBundler bundler = - new ThresholdBundler(BundlingThresholds.of(2)); + new ThresholdBundler(BundlingThresholds.of(2)); AccumulatingBundleReceiver receiver = new AccumulatingBundleReceiver(); ThresholdBundlingForwarder forwarder = diff --git a/src/test/java/com/google/api/gax/grpc/ApiCallableTest.java b/src/test/java/com/google/api/gax/grpc/ApiCallableTest.java index a657c13acc7d..16d4b642ee75 100644 --- a/src/test/java/com/google/api/gax/grpc/ApiCallableTest.java +++ b/src/test/java/com/google/api/gax/grpc/ApiCallableTest.java @@ -119,11 +119,11 @@ public void bind() { public void retry() { ImmutableSet retryable = ImmutableSet.of(Status.Code.UNAVAILABLE); Throwable t = Status.UNAVAILABLE.asException(); - Mockito.when(callInt.futureCall(Mockito.any())) - .thenReturn(Futures.immediateFailedFuture(t)) - .thenReturn(Futures.immediateFailedFuture(t)) - .thenReturn(Futures.immediateFailedFuture(t)) - .thenReturn(Futures.immediateFuture(2)); + Mockito.when(callInt.futureCall((CallContext)Mockito.any())) + .thenReturn(Futures.immediateFailedFuture(t)) + .thenReturn(Futures.immediateFailedFuture(t)) + .thenReturn(Futures.immediateFailedFuture(t)) + .thenReturn(Futures.immediateFuture(2)); ApiCallable callable = ApiCallable.create(callInt) .retryableOn(retryable) @@ -136,9 +136,9 @@ public void retryNoRecover() { thrown.expect(UncheckedExecutionException.class); thrown.expectMessage("foobar"); ImmutableSet retryable = ImmutableSet.of(Status.Code.UNAVAILABLE); - Mockito.when(callInt.futureCall(Mockito.any())) + Mockito.when(callInt.futureCall((CallContext)Mockito.any())) .thenReturn( - Futures.immediateFailedFuture( + Futures.immediateFailedFuture( Status.FAILED_PRECONDITION.withDescription("foobar").asException())) .thenReturn(Futures.immediateFuture(2)); ApiCallable callable = @@ -153,9 +153,9 @@ public void retryKeepFailing() { thrown.expect(UncheckedExecutionException.class); thrown.expectMessage("foobar"); ImmutableSet retryable = ImmutableSet.of(Status.Code.UNAVAILABLE); - Mockito.when(callInt.futureCall(Mockito.any())) + Mockito.when(callInt.futureCall((CallContext)Mockito.any())) .thenReturn( - Futures.immediateFailedFuture( + Futures.immediateFailedFuture( Status.UNAVAILABLE.withDescription("foobar").asException())); ApiCallable callable = ApiCallable.create(callInt) @@ -193,10 +193,10 @@ public Iterable extractResources(List payload) { @Test public void pageStreaming() { - Mockito.when(callIntList.futureCall(Mockito.any())) - .thenReturn(Futures.immediateFuture(Lists.newArrayList(0, 1, 2))) - .thenReturn(Futures.immediateFuture(Lists.newArrayList(3, 4))) - .thenReturn(Futures.immediateFuture(Collections.emptyList())); + Mockito.when(callIntList.futureCall((CallContext)Mockito.any())) + .thenReturn(Futures.>immediateFuture(Lists.newArrayList(0, 1, 2))) + .thenReturn(Futures.>immediateFuture(Lists.newArrayList(3, 4))) + .thenReturn(Futures.immediateFuture(Collections.emptyList())); Truth.assertThat( ApiCallable.>create(callIntList) .pageStreaming(new StreamingDescriptor()) @@ -281,7 +281,7 @@ public void splitException( }; private BundlingSettings createBundlingSettings( - int messageCountThreshold) { + final int messageCountThreshold) { return new BundlingSettings() { @Override public Duration getDelayThreshold() {