aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorEric Anderson <ejona@google.com>2018-10-26 09:58:30 -0700
committerEric Anderson <ejona@google.com>2018-10-26 10:32:57 -0700
commit4cc0734f3735b20ccdef3a777978873909a1d280 (patch)
tree0a13be6431dc2cb16bdf8a1eb286d2100a90a997 /core
parent63a24507658b3b9bab62be5f88b0f001824c808d (diff)
downloadgrpc-grpc-java-4cc0734f3735b20ccdef3a777978873909a1d280.tar.gz
core: Make MetadataApplier an interface again
Swapping MetadataApplier to an abstract class is not ABI-safe for callers. So I revert back to the previous interface definition and introduce a CallCredentials2.MetadataApplier which is an abstract class. Once everyone is on CallCredentials2 then we can swap it to an abstract class again. Fixes #5002
Diffstat (limited to 'core')
-rw-r--r--core/src/main/java/io/grpc/CallCredentials.java7
-rw-r--r--core/src/main/java/io/grpc/CallCredentials2.java19
-rw-r--r--core/src/main/java/io/grpc/internal/MetadataApplierImpl.java2
-rw-r--r--core/src/test/java/io/grpc/internal/CallCredentials2ApplyingTest.java2
-rw-r--r--core/src/test/java/io/grpc/internal/CallCredentialsApplyingTest.java24
-rw-r--r--core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java8
6 files changed, 40 insertions, 22 deletions
diff --git a/core/src/main/java/io/grpc/CallCredentials.java b/core/src/main/java/io/grpc/CallCredentials.java
index 2bc4b2876..03be65310 100644
--- a/core/src/main/java/io/grpc/CallCredentials.java
+++ b/core/src/main/java/io/grpc/CallCredentials.java
@@ -99,18 +99,19 @@ public interface CallCredentials {
*
* <p>Exactly one of its methods must be called to make the RPC proceed.
*/
+ @Deprecated
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1914")
- public abstract static class MetadataApplier {
+ public interface MetadataApplier {
/**
* Called when headers are successfully generated. They will be merged into the original
* headers.
*/
- public abstract void apply(Metadata headers);
+ void apply(Metadata headers);
/**
* Called when there has been an error when preparing the headers. This will fail the RPC.
*/
- public abstract void fail(Status status);
+ void fail(Status status);
}
/**
diff --git a/core/src/main/java/io/grpc/CallCredentials2.java b/core/src/main/java/io/grpc/CallCredentials2.java
index 458a04c9f..998df42db 100644
--- a/core/src/main/java/io/grpc/CallCredentials2.java
+++ b/core/src/main/java/io/grpc/CallCredentials2.java
@@ -54,7 +54,7 @@ public abstract class CallCredentials2 implements CallCredentials {
@SuppressWarnings("deprecation")
public final void applyRequestMetadata(
final MethodDescriptor<?, ?> method, final Attributes attrs,
- Executor appExecutor, CallCredentials.MetadataApplier applier) {
+ Executor appExecutor, final CallCredentials.MetadataApplier applier) {
final String authority = checkNotNull(attrs.get(ATTR_AUTHORITY), "authority");
final SecurityLevel securityLevel =
firstNonNull(attrs.get(ATTR_SECURITY_LEVEL), SecurityLevel.NONE);
@@ -79,6 +79,21 @@ public abstract class CallCredentials2 implements CallCredentials {
return attrs;
}
};
- applyRequestMetadata(requestInfo, appExecutor, applier);
+ MetadataApplier applierAdapter = new MetadataApplier() {
+ @Override
+ public void apply(Metadata headers) {
+ applier.apply(headers);
+ }
+
+ @Override
+ public void fail(Status status) {
+ applier.fail(status);
+ }
+ };
+ applyRequestMetadata(requestInfo, appExecutor, applierAdapter);
}
+
+ @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1914")
+ @SuppressWarnings("deprecation")
+ public abstract static class MetadataApplier implements CallCredentials.MetadataApplier {}
}
diff --git a/core/src/main/java/io/grpc/internal/MetadataApplierImpl.java b/core/src/main/java/io/grpc/internal/MetadataApplierImpl.java
index c3196ddd1..56548b282 100644
--- a/core/src/main/java/io/grpc/internal/MetadataApplierImpl.java
+++ b/core/src/main/java/io/grpc/internal/MetadataApplierImpl.java
@@ -20,7 +20,7 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
-import io.grpc.CallCredentials.MetadataApplier;
+import io.grpc.CallCredentials2.MetadataApplier;
import io.grpc.CallOptions;
import io.grpc.Context;
import io.grpc.Metadata;
diff --git a/core/src/test/java/io/grpc/internal/CallCredentials2ApplyingTest.java b/core/src/test/java/io/grpc/internal/CallCredentials2ApplyingTest.java
index f87e22810..fd2b2c18f 100644
--- a/core/src/test/java/io/grpc/internal/CallCredentials2ApplyingTest.java
+++ b/core/src/test/java/io/grpc/internal/CallCredentials2ApplyingTest.java
@@ -29,9 +29,9 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import io.grpc.Attributes;
-import io.grpc.CallCredentials.MetadataApplier;
import io.grpc.CallCredentials.RequestInfo;
import io.grpc.CallCredentials2;
+import io.grpc.CallCredentials2.MetadataApplier;
import io.grpc.CallOptions;
import io.grpc.IntegerMarshaller;
import io.grpc.Metadata;
diff --git a/core/src/test/java/io/grpc/internal/CallCredentialsApplyingTest.java b/core/src/test/java/io/grpc/internal/CallCredentialsApplyingTest.java
index 51df406b5..a8ca1219b 100644
--- a/core/src/test/java/io/grpc/internal/CallCredentialsApplyingTest.java
+++ b/core/src/test/java/io/grpc/internal/CallCredentialsApplyingTest.java
@@ -30,7 +30,6 @@ import static org.mockito.Mockito.when;
import io.grpc.Attributes;
import io.grpc.CallCredentials;
-import io.grpc.CallCredentials.MetadataApplier;
import io.grpc.CallOptions;
import io.grpc.IntegerMarshaller;
import io.grpc.Metadata;
@@ -128,7 +127,7 @@ public class CallCredentialsApplyingTest {
ArgumentCaptor<Attributes> attrsCaptor = ArgumentCaptor.forClass(null);
verify(mockCreds).applyRequestMetadata(same(method), attrsCaptor.capture(), same(mockExecutor),
- any(MetadataApplier.class));
+ any(CallCredentials.MetadataApplier.class));
Attributes attrs = attrsCaptor.getValue();
assertSame(ATTR_VALUE, attrs.get(ATTR_KEY));
assertSame(AUTHORITY, attrs.get(CallCredentials.ATTR_AUTHORITY));
@@ -148,7 +147,7 @@ public class CallCredentialsApplyingTest {
ArgumentCaptor<Attributes> attrsCaptor = ArgumentCaptor.forClass(null);
verify(mockCreds).applyRequestMetadata(same(method), attrsCaptor.capture(), same(mockExecutor),
- any(MetadataApplier.class));
+ any(CallCredentials.MetadataApplier.class));
Attributes attrs = attrsCaptor.getValue();
assertSame(ATTR_VALUE, attrs.get(ATTR_KEY));
assertEquals("transport-override-authority", attrs.get(CallCredentials.ATTR_AUTHORITY));
@@ -170,7 +169,7 @@ public class CallCredentialsApplyingTest {
ArgumentCaptor<Attributes> attrsCaptor = ArgumentCaptor.forClass(null);
verify(mockCreds).applyRequestMetadata(same(method), attrsCaptor.capture(),
- same(anotherExecutor), any(MetadataApplier.class));
+ same(anotherExecutor), any(CallCredentials.MetadataApplier.class));
Attributes attrs = attrsCaptor.getValue();
assertSame(ATTR_VALUE, attrs.get(ATTR_KEY));
assertEquals("calloptions-authority", attrs.get(CallCredentials.ATTR_AUTHORITY));
@@ -182,7 +181,8 @@ public class CallCredentialsApplyingTest {
final RuntimeException ex = new RuntimeException();
when(mockTransport.getAttributes()).thenReturn(Attributes.EMPTY);
doThrow(ex).when(mockCreds).applyRequestMetadata(
- same(method), any(Attributes.class), same(mockExecutor), any(MetadataApplier.class));
+ same(method), any(Attributes.class), same(mockExecutor),
+ any(CallCredentials.MetadataApplier.class));
FailingClientStream stream =
(FailingClientStream) transport.newStream(method, origHeaders, callOptions);
@@ -198,14 +198,15 @@ public class CallCredentialsApplyingTest {
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
- MetadataApplier applier = (MetadataApplier) invocation.getArguments()[3];
+ CallCredentials.MetadataApplier applier =
+ (CallCredentials.MetadataApplier) invocation.getArguments()[3];
Metadata headers = new Metadata();
headers.put(CREDS_KEY, CREDS_VALUE);
applier.apply(headers);
return null;
}
}).when(mockCreds).applyRequestMetadata(same(method), any(Attributes.class),
- same(mockExecutor), any(MetadataApplier.class));
+ same(mockExecutor), any(CallCredentials.MetadataApplier.class));
ClientStream stream = transport.newStream(method, origHeaders, callOptions);
@@ -222,12 +223,13 @@ public class CallCredentialsApplyingTest {
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
- MetadataApplier applier = (MetadataApplier) invocation.getArguments()[3];
+ CallCredentials.MetadataApplier applier =
+ (CallCredentials.MetadataApplier) invocation.getArguments()[3];
applier.fail(error);
return null;
}
}).when(mockCreds).applyRequestMetadata(same(method), any(Attributes.class),
- same(mockExecutor), any(MetadataApplier.class));
+ same(mockExecutor), any(CallCredentials.MetadataApplier.class));
FailingClientStream stream =
(FailingClientStream) transport.newStream(method, origHeaders, callOptions);
@@ -243,7 +245,7 @@ public class CallCredentialsApplyingTest {
// Will call applyRequestMetadata(), which is no-op.
DelayedStream stream = (DelayedStream) transport.newStream(method, origHeaders, callOptions);
- ArgumentCaptor<MetadataApplier> applierCaptor = ArgumentCaptor.forClass(null);
+ ArgumentCaptor<CallCredentials.MetadataApplier> applierCaptor = ArgumentCaptor.forClass(null);
verify(mockCreds).applyRequestMetadata(same(method), any(Attributes.class),
same(mockExecutor), applierCaptor.capture());
verify(mockTransport, never()).newStream(method, origHeaders, callOptions);
@@ -265,7 +267,7 @@ public class CallCredentialsApplyingTest {
// Will call applyRequestMetadata(), which is no-op.
DelayedStream stream = (DelayedStream) transport.newStream(method, origHeaders, callOptions);
- ArgumentCaptor<MetadataApplier> applierCaptor = ArgumentCaptor.forClass(null);
+ ArgumentCaptor<CallCredentials.MetadataApplier> applierCaptor = ArgumentCaptor.forClass(null);
verify(mockCreds).applyRequestMetadata(same(method), any(Attributes.class),
same(mockExecutor), applierCaptor.capture());
diff --git a/core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java b/core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java
index 863834a0f..c5fdf713e 100644
--- a/core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java
+++ b/core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java
@@ -57,7 +57,6 @@ import com.google.common.util.concurrent.SettableFuture;
import io.grpc.Attributes;
import io.grpc.BinaryLog;
import io.grpc.CallCredentials;
-import io.grpc.CallCredentials.MetadataApplier;
import io.grpc.CallOptions;
import io.grpc.Channel;
import io.grpc.ClientCall;
@@ -1404,7 +1403,7 @@ public class ManagedChannelImplTest {
}
}).when(creds).applyRequestMetadata( // TODO(zhangkun83): remove suppression of deprecations
any(MethodDescriptor.class), any(Attributes.class), any(Executor.class),
- any(MetadataApplier.class));
+ any(CallCredentials.MetadataApplier.class));
// First call will be on delayed transport. Only newCall() is run within the expected context,
// so that we can verify that the context is explicitly attached before calling newStream() and
@@ -1436,7 +1435,7 @@ public class ManagedChannelImplTest {
verify(creds, never()).applyRequestMetadata(
any(MethodDescriptor.class), any(Attributes.class), any(Executor.class),
- any(MetadataApplier.class));
+ any(CallCredentials.MetadataApplier.class));
// applyRequestMetadata() is called after the transport becomes ready.
transportInfo.listener.transportReady();
@@ -1445,7 +1444,8 @@ public class ManagedChannelImplTest {
helper.updateBalancingState(READY, mockPicker);
executor.runDueTasks();
ArgumentCaptor<Attributes> attrsCaptor = ArgumentCaptor.forClass(Attributes.class);
- ArgumentCaptor<MetadataApplier> applierCaptor = ArgumentCaptor.forClass(MetadataApplier.class);
+ ArgumentCaptor<CallCredentials.MetadataApplier> applierCaptor
+ = ArgumentCaptor.forClass(CallCredentials.MetadataApplier.class);
verify(creds).applyRequestMetadata(same(method), attrsCaptor.capture(),
same(executor.getScheduledExecutorService()), applierCaptor.capture());
assertEquals("testValue", testKey.get(credsApplyContexts.poll()));