KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > util > concurrent > TCTimerTest


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.util.concurrent;
5
6 import EDU.oswego.cs.dl.util.concurrent.Latch;
7 import EDU.oswego.cs.dl.util.concurrent.SynchronizedRef;
8
9 import com.tc.util.TCTimer;
10 import com.tc.util.TCTimerImpl;
11
12 import java.util.TimerTask JavaDoc;
13
14 import junit.framework.TestCase;
15
16 public class TCTimerTest extends TestCase {
17
18   public void test() throws InterruptedException JavaDoc {
19     final String JavaDoc name = "testing 1 2 3";
20     TCTimer timer = new TCTimerImpl(name, true);
21
22     final Latch proceed = new Latch();
23     final SynchronizedRef actualName = new SynchronizedRef(null);
24
25     TimerTask JavaDoc task = new TimerTask JavaDoc() {
26       public void run() {
27         actualName.set(Thread.currentThread().getName());
28         proceed.release();
29       }
30     };
31
32     timer.schedule(task, 0L);
33     proceed.acquire();
34
35     assertEquals(name, actualName.get());
36
37     timer.cancel();
38   }
39
40 }
41
Popular Tags