@@ -32,11 +32,11 @@ class PubSubEventListenerTest {
32
32
"""
33
33
# trackEvent, pubType, expAttempt, expSuccess, expFail
34
34
true, success, 1, 1, 0
35
- true, returnFailure , 1, 0, 1
36
- true, throwOnPublish , 1, 0, 1
35
+ true, return_failure , 1, 0, 1
36
+ true, throw_on_publish , 1, 0, 1
37
37
false, success, 0, 0, 0
38
- false, returnFailure , 0, 0, 0
39
- false, throwOnPublish , 0, 0, 0
38
+ false, return_failure , 0, 0, 0
39
+ false, throw_on_publish , 0, 0, 0
40
40
""" )
41
41
void testCounterForQueryCreated (
42
42
boolean trackEvent , String pubType , long expAttempt , long expSuccess , long expFail )
@@ -71,11 +71,11 @@ void testCounterForQueryCreated(
71
71
"""
72
72
# trackEvent, pubType, expAttempt, expSuccess, expFail
73
73
true, success, 1, 1, 0
74
- true, returnFailure , 1, 0, 1
75
- true, throwOnPublish , 1, 0, 1
74
+ true, return_failure , 1, 0, 1
75
+ true, throw_on_publish , 1, 0, 1
76
76
false, success, 0, 0, 0
77
- false, returnFailure , 0, 0, 0
78
- false, throwOnPublish , 0, 0, 0
77
+ false, return_failure , 0, 0, 0
78
+ false, throw_on_publish , 0, 0, 0
79
79
""" )
80
80
void testCounterForQueryCompleted (
81
81
boolean trackEvent , String pubType , long expAttempt , long expSuccess , long expFail )
@@ -110,11 +110,11 @@ void testCounterForQueryCompleted(
110
110
"""
111
111
# trackEvent, pubType, expAttempt, expSuccess, expFail
112
112
true, success, 1, 1, 0
113
- true, returnFailure , 1, 0, 1
114
- true, throwOnPublish , 1, 0, 1
113
+ true, return_failure , 1, 0, 1
114
+ true, throw_on_publish , 1, 0, 1
115
115
false, success, 0, 0, 0
116
- false, returnFailure , 0, 0, 0
117
- false, throwOnPublish , 0, 0, 0
116
+ false, return_failure , 0, 0, 0
117
+ false, throw_on_publish , 0, 0, 0
118
118
""" )
119
119
void testCounterForSplitCompleted (
120
120
boolean trackEvent , String pubType , long expAttempt , long expSuccess , long expFail )
@@ -146,7 +146,15 @@ void testCounterForSplitCompleted(
146
146
@ Test
147
147
void testQueryCreatedPublishCorrespondingMessage () {
148
148
var publisher = new SuccessPublisher ();
149
- var config = new PubSubEventListenerConfig (true , true , true , "" , "" , null , Encoding .JSON );
149
+ var config =
150
+ PubSubEventListenerConfig .builder ()
151
+ .trackQueryCreatedEvent (true )
152
+ .trackQueryCompletedEvent (true )
153
+ .trackSplitCompletedEvent (true )
154
+ .projectId ("" )
155
+ .topicId ("" )
156
+ .encoding (Encoding .JSON )
157
+ .build ();
150
158
var eventListener = new PubSubEventListener (config , publisher );
151
159
152
160
eventListener .queryCreated (TestData .FULL_QUERY_CREATED_EVENT );
@@ -157,7 +165,15 @@ void testQueryCreatedPublishCorrespondingMessage() {
157
165
@ Test
158
166
void testQueryCompletedPublishCorrespondingMessage () {
159
167
var publisher = new SuccessPublisher ();
160
- var config = new PubSubEventListenerConfig (true , true , true , "" , "" , null , Encoding .JSON );
168
+ var config =
169
+ PubSubEventListenerConfig .builder ()
170
+ .trackQueryCreatedEvent (true )
171
+ .trackQueryCompletedEvent (true )
172
+ .trackSplitCompletedEvent (true )
173
+ .projectId ("" )
174
+ .topicId ("" )
175
+ .encoding (Encoding .JSON )
176
+ .build ();
161
177
var eventListener = new PubSubEventListener (config , publisher );
162
178
163
179
eventListener .queryCompleted (TestData .FULL_QUERY_COMPLETED_EVENT );
@@ -168,7 +184,15 @@ void testQueryCompletedPublishCorrespondingMessage() {
168
184
@ Test
169
185
void testSplitCompletedPublishCorrespondingMessage () {
170
186
var publisher = new SuccessPublisher ();
171
- var config = new PubSubEventListenerConfig (true , true , true , "" , "" , null , Encoding .JSON );
187
+ var config =
188
+ PubSubEventListenerConfig .builder ()
189
+ .trackQueryCreatedEvent (true )
190
+ .trackQueryCompletedEvent (true )
191
+ .trackSplitCompletedEvent (true )
192
+ .projectId ("" )
193
+ .topicId ("" )
194
+ .encoding (Encoding .JSON )
195
+ .build ();
172
196
var eventListener = new PubSubEventListener (config , publisher );
173
197
174
198
eventListener .splitCompleted (TestData .FULL_SPLIT_COMPLETED_EVENT );
@@ -177,10 +201,18 @@ void testSplitCompletedPublishCorrespondingMessage() {
177
201
}
178
202
179
203
@ ParameterizedTest
180
- @ ValueSource (strings = {"success" , "throwOnClose " })
204
+ @ ValueSource (strings = {"success" , "throw_on_close " })
181
205
void testClosedNormally (String pubType ) {
182
206
var publisher = TestPublisher .from (pubType );
183
- var config = new PubSubEventListenerConfig (true , true , true , "" , "" , null , Encoding .JSON );
207
+ var config =
208
+ PubSubEventListenerConfig .builder ()
209
+ .trackQueryCreatedEvent (true )
210
+ .trackQueryCompletedEvent (true )
211
+ .trackSplitCompletedEvent (true )
212
+ .projectId ("" )
213
+ .topicId ("" )
214
+ .encoding (Encoding .JSON )
215
+ .build ();
184
216
var eventListener = new PubSubEventListener (config , publisher );
185
217
186
218
assertDoesNotThrow (() -> eventListener .close ());
@@ -197,6 +229,13 @@ public static <T> void assertThatEventually(Supplier<T> actual, Matcher<? super
197
229
}
198
230
199
231
abstract static class TestPublisher implements Publisher {
232
+ enum PubType {
233
+ SUCCESS ,
234
+ RETURN_FAILURE ,
235
+ THROW_ON_PUBLISH ,
236
+ THROW_ON_CLOSE
237
+ }
238
+
200
239
Message lastPublishedMessage ;
201
240
boolean closeCalled ;
202
241
@@ -213,12 +252,11 @@ public void close() throws Exception {
213
252
}
214
253
215
254
static TestPublisher from (String pubType ) {
216
- return switch (pubType ) {
217
- case "success" -> new SuccessPublisher ();
218
- case "returnFailure" -> new ReturnFailurePublisher ();
219
- case "throwOnPublish" -> new ThrowOnPublishPublisher ();
220
- case "throwOnClose" -> new ThrowOnClosePublisher ();
221
- default -> throw new IllegalArgumentException ("invalid pudType: " + pubType );
255
+ return switch (PubType .valueOf (pubType .toUpperCase ())) {
256
+ case SUCCESS -> new SuccessPublisher ();
257
+ case RETURN_FAILURE -> new ReturnFailurePublisher ();
258
+ case THROW_ON_PUBLISH -> new ThrowOnPublishPublisher ();
259
+ case THROW_ON_CLOSE -> new ThrowOnClosePublisher ();
222
260
};
223
261
}
224
262
0 commit comments