diff options
author | Sven Gothel <[email protected]> | 2012-09-21 20:19:21 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-09-21 20:19:21 +0200 |
commit | 3106532ef4d16e19f0ed3f9d8fa3634c3859e3f2 (patch) | |
tree | df583d22be2cf0eab8cfef22bcea96deede6499b | |
parent | c8a9b89b1f316c259eaec68309f32fdd8289e375 (diff) |
SingletonInstanceServerSocket: Add another (manual) unit tests for timeouts.
-rwxr-xr-x | make/scripts/runtest.sh | 10 | ||||
-rw-r--r-- | src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket02.java | 72 |
2 files changed, 77 insertions, 5 deletions
diff --git a/make/scripts/runtest.sh b/make/scripts/runtest.sh index 7979a13..12788b6 100755 --- a/make/scripts/runtest.sh +++ b/make/scripts/runtest.sh @@ -55,8 +55,6 @@ rm -f $LOG #D_ARGS="-Djogamp.debug=all" function onetest() { - clazz=$1 - shift CLASSPATH=lib/junit.jar:$ANT_JARS:$builddir/../make/lib/TestJarsInJar.jar:$builddir/gluegen-rt.jar:$builddir/gluegen.jar:$builddir/test/build/gluegen-test.jar libspath=$builddir/test/build/natives #CLASSPATH=lib/junit.jar:$ANT_JARS:$builddir/../make/lib/TestJarsInJar.jar:$builddir/classes:$builddir/test/build/classes @@ -65,7 +63,7 @@ function onetest() { echo LD_LIBRARY_PATH $LD_LIBRARY_PATH echo CLASSPATH $CLASSPATH echo java -cp $CLASSPATH $D_ARGS -Djava.library.path=$libspath $clazz - java -cp $CLASSPATH $D_ARGS -Djava.library.path=$libspath $clazz + java -cp $CLASSPATH $D_ARGS -Djava.library.path=$libspath $* echo } @@ -75,8 +73,10 @@ function onetest() { #onetest com.jogamp.common.util.TestIteratorIndexCORE 2>&1 | tee -a $LOG #onetest com.jogamp.common.util.locks.TestRecursiveLock01 2>&1 | tee -a $LOG #onetest com.jogamp.common.util.locks.TestRecursiveThreadGroupLock01 2>&1 | tee -a $LOG -onetest com.jogamp.common.util.locks.TestSingletonServerSocket00 2>&1 | tee -a $LOG -onetest com.jogamp.common.util.locks.TestSingletonServerSocket01 2>&1 | tee -a $LOG +#onetest com.jogamp.common.util.locks.TestSingletonServerSocket00 2>&1 | tee -a $LOG +#onetest com.jogamp.common.util.locks.TestSingletonServerSocket01 2>&1 | tee -a $LOG +#onetest com.jogamp.common.util.locks.TestSingletonServerSocket02 2>&1 | tee -a $LOG +onetest com.jogamp.common.util.locks.TestSingletonServerSocket02 2>&1 | tee -a $LOG #onetest com.jogamp.common.util.TestArrayHashSet01 2>&1 | tee -a $LOG #onetest com.jogamp.common.util.IntIntHashMapTest 2>&1 | tee -a $LOG #onetest com.jogamp.common.util.IntObjectHashMapTest 2>&1 | tee -a $LOG diff --git a/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket02.java b/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket02.java new file mode 100644 index 0000000..69128d1 --- /dev/null +++ b/src/junit/com/jogamp/common/util/locks/TestSingletonServerSocket02.java @@ -0,0 +1,72 @@ +/** + * Copyright 2012 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ +package com.jogamp.common.util.locks; + +import java.io.IOException; + +import junit.framework.Assert; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +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(); + } + + @Test + public void dummy() throws InterruptedException { + // make junit happy + } + + // @Test(timeout=10) // Only enable manually to test timeout behavior + public void testTimeout() throws InterruptedException { + Thread.sleep(3000); + } + + public static void main(String args[]) throws IOException, InterruptedException { + String tstname = TestSingletonServerSocket02.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } +} |