http2.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* TEST CASE FOR HTTP with Retransmission integrating event driven development */
  2. import { BehaviorSubject, buffer, filter, interval, map, Observable, startWith, Subject, Subscriber, Subscription, switchMap, takeUntil, tap } from "rxjs";
  3. import { ClientNotificationState } from "../interfaces/general.interface";
  4. import { rxjsBuffer } from "../services/utility/buffer-obs";
  5. import { LogSetting } from "../dependencies/logging/type/datatype";
  6. import { BaseMessage } from "../dependencies/logging/services/logging-service";
  7. import { prepareResponseMessages } from "../services/utility/prepareFISmessage";
  8. import { StorageService } from "../services/storage.service";
  9. import { RetransmissionService } from "../services/retransmission.service";
  10. let initialState: ClientNotificationState = { event: 'Initialization', message: 'InitialState', status: 'ONLINE' }
  11. let clientState: 'ONLINE' | 'OFFLINE' | null = 'ONLINE' // First assumption
  12. let logSettings: LogSetting = {
  13. cacheMessageLimit: 0,
  14. storage: "MongoDB",
  15. setting: {
  16. appName: 'Retransmission',
  17. appLocName: 'Local Mongo Buffer',
  18. logLocName: 'Local Mongo BUffer',
  19. },
  20. customSetting: {
  21. server: "localhost:27017",
  22. database: 'sender'
  23. }
  24. }
  25. let sender: Subject<BaseMessage> = prepareResponseMessages(3000, 1) // generate fake messages second argument is milliseconds interval
  26. let finalOutput: Subject<BaseMessage> = new Subject()
  27. let notificationSubject: BehaviorSubject<ClientNotificationState> = new BehaviorSubject(initialState)
  28. let retransmissionService: RetransmissionService = new RetransmissionService()
  29. setTimeout(() => {
  30. console.log(`Emulate Offline NOW`)
  31. notificationSubject.next({
  32. event: 'Test',
  33. message: 'test',
  34. status: 'OFFLINE'
  35. })
  36. }, 3000);
  37. setTimeout(() => {
  38. console.log(`Emulate Online NOW`)
  39. notificationSubject.next({
  40. event: 'Test',
  41. message: 'test',
  42. status: 'ONLINE'
  43. })
  44. }, 6000);
  45. // retransmissionService.buffer(sender, notificationSubject, 1000, null, null).subscribe({
  46. // next: (message: BaseMessage) => {
  47. // finalOutput.next(message)
  48. // },
  49. // error: err => console.error(err),
  50. // complete: () => { }
  51. // })
  52. let finalCount = 0
  53. finalOutput.subscribe(message => {
  54. finalCount++
  55. console.log(`final Output Count: ${finalCount}`)
  56. // console.log(message.header.messageID)
  57. })