@@ -37,7 +37,9 @@ func TestCheckpointFromBlobStorageAzureWebjob(t *testing.T) {
37
37
assert .Equal (t , err , nil )
38
38
39
39
expectedCheckpoint := Checkpoint {
40
- Offset : offset ,
40
+ baseCheckpoint : baseCheckpoint {
41
+ Offset : offset ,
42
+ },
41
43
PartitionID : partitionID ,
42
44
SequenceNumber : sequencenumber ,
43
45
}
@@ -55,7 +57,89 @@ func TestCheckpointFromBlobStorageAzureWebjob(t *testing.T) {
55
57
assert .Equal (t , check , expectedCheckpoint )
56
58
}
57
59
58
- func TestCheckpointFromBlobStorageWithDefault (t * testing.T ) {
60
+ func TestCheckpointFromBlobStorageDefault (t * testing.T ) {
61
+ if StorageConnectionString == "" {
62
+ return
63
+ }
64
+
65
+ partitionID := "0"
66
+ offset := "1005"
67
+ consumerGroup := "$Default"
68
+
69
+ sequencenumber := int64 (1 )
70
+
71
+ containerName := "defaultcontainer"
72
+ checkpointFormat := "{\" Offset\" :\" %s\" ,\" SequenceNumber\" :%d,\" PartitionId\" :\" %s\" ,\" Owner\" :\" \" ,\" Token\" :\" \" ,\" Epoch\" :0}"
73
+ checkpoint := fmt .Sprintf (checkpointFormat , offset , sequencenumber , partitionID )
74
+ urlPath := fmt .Sprintf ("%s/" , consumerGroup )
75
+
76
+ ctx , err := createNewCheckpointInStorage (urlPath , containerName , partitionID , checkpoint , nil )
77
+ assert .Equal (t , err , nil )
78
+
79
+ expectedCheckpoint := Checkpoint {
80
+ baseCheckpoint : baseCheckpoint {
81
+ Offset : offset ,
82
+ },
83
+ PartitionID : partitionID ,
84
+ SequenceNumber : sequencenumber ,
85
+ }
86
+
87
+ eventHubInfo := EventHubInfo {
88
+ EventHubConnection : "Endpoint=sb://eventhubnamespace.servicebus.windows.net/;EntityPath=hub" ,
89
+ StorageConnection : StorageConnectionString ,
90
+ EventHubConsumerGroup : consumerGroup ,
91
+ EventHubName : "hub" ,
92
+ BlobContainer : containerName ,
93
+ }
94
+
95
+ check , _ := GetCheckpointFromBlobStorage (ctx , http .DefaultClient , eventHubInfo , "0" )
96
+ _ = check .Offset
97
+ _ = expectedCheckpoint .Offset
98
+ assert .Equal (t , check , expectedCheckpoint )
99
+ }
100
+
101
+ func TestCheckpointFromBlobStorageDefaultDeprecatedPythonCheckpoint (t * testing.T ) {
102
+ if StorageConnectionString == "" {
103
+ return
104
+ }
105
+
106
+ partitionID := "0"
107
+ offset := "1006"
108
+ consumerGroup := "$Default"
109
+
110
+ sequencenumber := int64 (1 )
111
+
112
+ containerName := "defaultcontainerpython"
113
+ checkpointFormat := "{\" Offset\" :\" %s\" ,\" sequence_number\" :%d,\" partition_id\" :\" %s\" ,\" Owner\" :\" \" ,\" Token\" :\" \" ,\" Epoch\" :0}"
114
+ checkpoint := fmt .Sprintf (checkpointFormat , offset , sequencenumber , partitionID )
115
+ urlPath := fmt .Sprintf ("%s/" , consumerGroup )
116
+
117
+ ctx , err := createNewCheckpointInStorage (urlPath , containerName , partitionID , checkpoint , nil )
118
+ assert .Equal (t , err , nil )
119
+
120
+ expectedCheckpoint := Checkpoint {
121
+ baseCheckpoint : baseCheckpoint {
122
+ Offset : offset ,
123
+ },
124
+ PartitionID : partitionID ,
125
+ SequenceNumber : sequencenumber ,
126
+ }
127
+
128
+ eventHubInfo := EventHubInfo {
129
+ EventHubConnection : "Endpoint=sb://eventhubnamespace.servicebus.windows.net/;EntityPath=hub" ,
130
+ StorageConnection : StorageConnectionString ,
131
+ EventHubConsumerGroup : consumerGroup ,
132
+ EventHubName : "hub" ,
133
+ BlobContainer : containerName ,
134
+ }
135
+
136
+ check , _ := GetCheckpointFromBlobStorage (ctx , http .DefaultClient , eventHubInfo , "0" )
137
+ _ = check .Offset
138
+ _ = expectedCheckpoint .Offset
139
+ assert .Equal (t , check , expectedCheckpoint )
140
+ }
141
+
142
+ func TestCheckpointFromBlobStorageWithBlobMetadata (t * testing.T ) {
59
143
if StorageConnectionString == "" {
60
144
return
61
145
}
@@ -71,14 +155,16 @@ func TestCheckpointFromBlobStorageWithDefault(t *testing.T) {
71
155
"sequencenumber" : strconv .FormatInt (sequencenumber , 10 ),
72
156
}
73
157
74
- containerName := "defaultcontainer "
158
+ containerName := "blobmetadatacontainer "
75
159
urlPath := fmt .Sprintf ("eventhubnamespace.servicebus.windows.net/hub/%s/checkpoint/" , consumerGroup )
76
160
77
161
ctx , err := createNewCheckpointInStorage (urlPath , containerName , partitionID , "" , metadata )
78
162
assert .Equal (t , err , nil )
79
163
80
164
expectedCheckpoint := Checkpoint {
81
- Offset : offset ,
165
+ baseCheckpoint : baseCheckpoint {
166
+ Offset : offset ,
167
+ },
82
168
PartitionID : partitionID ,
83
169
SequenceNumber : sequencenumber ,
84
170
}
@@ -89,6 +175,7 @@ func TestCheckpointFromBlobStorageWithDefault(t *testing.T) {
89
175
EventHubConsumerGroup : consumerGroup ,
90
176
EventHubName : "hub" ,
91
177
BlobContainer : containerName ,
178
+ CheckpointType : "BlobMetadata" ,
92
179
}
93
180
94
181
check , _ := GetCheckpointFromBlobStorage (ctx , http .DefaultClient , eventHubInfo , "0" )
@@ -118,7 +205,9 @@ func TestCheckpointFromBlobStorageGoSdk(t *testing.T) {
118
205
assert .Equal (t , err , nil )
119
206
120
207
expectedCheckpoint := Checkpoint {
121
- Offset : offset ,
208
+ baseCheckpoint : baseCheckpoint {
209
+ Offset : offset ,
210
+ },
122
211
PartitionID : partitionID ,
123
212
SequenceNumber : sequencenumber ,
124
213
}
@@ -162,11 +251,24 @@ func TestShouldParseCheckpointForWebJobWithCheckpointType(t *testing.T) {
162
251
assert .Equal (t , url .Path , "/azure-webjobs-eventhub/eventhubnamespace.servicebus.windows.net/hub-test/$Default/0" )
163
252
}
164
253
165
- func TestShouldParseCheckpointForDefaultWithCheckpointType (t * testing.T ) {
254
+ func TestShouldParseCheckpointForDefault (t * testing.T ) {
255
+ eventHubInfo := EventHubInfo {
256
+ EventHubConnection : "Endpoint=sb://eventhubnamespace.servicebus.windows.net/;EntityPath=hub-test" ,
257
+ EventHubConsumerGroup : "$Default" ,
258
+ BlobContainer : "DefaultContainer" ,
259
+ }
260
+
261
+ cp := newCheckpointer (eventHubInfo , "0" )
262
+ url , _ := cp .resolvePath (eventHubInfo )
263
+
264
+ assert .Equal (t , url .Path , "/DefaultContainer/$Default/0" )
265
+ }
266
+
267
+ func TestShouldParseCheckpointForBlobMetadataWithCheckpointType (t * testing.T ) {
166
268
eventHubInfo := EventHubInfo {
167
269
EventHubConnection : "Endpoint=sb://eventhubnamespace.servicebus.windows.net/;EntityPath=hub-test" ,
168
270
EventHubConsumerGroup : "$Default" ,
169
- CheckpointType : "Default " ,
271
+ CheckpointType : "BlobMetadata " ,
170
272
BlobContainer : "containername" ,
171
273
}
172
274
@@ -176,11 +278,12 @@ func TestShouldParseCheckpointForDefaultWithCheckpointType(t *testing.T) {
176
278
assert .Equal (t , url .Path , "/containername/eventhubnamespace.servicebus.windows.net/hub-test/$Default/checkpoint/0" )
177
279
}
178
280
179
- func TestShouldParseCheckpointForDefault (t * testing.T ) {
281
+ func TestShouldParseCheckpointForBlobMetadata (t * testing.T ) {
180
282
eventHubInfo := EventHubInfo {
181
283
EventHubConnection : "Endpoint=sb://eventhubnamespace.servicebus.windows.net/;EntityPath=hub-test" ,
182
284
EventHubConsumerGroup : "$Default" ,
183
285
BlobContainer : "containername" ,
286
+ CheckpointType : "BlobMetadata" ,
184
287
}
185
288
186
289
cp := newCheckpointer (eventHubInfo , "0" )
0 commit comments