Skip to content

Commit 5410196

Browse files
committed
11246:: added the junit's for checked exception (StatusException)
1 parent 1024a7f commit 5410196

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

core/src/test/java/io/grpc/internal/ServerImplTest.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
import io.grpc.ServiceDescriptor;
7878
import io.grpc.Status;
7979
import io.grpc.Status.Code;
80+
import io.grpc.StatusException;
8081
import io.grpc.StatusRuntimeException;
8182
import io.grpc.StringMarshaller;
8283
import io.grpc.internal.ServerImpl.JumpToApplicationThreadServerStreamListener;
@@ -88,6 +89,7 @@
8889
import java.io.ByteArrayInputStream;
8990
import java.io.IOException;
9091
import java.io.InputStream;
92+
import java.lang.reflect.InvocationTargetException;
9193
import java.net.InetSocketAddress;
9294
import java.net.SocketAddress;
9395
import java.util.Arrays;
@@ -1606,7 +1608,7 @@ public void testInternalClose_otherExceptionBecomesUnknown() {
16061608
}
16071609

16081610
@Test
1609-
public void testInternalClose_propagatesResourceExhausted() {
1611+
public void testInternalClose_propagatesStatusRuntimeException() {
16101612
JumpToApplicationThreadServerStreamListener listener
16111613
= new JumpToApplicationThreadServerStreamListener(
16121614
executor.getScheduledExecutorService(),
@@ -1636,6 +1638,33 @@ public void testInternalClose_propagatesResourceExhausted() {
16361638
assertTrue(metadataCaptor.getValue().keys().isEmpty());
16371639
}
16381640

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+
16391668
private void createAndStartServer() throws IOException {
16401669
createServer();
16411670
server.start();

0 commit comments

Comments
 (0)