54
54
import org .junit .experimental .categories .Category ;
55
55
import org .junit .runner .RunWith ;
56
56
import org .junit .runners .JUnit4 ;
57
+ import org .threeten .bp .Duration ;
57
58
58
59
@ Category (TracerTest .class )
59
60
@ RunWith (JUnit4 .class )
@@ -103,11 +104,11 @@ public class OpenTelemetrySpanTest {
103
104
Statement .of ("UPDATE NON_EXISTENT_TABLE SET BAR=1 WHERE BAZ=2" );
104
105
105
106
private List <String > expectedBatchCreateSessionsRequestEvents =
106
- ImmutableList .of ("Requesting 25 sessions" , "Request for 25 sessions returned 25 sessions" );
107
+ ImmutableList .of ("Requesting 2 sessions" , "Request for 2 sessions returned 2 sessions" );
107
108
108
109
private int expectedBatchCreateSessionsRequestEventsCount = 2 ;
109
110
110
- private List <String > expectedBatchCreateSessionsEvents = ImmutableList .of ("Creating 25 sessions" );
111
+ private List <String > expectedBatchCreateSessionsEvents = ImmutableList .of ("Creating 2 sessions" );
111
112
112
113
private int expectedBatchCreateSessionsEventsCount = 1 ;
113
114
@@ -117,58 +118,45 @@ public class OpenTelemetrySpanTest {
117
118
private int expectedExecuteStreamingQueryEventsCount = 1 ;
118
119
119
120
private List <String > expectedReadOnlyTransactionSingleUseEvents =
120
- ImmutableList .of (
121
- "Acquiring session" ,
122
- "No session available" ,
123
- "Creating sessions" ,
124
- "Waiting for a session to come available" ,
125
- "Using Session" );
121
+ ImmutableList .of ("Acquiring session" , "Acquired session" , "Using Session" );
126
122
127
- private int expectedReadOnlyTransactionSingleUseEventsCount = 5 ;
123
+ private int expectedReadOnlyTransactionSingleUseEventsCount = 3 ;
128
124
129
125
private List <String > expectedReadOnlyTransactionMultiUseEvents =
130
126
ImmutableList .of (
131
127
"Acquiring session" ,
132
- "No session available" ,
133
- "Creating sessions" ,
134
- "Waiting for a session to come available" ,
128
+ "Acquired session" ,
135
129
"Using Session" ,
136
130
"Creating Transaction" ,
137
131
"Transaction Creation Done" );
138
132
139
- private int expectedReadOnlyTransactionMultiUseEventsCount = 7 ;
133
+ private int expectedReadOnlyTransactionMultiUseEventsCount = 5 ;
140
134
141
135
private List <String > expectedReadWriteTransactionErrorEvents =
142
136
ImmutableList .of (
143
137
"Acquiring session" ,
144
- "No session available" ,
145
- "Creating sessions" ,
146
- "Waiting for a session to come available" ,
138
+ "Acquired session" ,
147
139
"Using Session" ,
148
140
"Starting Transaction Attempt" ,
149
141
"Transaction Attempt Failed in user operation" ,
150
142
"exception" );
151
143
152
- private int expectedReadWriteTransactionErrorEventsCount = 8 ;
144
+ private int expectedReadWriteTransactionErrorEventsCount = 6 ;
153
145
private List <String > expectedReadWriteTransactionEvents =
154
146
ImmutableList .of (
155
147
"Acquiring session" ,
156
- "No session available" ,
157
- "Creating sessions" ,
158
- "Waiting for a session to come available" ,
148
+ "Acquired session" ,
159
149
"Using Session" ,
160
150
"Starting Transaction Attempt" ,
161
151
"Starting Commit" ,
162
152
"Commit Done" ,
163
153
"Transaction Attempt Succeeded" );
164
154
165
- private int expectedReadWriteTransactionCount = 9 ;
155
+ private int expectedReadWriteTransactionCount = 7 ;
166
156
private List <String > expectedReadWriteTransactionErrorWithBeginTransactionEvents =
167
157
ImmutableList .of (
168
158
"Acquiring session" ,
169
- "No session available" ,
170
- "Creating sessions" ,
171
- "Waiting for a session to come available" ,
159
+ "Acquired session" ,
172
160
"Using Session" ,
173
161
"Starting Transaction Attempt" ,
174
162
"Transaction Attempt Aborted in user operation. Retrying" ,
@@ -178,38 +166,34 @@ public class OpenTelemetrySpanTest {
178
166
"Commit Done" ,
179
167
"Transaction Attempt Succeeded" );
180
168
181
- private int expectedReadWriteTransactionErrorWithBeginTransactionEventsCount = 13 ;
169
+ private int expectedReadWriteTransactionErrorWithBeginTransactionEventsCount = 11 ;
182
170
private List <String > expectedReadOnlyTransactionSpans =
183
171
ImmutableList .of (
184
172
"CloudSpannerOperation.BatchCreateSessionsRequest" ,
185
173
"CloudSpannerOperation.ExecuteStreamingQuery" ,
186
174
"CloudSpannerOperation.BatchCreateSessions" ,
187
- "CloudSpanner.ReadOnlyTransaction" ,
188
- "SessionPool.WaitForSession" );
175
+ "CloudSpanner.ReadOnlyTransaction" );
189
176
190
177
private List <String > expectedReadWriteTransactionWithCommitSpans =
191
178
ImmutableList .of (
192
179
"CloudSpannerOperation.BatchCreateSessionsRequest" ,
193
180
"CloudSpannerOperation.Commit" ,
194
181
"CloudSpannerOperation.BatchCreateSessions" ,
195
- "CloudSpanner.ReadWriteTransaction" ,
196
- "SessionPool.WaitForSession" );
182
+ "CloudSpanner.ReadWriteTransaction" );
197
183
198
184
private List <String > expectedReadWriteTransactionSpans =
199
185
ImmutableList .of (
200
186
"CloudSpannerOperation.BatchCreateSessionsRequest" ,
201
187
"CloudSpannerOperation.BatchCreateSessions" ,
202
- "CloudSpanner.ReadWriteTransaction" ,
203
- "SessionPool.WaitForSession" );
188
+ "CloudSpanner.ReadWriteTransaction" );
204
189
205
190
private List <String > expectedReadWriteTransactionWithCommitAndBeginTransactionSpans =
206
191
ImmutableList .of (
207
192
"CloudSpannerOperation.BeginTransaction" ,
208
193
"CloudSpannerOperation.BatchCreateSessionsRequest" ,
209
194
"CloudSpannerOperation.Commit" ,
210
195
"CloudSpannerOperation.BatchCreateSessions" ,
211
- "CloudSpanner.ReadWriteTransaction" ,
212
- "SessionPool.WaitForSession" );
196
+ "CloudSpanner.ReadWriteTransaction" );
213
197
214
198
@ BeforeClass
215
199
public static void setupOpenTelemetry () {
@@ -282,7 +266,11 @@ public void setUp() throws Exception {
282
266
.setChannelProvider (channelProvider )
283
267
.setOpenTelemetry (openTelemetry )
284
268
.setCredentials (NoCredentials .getInstance ())
285
- .setSessionPoolOption (SessionPoolOptions .newBuilder ().setMinSessions (0 ).build ());
269
+ .setSessionPoolOption (
270
+ SessionPoolOptions .newBuilder ()
271
+ .setMinSessions (2 )
272
+ .setWaitForMinSessions (Duration .ofSeconds (5 ))
273
+ .build ());
286
274
287
275
spanner = builder .build ().getService ();
288
276
@@ -339,9 +327,6 @@ public void singleUse() {
339
327
expectedReadOnlyTransactionSingleUseEvents ,
340
328
expectedReadOnlyTransactionSingleUseEventsCount );
341
329
break ;
342
- case "SessionPool.WaitForSession" :
343
- assertEquals (0 , spanItem .getEvents ().size ());
344
- break ;
345
330
default :
346
331
assert false ;
347
332
}
@@ -385,9 +370,6 @@ public void multiUse() {
385
370
expectedExecuteStreamingQueryEvents ,
386
371
expectedExecuteStreamingQueryEventsCount );
387
372
break ;
388
- case "SessionPool.WaitForSession" :
389
- assertEquals (0 , spanItem .getEvents ().size ());
390
- break ;
391
373
case "CloudSpanner.ReadOnlyTransaction" :
392
374
verifyRequestEvents (
393
375
spanItem ,
@@ -406,7 +388,6 @@ public void multiUse() {
406
388
public void transactionRunner () {
407
389
TransactionRunner runner = client .readWriteTransaction ();
408
390
runner .run (transaction -> transaction .executeUpdate (UPDATE_STATEMENT ));
409
-
410
391
List <String > actualSpanItems = new ArrayList <>();
411
392
spanExporter
412
393
.getFinishedSpanItems ()
@@ -426,7 +407,6 @@ public void transactionRunner() {
426
407
expectedBatchCreateSessionsEvents ,
427
408
expectedBatchCreateSessionsEventsCount );
428
409
break ;
429
- case "SessionPool.WaitForSession" :
430
410
case "CloudSpannerOperation.Commit" :
431
411
assertEquals (0 , spanItem .getEvents ().size ());
432
412
break ;
@@ -472,9 +452,6 @@ public void transactionRunnerWithError() {
472
452
expectedBatchCreateSessionsEvents ,
473
453
expectedBatchCreateSessionsEventsCount );
474
454
break ;
475
- case "SessionPool.WaitForSession" :
476
- assertEquals (0 , spanItem .getEvents ().size ());
477
- break ;
478
455
case "CloudSpanner.ReadWriteTransaction" :
479
456
verifyRequestEvents (
480
457
spanItem ,
@@ -527,7 +504,6 @@ public void transactionRunnerWithFailedAndBeginTransaction() {
527
504
expectedBatchCreateSessionsEvents ,
528
505
expectedBatchCreateSessionsEventsCount );
529
506
break ;
530
- case "SessionPool.WaitForSession" :
531
507
case "CloudSpannerOperation.Commit" :
532
508
case "CloudSpannerOperation.BeginTransaction" :
533
509
assertEquals (0 , spanItem .getEvents ().size ());
@@ -551,13 +527,13 @@ private void verifyRequestEvents(SpanData spanItem, List<String> expectedEvents,
551
527
spanItem .getEvents ().stream ().map (EventData ::getName ).collect (Collectors .toList ());
552
528
assertEquals (eventCount , spanItem .getEvents ().size ());
553
529
assertEquals (
554
- eventNames .stream (). distinct ().sorted ().collect (Collectors .toList ()),
555
- expectedEvents .stream ().sorted ().collect (Collectors .toList ()));
530
+ expectedEvents .stream ().sorted ().collect (Collectors .toList ()),
531
+ eventNames .stream (). distinct ().sorted ().collect (Collectors .toList ()));
556
532
}
557
533
558
534
private static void verifySpans (List <String > actualSpanItems , List <String > expectedSpansItems ) {
559
535
assertEquals (
560
- actualSpanItems .stream (). distinct ().sorted ().collect (Collectors .toList ()),
561
- expectedSpansItems .stream ().sorted ().collect (Collectors .toList ()));
536
+ expectedSpansItems .stream ().sorted ().collect (Collectors .toList ()),
537
+ actualSpanItems .stream (). distinct ().sorted ().collect (Collectors .toList ()));
562
538
}
563
539
}
0 commit comments