1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.core.issue.LOGBACK_849;
15
16 import java.util.concurrent.ExecutorService;
17 import java.util.concurrent.TimeUnit;
18
19 import org.junit.jupiter.api.Disabled;
20 import org.junit.jupiter.api.Test;
21
22 import ch.qos.logback.core.Context;
23 import ch.qos.logback.core.ContextBase;
24 import ch.qos.logback.core.util.ExecutorServiceUtil;
25 import org.junit.jupiter.api.Timeout;
26
27 public class Basic {
28
29 ExecutorService executor = ExecutorServiceUtil.newScheduledExecutorService();
30 Context context = new ContextBase();
31
32 @Test
33 @Timeout(value=100, unit=TimeUnit.MILLISECONDS)
34 public void withNoSubmittedTasksShutdownNowShouldReturnImmediately() throws InterruptedException {
35 executor.shutdownNow();
36 executor.awaitTermination(5000, TimeUnit.MILLISECONDS);
37 }
38
39 @Disabled
40 @Test
41 public void withOneSlowTask() throws InterruptedException {
42 executor.execute(new InterruptIgnoring(1000));
43 Thread.sleep(100);
44 ExecutorServiceUtil.shutdown(executor);
45 }
46
47
48 static class InterruptIgnoring implements Runnable {
49
50 int delay;
51
52 InterruptIgnoring(int delay) {
53 this.delay = delay;
54 }
55
56 public void run() {
57 long runUntil = System.currentTimeMillis() + delay;
58
59 while (true) {
60 try {
61 long sleep = runUntil - System.currentTimeMillis();
62 System.out.println("will sleep " + sleep);
63 if (sleep > 0) {
64 Thread.sleep(delay);
65 } else {
66 return;
67 }
68 } catch (InterruptedException e) {
69
70 }
71 }
72 }
73 }
74
75 }