This is an automated email from the ASF dual-hosted git repository.

brandonwilliams pushed a commit to branch cassandra-4.0
in repository https://gitbox.apache.org/repos/asf/cassandra.git


The following commit(s) were added to refs/heads/cassandra-4.0 by this push:
     new 70478a1578 Fix testCommitLogInitWithException: signal condition 
instead of killing thread
70478a1578 is described below

commit 70478a1578fe4facb0f59fcb40529e0a4040ac81
Author: Brandon Williams <brandonwilli...@apache.org>
AuthorDate: Mon Oct 31 11:51:41 2022 -0500

    Fix testCommitLogInitWithException: signal condition instead of killing 
thread
    
    Patch by brandonwilliams; reviewed by adelapena and bereng for
    CASSANDRa-17928
---
 .../commitlog/CommitLogInitWithExceptionTest.java  | 33 +++++-----------------
 1 file changed, 7 insertions(+), 26 deletions(-)

diff --git 
a/test/unit/org/apache/cassandra/db/commitlog/CommitLogInitWithExceptionTest.java
 
b/test/unit/org/apache/cassandra/db/commitlog/CommitLogInitWithExceptionTest.java
index 690d9babfc..21d207bea2 100644
--- 
a/test/unit/org/apache/cassandra/db/commitlog/CommitLogInitWithExceptionTest.java
+++ 
b/test/unit/org/apache/cassandra/db/commitlog/CommitLogInitWithExceptionTest.java
@@ -24,14 +24,16 @@ import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.apache.cassandra.CassandraIsolatedJunit4ClassRunner;
+import org.apache.cassandra.Util;
 import org.apache.cassandra.config.Config;
 import org.apache.cassandra.config.DatabaseDescriptor;
 import org.apache.cassandra.utils.JVMStabilityInspector;
+import org.apache.cassandra.utils.concurrent.SimpleCondition;
 
 @RunWith(CassandraIsolatedJunit4ClassRunner.class)
 public class CommitLogInitWithExceptionTest
 {
-    private static Thread initThread;
+    private final static SimpleCondition killed = new SimpleCondition();
 
     @BeforeClass
     public static void setUp()
@@ -56,41 +58,20 @@ public class CommitLogInitWithExceptionTest
             }
             finally
             {
-                Assert.assertNotNull(initThread);
-                // We have to manually stop init thread because the JVM does 
not exit actually.
-                initThread.stop();
+                killed.signalAll();
             }
         };
     }
 
-    @Test(timeout = 30000)
+    @Test
     public void testCommitLogInitWithException() {
         // This line will trigger initialization process because it's the 
first time to access CommitLog class.
-        initThread = new Thread(CommitLog.instance::start);
+        Thread initThread = new Thread(CommitLog.instance::start);
 
         initThread.setName("initThread");
         initThread.start();
 
-        try
-        {
-            initThread.join(); // Should not block here
-        }
-        catch (InterruptedException expected)
-        {
-        }
-
-        Assert.assertFalse(initThread.isAlive());
-
-        try
-        {
-            Thread.sleep(1000); // Wait for COMMIT-LOG-ALLOCATOR exit
-        }
-        catch (InterruptedException e)
-        {
-            Assert.fail();
-        }
-
-        Assert.assertEquals(Thread.State.TERMINATED, 
CommitLog.instance.segmentManager.managerThread.getState()); // exit 
successfully
+        Util.spinAssertEquals(true, killed::isSignaled, 120);
     }
 
     private static class MockCommitLogSegmentMgr extends 
CommitLogSegmentManagerStandard {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org
For additional commands, e-mail: commits-h...@cassandra.apache.org

Reply via email to