1515 */
1616
1717import { describe , it , expect , beforeEach , vi , MockInstance } from 'vitest' ;
18- import { DEFAULT_EVENT_BATCH_SIZE , DEFAULT_EVENT_FLUSH_INTERVAL , getBatchEventProcessor } from './event_processor_factory' ;
18+ import { getBatchEventProcessor } from './event_processor_factory' ;
1919import { BatchEventProcessor , BatchEventProcessorConfig , EventWithId , DEFAULT_MAX_BACKOFF , DEFAULT_MIN_BACKOFF } from './batch_event_processor' ;
2020import { ExponentialBackoff , IntervalRepeater } from '../utils/repeater/repeater' ;
2121import { getMockSyncCache } from '../tests/mock/mock_cache' ;
@@ -44,6 +44,8 @@ describe('getBatchEventProcessor', () => {
4444 it ( 'returns an instane of BatchEventProcessor if no subclass constructor is provided' , ( ) => {
4545 const options = {
4646 eventDispatcher : getMockEventDispatcher ( ) ,
47+ defaultFlushInterval : 1000 ,
48+ defaultBatchSize : 10 ,
4749 } ;
4850
4951 const processor = getBatchEventProcessor ( options ) ;
@@ -60,6 +62,8 @@ describe('getBatchEventProcessor', () => {
6062
6163 const options = {
6264 eventDispatcher : getMockEventDispatcher ( ) ,
65+ defaultFlushInterval : 1000 ,
66+ defaultBatchSize : 10 ,
6367 } ;
6468
6569 const processor = getBatchEventProcessor ( options , CustomEventProcessor ) ;
@@ -70,6 +74,8 @@ describe('getBatchEventProcessor', () => {
7074 it ( 'does not use retry if retryOptions is not provided' , ( ) => {
7175 const options = {
7276 eventDispatcher : getMockEventDispatcher ( ) ,
77+ defaultFlushInterval : 1000 ,
78+ defaultBatchSize : 10 ,
7379 } ;
7480
7581 const processor = getBatchEventProcessor ( options ) ;
@@ -81,6 +87,8 @@ describe('getBatchEventProcessor', () => {
8187 const options = {
8288 eventDispatcher : getMockEventDispatcher ( ) ,
8389 retryOptions : { } ,
90+ defaultFlushInterval : 1000 ,
91+ defaultBatchSize : 10 ,
8492 } ;
8593
8694 const processor = getBatchEventProcessor ( options ) ;
@@ -94,6 +102,8 @@ describe('getBatchEventProcessor', () => {
94102 it ( 'uses the correct maxRetries value when retryOptions is provided' , ( ) => {
95103 const options1 = {
96104 eventDispatcher : getMockEventDispatcher ( ) ,
105+ defaultFlushInterval : 1000 ,
106+ defaultBatchSize : 10 ,
97107 retryOptions : {
98108 maxRetries : 10 ,
99109 } ,
@@ -105,6 +115,8 @@ describe('getBatchEventProcessor', () => {
105115
106116 const options2 = {
107117 eventDispatcher : getMockEventDispatcher ( ) ,
118+ defaultFlushInterval : 1000 ,
119+ defaultBatchSize : 10 ,
108120 retryOptions : { } ,
109121 } ;
110122
@@ -117,6 +129,8 @@ describe('getBatchEventProcessor', () => {
117129 it ( 'uses exponential backoff with default parameters when retryOptions is provided without backoff values' , ( ) => {
118130 const options = {
119131 eventDispatcher : getMockEventDispatcher ( ) ,
132+ defaultFlushInterval : 1000 ,
133+ defaultBatchSize : 10 ,
120134 retryOptions : { } ,
121135 } ;
122136
@@ -133,6 +147,8 @@ describe('getBatchEventProcessor', () => {
133147 it ( 'uses exponential backoff with provided backoff values in retryOptions' , ( ) => {
134148 const options = {
135149 eventDispatcher : getMockEventDispatcher ( ) ,
150+ defaultFlushInterval : 1000 ,
151+ defaultBatchSize : 10 ,
136152 retryOptions : { minBackoff : 1000 , maxBackoff : 2000 } ,
137153 } ;
138154
@@ -149,48 +165,54 @@ describe('getBatchEventProcessor', () => {
149165 it ( 'uses a IntervalRepeater with default flush interval and adds a startup log if flushInterval is not provided' , ( ) => {
150166 const options = {
151167 eventDispatcher : getMockEventDispatcher ( ) ,
168+ defaultFlushInterval : 12345 ,
169+ defaultBatchSize : 77 ,
152170 } ;
153171
154172 const processor = getBatchEventProcessor ( options ) ;
155173
156174 expect ( Object . is ( processor , MockBatchEventProcessor . mock . instances [ 0 ] ) ) . toBe ( true ) ;
157175 const usedRepeater = MockBatchEventProcessor . mock . calls [ 0 ] [ 0 ] . dispatchRepeater ;
158176 expect ( Object . is ( usedRepeater , MockIntervalRepeater . mock . instances [ 0 ] ) ) . toBe ( true ) ;
159- expect ( MockIntervalRepeater ) . toHaveBeenNthCalledWith ( 1 , DEFAULT_EVENT_FLUSH_INTERVAL ) ;
177+ expect ( MockIntervalRepeater ) . toHaveBeenNthCalledWith ( 1 , 12345 ) ;
160178
161179 const startupLogs = MockBatchEventProcessor . mock . calls [ 0 ] [ 0 ] . startupLogs ;
162180 expect ( startupLogs ) . toEqual ( expect . arrayContaining ( [ {
163181 level : LogLevel . Warn ,
164182 message : 'Invalid flushInterval %s, defaulting to %s' ,
165- params : [ undefined , DEFAULT_EVENT_FLUSH_INTERVAL ] ,
183+ params : [ undefined , 12345 ] ,
166184 } ] ) ) ;
167185 } ) ;
168186
169187 it ( 'uses default flush interval and adds a startup log if flushInterval is less than 1' , ( ) => {
170188 const options = {
171189 eventDispatcher : getMockEventDispatcher ( ) ,
172190 flushInterval : - 1 ,
191+ defaultFlushInterval : 12345 ,
192+ defaultBatchSize : 77 ,
173193 } ;
174194
175195 const processor = getBatchEventProcessor ( options ) ;
176196
177197 expect ( Object . is ( processor , MockBatchEventProcessor . mock . instances [ 0 ] ) ) . toBe ( true ) ;
178198 const usedRepeater = MockBatchEventProcessor . mock . calls [ 0 ] [ 0 ] . dispatchRepeater ;
179199 expect ( Object . is ( usedRepeater , MockIntervalRepeater . mock . instances [ 0 ] ) ) . toBe ( true ) ;
180- expect ( MockIntervalRepeater ) . toHaveBeenNthCalledWith ( 1 , DEFAULT_EVENT_FLUSH_INTERVAL ) ;
200+ expect ( MockIntervalRepeater ) . toHaveBeenNthCalledWith ( 1 , 12345 ) ;
181201
182202 const startupLogs = MockBatchEventProcessor . mock . calls [ 0 ] [ 0 ] . startupLogs ;
183203 expect ( startupLogs ) . toEqual ( expect . arrayContaining ( [ {
184204 level : LogLevel . Warn ,
185205 message : 'Invalid flushInterval %s, defaulting to %s' ,
186- params : [ - 1 , DEFAULT_EVENT_FLUSH_INTERVAL ] ,
206+ params : [ - 1 , 12345 ] ,
187207 } ] ) ) ;
188208 } ) ;
189209
190210 it ( 'uses a IntervalRepeater with provided flushInterval and adds no startup log if provided flushInterval is valid' , ( ) => {
191211 const options = {
192212 eventDispatcher : getMockEventDispatcher ( ) ,
193213 flushInterval : 12345 ,
214+ defaultFlushInterval : 1000 ,
215+ defaultBatchSize : 77 ,
194216 } ;
195217
196218 const processor = getBatchEventProcessor ( options ) ;
@@ -205,46 +227,52 @@ describe('getBatchEventProcessor', () => {
205227 } ) ;
206228
207229
208- it ( 'uses a IntervalRepeater with default flush interval and adds a startup log if flushInterval is not provided' , ( ) => {
230+ it ( 'uses default batch size and adds a startup log if batchSize is not provided' , ( ) => {
209231 const options = {
210232 eventDispatcher : getMockEventDispatcher ( ) ,
233+ defaultBatchSize : 77 ,
234+ defaultFlushInterval : 12345 ,
211235 } ;
212236
213237 const processor = getBatchEventProcessor ( options ) ;
214238
215239 expect ( Object . is ( processor , MockBatchEventProcessor . mock . instances [ 0 ] ) ) . toBe ( true ) ;
216- expect ( MockBatchEventProcessor . mock . calls [ 0 ] [ 0 ] . batchSize ) . toBe ( DEFAULT_EVENT_BATCH_SIZE ) ;
240+ expect ( MockBatchEventProcessor . mock . calls [ 0 ] [ 0 ] . batchSize ) . toBe ( 77 ) ;
217241
218242 const startupLogs = MockBatchEventProcessor . mock . calls [ 0 ] [ 0 ] . startupLogs ;
219243 expect ( startupLogs ) . toEqual ( expect . arrayContaining ( [ {
220244 level : LogLevel . Warn ,
221245 message : 'Invalid batchSize %s, defaulting to %s' ,
222- params : [ undefined , DEFAULT_EVENT_BATCH_SIZE ] ,
246+ params : [ undefined , 77 ] ,
223247 } ] ) ) ;
224248 } ) ;
225249
226250 it ( 'uses default size and adds a startup log if provided batchSize is less than 1' , ( ) => {
227251 const options = {
228252 eventDispatcher : getMockEventDispatcher ( ) ,
229253 batchSize : - 1 ,
254+ defaultBatchSize : 77 ,
255+ defaultFlushInterval : 12345 ,
230256 } ;
231257
232258 const processor = getBatchEventProcessor ( options ) ;
233259
234260 expect ( Object . is ( processor , MockBatchEventProcessor . mock . instances [ 0 ] ) ) . toBe ( true ) ;
235- expect ( MockBatchEventProcessor . mock . calls [ 0 ] [ 0 ] . batchSize ) . toBe ( DEFAULT_EVENT_BATCH_SIZE ) ;
261+ expect ( MockBatchEventProcessor . mock . calls [ 0 ] [ 0 ] . batchSize ) . toBe ( 77 ) ;
236262
237263 const startupLogs = MockBatchEventProcessor . mock . calls [ 0 ] [ 0 ] . startupLogs ;
238264 expect ( startupLogs ) . toEqual ( expect . arrayContaining ( [ {
239265 level : LogLevel . Warn ,
240266 message : 'Invalid batchSize %s, defaulting to %s' ,
241- params : [ - 1 , DEFAULT_EVENT_BATCH_SIZE ] ,
267+ params : [ - 1 , 77 ] ,
242268 } ] ) ) ;
243269 } ) ;
244270
245271 it ( 'does not use a failedEventRepeater if failedEventRetryInterval is not provided' , ( ) => {
246272 const options = {
247273 eventDispatcher : getMockEventDispatcher ( ) ,
274+ defaultBatchSize : 77 ,
275+ defaultFlushInterval : 12345 ,
248276 } ;
249277
250278 const processor = getBatchEventProcessor ( options ) ;
@@ -257,6 +285,8 @@ describe('getBatchEventProcessor', () => {
257285 const options = {
258286 eventDispatcher : getMockEventDispatcher ( ) ,
259287 failedEventRetryInterval : 12345 ,
288+ defaultBatchSize : 77 ,
289+ defaultFlushInterval : 12345 ,
260290 } ;
261291
262292 const processor = getBatchEventProcessor ( options ) ;
@@ -270,6 +300,8 @@ describe('getBatchEventProcessor', () => {
270300 const eventDispatcher = getMockEventDispatcher ( ) ;
271301 const options = {
272302 eventDispatcher,
303+ defaultBatchSize : 77 ,
304+ defaultFlushInterval : 12345 ,
273305 } ;
274306
275307 const processor = getBatchEventProcessor ( options ) ;
@@ -281,6 +313,8 @@ describe('getBatchEventProcessor', () => {
281313 it ( 'does not use any closingEventDispatcher if not provided' , ( ) => {
282314 const options = {
283315 eventDispatcher : getMockEventDispatcher ( ) ,
316+ defaultBatchSize : 77 ,
317+ defaultFlushInterval : 12345 ,
284318 } ;
285319
286320 const processor = getBatchEventProcessor ( options ) ;
@@ -294,6 +328,8 @@ describe('getBatchEventProcessor', () => {
294328 const options = {
295329 eventDispatcher : getMockEventDispatcher ( ) ,
296330 closingEventDispatcher,
331+ defaultBatchSize : 77 ,
332+ defaultFlushInterval : 12345 ,
297333 } ;
298334
299335 const processor = getBatchEventProcessor ( options ) ;
@@ -307,6 +343,8 @@ describe('getBatchEventProcessor', () => {
307343 const options = {
308344 eventDispatcher : getMockEventDispatcher ( ) ,
309345 eventStore,
346+ defaultBatchSize : 77 ,
347+ defaultFlushInterval : 12345 ,
310348 } ;
311349
312350 const processor = getBatchEventProcessor ( options ) ;
0 commit comments