HIGUCHI Yuta
Committed by Ray Milkey

Potential fix for ONOS-4521.

- Assumption is that problem is triggered, when response is already
  received before setting the completion stage to capture execution thread.

Change-Id: I17fdc82be1f6083ed3075858433b347b2caed4cf
(cherry picked from commit 2cb8d3e9)
...@@ -133,8 +133,16 @@ public class NettyMessagingManagerTest { ...@@ -133,8 +133,16 @@ public class NettyMessagingManagerTest {
133 AtomicReference<String> handlerThreadName = new AtomicReference<>(); 133 AtomicReference<String> handlerThreadName = new AtomicReference<>();
134 AtomicReference<String> completionThreadName = new AtomicReference<>(); 134 AtomicReference<String> completionThreadName = new AtomicReference<>();
135 135
136 + final CountDownLatch latch = new CountDownLatch(1);
137 +
136 BiFunction<Endpoint, byte[], byte[]> handler = (ep, data) -> { 138 BiFunction<Endpoint, byte[], byte[]> handler = (ep, data) -> {
137 handlerThreadName.set(Thread.currentThread().getName()); 139 handlerThreadName.set(Thread.currentThread().getName());
140 + try {
141 + latch.await();
142 + } catch (InterruptedException e1) {
143 + Thread.currentThread().interrupt();
144 + fail("InterruptedException");
145 + }
138 return "hello there".getBytes(); 146 return "hello there".getBytes();
139 }; 147 };
140 netty2.registerHandler("test-subject", handler, handlerExecutor); 148 netty2.registerHandler("test-subject", handler, handlerExecutor);
...@@ -146,6 +154,7 @@ public class NettyMessagingManagerTest { ...@@ -146,6 +154,7 @@ public class NettyMessagingManagerTest {
146 response.whenComplete((r, e) -> { 154 response.whenComplete((r, e) -> {
147 completionThreadName.set(Thread.currentThread().getName()); 155 completionThreadName.set(Thread.currentThread().getName());
148 }); 156 });
157 + latch.countDown();
149 158
150 // Verify that the message was request handling and response completion happens on the correct thread. 159 // Verify that the message was request handling and response completion happens on the correct thread.
151 assertTrue(Arrays.equals("hello there".getBytes(), response.join())); 160 assertTrue(Arrays.equals("hello there".getBytes(), response.join()));
......