test2.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* call server client service instance 3 times. */
  2. // Testing to isolate server client servicce
  3. import { Subject } from "rxjs";
  4. import { ConnectionRequest, Message } from "../interfaces/general.interface";
  5. import { ServerClientManager } from "../services/server-client.service";
  6. const serverClientManager = new ServerClientManager()
  7. let targetserver: string = 'localhost:3000'
  8. let targetserver2: string = 'localhost:3002'
  9. let hostServer: string = 'localhost:3001'
  10. let connectionRequest1: ConnectionRequest = {
  11. server: {
  12. name: 'G1',
  13. serverUrl: hostServer,
  14. connectionType: 'GRPC',
  15. messageToBePublishedFromApplication: new Subject<Message>()
  16. },
  17. client: {
  18. name: 'G2',
  19. targetServer: targetserver,
  20. connectionType: 'GRPC',
  21. messageToBeReceivedFromRemote: new Subject<Message>()
  22. }
  23. }
  24. let connectionRequest2: ConnectionRequest = {
  25. server: {
  26. name: 'G1',
  27. serverUrl: hostServer,
  28. connectionType: 'GRPC',
  29. messageToBePublishedFromApplication: new Subject<Message>()
  30. },
  31. client: {
  32. name: 'G0',
  33. targetServer: targetserver2,
  34. connectionType: 'GRPC',
  35. messageToBeReceivedFromRemote: new Subject<Message>()
  36. }
  37. }
  38. // Client 1 request connection
  39. serverClientManager.generateConnection(connectionRequest1).then((response) => {
  40. // console.log(response)
  41. serverClientManager.generateConnection(connectionRequest2).then((response) => {
  42. // console.log(response)
  43. serverClientManager.generateConnection(connectionRequest1);
  44. })
  45. })
  46. // Array size =1;
  47. // serverClientManager.generateConnection(connectionRequest2)
  48. // Client 2 request connection
  49. // Array size =2;
  50. // Client 1 request connection again
  51. // setTimeout(() => {
  52. // serverClientManager.generateConnection(connectionRequest1)
  53. // }, 4000)
  54. // Array size =2;