GlueGen: src/junit/com/jogamp/common/util/TestRunnableTask01.java Source File

GlueGen v2.6.0-rc-20250712 GlueGen, Native Binding Generator for Java™ (public API).

TestRunnableTask01.java
Go to the documentation of this file.
1/**
2 * Copyright 2011 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29package com.jogamp.common.util;
30
31import java.io.IOException;
32import java.lang.reflect.InvocationTargetException;
33
34import org.junit.Assert;
35import org.junit.Test;
36
37import com.jogamp.junit.util.SingletonJunitCase;
38
39import org.junit.FixMethodOrder;
40import org.junit.runners.MethodSorters;
41
42@FixMethodOrder(MethodSorters.NAME_ASCENDING)
43public class TestRunnableTask01 extends SingletonJunitCase {
44
45 @Test
46 public void testInvokeAndWait00() throws IOException, InterruptedException, InvocationTargetException {
47 final Object syncObject = new Object();
48 final boolean[] done = {false};
49 final Runnable clientAction = new Runnable() {
50 public void run() {
51 synchronized(syncObject) {
52 System.err.println("CA.1: "+syncObject);
53 done[ 0 ] = true;
54 System.err.println("CA.X");
55 syncObject.notifyAll();
56 }
57 }
58 };
59
60 System.err.println("BB.0: "+syncObject);
61 synchronized (syncObject) {
62 System.err.println("BB.1: "+syncObject);
63 new InterruptSource.Thread(null, clientAction, Thread.currentThread().getName()+"-clientAction").start();
64 try {
65 System.err.println("BB.2");
66 syncObject.wait();
67 System.err.println("BB.3");
68 } catch (final InterruptedException e) {
69 throw new RuntimeException(e);
70 }
71 Assert.assertTrue(done[0]);
72 System.err.println("BB.X");
73 }
74 }
75
76 @Test
77 public void testInvokeAndWait01() throws IOException, InterruptedException, InvocationTargetException {
78 final boolean[] done = {false};
79 final Runnable clientAction = new Runnable() {
80 public void run() {
81 System.err.println("CA.1");
82 done[ 0 ] = true;
83 System.err.println("CA.X");
84 }
85 };
86
87 final RunnableTask rTask = new RunnableTask(clientAction, new Object(), false, null);
88 System.err.println("BB.0: "+rTask.getSyncObject());
89 synchronized (rTask.getSyncObject()) {
90 System.err.println("BB.1: "+rTask.getSyncObject());
91 new InterruptSource.Thread(null, rTask, Thread.currentThread().getName()+"-clientAction").start();
92 try {
93 System.err.println("BB.2");
94 rTask.getSyncObject().wait();
95 System.err.println("BB.3");
96 } catch (final InterruptedException e) {
97 throw new RuntimeException(e);
98 }
99 Assert.assertTrue(done[0]);
100 System.err.println("BB.X");
101 }
102 }
103
104 public static void main(final String args[]) throws IOException {
105 final String tstname = TestRunnableTask01.class.getName();
106 org.junit.runner.JUnitCore.main(tstname);
107 }
108
109}
com.jogamp.common.util.InterruptSource.Thread
java.lang.Thread specialization implementing InterruptSource to track java.lang.Thread#interrupt() ca...
Definition: InterruptSource.java:80
com.jogamp.common.util.RunnableTask
Helper class to provide a Runnable queue implementation with a Runnable wrapper which notifies after ...
Definition: RunnableTask.java:39
com.jogamp.common.util.TaskBase.getSyncObject
final Object getSyncObject()
Return the synchronization object if any.
Definition: TaskBase.java:103
com.jogamp.common.util.TestRunnableTask01
Definition: TestRunnableTask01.java:43
com.jogamp.common.util.TestRunnableTask01.testInvokeAndWait01
void testInvokeAndWait01()
Definition: TestRunnableTask01.java:77
com.jogamp.common.util.TestRunnableTask01.main
static void main(final String args[])
Definition: TestRunnableTask01.java:104
com.jogamp.common.util.TestRunnableTask01.testInvokeAndWait00
void testInvokeAndWait00()
Definition: TestRunnableTask01.java:46
com.jogamp.junit.util.SingletonJunitCase
Definition: SingletonJunitCase.java:39
com.jogamp.common.util.InterruptSource
Interface exposing java.lang.Thread#interrupt() source, intended for java.lang.Thread specializations...
Definition: InterruptSource.java:36