@@ -11,13 +11,19 @@ import {
11
11
EventData ,
12
12
EventHubProducerClient ,
13
13
EventHubConsumerClient ,
14
- ReceivedEventData
14
+ ReceivedEventData ,
15
+ EventPosition
15
16
} from "../src" ;
16
17
import { EventHubClient } from "../src/impl/eventHubClient" ;
17
18
import { SendOptions , SendBatchOptions } from "../src/models/public" ;
18
- import { EnvVarKeys , getEnvVars } from "./utils/testUtils" ;
19
+ import {
20
+ EnvVarKeys ,
21
+ getEnvVars ,
22
+ getStartingPositionsForTests ,
23
+ setTracerForTest
24
+ } from "./utils/testUtils" ;
19
25
import { AbortController } from "@azure/abort-controller" ;
20
- import { TestTracer , setTracer , SpanGraph } from "@azure/core-tracing" ;
26
+ import { SpanGraph } from "@azure/core-tracing" ;
21
27
import { TRACEPARENT_PROPERTY } from "../src/diagnostics/instrumentEventData" ;
22
28
import { EventHubProducer } from "../src/sender" ;
23
29
import { SubscriptionHandlerForTests } from "./utils/subscriptionHandlerForTests" ;
@@ -118,8 +124,7 @@ describe("EventHub Sender", function(): void {
118
124
} ) ;
119
125
120
126
it ( "can be manually traced" , async function ( ) : Promise < void > {
121
- const tracer = new TestTracer ( ) ;
122
- setTracer ( tracer ) ;
127
+ const { tracer, resetTracer } = setTracerForTest ( ) ;
123
128
124
129
const rootSpan = tracer . startSpan ( "root" ) ;
125
130
@@ -164,6 +169,7 @@ describe("EventHub Sender", function(): void {
164
169
tracer . getActiveSpans ( ) . length . should . equal ( 0 , "All spans should have had end called." ) ;
165
170
166
171
await producer . close ( ) ;
172
+ resetTracer ( ) ;
167
173
} ) ;
168
174
} ) ;
169
175
@@ -338,9 +344,9 @@ describe("EventHub Sender", function(): void {
338
344
it ( "should be sent successfully with properties" , async function ( ) : Promise < void > {
339
345
const properties = { test : "super" } ;
340
346
const list = [
341
- { body : "Albert" , properties } ,
342
- { body : "Mike" , properties } ,
343
- { body : "Marie" , properties }
347
+ { body : "Albert-With-Properties " , properties } ,
348
+ { body : "Mike-With-Properties " , properties } ,
349
+ { body : "Marie-With-Properties " , properties }
344
350
] ;
345
351
346
352
const batch = await producerClient . createBatch ( {
@@ -356,6 +362,10 @@ describe("EventHub Sender", function(): void {
356
362
const receivedEvents : ReceivedEventData [ ] = [ ] ;
357
363
let waitUntilEventsReceivedResolver : Function ;
358
364
const waitUntilEventsReceived = new Promise ( ( r ) => ( waitUntilEventsReceivedResolver = r ) ) ;
365
+
366
+ const sequenceNumber = ( await consumerClient . getPartitionProperties ( "0" ) )
367
+ . lastEnqueuedSequenceNumber ;
368
+
359
369
const subscriber = consumerClient . subscribe (
360
370
"0" ,
361
371
{
@@ -369,8 +379,7 @@ describe("EventHub Sender", function(): void {
369
379
} ,
370
380
{
371
381
startPosition : {
372
- sequenceNumber : ( await consumerClient . getPartitionProperties ( "0" ) )
373
- . lastEnqueuedSequenceNumber
382
+ sequenceNumber
374
383
} ,
375
384
maxBatchSize : 3
376
385
}
@@ -380,6 +389,10 @@ describe("EventHub Sender", function(): void {
380
389
await waitUntilEventsReceived ;
381
390
await subscriber . close ( ) ;
382
391
392
+ sequenceNumber . should . be . lessThan ( receivedEvents [ 0 ] . sequenceNumber ) ;
393
+ sequenceNumber . should . be . lessThan ( receivedEvents [ 1 ] . sequenceNumber ) ;
394
+ sequenceNumber . should . be . lessThan ( receivedEvents [ 2 ] . sequenceNumber ) ;
395
+
383
396
[ list [ 0 ] , list [ 1 ] , list [ 2 ] ] . should . be . deep . eq (
384
397
receivedEvents . map ( ( event ) => {
385
398
return {
@@ -392,8 +405,7 @@ describe("EventHub Sender", function(): void {
392
405
} ) ;
393
406
394
407
it ( "can be manually traced" , async function ( ) : Promise < void > {
395
- const tracer = new TestTracer ( ) ;
396
- setTracer ( tracer ) ;
408
+ const { tracer, resetTracer } = setTracerForTest ( ) ;
397
409
398
410
const rootSpan = tracer . startSpan ( "root" ) ;
399
411
@@ -433,11 +445,11 @@ describe("EventHub Sender", function(): void {
433
445
434
446
tracer . getSpanGraph ( rootSpan . context ( ) . traceId ) . should . eql ( expectedGraph ) ;
435
447
tracer . getActiveSpans ( ) . length . should . equal ( 0 , "All spans should have had end called." ) ;
448
+ resetTracer ( ) ;
436
449
} ) ;
437
450
438
451
it ( "will not instrument already instrumented events" , async function ( ) : Promise < void > {
439
- const tracer = new TestTracer ( ) ;
440
- setTracer ( tracer ) ;
452
+ const { tracer, resetTracer } = setTracerForTest ( ) ;
441
453
442
454
const rootSpan = tracer . startSpan ( "test" ) ;
443
455
@@ -484,11 +496,11 @@ describe("EventHub Sender", function(): void {
484
496
485
497
tracer . getSpanGraph ( rootSpan . context ( ) . traceId ) . should . eql ( expectedGraph ) ;
486
498
tracer . getActiveSpans ( ) . length . should . equal ( 0 , "All spans should have had end called." ) ;
499
+ resetTracer ( ) ;
487
500
} ) ;
488
501
489
502
it ( "will support tracing batch and send" , async function ( ) : Promise < void > {
490
- const tracer = new TestTracer ( ) ;
491
- setTracer ( tracer ) ;
503
+ const { tracer, resetTracer } = setTracerForTest ( ) ;
492
504
493
505
const rootSpan = tracer . startSpan ( "root" ) ;
494
506
@@ -537,6 +549,7 @@ describe("EventHub Sender", function(): void {
537
549
538
550
tracer . getSpanGraph ( rootSpan . context ( ) . traceId ) . should . eql ( expectedGraph ) ;
539
551
tracer . getActiveSpans ( ) . length . should . equal ( 0 , "All spans should have had end called." ) ;
552
+ resetTracer ( ) ;
540
553
} ) ;
541
554
542
555
it ( "with partition key should be sent successfully." , async function ( ) : Promise < void > {
@@ -777,8 +790,7 @@ describe("EventHub Sender", function(): void {
777
790
} ) ;
778
791
779
792
it ( "can be manually traced" , async function ( ) : Promise < void > {
780
- const tracer = new TestTracer ( ) ;
781
- setTracer ( tracer ) ;
793
+ const { tracer, resetTracer } = setTracerForTest ( ) ;
782
794
783
795
const rootSpan = tracer . startSpan ( "root" ) ;
784
796
@@ -839,11 +851,11 @@ describe("EventHub Sender", function(): void {
839
851
tracer . getActiveSpans ( ) . length . should . equal ( 0 , "All spans should have had end called." ) ;
840
852
841
853
await producer . close ( ) ;
854
+ resetTracer ( ) ;
842
855
} ) ;
843
856
844
857
it ( "skips already instrumented events when manually traced" , async function ( ) : Promise < void > {
845
- const tracer = new TestTracer ( ) ;
846
- setTracer ( tracer ) ;
858
+ const { tracer, resetTracer } = setTracerForTest ( ) ;
847
859
848
860
const rootSpan = tracer . startSpan ( "root" ) ;
849
861
@@ -901,17 +913,22 @@ describe("EventHub Sender", function(): void {
901
913
tracer . getActiveSpans ( ) . length . should . equal ( 0 , "All spans should have had end called." ) ;
902
914
903
915
await producer . close ( ) ;
916
+ resetTracer ( ) ;
904
917
} ) ;
905
918
} ) ;
906
919
907
920
describe ( "Array of events" , function ( ) {
908
921
let consumerClient : EventHubConsumerClient ;
909
- beforeEach ( ( ) => {
922
+ let startPosition : { [ partitionId : string ] : EventPosition } ;
923
+
924
+ beforeEach ( async ( ) => {
910
925
consumerClient = new EventHubConsumerClient (
911
926
EventHubConsumerClient . defaultConsumerGroupName ,
912
927
service . connectionString ,
913
928
service . path
914
929
) ;
930
+
931
+ startPosition = await getStartingPositionsForTests ( consumerClient ) ;
915
932
} ) ;
916
933
917
934
afterEach ( ( ) => {
@@ -922,6 +939,7 @@ describe("EventHub Sender", function(): void {
922
939
const data : EventData [ ] = [ { body : "Hello World 1" } , { body : "Hello World 2" } ] ;
923
940
const receivedEvents : ReceivedEventData [ ] = [ ] ;
924
941
let receivingResolver : Function ;
942
+
925
943
const receivingPromise = new Promise ( ( r ) => ( receivingResolver = r ) ) ;
926
944
const subscription = consumerClient . subscribe (
927
945
{
@@ -932,7 +950,7 @@ describe("EventHub Sender", function(): void {
932
950
}
933
951
} ,
934
952
{
935
- startPosition : { enqueuedOn : new Date ( ) , isInclusive : true } ,
953
+ startPosition,
936
954
maxBatchSize : data . length
937
955
}
938
956
) ;
@@ -960,7 +978,7 @@ describe("EventHub Sender", function(): void {
960
978
}
961
979
} ,
962
980
{
963
- startPosition : { enqueuedOn : new Date ( ) , isInclusive : true } ,
981
+ startPosition,
964
982
maxBatchSize : data . length
965
983
}
966
984
) ;
@@ -993,7 +1011,7 @@ describe("EventHub Sender", function(): void {
993
1011
}
994
1012
} ,
995
1013
{
996
- startPosition : { enqueuedOn : new Date ( ) , isInclusive : true } ,
1014
+ startPosition,
997
1015
maxBatchSize : data . length
998
1016
}
999
1017
) ;
@@ -1011,8 +1029,7 @@ describe("EventHub Sender", function(): void {
1011
1029
} ) ;
1012
1030
1013
1031
it ( "can be manually traced" , async function ( ) : Promise < void > {
1014
- const tracer = new TestTracer ( ) ;
1015
- setTracer ( tracer ) ;
1032
+ const { tracer, resetTracer } = setTracerForTest ( ) ;
1016
1033
1017
1034
const rootSpan = tracer . startSpan ( "root" ) ;
1018
1035
@@ -1069,11 +1086,11 @@ describe("EventHub Sender", function(): void {
1069
1086
1070
1087
tracer . getSpanGraph ( rootSpan . context ( ) . traceId ) . should . eql ( expectedGraph ) ;
1071
1088
tracer . getActiveSpans ( ) . length . should . equal ( 0 , "All spans should have had end called." ) ;
1089
+ resetTracer ( ) ;
1072
1090
} ) ;
1073
1091
1074
1092
it ( "skips already instrumented events when manually traced" , async function ( ) : Promise < void > {
1075
- const tracer = new TestTracer ( ) ;
1076
- setTracer ( tracer ) ;
1093
+ const { tracer, resetTracer } = setTracerForTest ( ) ;
1077
1094
1078
1095
const rootSpan = tracer . startSpan ( "root" ) ;
1079
1096
@@ -1127,6 +1144,7 @@ describe("EventHub Sender", function(): void {
1127
1144
1128
1145
tracer . getSpanGraph ( rootSpan . context ( ) . traceId ) . should . eql ( expectedGraph ) ;
1129
1146
tracer . getActiveSpans ( ) . length . should . equal ( 0 , "All spans should have had end called." ) ;
1147
+ resetTracer ( ) ;
1130
1148
} ) ;
1131
1149
} ) ;
1132
1150
0 commit comments