test3a.ts 4.2 KB

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