2
2
3
3
import java .util .List ;
4
4
import java .util .concurrent .Callable ;
5
+ import java .util .concurrent .CompletableFuture ;
5
6
import java .util .concurrent .TimeUnit ;
6
7
import java .util .function .Function ;
7
8
@@ -68,14 +69,14 @@ public void testSimpleEventLogger() {
68
69
public void testWrapCallable () throws Exception {
69
70
String parentTaskId = el .startEvent (QUERY , EMPTY_LOG_PARAMS );
70
71
Callable <String > wrappedCallable = el .wrapCallable (() -> {
71
- return el .getCurrentTaskId ();
72
+ return EventLogger . get () .getCurrentTaskId ();
72
73
});
73
74
74
75
String childTaskId = el .startEvent (QUERY , EMPTY_LOG_PARAMS );
75
76
76
77
String callableVisibleTaskId = wrappedCallable .call ();
77
78
78
- assertEquals (callableVisibleTaskId , parentTaskId );
79
+ assertEquals (parentTaskId , callableVisibleTaskId );
79
80
}
80
81
81
82
@ Test
@@ -92,18 +93,45 @@ public void testWrapCallableOnEmptyStack() throws Exception {
92
93
assertNull (callableVisibleTaskId );
93
94
}
94
95
96
+ @ Test
97
+ public void testWrapCallableThreaded () throws Exception {
98
+ String parentTaskId = el .startEvent (QUERY , EMPTY_LOG_PARAMS );
99
+ Callable <String > wrappedCallable = el .wrapCallable (() -> {
100
+ return EventLogger .get ().getCurrentTaskId ();
101
+ });
102
+
103
+ String childTaskId = el .startEvent (QUERY , EMPTY_LOG_PARAMS );
104
+
105
+ CompletableFuture <String > future = new CompletableFuture <String >();
106
+
107
+ new Thread () {
108
+ @ Override
109
+ public void run () {
110
+ try {
111
+ future .complete (wrappedCallable .call ());
112
+ } catch (Exception ex ) {
113
+ future .completeExceptionally (ex );
114
+ }
115
+ }
116
+ }.start ();
117
+
118
+ String futureVisibleTaskId = future .get ();
119
+
120
+ assertEquals (parentTaskId , futureVisibleTaskId );
121
+ }
122
+
95
123
@ Test
96
124
public void testWrapFunction () throws Exception {
97
125
String parentTaskId = el .startEvent (QUERY , EMPTY_LOG_PARAMS );
98
126
Function <Integer , String > wrappedFunction = el .<Integer , String >wrapFunction (ignored -> {
99
- return el .getCurrentTaskId ();
127
+ return EventLogger . get () .getCurrentTaskId ();
100
128
});
101
129
102
130
String childTaskId = el .startEvent (QUERY , EMPTY_LOG_PARAMS );
103
131
104
132
String callableVisibleTaskId = wrappedFunction .apply (42 );
105
133
106
- assertEquals (callableVisibleTaskId , parentTaskId );
134
+ assertEquals (parentTaskId , callableVisibleTaskId );
107
135
}
108
136
109
137
@ Test
0 commit comments