1
1
package com .datorama .oss .timbermill ;
2
2
3
3
import java .util .List ;
4
+ import java .util .concurrent .Callable ;
4
5
import java .util .concurrent .TimeUnit ;
6
+ import java .util .function .Function ;
5
7
6
8
import org .awaitility .Awaitility ;
7
9
import org .junit .After ;
10
+ import org .junit .Before ;
8
11
import org .junit .BeforeClass ;
9
12
import org .junit .Test ;
10
13
@@ -39,6 +42,7 @@ public static void init(){
39
42
40
43
@ After
41
44
public void tearDown () {
45
+ el .clearStack ();
42
46
EventLogger .exit ();
43
47
mockPipe .close ();
44
48
}
@@ -60,6 +64,48 @@ public void testSimpleEventLogger() {
60
64
assertEquals (TEST , startEvent .getStrings ().get (BOOTSTRAP ));
61
65
}
62
66
67
+ @ Test
68
+ public void testWrapCallable () throws Exception {
69
+ String parentTaskId = el .startEvent (QUERY , EMPTY_LOG_PARAMS );
70
+ Callable <String > wrappedCallable = el .wrapCallable (() -> {
71
+ return el .getCurrentTaskId ();
72
+ });
73
+
74
+ String childTaskId = el .startEvent (QUERY , EMPTY_LOG_PARAMS );
75
+
76
+ String callableVisibleTaskId = wrappedCallable .call ();
77
+
78
+ assertEquals (callableVisibleTaskId , parentTaskId );
79
+ }
80
+
81
+ @ Test
82
+ public void testWrapCallableOnEmptyStack () throws Exception {
83
+ Callable <String > wrappedCallable = el .wrapCallable (() -> {
84
+ String parentTaskId = TimberLogger .getCurrentTaskId ();
85
+ String selfTaskId = TimberLogger .start ("some_nifty_task" );
86
+ TimberLogger .success ();
87
+ return parentTaskId ;
88
+ });
89
+
90
+ String callableVisibleTaskId = wrappedCallable .call ();
91
+
92
+ assertNull (callableVisibleTaskId );
93
+ }
94
+
95
+ @ Test
96
+ public void testWrapFunction () throws Exception {
97
+ String parentTaskId = el .startEvent (QUERY , EMPTY_LOG_PARAMS );
98
+ Function <Integer , String > wrappedFunction = el .<Integer , String >wrapFunction (ignored -> {
99
+ return el .getCurrentTaskId ();
100
+ });
101
+
102
+ String childTaskId = el .startEvent (QUERY , EMPTY_LOG_PARAMS );
103
+
104
+ String callableVisibleTaskId = wrappedFunction .apply (42 );
105
+
106
+ assertEquals (callableVisibleTaskId , parentTaskId );
107
+ }
108
+
63
109
@ Test
64
110
public void testFailedEventLogger () {
65
111
el .startEvent (QUERY , EMPTY_LOG_PARAMS );
0 commit comments