MCPcopy Create free account
hub / github.com/grpc/grpc-java / setUp

Method setUp

netty/src/test/java/io/grpc/netty/WriteQueueTest.java:70–112  ·  view source on GitHub ↗

Set up for test.

()

Source from the content-addressed store, hash-verified

68 * Set up for test.
69 */
70 @Before
71 public void setUp() throws Exception {
72 when(channel.newPromise()).thenReturn(promise);
73
74 EventLoop eventLoop = Mockito.mock(EventLoop.class);
75 doAnswer(new Answer<Void>() {
76 @Override
77 public Void answer(InvocationOnMock invocation) throws Throwable {
78 Runnable r = (Runnable) invocation.getArguments()[0];
79 r.run();
80 return null;
81 }
82 }).when(eventLoop).execute(any(Runnable.class));
83 when(eventLoop.inEventLoop()).thenReturn(true);
84 when(channel.eventLoop()).thenReturn(eventLoop);
85
86 when(channel.flush()).thenAnswer(new Answer<Channel>() {
87 @Override
88 public Channel answer(InvocationOnMock invocation) throws Throwable {
89 synchronized (lock) {
90 flushCalledNanos = System.nanoTime();
91 if (flushCalledNanos == writeCalledNanos) {
92 flushCalledNanos += 1;
93 }
94 }
95 return channel;
96 }
97 });
98
99 when(channel.write(any(QueuedCommand.class), eq(promise))).thenAnswer(
100 new Answer<ChannelFuture>() {
101 @Override
102 public ChannelFuture answer(InvocationOnMock invocation) throws Throwable {
103 synchronized (lock) {
104 writeCalledNanos = System.nanoTime();
105 if (writeCalledNanos == flushCalledNanos) {
106 writeCalledNanos += 1;
107 }
108 }
109 return promise;
110 }
111 });
112 }
113
114 @Test
115 public void singleWriteShouldWork() {

Callers

nothing calls this directly

Calls 5

eventLoopMethod · 0.80
flushMethod · 0.65
writeMethod · 0.65
newPromiseMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected