test3c.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* ----------------------- TEST3A {Mongo to Mongo} ----------------------- */
  2. /* This test is focusing on comparing 2 different arrays of message logs from 2 different storage.
  3. Which is local file mongo as the control/source, and then comparing the data from cloud mongoDB
  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(4))
  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(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(2))
  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. // Declare Source Storage
  44. let source_storage: LogSetting = {
  45. storage: "MongoDB",
  46. setting: {
  47. appName: 'Default from client',
  48. appLocName: 'To be generated in client',
  49. logLocName: 'To be generated in client',
  50. },
  51. customSetting: {
  52. server: "localhost:27017",
  53. collection: "log"
  54. }
  55. }
  56. let source_dataSet: LogSetting & { incomingObservable: Observable<BaseMessage> } = {
  57. storage: source_storage.storage,
  58. setting: source_storage.setting,
  59. customSetting: source_storage.customSetting,
  60. incomingObservable: source_payload_subject
  61. }
  62. //Declare Target Storage
  63. let target_storage: LogSetting = {
  64. storage: "MongoDB",
  65. setting: {
  66. appName: 'Default from client',
  67. appLocName: 'To be generated in client',
  68. logLocName: 'To be generated in client',
  69. },
  70. customSetting: {
  71. srv: true,
  72. user: "testDB",
  73. password: "h1nt1OyXw6QeUnzS",
  74. server: "cluster0.29sklte.mongodb.net",
  75. collection: "log",
  76. }
  77. }
  78. let target_dataSet: LogSetting & { incomingObservable: Observable<BaseMessage> } = {
  79. storage: target_storage.storage,
  80. setting: target_storage.setting,
  81. customSetting: target_storage.customSetting,
  82. incomingObservable: target_payload_subject
  83. }
  84. // Combine source and target storage to form MessageSynchronisationServiceSetting
  85. let settings: MessageSynchronisationServiceSetting = {
  86. incomingSource: {
  87. //all of the settings to be combined here
  88. ...source_storage,
  89. tags: ['Incoming']
  90. }, //LogSetting & {tags:string[] },
  91. target: {
  92. ...target_storage,
  93. tags: ['Incoming']
  94. } //LogSetting & {tags:string[] }
  95. }
  96. /* -------- SYNCHRONIZATION --------- */
  97. function initializeData() {
  98. source_incoming.init(source_dataSet)
  99. target_incoming.init(target_dataSet)
  100. }
  101. // Done by appoximately 5-8 Seconds
  102. initializeData()
  103. source_synchronize.init(settings)
  104. // by 10th second
  105. setTimeout(() => {
  106. let triggerSync = from(['Newsynch'])
  107. let sync = source_synchronize.subscribe(triggerSync)
  108. sync.subscribe({
  109. next: (msgToBeSynched) => {
  110. // console.log(`synching ... ${msgToBeSynched.header.messageID}`)
  111. target_payload_subject.next(msgToBeSynched)
  112. }
  113. })
  114. }, 7000)