Skip to content

Commit 7ad2e92

Browse files
authored
Merge pull request #33 from Nordstrom/pr/fix-parallel-methods
Pr/fix parallel methods
2 parents 140f619 + d628efb commit 7ad2e92

File tree

10 files changed

+396
-356
lines changed

10 files changed

+396
-356
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>com.nordstrom.tools</groupId>
44
<artifactId>junit-foundation</artifactId>
5-
<version>8.0.2-SNAPSHOT</version>
5+
<version>9.0.1-SNAPSHOT</version>
66
<packaging>jar</packaging>
77

88
<name>JUnit Foundation</name>
@@ -36,7 +36,7 @@
3636
<settings.version>2.2.2</settings.version>
3737
<junit.version>4.12</junit.version>
3838
<testng.version>6.10</testng.version>
39-
<bytebuddy.version>1.9.3</bytebuddy.version>
39+
<bytebuddy.version>1.9.5</bytebuddy.version>
4040
<logback.version>1.2.2</logback.version>
4141
<gpg-plugin.version>1.6</gpg-plugin.version>
4242
<staging-plugin.version>1.6.7</staging-plugin.version>
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package com.nordstrom.automation.junit;
2+
3+
import java.util.Map;
4+
import java.util.ServiceLoader;
5+
import java.util.concurrent.Callable;
6+
import java.util.concurrent.ConcurrentHashMap;
7+
8+
import net.bytebuddy.implementation.bind.annotation.RuntimeType;
9+
import net.bytebuddy.implementation.bind.annotation.SuperCall;
10+
import net.bytebuddy.implementation.bind.annotation.This;
11+
12+
/**
13+
* This class declares the interceptor for the {@link org.junit.runners.BlockJUnit4ClassRunner#createTest
14+
* createTest} method.
15+
*/
16+
@SuppressWarnings("squid:S1118")
17+
public class CreateTest {
18+
19+
private static final ServiceLoader<TestObjectWatcher> objectWatcherLoader;
20+
private static final Map<Object, Object> TARGET_TO_RUNNER = new ConcurrentHashMap<>();
21+
private static final Map<Object, Object> RUNNER_TO_TARGET = new ConcurrentHashMap<>();
22+
private static final ThreadLocal<Integer> COUNTER;
23+
private static final DepthGauge DEPTH;
24+
25+
static {
26+
objectWatcherLoader = ServiceLoader.load(TestObjectWatcher.class);
27+
COUNTER = DepthGauge.getCounter();
28+
DEPTH = new DepthGauge(COUNTER);
29+
}
30+
31+
/**
32+
* Interceptor for the {@link org.junit.runners.BlockJUnit4ClassRunner#createTest createTest} method.
33+
*
34+
* @param runner target {@link org.junit.runners.BlockJUnit4ClassRunner BlockJUnit4ClassRunner} object
35+
* @param proxy callable proxy for the intercepted method
36+
* @return {@code anything} - JUnit test class instance
37+
* @throws Exception {@code anything} (exception thrown by the intercepted method)
38+
*/
39+
@RuntimeType
40+
public static Object intercept(@This final Object runner,
41+
@SuperCall final Callable<?> proxy) throws Exception {
42+
43+
Object testObj;
44+
try {
45+
DEPTH.increaseDepth();
46+
testObj = LifecycleHooks.callProxy(proxy);
47+
} finally {
48+
DEPTH.decreaseDepth();
49+
}
50+
51+
TARGET_TO_RUNNER.put(testObj, runner);
52+
RUNNER_TO_TARGET.put(runner, testObj);
53+
LifecycleHooks.applyTimeout(testObj);
54+
55+
if (DEPTH.atGroundLevel()) {
56+
synchronized(objectWatcherLoader) {
57+
for (TestObjectWatcher watcher : objectWatcherLoader) {
58+
watcher.testObjectCreated(testObj, runner);
59+
}
60+
}
61+
}
62+
63+
return testObj;
64+
}
65+
66+
/**
67+
* Get the class runner associated with the specified instance.
68+
*
69+
* @param target instance of JUnit test class
70+
* @return {@link org.junit.runners.BlockJUnit4ClassRunner BlockJUnit4ClassRunner} for specified instance
71+
*/
72+
static Object getRunnerForTarget(Object target) {
73+
return TARGET_TO_RUNNER.get(target);
74+
}
75+
76+
/**
77+
* Get the JUnit test class instance for the specified class runner.
78+
*
79+
* @param runner JUnit class runner
80+
* @return JUnit test class instance for specified runner
81+
*/
82+
static Object getTargetForRunner(Object runner) {
83+
return RUNNER_TO_TARGET.get(runner);
84+
}
85+
}

src/main/java/com/nordstrom/automation/junit/CreateTestClass.java

Lines changed: 0 additions & 75 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.nordstrom.automation.junit;
2+
3+
import java.util.concurrent.Callable;
4+
5+
import net.bytebuddy.implementation.bind.annotation.SuperCall;
6+
import net.bytebuddy.implementation.bind.annotation.This;
7+
8+
public class Finished {
9+
public static void intercept(@This final Object scheduler, @SuperCall final Callable<?> proxy) throws Exception {
10+
LifecycleHooks.callProxy(proxy);
11+
RunChild.finished();
12+
}
13+
}

0 commit comments

Comments
 (0)