123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- /* TEST CASE FOR HTTP with Retransmission integrating event driven development */
- import { BehaviorSubject, buffer, filter, interval, map, Observable, startWith, Subject, Subscriber, Subscription, switchMap, takeUntil, tap } from "rxjs";
- import { ClientNotificationState } from "../interfaces/general.interface";
- import { LogSetting } from "../dependencies/logging/type/datatype";
- import { BaseMessage } from "../dependencies/logging/services/logging-service";
- import { prepareResponseMessages } from "../services/utility/prepareFISmessage";
- import { RetransmissionService } from "../services/retransmission.service";
- let initialState: ClientNotificationState = { event: 'Initialization', message: 'InitialState', status: 'ONLINE' }
- let clientState: 'ONLINE' | 'OFFLINE' | null = 'ONLINE' // First assumption
- let logSettings: LogSetting = {
- cacheMessageLimit: 0,
- storage: "MongoDB",
- setting: {
- appName: 'Retransmission',
- appLocName: 'Local Mongo Buffer',
- logLocName: 'Local Mongo BUffer',
- },
- customSetting: {
- server: "localhost:27017",
- database: 'sender'
- }
- }
- let sender: Subject<BaseMessage> = prepareResponseMessages(3000, 1) // generate fake messages second argument is milliseconds interval
- let finalOutput: Subject<BaseMessage> = new Subject()
- let notificationSubject: BehaviorSubject<ClientNotificationState> = new BehaviorSubject(initialState)
- let retransmissionService: RetransmissionService = new RetransmissionService()
- setTimeout(() => {
- console.log(`Emulate Offline NOW`)
- notificationSubject.next({
- event: 'Test',
- message: 'test',
- status: 'OFFLINE'
- })
- }, 3000);
- setTimeout(() => {
- console.log(`Emulate Online NOW`)
- notificationSubject.next({
- event: 'Test',
- message: 'test',
- status: 'ONLINE'
- })
- }, 6000);
- // retransmissionService.buffer(sender, notificationSubject, 1000, null, null).subscribe({
- // next: (message: BaseMessage) => {
- // finalOutput.next(message)
- // },
- // error: err => console.error(err),
- // complete: () => { }
- // })
- let finalCount = 0
- finalOutput.subscribe(message => {
- finalCount++
- console.log(`final Output Count: ${finalCount}`)
- // console.log(message.header.messageID)
- })
|