summaryrefslogtreecommitdiffstats
path: root/src/test/com/jogamp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-05-01 01:12:56 +0200
committerSven Gothel <[email protected]>2011-05-01 01:12:56 +0200
commitff91e88700339dac7e91ffcf7ee3f43c446a4e37 (patch)
treebf9ad2e3e3b7caf50b803b80a553a1872eb54327 /src/test/com/jogamp
parent9ffd8a9687770a4cadb5df19ec206436f9a9b0e4 (diff)
UI Unit Tests: Add test name to log and singleton lock, better log output
Diffstat (limited to 'src/test/com/jogamp')
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/SingletonInstance.java23
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/UITestCase.java21
2 files changed, 29 insertions, 15 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/util/SingletonInstance.java b/src/test/com/jogamp/opengl/test/junit/util/SingletonInstance.java
index 90acd7b74..f72a41e15 100644
--- a/src/test/com/jogamp/opengl/test/junit/util/SingletonInstance.java
+++ b/src/test/com/jogamp/opengl/test/junit/util/SingletonInstance.java
@@ -32,6 +32,7 @@ import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileLock;
+import java.util.Date;
public class SingletonInstance {
@@ -59,16 +60,20 @@ public class SingletonInstance {
return getCanonicalTempPath() + File.separator + basename;
}
- public SingletonInstance(String lockFileBasename) {
+ public SingletonInstance(String name, String lockFileBasename) {
+ this.name = name;
this.file = new File ( getCanonicalTempLockFilePath ( lockFileBasename ) );
setupFileCleanup();
}
- public SingletonInstance(File lockFile) {
+ public SingletonInstance(String name, File lockFile) {
+ this.name = name;
this.file = lockFile ;
setupFileCleanup();
}
+ public String getName() { return name; }
+
void setupFileCleanup() {
file.deleteOnExit();
Runtime.getRuntime().addShutdownHook(new Thread() {
@@ -86,7 +91,7 @@ public class SingletonInstance {
return;
}
if(DEBUG && 0==i) {
- System.err.println("Wait for lock " + file);
+ System.err.println("SLOCK "+System.currentTimeMillis()+" ??? "+name+" - Wait for lock " + file);
}
i++;
Thread.sleep(poll_ms);
@@ -94,7 +99,7 @@ public class SingletonInstance {
} catch ( InterruptedException ie ) {
throw new RuntimeException(ie);
}
- throw new RuntimeException("SingletonInstance couldn't get lock within "+timeout_ms+"ms");
+ throw new RuntimeException("SLOCK "+System.currentTimeMillis()+" EEE "+name+" - couldn't get lock within "+timeout_ms+"ms");
}
public synchronized boolean tryLock() {
@@ -105,12 +110,12 @@ public class SingletonInstance {
if (fileLock != null) {
locked = true;
if(DEBUG) {
- System.err.println("Locked " + file);
+ System.err.println("SLOCK "+System.currentTimeMillis()+" +++ "+name+" - Locked " + file);
}
return true;
}
} catch (Exception e) {
- System.err.println("Unable to create and/or lock file: " + file);
+ System.err.println("SLOCK "+System.currentTimeMillis()+" EEE "+name+" - Unable to create and/or lock file: " + file);
e.printStackTrace();
}
return false;
@@ -121,6 +126,9 @@ public class SingletonInstance {
if(null != fileLock) {
if(locked) {
fileLock.release();
+ if(DEBUG) {
+ System.err.println("SLOCK "+System.currentTimeMillis()+" --- "+name+" - Unlocked " + file);
+ }
}
fileLock = null;
}
@@ -134,7 +142,7 @@ public class SingletonInstance {
}
return true;
} catch (Exception e) {
- System.err.println("Unable to remove lock file: " + file);
+ System.err.println("SLOCK "+System.currentTimeMillis()+" EEE "+name+" - Unable to remove lock file: " + file);
e.printStackTrace();
} finally {
fileLock = null;
@@ -148,6 +156,7 @@ public class SingletonInstance {
return locked;
}
+ String name;
File file = null;
RandomAccessFile randomAccessFile = null;
FileLock fileLock = null;
diff --git a/src/test/com/jogamp/opengl/test/junit/util/UITestCase.java b/src/test/com/jogamp/opengl/test/junit/util/UITestCase.java
index b01ba1be9..ff2e838f6 100644
--- a/src/test/com/jogamp/opengl/test/junit/util/UITestCase.java
+++ b/src/test/com/jogamp/opengl/test/junit/util/UITestCase.java
@@ -32,23 +32,27 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.After;
import org.junit.AfterClass;
+import org.junit.Rule;
+import org.junit.rules.TestName;
public abstract class UITestCase {
+ @Rule public TestName _unitTestName = new TestName();
public static final String SINGLE_INSTANCE_LOCK_FILE = "UITestCase.lock";
- static SingletonInstance singletonInstance;
+ static volatile SingletonInstance singletonInstance;
- protected SingletonInstance getSingletonInstance() {
- return singletonInstance;
+ private final synchronized void initSingletonInstance() {
+ if( null == singletonInstance ) {
+ singletonInstance = new SingletonInstance(getClass().getName(), SINGLE_INSTANCE_LOCK_FILE);
+ singletonInstance.lock(3*60*1000, 1000); // wait up to 3 min, poll every 1s
+ }
}
@BeforeClass
public static void oneTimeSetUp() {
- // one-time initialization code
- singletonInstance = new SingletonInstance(SINGLE_INSTANCE_LOCK_FILE);
- singletonInstance.lock(3*60*1000, 100); // wait up to 3 min, poll every 100ms
+ // one-time initialization code
}
@AfterClass
@@ -60,12 +64,13 @@ public abstract class UITestCase {
@Before
public void setUp() {
- System.err.println("++++ UITestCase.setUp: "+getClass().getName());
+ initSingletonInstance();
+ System.err.println("++++ UITestCase.setUp: "+getClass().getName()+" - "+_unitTestName.getMethodName());
}
@After
public void tearDown() {
- System.err.println("++++ UITestCase.tearDown: "+getClass().getName());
+ System.err.println("++++ UITestCase.tearDown: "+getClass().getName()+" - "+_unitTestName.getMethodName());
}
}