Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/src/main/java/io/grpc/MethodDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,8 @@ public <NewReqT, NewRespT> Builder<NewReqT, NewRespT> toBuilder(
.setFullMethodName(fullMethodName)
.setIdempotent(idempotent)
.setSafe(safe)
.setSampledToLocalTracing(sampledToLocalTracing);
.setSampledToLocalTracing(sampledToLocalTracing)
.setSchemaDescriptor(schemaDescriptor);
}

/**
Expand Down
41 changes: 41 additions & 0 deletions core/src/test/java/io/grpc/MethodDescriptorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

package io.grpc;

import static junit.framework.TestCase.assertSame;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;

import io.grpc.MethodDescriptor.MethodType;
Expand Down Expand Up @@ -129,4 +131,43 @@ public void sampledToLocalTracing() {
.build();
assertTrue(md4.isSampledToLocalTracing());
}

@Test
public void toBuilderTest() {
MethodDescriptor<String, String> md1 = MethodDescriptor.<String, String>newBuilder()
.setType(MethodType.UNARY)
.setFullMethodName("package.service/method")
.setRequestMarshaller(StringMarshaller.INSTANCE)
.setResponseMarshaller(StringMarshaller.INSTANCE)
.setSampledToLocalTracing(true)
.setIdempotent(true)
.setSafe(true)
.setSchemaDescriptor(new Object())
.build();
// Verify that we are not using any default builder values, so if md1 and md2 matches,
// it's because toBuilder explicitly copied it.
MethodDescriptor<String, String> defaults = MethodDescriptor.<String, String>newBuilder()
.setType(MethodType.UNARY)
.setFullMethodName("package.service/method")
.setRequestMarshaller(StringMarshaller.INSTANCE)
.setResponseMarshaller(StringMarshaller.INSTANCE)
.build();
assertNotEquals(md1.isSampledToLocalTracing(), defaults.isSampledToLocalTracing());
assertNotEquals(md1.isIdempotent(), defaults.isIdempotent());
assertNotEquals(md1.isSafe(), defaults.isSafe());
assertNotEquals(md1.getSchemaDescriptor(), defaults.getSchemaDescriptor());

// Verify that the builder correctly copied over the values
MethodDescriptor<Integer, Integer> md2 = md1.toBuilder(
IntegerMarshaller.INSTANCE,
IntegerMarshaller.INSTANCE).build();
assertSame(md1.getType(), md2.getType());
assertSame(md1.getFullMethodName(), md2.getFullMethodName());
assertSame(IntegerMarshaller.INSTANCE, md2.getRequestMarshaller());
assertSame(IntegerMarshaller.INSTANCE, md2.getResponseMarshaller());
assertEquals(md1.isSampledToLocalTracing(), md2.isSampledToLocalTracing());
assertEquals(md1.isIdempotent(), md2.isIdempotent());
assertEquals(md1.isSafe(), md2.isSafe());
assertSame(md1.getSchemaDescriptor(), md2.getSchemaDescriptor());
}
}