http2.ts 2.2 KB

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