29package com.jogamp.junit.util;
31import com.jogamp.common.util.locks.SingletonInstance;
33import org.junit.BeforeClass;
34import org.junit.AfterClass;
35import org.junit.FixMethodOrder;
36import org.junit.runners.MethodSorters;
38@FixMethodOrder(MethodSorters.NAME_ASCENDING)
40 public static final String SINGLE_INSTANCE_LOCK_FILE =
"SingletonTestCase.lock";
41 public static final int SINGLE_INSTANCE_LOCK_PORT = 59999;
43 public static final long SINGLE_INSTANCE_LOCK_TO = 15*60*1000;
44 public static final long SINGLE_INSTANCE_LOCK_POLL = 500;
47 private static final Object singletonSync =
new Object();
48 private static boolean enabled =
true;
60 synchronized( singletonSync ) {
62 if(
null == singletonInstance ) {
63 System.err.println(
"++++ Test Singleton.ctor()");
67 System.err.println(
"++++ Test Singleton.lock()");
68 if(!singletonInstance.
tryLock(SINGLE_INSTANCE_LOCK_TO)) {
69 throw new RuntimeException(
"Fatal: Could not lock single instance: "+singletonInstance.
getName());
78 synchronized( singletonSync ) {
81 System.err.println(
"++++ Test Singleton.unlock()");
82 singletonInstance.
unlock();
85 Thread.sleep( SINGLE_INSTANCE_LOCK_POLL );
86 }
catch (
final InterruptedException e) { }
abstract String getName()
synchronized boolean tryLock(long maxwait)
Blocking until the lock is acquired by this Thread or maxwait in ms is reached.
static SingletonInstance createServerSocket(final long poll_ms, final int portNumber)
A user shall use ephemeral ports:
void unlock()
Release the lock.
static final void oneTimeTearDownSingleton()
static final void enableSingletonLock(final boolean v)
Default is true.
static final void oneTimeSetUpSingleton()