1 // Simple tests of InheritableThreadLocal |
|
2 |
|
3 // Copyright (C) 2001 Red Hat, Inc. |
|
4 |
|
5 // This file is part of Mauve. |
|
6 |
|
7 // Mauve is free software; you can redistribute it and/or modify |
|
8 // it under the terms of the GNU General Public License as published by |
|
9 // the Free Software Foundation; either version 2, or (at your option) |
|
10 // any later version. |
|
11 |
|
12 // Mauve is distributed in the hope that it will be useful, |
|
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15 // GNU General Public License for more details. |
|
16 |
|
17 // You should have received a copy of the GNU General Public License |
|
18 // along with Mauve; see the file COPYING. If not, write to |
|
19 // the Free Software Foundation, 59 Temple Place - Suite 330, |
|
20 // Boston, MA 02111-1307, USA. |
|
21 |
|
22 // Tags: JDK1.3 |
|
23 |
|
24 package gnu.testlet.java.lang.InheritableThreadLocal; |
|
25 |
|
26 import gnu.testlet.Testlet; |
|
27 import gnu.testlet.TestHarness; |
|
28 |
|
29 public class simple implements Testlet, Runnable |
|
30 { |
|
31 private class TestInheritableThreadLocal extends InheritableThreadLocal |
|
32 { |
|
33 public Object initialValue () |
|
34 { |
|
35 return "Maude"; |
|
36 } |
|
37 |
|
38 protected Object childValue(Object parentValue) |
|
39 { |
|
40 myHarness.check (parentValue, "Liver", "Check parent value"); |
|
41 return "Spice"; |
|
42 } |
|
43 } |
|
44 |
|
45 private TestHarness myHarness; |
|
46 private TestInheritableThreadLocal loc = new TestInheritableThreadLocal(); |
|
47 |
|
48 public void run () |
|
49 { |
|
50 myHarness.check (loc.get (), "Spice", "Child value in new thread"); |
|
51 loc.set ("Wednesday"); |
|
52 myHarness.check (loc.get (), "Wednesday", "Changed value in new thread"); |
|
53 } |
|
54 |
|
55 public void test (TestHarness harness) |
|
56 { |
|
57 this.myHarness = harness; |
|
58 |
|
59 harness.check (loc.get (), "Maude", "Check initial value"); |
|
60 |
|
61 loc.set ("Liver"); |
|
62 harness.check (loc.get (), "Liver", "Check changed value"); |
|
63 |
|
64 try |
|
65 { |
|
66 Thread t = new Thread(this); |
|
67 t.start (); |
|
68 t.join (); |
|
69 } |
|
70 catch (InterruptedException _) |
|
71 { |
|
72 } |
|
73 |
|
74 harness.check (loc.get (), "Liver", "Value didn't change"); |
|
75 } |
|
76 } |
|