@@ -7,21 +7,17 @@ import {
77 DataSourceState ,
88 DataSystemInitializer ,
99 DataSystemSynchronizer ,
10- InitializerFactory ,
11- SynchronizerFactory ,
10+ LDInitializerFactory ,
11+ LDSynchronizerFactory ,
1212} from '../../../src/api/subsystem/DataSystem/DataSource' ;
1313import { Backoff } from '../../../src/datasource/Backoff' ;
1414
15- function makeInitializerFactory ( internal : DataSystemInitializer ) : InitializerFactory {
16- return {
17- create : ( ) => internal ,
18- } ;
15+ function makeInitializerFactory ( internal : DataSystemInitializer ) : LDInitializerFactory {
16+ return ( ) => internal ;
1917}
2018
21- function makeSynchronizerFactory ( internal : DataSystemSynchronizer ) : SynchronizerFactory {
22- return {
23- create : ( ) => internal ,
24- } ;
19+ function makeSynchronizerFactory ( internal : DataSystemSynchronizer ) : LDSynchronizerFactory {
20+ return ( ) => internal ;
2521}
2622
2723function makeTestTransitionConditions ( ) : TransitionConditions {
@@ -58,7 +54,7 @@ function makeZeroBackoff(): Backoff {
5854
5955it ( 'handles initializer getting basis, switching to syncrhonizer' , async ( ) => {
6056 const mockInitializer1 = {
61- run : jest
57+ start : jest
6258 . fn ( )
6359 . mockImplementation (
6460 (
@@ -73,7 +69,7 @@ it('handles initializer getting basis, switching to syncrhonizer', async () => {
7369
7470 const mockSynchronizer1Data = { key : 'sync1' } ;
7571 const mockSynchronizer1 = {
76- run : jest
72+ start : jest
7773 . fn ( )
7874 . mockImplementation (
7975 (
@@ -101,19 +97,19 @@ it('handles initializer getting basis, switching to syncrhonizer', async () => {
10197 }
10298 } ) ;
10399
104- underTest . run ( callback , jest . fn ( ) ) ;
100+ underTest . start ( callback , jest . fn ( ) ) ;
105101 } ) ;
106102
107- expect ( mockInitializer1 . run ) . toHaveBeenCalledTimes ( 1 ) ;
108- expect ( mockSynchronizer1 . run ) . toHaveBeenCalledTimes ( 1 ) ;
103+ expect ( mockInitializer1 . start ) . toHaveBeenCalledTimes ( 1 ) ;
104+ expect ( mockSynchronizer1 . start ) . toHaveBeenCalledTimes ( 1 ) ;
109105 expect ( callback ) . toHaveBeenCalledTimes ( 2 ) ;
110106 expect ( callback ) . toHaveBeenNthCalledWith ( 1 , true , { key : 'init1' } ) ;
111107 expect ( callback ) . toHaveBeenNthCalledWith ( 2 , false , { key : 'sync1' } ) ;
112108} ) ;
113109
114110it ( 'handles initializer getting basis, switches to synchronizer 1, falls back to synchronizer 2, recovers to synchronizer 1' , async ( ) => {
115111 const mockInitializer1 : DataSystemInitializer = {
116- run : jest
112+ start : jest
117113 . fn ( )
118114 . mockImplementation (
119115 (
@@ -129,7 +125,7 @@ it('handles initializer getting basis, switches to synchronizer 1, falls back to
129125 let sync1RunCount = 0 ;
130126 const mockSynchronizer1Data = { key : 'sync1' } ;
131127 const mockSynchronizer1 = {
132- run : jest
128+ start : jest
133129 . fn ( )
134130 . mockImplementation (
135131 (
@@ -142,7 +138,7 @@ it('handles initializer getting basis, switches to synchronizer 1, falls back to
142138 message : 'I am error...man!' ,
143139 } ) ; // error that will lead to fallback
144140 } else {
145- _dataCallback ( false , mockSynchronizer1Data ) ; // second run will lead to data
141+ _dataCallback ( false , mockSynchronizer1Data ) ; // second start will lead to data
146142 }
147143 sync1RunCount += 1 ;
148144 } ,
@@ -152,7 +148,7 @@ it('handles initializer getting basis, switches to synchronizer 1, falls back to
152148
153149 const mockSynchronizer2Data = { key : 'sync2' } ;
154150 const mockSynchronizer2 = {
155- run : jest
151+ start : jest
156152 . fn ( )
157153 . mockImplementation (
158154 (
@@ -181,12 +177,12 @@ it('handles initializer getting basis, switches to synchronizer 1, falls back to
181177 }
182178 } ) ;
183179
184- underTest . run ( callback , jest . fn ( ) ) ;
180+ underTest . start ( callback , jest . fn ( ) ) ;
185181 } ) ;
186182
187- expect ( mockInitializer1 . run ) . toHaveBeenCalledTimes ( 1 ) ;
188- expect ( mockSynchronizer1 . run ) . toHaveBeenCalledTimes ( 2 ) ;
189- expect ( mockSynchronizer2 . run ) . toHaveBeenCalledTimes ( 1 ) ;
183+ expect ( mockInitializer1 . start ) . toHaveBeenCalledTimes ( 1 ) ;
184+ expect ( mockSynchronizer1 . start ) . toHaveBeenCalledTimes ( 2 ) ;
185+ expect ( mockSynchronizer2 . start ) . toHaveBeenCalledTimes ( 1 ) ;
190186 expect ( callback ) . toHaveBeenCalledTimes ( 3 ) ;
191187 expect ( callback ) . toHaveBeenNthCalledWith ( 1 , true , { key : 'init1' } ) ;
192188 expect ( callback ) . toHaveBeenNthCalledWith ( 2 , false , { key : 'sync2' } ) ; // sync1 errors and fallsback
@@ -199,7 +195,7 @@ it('reports error when all initializers fail', async () => {
199195 message : 'I am initializer1 error!' ,
200196 } ;
201197 const mockInitializer1 : DataSystemInitializer = {
202- run : jest
198+ start : jest
203199 . fn ( )
204200 . mockImplementation (
205201 (
@@ -217,7 +213,7 @@ it('reports error when all initializers fail', async () => {
217213 message : 'I am initializer2 error!' ,
218214 } ;
219215 const mockInitializer2 : DataSystemInitializer = {
220- run : jest
216+ start : jest
221217 . fn ( )
222218 . mockImplementation (
223219 (
@@ -246,11 +242,11 @@ it('reports error when all initializers fail', async () => {
246242 }
247243 } ) ;
248244
249- underTest . run ( dataCallback , statusCallback ) ;
245+ underTest . start ( dataCallback , statusCallback ) ;
250246 } ) ;
251247
252- expect ( mockInitializer1 . run ) . toHaveBeenCalledTimes ( 1 ) ;
253- expect ( mockInitializer2 . run ) . toHaveBeenCalledTimes ( 1 ) ;
248+ expect ( mockInitializer1 . start ) . toHaveBeenCalledTimes ( 1 ) ;
249+ expect ( mockInitializer2 . start ) . toHaveBeenCalledTimes ( 1 ) ;
254250 expect ( dataCallback ) . toHaveBeenCalledTimes ( 0 ) ;
255251 expect ( statusCallback ) . toHaveBeenNthCalledWith (
256252 1 ,
@@ -272,7 +268,7 @@ it('reports error when all initializers fail', async () => {
272268
273269it ( 'can be stopped when in thrashing synchronizer fallback loop' , async ( ) => {
274270 const mockInitializer1 = {
275- run : jest
271+ start : jest
276272 . fn ( )
277273 . mockImplementation (
278274 (
@@ -287,7 +283,7 @@ it('can be stopped when in thrashing synchronizer fallback loop', async () => {
287283
288284 const mockSynchronizer1Error = { name : 'Error' , message : 'I am error...man!' } ;
289285 const mockSynchronizer1 = {
290- run : jest
286+ start : jest
291287 . fn ( )
292288 . mockImplementation (
293289 (
@@ -316,11 +312,11 @@ it('can be stopped when in thrashing synchronizer fallback loop', async () => {
316312 }
317313 } ) ;
318314
319- underTest . run ( dataCallback , statusCallback ) ;
315+ underTest . start ( dataCallback , statusCallback ) ;
320316 } ) ;
321317
322- expect ( mockInitializer1 . run ) . toHaveBeenCalled ( ) ;
323- expect ( mockSynchronizer1 . run ) . toHaveBeenCalled ( ) ;
318+ expect ( mockInitializer1 . start ) . toHaveBeenCalled ( ) ;
319+ expect ( mockSynchronizer1 . start ) . toHaveBeenCalled ( ) ;
324320 expect ( dataCallback ) . toHaveBeenNthCalledWith ( 1 , true , { key : 'init1' } ) ;
325321 underTest . stop ( ) ;
326322
@@ -340,7 +336,7 @@ it('can be stopped when in thrashing synchronizer fallback loop', async () => {
340336it ( 'can be stopped and restarted' , async ( ) => {
341337 const mockInitializer1Data = { key : 'init1' } ;
342338 const mockInitializer1 = {
343- run : jest
339+ start : jest
344340 . fn ( )
345341 . mockImplementation (
346342 (
@@ -355,7 +351,7 @@ it('can be stopped and restarted', async () => {
355351
356352 const mockSynchronizer1Data = { key : 'sync1' } ;
357353 const mockSynchronizer1 = {
358- run : jest
354+ start : jest
359355 . fn ( )
360356 . mockImplementation (
361357 (
@@ -383,13 +379,13 @@ it('can be stopped and restarted', async () => {
383379 resolve ( ) ;
384380 }
385381 } ) ;
386- // first run
387- underTest . run ( callback1 , jest . fn ( ) ) ;
382+ // first start
383+ underTest . start ( callback1 , jest . fn ( ) ) ;
388384 } ) ;
389385
390- // check first run triggered underlying data sources
391- expect ( mockInitializer1 . run ) . toHaveBeenCalledTimes ( 1 ) ;
392- expect ( mockSynchronizer1 . run ) . toHaveBeenCalledTimes ( 1 ) ;
386+ // check first start triggered underlying data sources
387+ expect ( mockInitializer1 . start ) . toHaveBeenCalledTimes ( 1 ) ;
388+ expect ( mockSynchronizer1 . start ) . toHaveBeenCalledTimes ( 1 ) ;
393389 expect ( callback1 ) . toHaveBeenCalledTimes ( 2 ) ;
394390
395391 // wait a moment for pending awaits to resolve the stop request
@@ -404,13 +400,13 @@ it('can be stopped and restarted', async () => {
404400 resolve ( ) ;
405401 }
406402 } ) ;
407- // second run
408- underTest . run ( callback2 , jest . fn ( ) ) ;
403+ // second start
404+ underTest . start ( callback2 , jest . fn ( ) ) ;
409405 } ) ;
410406
411- // check that second run triggers underlying data sources again
412- expect ( mockInitializer1 . run ) . toHaveBeenCalledTimes ( 2 ) ;
413- expect ( mockSynchronizer1 . run ) . toHaveBeenCalledTimes ( 2 ) ;
407+ // check that second start triggers underlying data sources again
408+ expect ( mockInitializer1 . start ) . toHaveBeenCalledTimes ( 2 ) ;
409+ expect ( mockSynchronizer1 . start ) . toHaveBeenCalledTimes ( 2 ) ;
414410 expect ( callback2 ) . toHaveBeenCalledTimes ( 2 ) ;
415411} ) ;
416412
@@ -428,7 +424,7 @@ it('is well behaved with no initializers and no synchronizers configured', async
428424 resolve ( ) ;
429425 } ) ;
430426
431- underTest . run ( jest . fn ( ) , statusCallback ) ;
427+ underTest . start ( jest . fn ( ) , statusCallback ) ;
432428 } ) ;
433429
434430 expect ( statusCallback ) . toHaveBeenNthCalledWith ( 1 , DataSourceState . Closed , {
@@ -440,7 +436,7 @@ it('is well behaved with no initializers and no synchronizers configured', async
440436
441437it ( 'is well behaved with an initializer and no synchronizers configured' , async ( ) => {
442438 const mockInitializer1 = {
443- run : jest
439+ start : jest
444440 . fn ( )
445441 . mockImplementation (
446442 (
@@ -466,7 +462,7 @@ it('is well behaved with an initializer and no synchronizers configured', async
466462 resolve ( ) ;
467463 } ) ;
468464
469- underTest . run ( jest . fn ( ) , statusCallback ) ;
465+ underTest . start ( jest . fn ( ) , statusCallback ) ;
470466 } ) ;
471467
472468 expect ( statusCallback ) . toHaveBeenNthCalledWith ( 1 , DataSourceState . Closed , {
0 commit comments