test3b.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* ----------------------- TEST3B {Mongo to File} ----------------------- */
  2. /* This test is focusing on comparing 2 different arrays of message logs from 2 different storage.
  3. Which is cloud mongo storage as the control/source, and then comparing the data from local file
  4. server data, and then synchronizing them */
  5. import { Observable, map, Subject, takeUntil, take, of, timer, from } from "rxjs";
  6. import { BaseMessage } from "../dependencies/fisappmessagejsutilty/dependencies/dependencies";
  7. import { LogSetting, MessageLog } from "../dependencies/fisloggingservice/type/datatype";
  8. import { AcknowledgementService } from "../services/acknowledgement.service";
  9. import { IncomingMessageService } from "../services/incomingMessage.service";
  10. import { MessageSyncrhonizationService } from "../services/synchronization.service";
  11. import { MessageSynchronisationServiceSetting } from "../type/datatype";
  12. import { StreamingService } from "./test-streamOBS";
  13. /* Pre - Defined Data && Settings */
  14. const stream = new StreamingService()
  15. // Declare source Services && Observables (Using File Storage) Simulating Full Logs
  16. const source_synchronize = new MessageSyncrhonizationService()
  17. const source_payload: Observable<BaseMessage> = stream.stream().pipe(take(2))
  18. const source_incoming = new IncomingMessageService()
  19. const source_payload_subject: Subject<BaseMessage> = new Subject()
  20. source_payload.subscribe({
  21. next: (data) => {
  22. source_payload_subject.next(<BaseMessage>data)
  23. // console.log(data)
  24. }
  25. })
  26. // Declare target Services && Observables (Using MongoDB Storage) Simulating Partial Logs
  27. const target_payload: Observable<BaseMessage> = stream.stream().pipe(take(4))
  28. const target_payload_subject: Subject<BaseMessage> = new Subject()
  29. const target_incoming = new IncomingMessageService()
  30. target_payload.subscribe({
  31. next: (data) => {
  32. target_payload_subject.next(<BaseMessage>data)
  33. },
  34. error: e => console.error(e),
  35. complete: () => { `Target Payload Completed` }
  36. })
  37. // testing to see if data is sent in
  38. target_payload_subject.subscribe({
  39. next: element => {
  40. console.log(`target_payload_subject emits :00 ${element.header.messageID}`)
  41. }
  42. })
  43. source_payload_subject.subscribe({
  44. next: element => {
  45. console.log(`source_payload_subject emits :00 ${element.header.messageID}`)
  46. }
  47. })
  48. // Declare Source Storage
  49. let source_storage: LogSetting = {
  50. storage: "MongoDB",
  51. setting: {
  52. appName: 'Default from client',
  53. appLocName: 'To be generated in client',
  54. logLocName: 'To be generated in client',
  55. },
  56. customSetting: {
  57. srv: true,
  58. user: "testDB",
  59. password: "h1nt1OyXw6QeUnzS",
  60. server: "cluster0.29sklte.mongodb.net",
  61. collection: "log",
  62. }
  63. }
  64. let source_dataSet: LogSetting & { incomingObservable: Observable<BaseMessage> } = {
  65. storage: source_storage.storage,
  66. setting: source_storage.setting,
  67. customSetting: source_storage.customSetting,
  68. incomingObservable: source_payload_subject
  69. }
  70. //Declare Target Storage
  71. let target_storage: LogSetting = {
  72. storage: "File",
  73. setting: {
  74. appName: 'Default from client',
  75. appLocName: 'To be generated in client',
  76. logLocName: 'To be generated in client',
  77. }
  78. }
  79. let target_dataSet: LogSetting & { incomingObservable: Observable<BaseMessage> } = {
  80. storage: target_storage.storage,
  81. setting: target_storage.setting,
  82. customSetting: target_storage.customSetting,
  83. incomingObservable: target_payload_subject
  84. }
  85. // Combine source and target storage to form MessageSynchronisationServiceSetting
  86. let settings: MessageSynchronisationServiceSetting = {
  87. incomingSource: {
  88. //all of the settings to be combined here
  89. ...target_storage,
  90. tags: ['Incoming']
  91. }, //LogSetting & {tags:string[] },
  92. target: {
  93. ...source_storage,
  94. tags: ['Incoming']
  95. } //LogSetting & {tags:string[] }
  96. }
  97. /* -------- SYNCHRONIZATION --------- */
  98. function initializeData() {
  99. source_incoming.init(source_dataSet)
  100. target_incoming.init(target_dataSet)
  101. }
  102. // Done by appoximately 5-8 Seconds
  103. initializeData()
  104. source_synchronize.init(settings)
  105. // by 10th second
  106. setTimeout(() => {
  107. let triggerSync = from(['Newsynch'])
  108. let sync = source_synchronize.subscribe(triggerSync)
  109. sync.subscribe({
  110. next: (msgToBeSynched) => {
  111. // console.log(`synching ... ${msgToBeSynched.header.messageID}`)
  112. source_payload_subject.next(msgToBeSynched)
  113. }
  114. })
  115. }, 7000)//30s