|
19 | 19 | import static org.junit.Assert.assertEquals; |
20 | 20 | import static org.junit.Assert.assertTrue; |
21 | 21 |
|
| 22 | +import com.google.api.gax.core.ExecutorProvider; |
22 | 23 | import com.google.api.gax.core.FixedExecutorProvider; |
23 | 24 | import com.google.api.gax.core.InstantiatingExecutorProvider; |
24 | 25 | import com.google.api.gax.core.NoCredentialsProvider; |
|
36 | 37 | import io.grpc.StatusException; |
37 | 38 | import io.grpc.inprocess.InProcessChannelBuilder; |
38 | 39 | import io.grpc.inprocess.InProcessServerBuilder; |
| 40 | +import java.util.concurrent.Executors; |
| 41 | +import java.util.concurrent.ScheduledExecutorService; |
| 42 | +import java.util.concurrent.TimeUnit; |
39 | 43 | import org.junit.After; |
40 | 44 | import org.junit.Before; |
41 | 45 | import org.junit.Rule; |
@@ -112,6 +116,38 @@ public void testFailedChannel_recoverableError_channelReopened() throws Exceptio |
112 | 116 | subscriber.stopAsync().awaitTerminated(); |
113 | 117 | } |
114 | 118 |
|
| 119 | + @Test |
| 120 | + public void testFailedChannel_testTerminated() throws Exception { |
| 121 | + final ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(5); |
| 122 | + ExecutorProvider provider = |
| 123 | + new ExecutorProvider() { |
| 124 | + @Override |
| 125 | + public boolean shouldAutoClose() { |
| 126 | + return true; |
| 127 | + } |
| 128 | + |
| 129 | + @Override |
| 130 | + public ScheduledExecutorService getExecutor() { |
| 131 | + return scheduledExecutorService; |
| 132 | + } |
| 133 | + }; |
| 134 | + |
| 135 | + try { |
| 136 | + Subscriber subscriber = |
| 137 | + startSubscriber( |
| 138 | + getTestSubscriberBuilder(testReceiver).setSystemExecutorProvider(provider)); |
| 139 | + |
| 140 | + // wait long enough for the MessageDispatcher to set up, which at one point |
| 141 | + // caused shutdown problems. |
| 142 | + Thread.sleep(100); |
| 143 | + subscriber.stopAsync().awaitTerminated(); |
| 144 | + |
| 145 | + assertTrue(scheduledExecutorService.awaitTermination(10, TimeUnit.SECONDS)); |
| 146 | + } finally { |
| 147 | + scheduledExecutorService.shutdownNow(); |
| 148 | + } |
| 149 | + } |
| 150 | + |
115 | 151 | @Test(expected = IllegalStateException.class) |
116 | 152 | public void testFailedChannel_fatalError_subscriberFails() throws Exception { |
117 | 153 | Subscriber subscriber = |
|
0 commit comments