Skip to content

Commit 6c5e5f7

Browse files
committed
fix coverage
1 parent c730da4 commit 6c5e5f7

File tree

1 file changed

+54
-4
lines changed

1 file changed

+54
-4
lines changed

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

Lines changed: 54 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,50 @@ 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+
File file = new File(FileUtils.tempFile("temp"));
565+
CorruptBlockException corruptBlockException = new CorruptBlockException(file, chunk);
566+
assertThat(corruptBlockException.getFile()).isEqualTo(file);
567+
return corruptBlockException;
568+
}
569+
catch (IOException e)
570+
{
571+
throw new RuntimeException(e);
572+
}
573+
});
574+
}
575+
576+
@Test
577+
public void handleCorruptionFileException()
578+
{
579+
handleCorruptionException(() -> {
580+
try
581+
{
582+
File file = new File(FileUtils.tempFile("temp"));
583+
CorruptFileException corruptFileException = new CorruptFileException(null, file);
584+
assertThat(corruptFileException.getFile()).isEqualTo(file);
585+
return corruptFileException;
586+
}
587+
catch (IOException e)
588+
{
589+
throw new RuntimeException(e);
590+
}
591+
});
592+
}
593+
594+
595+
private void handleCorruptionException(Supplier<Exception> provider)
547596
{
548597
JVMKiller originalKiller = JVMStabilityInspector.replaceKiller(new KillerForTests());
549598
Config.DiskFailurePolicy originalPolicy = DatabaseDescriptor.getDiskFailurePolicy();
@@ -558,10 +607,10 @@ public void handleCorruptionException()
558607

559608
long before = CompactionManager.instance.getMetrics().totalCompactionsFailed.getCount();
560609

561-
CorruptSSTableException corruptSSTableException = new CorruptSSTableException(null, "corrupted");
562-
BackgroundCompactionRunner.handleCompactionError(corruptSSTableException, cfs);
610+
Exception exception = provider.get();
611+
BackgroundCompactionRunner.handleCompactionError(exception, cfs);
563612

564-
assertThat(diskErrorEncountered.get()).isSameAs(corruptSSTableException);
613+
assertThat(diskErrorEncountered.get()).isSameAs(exception);
565614
assertThat(CompactionManager.instance.getMetrics().totalCompactionsFailed.getCount()).isEqualTo(before + 1);
566615
}
567616
finally
@@ -572,6 +621,7 @@ public void handleCorruptionException()
572621
}
573622
}
574623

624+
575625
@Test
576626
public void handleFSWriteError()
577627
{

0 commit comments

Comments
 (0)