Skip to content

Commit

Permalink
errorprone :: InterruptedExceptionSwallowed (#790)
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-mlb authored May 30, 2024
1 parent e26c2ff commit 8fb2b03
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ protected void setupRoller() {
logger.info("Added Roller for {} running every {} {}(s) or on size {} (bytes).", getFilterName(), this.rollInterval,
this.rollIntervalUnits, this.maxRollFileSize);
} catch (Exception ex) {
if (ex instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
logger.error("Unable to instantiate Roller for handling {} file output", getFilterName(), ex);
System.exit(1);
}
Expand Down
4 changes: 3 additions & 1 deletion src/test/java/emissary/core/FTestMovingAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ private void runTest(@Nullable final String agentClass) {
try {
Thread.sleep(250);
} catch (Exception ex) {
// empty catch block
if (ex instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
}
waitCounter++;
}
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/emissary/core/ResourceWatcherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.codahale.metrics.Timer;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Random;
Expand All @@ -26,7 +27,7 @@ class ResourceWatcherTest extends UnitTest {
public IServiceProviderPlace place = null;

@Test
void testResourceWatcherWithMultipleThreads() throws Exception {
void testResourceWatcherWithMultipleThreads() throws IOException, InterruptedException {
this.resourceWatcher = new ResourceWatcher();
this.place = new DevNullPlace();
int threadCount = 10;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/emissary/core/TimedResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void testCheckState() {
}

@TestAttempts
void test() throws Exception {
void test() throws InterruptedException {
TestMobileAgent tma = new TestMobileAgent();
// timeout almost immediately
try (TimedResource tr = new TimedResource(tma, tp, 1, new Timer())) {
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/emissary/kff/KffFileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.List;
import java.util.Random;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
Expand Down Expand Up @@ -90,7 +91,7 @@ void testKffFileCheck() {
* Tests concurrent {@link KffFile#check(String, ChecksumResults)} invocations to ensure that method's thread-safety
*/
@Test
void testConcurrentKffFileCheckCalls() throws Exception {
void testConcurrentKffFileCheckCalls() throws ExecutionException, IOException, InterruptedException {
int EXPECTED_FAILURE_COUNT = 200;

// the inputs we'll submit, along wth their expected KffFile.check return values
Expand Down
14 changes: 7 additions & 7 deletions src/test/java/emissary/output/roller/JournaledCoalescerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class JournaledCoalescerTest extends UnitTest {
private final List<String> BUD2_LINES = Arrays.asList("Line3", "Line4");

@BeforeEach
public void setUp(@TempDir final Path tempFilesPath) throws Exception {
public void setUp(@TempDir final Path tempFilesPath) throws IOException, InterruptedException {
fileNameGenerator = new SimpleFileNameGenerator();
targetBudPath = tempFilesPath;
journaledCoalescer = new JournaledCoalescer(targetBudPath, fileNameGenerator);
Expand Down Expand Up @@ -119,7 +119,7 @@ void testNonWritable() throws Exception {
}

@Test
void testRollOrphanedFiles() throws Exception {
void testRollOrphanedFiles() throws IOException, InterruptedException {
// setup
try (JournaledChannelPool pool = new JournaledChannelPool(targetBudPath, BUD1_NAME, 2);
KeyedOutput one = pool.getFree();
Expand Down Expand Up @@ -205,7 +205,7 @@ void testAddFilesWithRoll() throws Exception {
* run, which should be deleted and normal operations carried out from there.
*/
@Test
void testCrashWhileRolling() throws Exception {
void testCrashWhileRolling() throws IOException, InterruptedException {
// setup
Path finalBudOutput;
try (KeyedOutput one = journaledCoalescer.getOutput()) {
Expand All @@ -232,7 +232,7 @@ void testCrashWhileRolling() throws Exception {
* Test to see the rolled and part files are cleaned up without rolling again.
*/
@Test
void testCrashAfterRolled() throws Exception {
void testCrashAfterRolled() throws IOException, InterruptedException {
try (JournaledChannelPool pool = new JournaledChannelPool(targetBudPath, BUD1_NAME, 2);
KeyedOutput one = pool.getFree();
KeyedOutput two = pool.getFree()) {
Expand Down Expand Up @@ -261,7 +261,7 @@ void testCrashAfterRolled() throws Exception {
* are deleted, but the rolled file is not renamed.
*/
@Test
void testCrashAfterRolledNoPartFiles() throws Exception {
void testCrashAfterRolledNoPartFiles() throws IOException, InterruptedException {
// create the rolled file without any part/journal files
Path oldRolled = Files.createFile(targetBudPath.resolve(BUD1_NAME + JournaledCoalescer.ROLLED_EXT));
Files.write(oldRolled, BUD1_LINES, StandardCharsets.UTF_8, StandardOpenOption.WRITE);
Expand All @@ -274,7 +274,7 @@ void testCrashAfterRolledNoPartFiles() throws Exception {
}

@Test
void testCrashAfterRolledEmpty() throws Exception {
void testCrashAfterRolledEmpty() throws IOException, InterruptedException {
try (JournaledChannelPool pool = new JournaledChannelPool(targetBudPath, BUD1_NAME, 2);
KeyedOutput one = pool.getFree();
KeyedOutput two = pool.getFree()) {
Expand All @@ -295,7 +295,7 @@ void testCrashAfterRolledEmpty() throws Exception {
}

@Test
void testCrashAfterRolledEmptyNoPartFiles() throws Exception {
void testCrashAfterRolledEmptyNoPartFiles() throws IOException, InterruptedException {
// create the rolled file without any part/journal files
Path oldRolled = Files.createFile(targetBudPath.resolve(BUD1_NAME + JournaledCoalescer.ROLLED_EXT));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void tearDown() throws Exception {
* Test of freeChannel method, of class JournaledChannelPool.
*/
@Test
void testGetAndFree() throws Exception {
void testGetAndFree() throws IOException, InterruptedException {
final SeekableByteChannel out = this.instance.getFree();
final int created = this.instance.getCreatedCount();
assertTrue(created > 0, "Should have recorded creation of at least 1 object");
Expand All @@ -60,7 +60,7 @@ void testGetAndFree() throws Exception {
* Test of getJournalEntries method, of class JournaledChannelPool.
*/
@Test
void testGetJournalEntries() throws Exception {
void testGetJournalEntries() throws IOException, InterruptedException {
final String onetext = "one line of text";
final String twotext = "two lines of text\nthe second line";
try (KeyedOutput k1 = this.instance.getFree(); KeyedOutput k2 = this.instance.getFree()) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/emissary/roll/RollManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void testAutoConfig() throws IOException {
}

@Test
void testFailedRoller() throws Exception {
void testFailedRoller() throws IOException, InterruptedException {
RollManager rm = new RollManager(ConfigUtil.getConfigInfo(this.getClass()));
CountDownLatch latch = new CountDownLatch(1);
Roller r = new Roller(TimeUnit.MILLISECONDS, 250, new Rollable() {
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/emissary/test/core/junit5/UnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ protected void pause(long millis) {
Thread.sleep(millis);
} catch (Exception ex) {
// empty exception block
if (ex instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
logger.debug("Thread interrupted", ex);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/emissary/util/io/LoggingPrintStreamTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ void testSingleThread() {
}

@Test
void testMultiThread() throws Exception {
void testMultiThread() throws InterruptedException {
final org.slf4j.event.Level slf4jLevel = org.slf4j.event.Level.INFO;

LogbackTester logbackTester = new LogbackTester(LoggingPrintStreamTest.class.getName());
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/emissary/util/shell/ProcessReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.slf4j.MDC;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.annotation.Nullable;

import static emissary.log.MDCConstants.SERVICE_LOCATION;
Expand Down Expand Up @@ -78,7 +79,7 @@ public void tearDown() throws Exception {
* {@link ProcessReader#applyLogContextMap()}
*/
@Test
void testFormattedLogMessageWithMDCTransfer() throws Exception {
void testFormattedLogMessageWithMDCTransfer() throws IOException, InterruptedException {

try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
appender.setOutputStream(outputStream);
Expand All @@ -95,7 +96,7 @@ void testFormattedLogMessageWithMDCTransfer() throws Exception {
}

@Test
void testFormattedLogMessageWithoutMDCTransfer() throws Exception {
void testFormattedLogMessageWithoutMDCTransfer() throws IOException, InterruptedException {

try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
appender.setOutputStream(outputStream);
Expand Down

0 comments on commit 8fb2b03

Please sign in to comment.