smiklosovic commented on code in PR #4691:
URL: https://github.com/apache/cassandra/pull/4691#discussion_r2991012834


##########
test/unit/org/apache/cassandra/utils/JVMStabilityInspectorTest.java:
##########
@@ -239,4 +240,94 @@ public void fileHandleTest()
             JVMStabilityInspector.replaceKiller(originalKiller);
         }
     }
+
+    @Test
+    public void testShutdownHookNotRemovedForNonFatalOom() throws Exception
+    {
+        // CASSANDRA-16939: non-fatal OOMs (direct buffer, native thread) 
should not remove
+        // the shutdown hook so that graceful drain can still occur on 
shutdown.
+        Thread testHook = new Thread(() -> {}, "TestDrainHook"); // 
checkstyle: permit this instantiation
+        Runtime.getRuntime().addShutdownHook(testHook);
+
+        Field drainField = 
StorageService.class.getDeclaredField("drainOnShutdown");
+        drainField.setAccessible(true);
+        Thread originalHook = (Thread) drainField.get(StorageService.instance);
+
+        try
+        {
+            drainField.set(StorageService.instance, testHook);
+
+            // "Direct buffer memory" is a non-fatal OOM — the shutdown hook 
must be preserved
+            try

Review Comment:
   @Shanzita please rework this to more idiomatic  
`org.assertj.core.api.Assertions.assertThatThrownBy` which is use extensively 
through the code base and is more succinct / readable. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to