happytimor commented on PR #10164:
URL: https://github.com/apache/dubbo/pull/10164#issuecomment-1179537089
>
> would you please add some test cases to verify this
it is a bit difficult for me to setup the ut environment with mockito, i can
only provide basic code
## consumer:
``` java
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1, 1, 0,
TimeUnit.SECONDS, new LinkedBlockingQueue<>());
String name = "world" + System.currentTimeMillis();
int initialFlag = 0, runningFlag = 1, normalReturn = 2, interruptReturn = 3;
AtomicInteger flag = new AtomicInteger(initialFlag);
Future<?> future = threadPoolExecutor.submit(() -> {
try {
flag.set(runningFlag);
service.sayHello(name);
flag.set(normalReturn);
} catch (Exception e) {
flag.set(interruptReturn);
}
});
Thread.sleep(100);
future.cancel(true);
while (flag.get() == initialFlag || flag.get() == runningFlag) {
Thread.yield();
}
Assertions.assertEquals(flag.get(), interruptReturn);
```
## provider:
``` java
String lastName = "";
@Override
public String sayHello(String name) {
if (!lastName.equals(name)) {
lastName = name;
try {
//will be interrupted at first time
Thread.sleep(200);
} catch (InterruptedException ignore) {
}
}
return "Hello " + name + ", response from provider: " +
RpcContext.getContext().getLocalAddress();
}
```
## important parameter:
retries=3&cluster=failover
------
flag will return normalReturn if we don`t add
`Thread.currentThread().interrupt()`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]