27package jau.test.junit.util;
29import org.junit.BeforeClass;
30import org.junit.AfterClass;
31import org.junit.FixMethodOrder;
32import org.junit.runners.MethodSorters;
34import jau.test.util.parallel.locks.SingletonInstance;
36@FixMethodOrder(MethodSorters.NAME_ASCENDING)
38 public static final String SINGLE_INSTANCE_LOCK_FILE =
"SingletonTestCase.lock";
39 public static final int SINGLE_INSTANCE_LOCK_PORT = 59999;
41 public static final long SINGLE_INSTANCE_LOCK_TO = 15*60*1000;
42 public static final long SINGLE_INSTANCE_LOCK_POLL = 500;
45 private static final Object singletonSync =
new Object();
46 private static boolean enabled =
true;
58 synchronized( singletonSync ) {
60 if(
null == singletonInstance ) {
61 System.err.println(
"++++ Test Singleton.ctor()");
65 System.err.println(
"++++ Test Singleton.lock()");
66 if(!singletonInstance.
tryLock(SINGLE_INSTANCE_LOCK_TO)) {
67 throw new RuntimeException(
"Fatal: Could not lock single instance: "+singletonInstance.
getName());
76 synchronized( singletonSync ) {
79 System.err.println(
"++++ Test Singleton.unlock()");
80 singletonInstance.
unlock();
83 Thread.sleep( SINGLE_INSTANCE_LOCK_POLL );
84 }
catch (
final InterruptedException e) { }
static final void oneTimeTearDownSingleton()
static final void oneTimeSetUpSingleton()
static final void enableSingletonLock(final boolean v)
Default is true.
abstract String getName()
void unlock()
Release the lock.
static SingletonInstance createServerSocket(final long poll_ms, final int portNumber)
A user shall use ephemeral ports:
synchronized boolean tryLock(long maxwait)
Blocking until the lock is acquired by this Thread or maxwait in ms is reached.