diff options
author | Sven Gothel <[email protected]> | 2014-10-03 05:49:57 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-10-03 05:49:57 +0200 |
commit | 773d96584b4edc13eb6ff689eaf891aab09aa5a4 (patch) | |
tree | b670122688f8c6f327664f600fc13d2f54f906f7 /src/junit/com/jogamp/common/util/locks | |
parent | db12572b4f674884c3f7ad8f7e15ba9e97cf865a (diff) |
SingletonTestCase -> SingletonJunitCase: Accomodate ClassLoader lifecycle of static fields; Change name to avoid testing itself.
Diffstat (limited to 'src/junit/com/jogamp/common/util/locks')
5 files changed, 24 insertions, 43 deletions
diff --git a/src/junit/com/jogamp/common/util/locks/TestRecursiveLock01.java b/src/junit/com/jogamp/common/util/locks/TestRecursiveLock01.java index 09d96f2..4508f94 100644 --- a/src/junit/com/jogamp/common/util/locks/TestRecursiveLock01.java +++ b/src/junit/com/jogamp/common/util/locks/TestRecursiveLock01.java @@ -38,13 +38,13 @@ import org.junit.Assert; import org.junit.Test; import com.jogamp.common.os.Platform; -import com.jogamp.junit.util.SingletonTestCase; +import com.jogamp.junit.util.SingletonJunitCase; import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; @FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class TestRecursiveLock01 extends SingletonTestCase { +public class TestRecursiveLock01 extends SingletonJunitCase { public enum YieldMode { NONE(0), YIELD(1), SLEEP(2); diff --git a/src/junit/com/jogamp/common/util/locks/TestRecursiveThreadGroupLock01.java b/src/junit/com/jogamp/common/util/locks/TestRecursiveThreadGroupLock01.java index b338abe..e35d146 100644 --- a/src/junit/com/jogamp/common/util/locks/TestRecursiveThreadGroupLock01.java +++ b/src/junit/com/jogamp/common/util/locks/TestRecursiveThreadGroupLock01.java @@ -34,13 +34,13 @@ import org.junit.Assert; import org.junit.Test; import com.jogamp.common.os.Platform; -import com.jogamp.junit.util.SingletonTestCase; +import com.jogamp.junit.util.SingletonJunitCase; import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; @FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class TestRecursiveThreadGroupLock01 extends SingletonTestCase { +public class TestRecursiveThreadGroupLock01 extends SingletonJunitCase { public enum YieldMode { NONE(0), YIELD(1), SLEEP(2); diff --git a/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket00.java b/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket00.java index 775d46f..b018a79 100644 --- a/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket00.java +++ b/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket00.java @@ -32,35 +32,37 @@ import java.io.IOException; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; - import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; +import com.jogamp.junit.util.SingletonJunitCase; + @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class TestSingletonServerSocket00 { - // public static final String SINGLE_INSTANCE_LOCK_FILE = "UITestCase.lock"; - public static final int SINGLE_INSTANCE_LOCK_PORT = 59999; - public static final long SINGLE_INSTANCE_LOCK_TO = 3*60*1000; // wait up to 3 min - public static final long SINGLE_INSTANCE_LOCK_POLL = 100; // poll every 100ms + public static final long SINGLE_INSTANCE_LOCK_TO = SingletonJunitCase.SINGLE_INSTANCE_LOCK_TO; + + public static final long SINGLE_INSTANCE_LOCK_POLL = 100; // poll every 100ms + private static volatile SingletonInstance singletonInstance; @BeforeClass public static void oneTimeSetUp() { // one-time initialization code - singletonInstance = SingletonInstance.createServerSocket(SINGLE_INSTANCE_LOCK_POLL, SINGLE_INSTANCE_LOCK_PORT); + singletonInstance = SingletonInstance.createServerSocket(SINGLE_INSTANCE_LOCK_POLL, + SingletonJunitCase.SINGLE_INSTANCE_LOCK_PORT); } @Test - public void testLockUnlock() { + public void test01_LockUnlock() { Assert.assertTrue("Could not lock single instance: "+singletonInstance.getName(), singletonInstance.tryLock(SINGLE_INSTANCE_LOCK_TO)); System.gc(); // force cleanup singletonInstance.unlock(); } @Test - public void test2ndInstanceLockTimeout() { + public void test02_2ndInstanceLockTimeout() { Assert.assertTrue("Could not lock single instance: "+singletonInstance.getName(), singletonInstance.tryLock(SINGLE_INSTANCE_LOCK_TO)); - final SingletonInstance instanceTwo = SingletonInstance.createServerSocket(SINGLE_INSTANCE_LOCK_POLL, SINGLE_INSTANCE_LOCK_PORT); + final SingletonInstance instanceTwo = SingletonInstance.createServerSocket(SINGLE_INSTANCE_LOCK_POLL, SingletonJunitCase.SINGLE_INSTANCE_LOCK_PORT); Assert.assertFalse("Could lock 2nd instance: "+instanceTwo.getName(), instanceTwo.tryLock(1000)); // 10x System.gc(); // force cleanup singletonInstance.unlock(); @@ -69,7 +71,7 @@ public class TestSingletonServerSocket00 { private Thread startLockUnlockOffThread(final int i) { final Thread t = new Thread(new Runnable() { public void run() { - final SingletonInstance myLock = SingletonInstance.createServerSocket(10, SINGLE_INSTANCE_LOCK_PORT); + final SingletonInstance myLock = SingletonInstance.createServerSocket(10, SingletonJunitCase.SINGLE_INSTANCE_LOCK_PORT); System.err.println(Thread.currentThread().getName()+" LOCK try .."); Assert.assertTrue(Thread.currentThread().getName()+" - Could not lock instance: "+myLock.getName(), myLock.tryLock(1000)); System.err.println(Thread.currentThread().getName()+" LOCK ON"); diff --git a/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket01.java b/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket01.java index 82ca89b..b37e600 100644 --- a/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket01.java +++ b/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket01.java @@ -32,27 +32,24 @@ import java.io.IOException; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; - import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; +import com.jogamp.junit.util.SingletonJunitCase; + @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class TestSingletonServerSocket01 { - // public static final String SINGLE_INSTANCE_LOCK_FILE = "UITestCase.lock"; - public static final int SINGLE_INSTANCE_LOCK_PORT = 59999; - public static final long SINGLE_INSTANCE_LOCK_TO = 3*60*1000; // wait up to 3 min - public static final long SINGLE_INSTANCE_LOCK_POLL = 1000; // poll every 1s private static volatile SingletonInstance singletonInstance; @BeforeClass public static void oneTimeSetUp() { // one-time initialization code - singletonInstance = SingletonInstance.createServerSocket(SINGLE_INSTANCE_LOCK_POLL, SINGLE_INSTANCE_LOCK_PORT); + singletonInstance = SingletonInstance.createServerSocket(SingletonJunitCase.SINGLE_INSTANCE_LOCK_POLL, SingletonJunitCase.SINGLE_INSTANCE_LOCK_PORT); } @Test public void testJVMShutdown() { - Assert.assertTrue("Could not lock single instance: "+singletonInstance.getName(), singletonInstance.tryLock(SINGLE_INSTANCE_LOCK_TO)); + Assert.assertTrue("Could not lock single instance: "+singletonInstance.getName(), singletonInstance.tryLock(SingletonJunitCase.SINGLE_INSTANCE_LOCK_TO)); singletonInstance.unlock(); } diff --git a/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket02.java b/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket02.java index 50eebd6..d29abf0 100644 --- a/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket02.java +++ b/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket02.java @@ -33,31 +33,13 @@ import org.junit.Assert; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; - import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class TestSingletonServerSocket02 { - // public static final String SINGLE_INSTANCE_LOCK_FILE = "UITestCase.lock"; - public static final int SINGLE_INSTANCE_LOCK_PORT = 59999; - public static final long SINGLE_INSTANCE_LOCK_TO = 3*60*1000; // wait up to 3 min - public static final long SINGLE_INSTANCE_LOCK_POLL = 1000; // poll every 1s - private static volatile SingletonInstance singletonInstance; - - @BeforeClass - public static void oneTimeSetUp() { - // one-time initialization code - singletonInstance = SingletonInstance.createServerSocket(SINGLE_INSTANCE_LOCK_POLL, SINGLE_INSTANCE_LOCK_PORT); - Assert.assertTrue("Could not lock single instance: "+singletonInstance.getName(), singletonInstance.tryLock(SINGLE_INSTANCE_LOCK_TO)); - } - - @AfterClass - public static void oneTimeTearDown() { - System.gc(); // force cleanup - singletonInstance.unlock(); - } +import com.jogamp.junit.util.SingletonJunitCase; +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class TestSingletonServerSocket02 extends SingletonJunitCase { @Test public void dummy() throws InterruptedException { // make junit happy @@ -65,7 +47,7 @@ public class TestSingletonServerSocket02 { // @Test(timeout=10) // Only enable manually to test timeout behavior public void testTimeout() throws InterruptedException { - Thread.sleep(3000); + Thread.sleep(SingletonJunitCase.SINGLE_INSTANCE_LOCK_TO+3000); } public static void main(final String args[]) throws IOException, InterruptedException { |