Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/MergeSpecializationsTest.java @ 19709:678a3de139ad
Add test for concurrent DSL node specializations.
author | Benoit Daloze <benoit.daloze@jku.at> |
---|---|
date | Thu, 05 Mar 2015 14:19:23 +0100 |
parents | |
children | e8d2f3f95dcd |
rev | line source |
---|---|
19709
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
1 /* |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
4 * |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
8 * |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
13 * accompanied this code). |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
14 * |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
18 * |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
21 * questions. |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
22 */ |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
23 package com.oracle.truffle.api.dsl.test; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
24 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
25 import static com.oracle.truffle.api.dsl.test.TestHelper.*; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
26 import static org.junit.Assert.*; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
27 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
28 import java.util.*; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
29 import java.util.concurrent.*; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
30 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
31 import org.junit.*; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
32 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
33 import com.oracle.truffle.api.dsl.*; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
34 import com.oracle.truffle.api.dsl.internal.*; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
35 import com.oracle.truffle.api.dsl.test.MergeSpecializationsTestFactory.TestCachedNodeFactory; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
36 import com.oracle.truffle.api.dsl.test.MergeSpecializationsTestFactory.TestNodeFactory; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
37 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
38 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
39 import com.oracle.truffle.api.nodes.*; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
40 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
41 public class MergeSpecializationsTest { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
42 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
43 private static final int THREADS = 8; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
44 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
45 @NodeChild |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
46 @SuppressWarnings("unused") |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
47 abstract static class TestNode extends ValueNode { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
48 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
49 @Specialization |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
50 int s1(int a) { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
51 return 1; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
52 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
53 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
54 @Specialization |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
55 int s2(long a) { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
56 return 2; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
57 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
58 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
59 @Specialization |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
60 int s3(double a) { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
61 return 3; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
62 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
63 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
64 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
65 @NodeChild |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
66 @SuppressWarnings("unused") |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
67 abstract static class TestCachedNode extends ValueNode { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
68 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
69 @Specialization(guards = "a == cachedA", limit = "3") |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
70 int s1(int a, @Cached("a") int cachedA) { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
71 return 1; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
72 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
73 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
74 @Specialization |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
75 int s2(long a) { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
76 return 2; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
77 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
78 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
79 @Specialization |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
80 int s3(double a) { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
81 return 3; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
82 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
83 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
84 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
85 @Test |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
86 public void testMultithreadedMergeInOrder() { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
87 multithreadedMerge(TestNodeFactory.getInstance(), new Executions(1, 1L << 32, 1.0), 1, 2, 3); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
88 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
89 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
90 @Test |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
91 public void testMultithreadedMergeReverse() { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
92 multithreadedMerge(TestNodeFactory.getInstance(), new Executions(1.0, 1L << 32, 1), 3, 2, 1); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
93 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
94 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
95 @Ignore |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
96 @Test |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
97 public void testMultithreadedMergeCachedInOrder() { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
98 multithreadedMerge(TestCachedNodeFactory.getInstance(), new Executions(1, 1L << 32, 1.0), 1, 2, 3); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
99 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
100 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
101 @Ignore |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
102 @Test |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
103 public void testMultithreadedMergeCachedTwoEntries() { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
104 multithreadedMerge(TestCachedNodeFactory.getInstance(), new Executions(1, 2, 1.0), 1, 1, 3); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
105 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
106 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
107 @Ignore |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
108 @Test |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
109 public void testMultithreadedMergeCachedThreeEntries() { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
110 multithreadedMerge(TestCachedNodeFactory.getInstance(), new Executions(1, 2, 3), 1, 1, 1); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
111 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
112 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
113 private static <T extends ValueNode> void multithreadedMerge(NodeFactory<T> factory, final Executions executions, int... order) { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
114 assertEquals(3, order.length); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
115 final TestRootNode<T> node = createRoot(factory); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
116 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
117 final CountDownLatch threadsStarted = new CountDownLatch(THREADS); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
118 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
119 final CountDownLatch beforeFirst = new CountDownLatch(1); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
120 final CountDownLatch executedFirst = new CountDownLatch(THREADS); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
121 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
122 final CountDownLatch beforeSecond = new CountDownLatch(1); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
123 final CountDownLatch executedSecond = new CountDownLatch(THREADS); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
124 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
125 final CountDownLatch beforeThird = new CountDownLatch(1); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
126 final CountDownLatch executedThird = new CountDownLatch(THREADS); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
127 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
128 Thread[] threads = new Thread[THREADS]; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
129 for (int i = 0; i < threads.length; i++) { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
130 threads[i] = new Thread(new Runnable() { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
131 public void run() { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
132 threadsStarted.countDown(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
133 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
134 MergeSpecializationsTest.await(beforeFirst); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
135 executeWith(node, executions.firstValue); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
136 executedFirst.countDown(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
137 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
138 MergeSpecializationsTest.await(beforeSecond); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
139 executeWith(node, executions.secondValue); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
140 executedSecond.countDown(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
141 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
142 MergeSpecializationsTest.await(beforeThird); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
143 executeWith(node, executions.thirdValue); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
144 executedThird.countDown(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
145 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
146 }); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
147 threads[i].start(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
148 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
149 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
150 final SpecializedNode gen = (SpecializedNode) node.getNode(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
151 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
152 final SpecializationNode start0 = gen.getSpecializationNode(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
153 assertEquals("UninitializedNode_", start0.getClass().getSimpleName()); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
154 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
155 await(threadsStarted); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
156 beforeFirst.countDown(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
157 await(executedFirst); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
158 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
159 final SpecializationNode start1 = gen.getSpecializationNode(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
160 assertEquals("S" + order[0] + "Node_", start1.getClass().getSimpleName()); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
161 assertEquals("UninitializedNode_", nthChild(1, start1).getClass().getSimpleName()); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
162 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
163 beforeSecond.countDown(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
164 await(executedSecond); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
165 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
166 final SpecializationNode start2 = gen.getSpecializationNode(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
167 Arrays.sort(order, 0, 2); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
168 assertEquals("PolymorphicNode_", start2.getClass().getSimpleName()); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
169 assertEquals("S" + order[0] + "Node_", nthChild(1, start2).getClass().getSimpleName()); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
170 assertEquals("S" + order[1] + "Node_", nthChild(2, start2).getClass().getSimpleName()); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
171 assertEquals("UninitializedNode_", nthChild(3, start2).getClass().getSimpleName()); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
172 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
173 beforeThird.countDown(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
174 await(executedThird); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
175 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
176 final SpecializationNode start3 = gen.getSpecializationNode(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
177 Arrays.sort(order); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
178 assertEquals("PolymorphicNode_", start3.getClass().getSimpleName()); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
179 assertEquals("S" + order[0] + "Node_", nthChild(1, start3).getClass().getSimpleName()); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
180 assertEquals("S" + order[1] + "Node_", nthChild(2, start3).getClass().getSimpleName()); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
181 assertEquals("S" + order[2] + "Node_", nthChild(3, start3).getClass().getSimpleName()); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
182 assertEquals("UninitializedNode_", nthChild(4, start3).getClass().getSimpleName()); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
183 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
184 for (Thread thread : threads) { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
185 try { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
186 thread.join(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
187 } catch (InterruptedException e) { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
188 fail("interrupted"); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
189 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
190 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
191 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
192 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
193 private static class Executions { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
194 public final Object firstValue; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
195 public final Object secondValue; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
196 public final Object thirdValue; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
197 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
198 public Executions(Object firstValue, Object secondValue, Object thirdValue) { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
199 this.firstValue = firstValue; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
200 this.secondValue = secondValue; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
201 this.thirdValue = thirdValue; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
202 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
203 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
204 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
205 private static void await(final CountDownLatch latch) { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
206 try { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
207 latch.await(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
208 } catch (InterruptedException e) { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
209 fail("interrupted"); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
210 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
211 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
212 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
213 private static Node firstChild(Node node) { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
214 return node.getChildren().iterator().next(); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
215 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
216 |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
217 private static Node nthChild(int n, Node node) { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
218 if (n == 0) { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
219 return node; |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
220 } else { |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
221 return nthChild(n - 1, firstChild(node)); |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
222 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
223 } |
678a3de139ad
Add test for concurrent DSL node specializations.
Benoit Daloze <benoit.daloze@jku.at>
parents:
diff
changeset
|
224 } |