Skip to content

Commit bead4ff

Browse files
committed
Add a test for rethrowing an unhandled exception
1 parent 99be4ca commit bead4ff

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import org.jboss.byteman.contrib.bmunit.BMUnitRunner;
6161

6262
import static org.apache.cassandra.db.ColumnFamilyStore.FlushReason.UNIT_TESTS;
63+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
6364
import static org.junit.Assert.assertEquals;
6465
import static org.junit.Assert.assertFalse;
6566
import static org.junit.Assert.assertNotEquals;
@@ -72,12 +73,12 @@ public class CompactionControllerTest extends SchemaLoader
7273
private static final String KEYSPACE = "CompactionControllerTest";
7374
private static final String CF1 = "Standard1";
7475
private static final String CF2 = "Standard2";
75-
private static final int TTL_SECONDS = 10;
7676
private static CountDownLatch compaction2FinishLatch = new CountDownLatch(1);
7777
private static CountDownLatch createCompactionControllerLatch = new CountDownLatch(1);
7878
private static CountDownLatch compaction1RefreshLatch = new CountDownLatch(1);
7979
private static CountDownLatch refreshCheckLatch = new CountDownLatch(1);
8080
private static int overlapRefreshCounter = 0;
81+
private static boolean shouldThrowOnConfigCleanup = false;
8182

8283
@BeforeClass
8384
public static void defineSchema() throws ConfigurationException
@@ -267,6 +268,34 @@ public void testInFlightBloomFilterMemory()
267268
}
268269
}
269270

271+
@Test
272+
@BMRule(name = "Simulate an non standard exception while opening a keyspace",
273+
targetClass = "org.apache.cassandra.schema.Schema",
274+
targetMethod = "getKeyspaceInstance",
275+
targetLocation = "AT ENTRY",
276+
condition = "org.apache.cassandra.db.compaction.CompactionControllerTest.shouldThrowOnConfigCleanup",
277+
action = "throw new java.lang.RuntimeException(\"Expected exception\");")
278+
public void testRethrowingExceptionOnConfigCleanup()
279+
{
280+
try
281+
{
282+
// given the config was stored
283+
CompactionManager.storeControllerConfig();
284+
// below flag is read by byteman, it is needed to throw the exception on the second call of cleanupControllerConfig
285+
shouldThrowOnConfigCleanup = true;
286+
// when
287+
// unhandled exception is throw while cleaning up the controller config
288+
// then the excepion is not swallowed
289+
assertThatExceptionOfType(RuntimeException.class)
290+
.isThrownBy(CompactionManager::cleanupControllerConfig)
291+
.withMessage("Expected exception");
292+
}
293+
finally
294+
{
295+
shouldThrowOnConfigCleanup = false;
296+
}
297+
}
298+
270299
@Test
271300
@BMRules(rules = {
272301
@BMRule(name = "Pause compaction",

0 commit comments

Comments
 (0)