Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
illustrates that line 62 in ExecutorServiceUtil will never be reached
- Loading branch information
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
logback-core/src/test/java/ch/qos/logback/core/issue/LOGBACK_849/Basic.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package ch.qos.logback.core.issue.LOGBACK_849; | ||
|
||
import ch.qos.logback.core.Context; | ||
import ch.qos.logback.core.ContextBase; | ||
import ch.qos.logback.core.CoreConstants; | ||
import ch.qos.logback.core.util.ExecutorServiceUtil; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
|
||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
|
||
public class Basic { | ||
|
||
ExecutorService executor = ExecutorServiceUtil.newExecutorService(); | ||
Context context = new ContextBase(); | ||
|
||
@Test(timeout = 100) | ||
public void withNoSubmittedTasksShutdownNowShouldReturnImmediately() throws InterruptedException { | ||
executor.shutdownNow(); | ||
executor.awaitTermination(CoreConstants.EXECUTOR_SHUTDOWN_DELAY, TimeUnit.MILLISECONDS); | ||
} | ||
|
||
@Ignore | ||
@Test | ||
public void withOneSlowTask() throws InterruptedException { | ||
executor.execute(new InterruptIgnoring(CoreConstants.EXECUTOR_SHUTDOWN_DELAY + 1000)); | ||
Thread.sleep(100); | ||
ExecutorServiceUtil.shutdown(executor, context.getStatusManager()); | ||
} | ||
|
||
// InterruptIgnoring =========================================== | ||
static class InterruptIgnoring implements Runnable { | ||
|
||
int delay; | ||
|
||
InterruptIgnoring(int delay) { | ||
this.delay = delay; | ||
} | ||
|
||
public void run() { | ||
long runUntil = System.currentTimeMillis() + delay; | ||
|
||
while (true) { | ||
try { | ||
long sleep = runUntil - System.currentTimeMillis(); | ||
System.out.println("will sleep " + sleep); | ||
if (sleep > 0) { | ||
Thread.currentThread().sleep(delay); | ||
} else { | ||
return; | ||
} | ||
} catch (InterruptedException e) { | ||
// ignore the exception | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
} |