Skip to content

Commit 11e07ba

Browse files
committed
fix coverage
1 parent c730da4 commit 11e07ba

File tree

1 file changed

+51
-4
lines changed

1 file changed

+51
-4
lines changed

test/unit/org/apache/cassandra/db/compaction/BackgroundCompactionRunnerTest.java

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,17 @@
3030
import java.util.concurrent.RejectedExecutionException;
3131
import java.util.concurrent.atomic.AtomicReference;
3232
import java.util.function.Consumer;
33+
import java.util.function.Supplier;
3334

3435
import com.google.common.collect.ImmutableList;
3536
import com.google.common.collect.ImmutableSet;
3637
import org.apache.cassandra.config.Config;
3738
import org.apache.cassandra.io.FSWriteError;
39+
import org.apache.cassandra.io.compress.CompressionMetadata;
40+
import org.apache.cassandra.io.compress.CorruptBlockException;
3841
import org.apache.cassandra.io.sstable.CorruptSSTableException;
42+
import org.apache.cassandra.io.util.CorruptFileException;
43+
import org.apache.cassandra.io.util.File;
3944
import org.apache.cassandra.utils.JVMKiller;
4045
import org.apache.cassandra.utils.JVMStabilityInspector;
4146
import org.apache.cassandra.utils.KillerForTests;
@@ -58,6 +63,7 @@
5863
import org.mockito.ArgumentCaptor;
5964
import org.mockito.ArgumentMatchers;
6065
import org.mockito.Mockito;
66+
import org.openjdk.jmh.util.FileUtils;
6167

6268
import static org.assertj.core.api.Assertions.*;
6369
import static org.mockito.ArgumentMatchers.anyInt;
@@ -543,7 +549,47 @@ public void handleOOMError()
543549
}
544550

545551
@Test
546-
public void handleCorruptionException()
552+
public void handleCorruptionSSTableException()
553+
{
554+
handleCorruptionException(() -> new CorruptSSTableException(null, "corrupted"));
555+
}
556+
557+
@Test
558+
public void handleCorruptionBlockException()
559+
{
560+
handleCorruptionException(() -> {
561+
try
562+
{
563+
CompressionMetadata.Chunk chunk = new CompressionMetadata.Chunk(1L, 1);
564+
return new CorruptBlockException(new File(FileUtils.tempFile("temp")), chunk);
565+
}
566+
catch (IOException e)
567+
{
568+
throw new RuntimeException(e);
569+
}
570+
});
571+
}
572+
573+
@Test
574+
public void handleCorruptionFileException()
575+
{
576+
handleCorruptionException(() -> {
577+
try
578+
{
579+
File file = new File(FileUtils.tempFile("temp"));
580+
CorruptFileException corruptFileException = new CorruptFileException(null, file);
581+
assertThat(corruptFileException.getFile()).isEqualTo(file);
582+
return corruptFileException;
583+
}
584+
catch (IOException e)
585+
{
586+
throw new RuntimeException(e);
587+
}
588+
});
589+
}
590+
591+
592+
private void handleCorruptionException(Supplier<Exception> provider)
547593
{
548594
JVMKiller originalKiller = JVMStabilityInspector.replaceKiller(new KillerForTests());
549595
Config.DiskFailurePolicy originalPolicy = DatabaseDescriptor.getDiskFailurePolicy();
@@ -558,10 +604,10 @@ public void handleCorruptionException()
558604

559605
long before = CompactionManager.instance.getMetrics().totalCompactionsFailed.getCount();
560606

561-
CorruptSSTableException corruptSSTableException = new CorruptSSTableException(null, "corrupted");
562-
BackgroundCompactionRunner.handleCompactionError(corruptSSTableException, cfs);
607+
Exception exception = provider.get();
608+
BackgroundCompactionRunner.handleCompactionError(exception, cfs);
563609

564-
assertThat(diskErrorEncountered.get()).isSameAs(corruptSSTableException);
610+
assertThat(diskErrorEncountered.get()).isSameAs(exception);
565611
assertThat(CompactionManager.instance.getMetrics().totalCompactionsFailed.getCount()).isEqualTo(before + 1);
566612
}
567613
finally
@@ -572,6 +618,7 @@ public void handleCorruptionException()
572618
}
573619
}
574620

621+
575622
@Test
576623
public void handleFSWriteError()
577624
{

0 commit comments

Comments
 (0)