11import {
22 CompositeDataSource ,
3- Transition ,
43 TransitionConditions ,
54} from '../../../src/api/subsystem/DataSystem/CompositeDataSource' ;
65import {
76 Data ,
87 DataSourceState ,
98 DataSystemInitializer ,
109 DataSystemSynchronizer ,
11- InitializerFactory ,
12- SynchronizerFactory ,
10+ LDInitializerFactory ,
11+ LDSynchronizerFactory ,
1312} from '../../../src/api/subsystem/DataSystem/DataSource' ;
1413import { Backoff } from '../../../src/datasource/Backoff' ;
1514
16- function makeInitializerFactory ( internal : DataSystemInitializer ) : InitializerFactory {
17- return {
18- create : ( ) => internal ,
19- } ;
15+ function makeInitializerFactory ( internal : DataSystemInitializer ) : LDInitializerFactory {
16+ return ( ) => internal ;
2017}
2118
22- function makeSynchronizerFactory ( internal : DataSystemSynchronizer ) : SynchronizerFactory {
23- return {
24- create : ( ) => internal ,
25- } ;
19+ function makeSynchronizerFactory ( internal : DataSystemSynchronizer ) : LDSynchronizerFactory {
20+ return ( ) => internal ;
2621}
2722
2823function makeTestTransitionConditions ( ) : TransitionConditions {
@@ -59,7 +54,7 @@ function makeZeroBackoff(): Backoff {
5954
6055it ( 'initializer gets basis, switch to syncrhonizer' , async ( ) => {
6156 const mockInitializer1 = {
62- run : jest
57+ start : jest
6358 . fn ( )
6459 . mockImplementation (
6560 (
@@ -74,7 +69,7 @@ it('initializer gets basis, switch to syncrhonizer', async () => {
7469
7570 const mockSynchronizer1Data = { key : 'sync1' } ;
7671 const mockSynchronizer1 = {
77- run : jest
72+ start : jest
7873 . fn ( )
7974 . mockImplementation (
8075 (
@@ -102,19 +97,19 @@ it('initializer gets basis, switch to syncrhonizer', async () => {
10297 }
10398 } ) ;
10499
105- underTest . run ( callback , jest . fn ( ) ) ;
100+ underTest . start ( callback , jest . fn ( ) ) ;
106101 } ) ;
107102
108- expect ( mockInitializer1 . run ) . toHaveBeenCalledTimes ( 1 ) ;
109- expect ( mockSynchronizer1 . run ) . toHaveBeenCalledTimes ( 1 ) ;
103+ expect ( mockInitializer1 . start ) . toHaveBeenCalledTimes ( 1 ) ;
104+ expect ( mockSynchronizer1 . start ) . toHaveBeenCalledTimes ( 1 ) ;
110105 expect ( callback ) . toHaveBeenCalledTimes ( 2 ) ;
111106 expect ( callback ) . toHaveBeenNthCalledWith ( 1 , true , { key : 'init1' } ) ;
112107 expect ( callback ) . toHaveBeenNthCalledWith ( 2 , false , { key : 'sync1' } ) ;
113108} ) ;
114109
115110it ( 'initializer gets basis, switch to synchronizer 1, fallback to synchronizer 2, recover to synchronizer 1' , async ( ) => {
116111 const mockInitializer1 : DataSystemInitializer = {
117- run : jest
112+ start : jest
118113 . fn ( )
119114 . mockImplementation (
120115 (
@@ -130,7 +125,7 @@ it('initializer gets basis, switch to synchronizer 1, fallback to synchronizer 2
130125 let sync1RunCount = 0 ;
131126 const mockSynchronizer1Data = { key : 'sync1' } ;
132127 const mockSynchronizer1 = {
133- run : jest
128+ start : jest
134129 . fn ( )
135130 . mockImplementation (
136131 (
@@ -143,7 +138,7 @@ it('initializer gets basis, switch to synchronizer 1, fallback to synchronizer 2
143138 message : 'I am error...man!' ,
144139 } ) ; // error that will lead to fallback
145140 } else {
146- _dataCallback ( false , mockSynchronizer1Data ) ; // second run will lead to data
141+ _dataCallback ( false , mockSynchronizer1Data ) ; // second start will lead to data
147142 }
148143 sync1RunCount += 1 ;
149144 } ,
@@ -153,7 +148,7 @@ it('initializer gets basis, switch to synchronizer 1, fallback to synchronizer 2
153148
154149 const mockSynchronizer2Data = { key : 'sync2' } ;
155150 const mockSynchronizer2 = {
156- run : jest
151+ start : jest
157152 . fn ( )
158153 . mockImplementation (
159154 (
@@ -182,12 +177,12 @@ it('initializer gets basis, switch to synchronizer 1, fallback to synchronizer 2
182177 }
183178 } ) ;
184179
185- underTest . run ( callback , jest . fn ( ) ) ;
180+ underTest . start ( callback , jest . fn ( ) ) ;
186181 } ) ;
187182
188- expect ( mockInitializer1 . run ) . toHaveBeenCalledTimes ( 1 ) ;
189- expect ( mockSynchronizer1 . run ) . toHaveBeenCalledTimes ( 2 ) ;
190- expect ( mockSynchronizer2 . run ) . toHaveBeenCalledTimes ( 1 ) ;
183+ expect ( mockInitializer1 . start ) . toHaveBeenCalledTimes ( 1 ) ;
184+ expect ( mockSynchronizer1 . start ) . toHaveBeenCalledTimes ( 2 ) ;
185+ expect ( mockSynchronizer2 . start ) . toHaveBeenCalledTimes ( 1 ) ;
191186 expect ( callback ) . toHaveBeenCalledTimes ( 3 ) ;
192187 expect ( callback ) . toHaveBeenNthCalledWith ( 1 , true , { key : 'init1' } ) ;
193188 expect ( callback ) . toHaveBeenNthCalledWith ( 2 , false , { key : 'sync2' } ) ; // sync1 errors and fallsback
@@ -200,7 +195,7 @@ it('it reports error when all initializers fail', async () => {
200195 message : 'I am initializer1 error!' ,
201196 } ;
202197 const mockInitializer1 : DataSystemInitializer = {
203- run : jest
198+ start : jest
204199 . fn ( )
205200 . mockImplementation (
206201 (
@@ -218,7 +213,7 @@ it('it reports error when all initializers fail', async () => {
218213 message : 'I am initializer2 error!' ,
219214 } ;
220215 const mockInitializer2 : DataSystemInitializer = {
221- run : jest
216+ start : jest
222217 . fn ( )
223218 . mockImplementation (
224219 (
@@ -247,11 +242,11 @@ it('it reports error when all initializers fail', async () => {
247242 }
248243 } ) ;
249244
250- underTest . run ( dataCallback , statusCallback ) ;
245+ underTest . start ( dataCallback , statusCallback ) ;
251246 } ) ;
252247
253- expect ( mockInitializer1 . run ) . toHaveBeenCalledTimes ( 1 ) ;
254- expect ( mockInitializer2 . run ) . toHaveBeenCalledTimes ( 1 ) ;
248+ expect ( mockInitializer1 . start ) . toHaveBeenCalledTimes ( 1 ) ;
249+ expect ( mockInitializer2 . start ) . toHaveBeenCalledTimes ( 1 ) ;
255250 expect ( dataCallback ) . toHaveBeenCalledTimes ( 0 ) ;
256251 expect ( statusCallback ) . toHaveBeenNthCalledWith (
257252 1 ,
@@ -273,7 +268,7 @@ it('it reports error when all initializers fail', async () => {
273268
274269it ( 'it can be stopped when in thrashing synchronizer fallback loop' , async ( ) => {
275270 const mockInitializer1 = {
276- run : jest
271+ start : jest
277272 . fn ( )
278273 . mockImplementation (
279274 (
@@ -288,7 +283,7 @@ it('it can be stopped when in thrashing synchronizer fallback loop', async () =>
288283
289284 const mockSynchronizer1Error = { name : 'Error' , message : 'I am error...man!' } ;
290285 const mockSynchronizer1 = {
291- run : jest
286+ start : jest
292287 . fn ( )
293288 . mockImplementation (
294289 (
@@ -317,11 +312,11 @@ it('it can be stopped when in thrashing synchronizer fallback loop', async () =>
317312 }
318313 } ) ;
319314
320- underTest . run ( dataCallback , statusCallback ) ;
315+ underTest . start ( dataCallback , statusCallback ) ;
321316 } ) ;
322317
323- expect ( mockInitializer1 . run ) . toHaveBeenCalled ( ) ;
324- expect ( mockSynchronizer1 . run ) . toHaveBeenCalled ( ) ;
318+ expect ( mockInitializer1 . start ) . toHaveBeenCalled ( ) ;
319+ expect ( mockSynchronizer1 . start ) . toHaveBeenCalled ( ) ;
325320 expect ( dataCallback ) . toHaveBeenNthCalledWith ( 1 , true , { key : 'init1' } ) ;
326321 underTest . stop ( ) ;
327322
@@ -341,7 +336,7 @@ it('it can be stopped when in thrashing synchronizer fallback loop', async () =>
341336it ( 'it can be stopped and restarted' , async ( ) => {
342337 const mockInitializer1Data = { key : 'init1' } ;
343338 const mockInitializer1 = {
344- run : jest
339+ start : jest
345340 . fn ( )
346341 . mockImplementation (
347342 (
@@ -356,7 +351,7 @@ it('it can be stopped and restarted', async () => {
356351
357352 const mockSynchronizer1Data = { key : 'sync1' } ;
358353 const mockSynchronizer1 = {
359- run : jest
354+ start : jest
360355 . fn ( )
361356 . mockImplementation (
362357 (
@@ -384,13 +379,13 @@ it('it can be stopped and restarted', async () => {
384379 resolve ( ) ;
385380 }
386381 } ) ;
387- // first run
388- underTest . run ( callback1 , jest . fn ( ) ) ;
382+ // first start
383+ underTest . start ( callback1 , jest . fn ( ) ) ;
389384 } ) ;
390385
391- // check first run triggered underlying data sources
392- expect ( mockInitializer1 . run ) . toHaveBeenCalledTimes ( 1 ) ;
393- 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 ) ;
394389 expect ( callback1 ) . toHaveBeenCalledTimes ( 2 ) ;
395390
396391 // wait a moment for pending awaits to resolve the stop request
@@ -405,13 +400,13 @@ it('it can be stopped and restarted', async () => {
405400 resolve ( ) ;
406401 }
407402 } ) ;
408- // second run
409- underTest . run ( callback2 , jest . fn ( ) ) ;
403+ // second start
404+ underTest . start ( callback2 , jest . fn ( ) ) ;
410405 } ) ;
411406
412- // check that second run triggers underlying data sources again
413- expect ( mockInitializer1 . run ) . toHaveBeenCalledTimes ( 2 ) ;
414- 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 ) ;
415410 expect ( callback2 ) . toHaveBeenCalledTimes ( 2 ) ;
416411} ) ;
417412
@@ -429,7 +424,7 @@ it('it is well behaved with no initializers and no synchronizers configured', as
429424 resolve ( ) ;
430425 } ) ;
431426
432- underTest . run ( jest . fn ( ) , statusCallback ) ;
427+ underTest . start ( jest . fn ( ) , statusCallback ) ;
433428 } ) ;
434429
435430 expect ( statusCallback ) . toHaveBeenNthCalledWith ( 1 , DataSourceState . Closed , {
@@ -441,7 +436,7 @@ it('it is well behaved with no initializers and no synchronizers configured', as
441436
442437it ( 'it is well behaved with an initializer and no synchronizers configured' , async ( ) => {
443438 const mockInitializer1 = {
444- run : jest
439+ start : jest
445440 . fn ( )
446441 . mockImplementation (
447442 (
@@ -467,7 +462,7 @@ it('it is well behaved with an initializer and no synchronizers configured', asy
467462 resolve ( ) ;
468463 } ) ;
469464
470- underTest . run ( jest . fn ( ) , statusCallback ) ;
465+ underTest . start ( jest . fn ( ) , statusCallback ) ;
471466 } ) ;
472467
473468 expect ( statusCallback ) . toHaveBeenNthCalledWith ( 1 , DataSourceState . Closed , {
0 commit comments