Skip to content

Commit

Permalink
Address code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pkern committed Aug 26, 2020
1 parent c1c2ac1 commit 8de2605
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
9 changes: 4 additions & 5 deletions api/src/main/java/io/grpc/MethodDescriptor.java
Expand Up @@ -42,7 +42,6 @@ public final class MethodDescriptor<ReqT, RespT> {
private final MethodType type;
private final String fullMethodName;
@Nullable private final String serviceName;
@Nullable private final String methodName;
private final Marshaller<ReqT> requestMarshaller;
private final Marshaller<RespT> responseMarshaller;
private final @Nullable Object schemaDescriptor;
Expand Down Expand Up @@ -226,7 +225,6 @@ private MethodDescriptor(
this.type = Preconditions.checkNotNull(type, "type");
this.fullMethodName = Preconditions.checkNotNull(fullMethodName, "fullMethodName");
this.serviceName = extractFullServiceName(fullMethodName);
this.methodName = extractMethodName(fullMethodName);
this.requestMarshaller = Preconditions.checkNotNull(requestMarshaller, "requestMarshaller");
this.responseMarshaller = Preconditions.checkNotNull(responseMarshaller, "responseMarshaller");
this.schemaDescriptor = schemaDescriptor;
Expand Down Expand Up @@ -271,8 +269,8 @@ public String getServiceName() {
*/
@Nullable
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/5635")
public String getMethodName() {
return methodName;
public String getBareMethodName() {
return extractBareMethodName(fullMethodName);
}

/**
Expand Down Expand Up @@ -418,7 +416,8 @@ public static String extractFullServiceName(String fullMethodName) {
* @since 1.32.0
*/
@Nullable
public static String extractMethodName(String fullMethodName) {
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/5635")
public static String extractBareMethodName(String fullMethodName) {
int index = checkNotNull(fullMethodName, "fullMethodName").lastIndexOf('/');
if (index == -1) {
return null;
Expand Down
12 changes: 6 additions & 6 deletions api/src/test/java/io/grpc/MethodDescriptorTest.java
Expand Up @@ -178,36 +178,36 @@ public void getServiceName_returnsNull() {
}

@Test
public void getMethodName_extractsMethod() {
public void getBareMethodName_extractsMethod() {
Marshaller<Void> marshaller = TestMethodDescriptors.voidMarshaller();
MethodDescriptor<?, ?> md = MethodDescriptor.newBuilder(marshaller, marshaller)
.setType(MethodType.UNARY)
.setFullMethodName("foo/bar")
.build();

assertEquals("bar", md.getMethodName());
assertEquals("bar", md.getBareMethodName());
}

@Test
public void getMethodName_returnsNull() {
public void getBareMethodName_returnsNull() {
Marshaller<Void> marshaller = TestMethodDescriptors.voidMarshaller();
MethodDescriptor<?, ?> md = MethodDescriptor.newBuilder(marshaller, marshaller)
.setType(MethodType.UNARY)
.setFullMethodName("foo-bar")
.build();

assertNull(md.getMethodName());
assertNull(md.getBareMethodName());
}

@Test
public void getMethodName_returnsEmptyStringWithMethodMissing() {
public void getBareMethodName_returnsEmptyStringWithMethodMissing() {
Marshaller<Void> marshaller = TestMethodDescriptors.voidMarshaller();
MethodDescriptor<?, ?> md = MethodDescriptor.newBuilder(marshaller, marshaller)
.setType(MethodType.UNARY)
.setFullMethodName("foo/")
.build();

assertTrue(md.getMethodName().isEmpty());
assertTrue(md.getBareMethodName().isEmpty());
}

@Test
Expand Down

0 comments on commit 8de2605

Please sign in to comment.