Skip to content

Commit

Permalink
Merge pull request googleapis#18 from garrettjonesgoogle/master
Browse files Browse the repository at this point in the history
Making GAX compatible with Java 1.7
  • Loading branch information
garrettjonesgoogle committed Feb 24, 2016
2 parents 43df9fb + 2306f85 commit 7d57f2a
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 25 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ group = "com.google.api"
archivesBaseName = "gax"
version = "0.0.2-SNAPSHOT"

sourceCompatibility = 1.7
targetCompatibility = 1.7

// Dependencies
// ------------

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/google/api/gax/core/ConnectionSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -91,7 +91,7 @@ public Credentials getCredentials() {
/**
* Sets the credentials using application default, applying the given scopes if needed.
*/
public Builder provideCredentialsWith(List<String> scopes) {
public Builder provideCredentialsWith(final List<String> scopes) {
return setCredentialsProvider(new CredentialsProvider() {
@Override
public Credentials getCredentials() throws IOException {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/google/api/gax/grpc/ApiCallable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<RequestT> context, StreamObserver<ResponseT> observer) {
public void asyncCall(CallContext<RequestT> context, final StreamObserver<ResponseT> observer) {
Futures.addCallback(
futureCall(context),
new FutureCallback<ResponseT>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class ExceptionTransformingCallable<RequestT, ResponseT>
}

public ListenableFuture<ResponseT> futureCall(CallContext<RequestT> context) {
SettableFuture<ResponseT> result = SettableFuture.<ResponseT>create();
final SettableFuture<ResponseT> result = SettableFuture.<ResponseT>create();
ListenableFuture<ResponseT> innerCall = callable.futureCall(context);
Futures.addCallback(
innerCall,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public String toString() {
}

public ListenableFuture<Iterable<ResourceT>> futureCall(CallContext<RequestT> context) {
return Futures.immediateFuture(new StreamingIterable(context));
return Futures.immediateFuture((Iterable<ResourceT>)new StreamingIterable(context));
}

private class StreamingIterable implements Iterable<ResourceT> {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/google/api/gax/grpc/ServiceApiSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public abstract Builder<MethodId> setRetryableCodes(
public abstract Builder<MethodId> setRetryParams(
ImmutableMap<MethodId, RetryParams> retryParams);

public Builder<MethodId> provideChannelWith(ManagedChannel channel) {
public Builder<MethodId> provideChannelWith(final ManagedChannel channel) {
ChannelProvider provider = new ChannelProvider() {
@Override
public ManagedChannel getChannel(Executor executor) {
Expand All @@ -138,7 +138,7 @@ public ManagedChannel getChannel(Executor executor) {
return setChannelProvider(provider);
}

public Builder<MethodId> provideChannelWith(ConnectionSettings settings) {
public Builder<MethodId> provideChannelWith(final ConnectionSettings settings) {
ChannelProvider provider = new ChannelProvider() {
@Override
public ManagedChannel getChannel(Executor executor) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class ThresholdBundlerTest {
@Test
public void testEmptyAddAndDrain() {
ThresholdBundler<Integer> bundler =
new ThresholdBundler<Integer>(BundlingThresholds.of(5));
new ThresholdBundler<Integer>(BundlingThresholds.<Integer>of(5));
List<Integer> resultBundle = new ArrayList<>();
Truth.assertThat(bundler.size()).isEqualTo(0);
Truth.assertThat(bundler.toArray()).isEqualTo(new Integer[]{});
Expand All @@ -58,7 +58,7 @@ public void testEmptyAddAndDrain() {
@Test
public void testAddAndDrain() {
ThresholdBundler<Integer> bundler =
new ThresholdBundler<Integer>(BundlingThresholds.of(5));
new ThresholdBundler<Integer>(BundlingThresholds.<Integer>of(5));
bundler.add(14);
Truth.assertThat(bundler.size()).isEqualTo(1);
Truth.assertThat(bundler.toArray()).isEqualTo(new Integer[]{14});
Expand All @@ -79,7 +79,7 @@ public void testAddAndDrain() {
@Test
public void testBundling() throws Exception {
ThresholdBundler<Integer> bundler =
new ThresholdBundler<Integer>(BundlingThresholds.of(2));
new ThresholdBundler<Integer>(BundlingThresholds.<Integer>of(2));
AccumulatingBundleReceiver<Integer> receiver =
new AccumulatingBundleReceiver<Integer>();
ThresholdBundlingForwarder<Integer> forwarder =
Expand Down Expand Up @@ -143,7 +143,7 @@ public void testBundlingWithDelay() throws Exception {
@Test
public void testFlush() throws Exception {
ThresholdBundler<Integer> bundler =
new ThresholdBundler<Integer>(BundlingThresholds.of(2));
new ThresholdBundler<Integer>(BundlingThresholds.<Integer>of(2));
AccumulatingBundleReceiver<Integer> receiver =
new AccumulatingBundleReceiver<Integer>();
ThresholdBundlingForwarder<Integer> forwarder =
Expand Down
28 changes: 14 additions & 14 deletions src/test/java/com/google/api/gax/grpc/ApiCallableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ public void bind() {
public void retry() {
ImmutableSet<Status.Code> retryable = ImmutableSet.<Status.Code>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<Integer>)Mockito.any()))
.thenReturn(Futures.<Integer>immediateFailedFuture(t))
.thenReturn(Futures.<Integer>immediateFailedFuture(t))
.thenReturn(Futures.<Integer>immediateFailedFuture(t))
.thenReturn(Futures.<Integer>immediateFuture(2));
ApiCallable<Integer, Integer> callable =
ApiCallable.<Integer, Integer>create(callInt)
.retryableOn(retryable)
Expand All @@ -136,9 +136,9 @@ public void retryNoRecover() {
thrown.expect(UncheckedExecutionException.class);
thrown.expectMessage("foobar");
ImmutableSet<Status.Code> retryable = ImmutableSet.<Status.Code>of(Status.Code.UNAVAILABLE);
Mockito.when(callInt.futureCall(Mockito.any()))
Mockito.when(callInt.futureCall((CallContext<Integer>)Mockito.any()))
.thenReturn(
Futures.immediateFailedFuture(
Futures.<Integer>immediateFailedFuture(
Status.FAILED_PRECONDITION.withDescription("foobar").asException()))
.thenReturn(Futures.immediateFuture(2));
ApiCallable<Integer, Integer> callable =
Expand All @@ -153,9 +153,9 @@ public void retryKeepFailing() {
thrown.expect(UncheckedExecutionException.class);
thrown.expectMessage("foobar");
ImmutableSet<Status.Code> retryable = ImmutableSet.<Status.Code>of(Status.Code.UNAVAILABLE);
Mockito.when(callInt.futureCall(Mockito.any()))
Mockito.when(callInt.futureCall((CallContext<Integer>)Mockito.any()))
.thenReturn(
Futures.immediateFailedFuture(
Futures.<Integer>immediateFailedFuture(
Status.UNAVAILABLE.withDescription("foobar").asException()));
ApiCallable<Integer, Integer> callable =
ApiCallable.<Integer, Integer>create(callInt)
Expand Down Expand Up @@ -193,10 +193,10 @@ public Iterable<Integer> extractResources(List<Integer> 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<Integer>)Mockito.any()))
.thenReturn(Futures.<List<Integer>>immediateFuture(Lists.newArrayList(0, 1, 2)))
.thenReturn(Futures.<List<Integer>>immediateFuture(Lists.newArrayList(3, 4)))
.thenReturn(Futures.immediateFuture(Collections.<Integer>emptyList()));
Truth.assertThat(
ApiCallable.<Integer, List<Integer>>create(callIntList)
.pageStreaming(new StreamingDescriptor())
Expand Down Expand Up @@ -281,7 +281,7 @@ public void splitException(
};

private <RequestT, ResponseT> BundlingSettings<RequestT, ResponseT> createBundlingSettings(
int messageCountThreshold) {
final int messageCountThreshold) {
return new BundlingSettings<RequestT, ResponseT>() {
@Override
public Duration getDelayThreshold() {
Expand Down

0 comments on commit 7d57f2a

Please sign in to comment.