|
17 | 17 |
|
18 | 18 | package org.apache.arrow.flight;
|
19 | 19 |
|
| 20 | +import static org.junit.Assert.assertEquals; |
| 21 | +import static org.junit.Assert.assertNotNull; |
| 22 | + |
20 | 23 | import java.io.File;
|
| 24 | +import java.util.HashMap; |
| 25 | +import java.util.Map; |
21 | 26 | import java.util.concurrent.ExecutorService;
|
22 | 27 | import java.util.concurrent.Executors;
|
23 | 28 | import java.util.concurrent.atomic.AtomicBoolean;
|
24 | 29 | import java.util.function.Consumer;
|
25 | 30 |
|
26 | 31 | import org.apache.arrow.flight.TestBasicOperation.Producer;
|
| 32 | +import org.apache.arrow.flight.auth.ServerAuthHandler; |
| 33 | +import org.apache.arrow.flight.impl.FlightServiceGrpc; |
27 | 34 | import org.apache.arrow.memory.BufferAllocator;
|
28 | 35 | import org.apache.arrow.memory.RootAllocator;
|
29 | 36 | import org.apache.arrow.vector.IntVector;
|
|
34 | 41 | import org.junit.runner.RunWith;
|
35 | 42 | import org.junit.runners.JUnit4;
|
36 | 43 |
|
| 44 | +import io.grpc.MethodDescriptor; |
| 45 | +import io.grpc.ServerServiceDefinition; |
37 | 46 | import io.grpc.netty.NettyServerBuilder;
|
38 | 47 |
|
39 | 48 | @RunWith(JUnit4.class)
|
@@ -69,7 +78,7 @@ public void defaultExecutorClosed() throws Exception {
|
69 | 78 | (location) -> FlightServer.builder(a, location, new NoOpFlightProducer())
|
70 | 79 | .build()
|
71 | 80 | )) {
|
72 |
| - Assert.assertNotNull(server.grpcExecutor); |
| 81 | + assertNotNull(server.grpcExecutor); |
73 | 82 | executor = server.grpcExecutor;
|
74 | 83 | }
|
75 | 84 | Assert.assertTrue(executor.isShutdown());
|
@@ -128,4 +137,39 @@ public void domainSocket() throws Exception {
|
128 | 137 | }
|
129 | 138 | }
|
130 | 139 | }
|
| 140 | + |
| 141 | + @Test |
| 142 | + public void checkReflectionMetadata() { |
| 143 | + // This metadata is needed for gRPC reflection to work. |
| 144 | + final ExecutorService executorService = Executors.newSingleThreadExecutor(); |
| 145 | + try (final BufferAllocator allocator = new RootAllocator(Integer.MAX_VALUE)) { |
| 146 | + final FlightBindingService service = new FlightBindingService(allocator, new NoOpFlightProducer(), |
| 147 | + ServerAuthHandler.NO_OP, executorService); |
| 148 | + final ServerServiceDefinition definition = service.bindService(); |
| 149 | + assertEquals(FlightServiceGrpc.getServiceDescriptor().getSchemaDescriptor(), |
| 150 | + definition.getServiceDescriptor().getSchemaDescriptor()); |
| 151 | + |
| 152 | + final Map<String, MethodDescriptor<?, ?>> definedMethods = new HashMap<>(); |
| 153 | + final Map<String, MethodDescriptor<?, ?>> serviceMethods = new HashMap<>(); |
| 154 | + |
| 155 | + // Make sure that the reflection metadata object is identical across all the places where it's accessible |
| 156 | + definition.getMethods().forEach( |
| 157 | + method -> definedMethods.put(method.getMethodDescriptor().getFullMethodName(), method.getMethodDescriptor())); |
| 158 | + definition.getServiceDescriptor().getMethods().forEach( |
| 159 | + method -> serviceMethods.put(method.getFullMethodName(), method)); |
| 160 | + |
| 161 | + for (final MethodDescriptor<?, ?> descriptor : FlightServiceGrpc.getServiceDescriptor().getMethods()) { |
| 162 | + final String methodName = descriptor.getFullMethodName(); |
| 163 | + Assert.assertTrue("Method is missing from ServerServiceDefinition: " + methodName, |
| 164 | + definedMethods.containsKey(methodName)); |
| 165 | + Assert.assertTrue("Method is missing from ServiceDescriptor: " + methodName, |
| 166 | + definedMethods.containsKey(methodName)); |
| 167 | + |
| 168 | + assertEquals(descriptor.getSchemaDescriptor(), definedMethods.get(methodName).getSchemaDescriptor()); |
| 169 | + assertEquals(descriptor.getSchemaDescriptor(), serviceMethods.get(methodName).getSchemaDescriptor()); |
| 170 | + } |
| 171 | + } finally { |
| 172 | + executorService.shutdown(); |
| 173 | + } |
| 174 | + } |
131 | 175 | }
|
0 commit comments