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.Ignore;
20 import org.junit.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
26 public class Basic {
27
28 ExecutorService executor = ExecutorServiceUtil.newScheduledExecutorService();
29 Context context = new ContextBase();
30
31 @Test(timeout = 100)
32 public void withNoSubmittedTasksShutdownNowShouldReturnImmediately() throws InterruptedException {
33 executor.shutdownNow();
34 executor.awaitTermination(5000, TimeUnit.MILLISECONDS);
35 }
36
37 @Ignore
38 @Test
39 public void withOneSlowTask() throws InterruptedException {
40 executor.execute(new InterruptIgnoring(1000));
41 Thread.sleep(100);
42 ExecutorServiceUtil.shutdown(executor);
43 }
44
45
46 static class InterruptIgnoring implements Runnable {
47
48 int delay;
49
50 InterruptIgnoring(int delay) {
51 this.delay = delay;
52 }
53
54 public void run() {
55 long runUntil = System.currentTimeMillis() + delay;
56
57 while (true) {
58 try {
59 long sleep = runUntil - System.currentTimeMillis();
60 System.out.println("will sleep " + sleep);
61 if (sleep > 0) {
62 Thread.sleep(delay);
63 } else {
64 return;
65 }
66 } catch (InterruptedException e) {
67
68 }
69 }
70 }
71 }
72
73 }