|
77 | 77 | import io.grpc.ServiceDescriptor; |
78 | 78 | import io.grpc.Status; |
79 | 79 | import io.grpc.Status.Code; |
| 80 | +import io.grpc.StatusException; |
80 | 81 | import io.grpc.StatusRuntimeException; |
81 | 82 | import io.grpc.StringMarshaller; |
82 | 83 | import io.grpc.internal.ServerImpl.JumpToApplicationThreadServerStreamListener; |
|
88 | 89 | import java.io.ByteArrayInputStream; |
89 | 90 | import java.io.IOException; |
90 | 91 | import java.io.InputStream; |
| 92 | +import java.lang.reflect.InvocationTargetException; |
91 | 93 | import java.net.InetSocketAddress; |
92 | 94 | import java.net.SocketAddress; |
93 | 95 | import java.util.Arrays; |
@@ -1606,7 +1608,7 @@ public void testInternalClose_otherExceptionBecomesUnknown() { |
1606 | 1608 | } |
1607 | 1609 |
|
1608 | 1610 | @Test |
1609 | | - public void testInternalClose_propagatesResourceExhausted() { |
| 1611 | + public void testInternalClose_propagatesStatusRuntimeException() { |
1610 | 1612 | JumpToApplicationThreadServerStreamListener listener |
1611 | 1613 | = new JumpToApplicationThreadServerStreamListener( |
1612 | 1614 | executor.getScheduledExecutorService(), |
@@ -1636,6 +1638,33 @@ public void testInternalClose_propagatesResourceExhausted() { |
1636 | 1638 | assertTrue(metadataCaptor.getValue().keys().isEmpty()); |
1637 | 1639 | } |
1638 | 1640 |
|
| 1641 | + @Test |
| 1642 | + public void testInternalClose_propagatesStatusException() |
| 1643 | + throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { |
| 1644 | + JumpToApplicationThreadServerStreamListener listener |
| 1645 | + = new JumpToApplicationThreadServerStreamListener( |
| 1646 | + executor.getScheduledExecutorService(), |
| 1647 | + executor.getScheduledExecutorService(), |
| 1648 | + stream, |
| 1649 | + Context.ROOT.withCancellation(), |
| 1650 | + PerfMark.createTag()); |
| 1651 | + |
| 1652 | + StatusException statusException |
| 1653 | + = new StatusException(Status.RESOURCE_EXHAUSTED.withDescription("exhausted")); |
| 1654 | + java.lang.reflect.Method internalClose = |
| 1655 | + JumpToApplicationThreadServerStreamListener.class.getDeclaredMethod( |
| 1656 | + "internalClose", Throwable.class); |
| 1657 | + internalClose.setAccessible(true); |
| 1658 | + |
| 1659 | + internalClose.invoke(listener, statusException); |
| 1660 | + verify(stream).close(statusCaptor.capture(), metadataCaptor.capture()); |
| 1661 | + Status status = statusCaptor.getValue(); |
| 1662 | + assertEquals(Status.Code.RESOURCE_EXHAUSTED, status.getCode()); |
| 1663 | + assertEquals("exhausted", status.getDescription()); |
| 1664 | + assertEquals(statusException, status.getCause()); |
| 1665 | + assertTrue(metadataCaptor.getValue().keys().isEmpty()); |
| 1666 | + } |
| 1667 | + |
1639 | 1668 | private void createAndStartServer() throws IOException { |
1640 | 1669 | createServer(); |
1641 | 1670 | server.start(); |
|
0 commit comments