diff options
author | Sven Gothel <[email protected]> | 2015-09-05 05:00:14 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2015-09-05 05:00:14 +0200 |
commit | b94d0c4e2ac4b29ffe6bb832d37b83c6d32497fe (patch) | |
tree | 2c946a84e6064c495fb3895da312deb3771f674a | |
parent | db7ce1c9c271edf6dc08db9f920adc93df9b2bb0 (diff) |
SingletonJunitCase: Allow explicit disabling singletonLock to allow manual test cases to run concurrently
-rw-r--r-- | src/junit/com/jogamp/junit/util/SingletonJunitCase.java | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/src/junit/com/jogamp/junit/util/SingletonJunitCase.java b/src/junit/com/jogamp/junit/util/SingletonJunitCase.java index 7fb5fea..ad80bde 100644 --- a/src/junit/com/jogamp/junit/util/SingletonJunitCase.java +++ b/src/junit/com/jogamp/junit/util/SingletonJunitCase.java @@ -45,19 +45,29 @@ public abstract class SingletonJunitCase extends JunitTracer { private static SingletonInstance singletonInstance = null; // system wide lock via port locking private static final Object singletonSync = new Object(); // classloader wide lock + private static boolean enabled = true; + + /** + * Default is {@code true}. + */ + public static final void enableSingletonLock(final boolean v) { + enabled = v; + } @BeforeClass public static final void oneTimeSetUpSingleton() { // one-time initialization code synchronized( singletonSync ) { - if( null == singletonInstance ) { - System.err.println("++++ Test Singleton.ctor()"); - // singletonInstance = SingletonInstance.createFileLock(SINGLE_INSTANCE_LOCK_POLL, SINGLE_INSTANCE_LOCK_FILE); - singletonInstance = SingletonInstance.createServerSocket(SINGLE_INSTANCE_LOCK_POLL, SINGLE_INSTANCE_LOCK_PORT); - } - System.err.println("++++ Test Singleton.lock()"); - if(!singletonInstance.tryLock(SINGLE_INSTANCE_LOCK_TO)) { - throw new RuntimeException("Fatal: Could not lock single instance: "+singletonInstance.getName()); + if( enabled ) { + if( null == singletonInstance ) { + System.err.println("++++ Test Singleton.ctor()"); + // singletonInstance = SingletonInstance.createFileLock(SINGLE_INSTANCE_LOCK_POLL, SINGLE_INSTANCE_LOCK_FILE); + singletonInstance = SingletonInstance.createServerSocket(SINGLE_INSTANCE_LOCK_POLL, SINGLE_INSTANCE_LOCK_PORT); + } + System.err.println("++++ Test Singleton.lock()"); + if(!singletonInstance.tryLock(SINGLE_INSTANCE_LOCK_TO)) { + throw new RuntimeException("Fatal: Could not lock single instance: "+singletonInstance.getName()); + } } } } @@ -67,12 +77,14 @@ public abstract class SingletonJunitCase extends JunitTracer { // one-time cleanup code synchronized( singletonSync ) { System.gc(); // force cleanup - System.err.println("++++ Test Singleton.unlock()"); - singletonInstance.unlock(); - try { - // allowing other JVM instances to pick-up socket - Thread.sleep( SINGLE_INSTANCE_LOCK_POLL ); - } catch (final InterruptedException e) { } + if( enabled ) { + System.err.println("++++ Test Singleton.unlock()"); + singletonInstance.unlock(); + try { + // allowing other JVM instances to pick-up socket + Thread.sleep( SINGLE_INSTANCE_LOCK_POLL ); + } catch (final InterruptedException e) { } + } } } } |