How do we mock TCP (Java Socket API) calls? Couldn't find a complete example as how it could be achieved in a Spring Boot Test & JUnit5 environment.
Related
Since Grails 4 it is not possible anymore to get the server port in grails integration tests this way:
#Value('${local.server.port}')
Integer serverPort
What's the correct way to get the server port in tests?
The serverPort is already injected in Grails 4 integration tests as serverPort. There is no need to create a variable for it.
What is the best npm library to make ActiveMQ calls from nodejs? I've tried 'stomp' but sometimes it acts wired.
Whenever I use stomp port (61613) it worked
but when I use tcp port (61616) it throws an exception in ActiveMQ logs saying packet size is max out.
The behavior you describe as "weird" is the behavior I would expect. The listener on port 61616 in ActiveMQ 5.x is for OpenWire clients and therefore not suitable for STOMP clients. If you use a STOMP transportConnector then you shouldn't have any problem.
There will be no human being in the loop, and both endpoints are autonomous Node.js applications operating as independent services.
Endpoint A is responsible for contacting Endpoint B via secure web socket, and maintaining that connection 24/7/365.
Both endpoints will initiate messages independently (without human intervention), and both endpoints will have an API (RESTful or otherwise) to receive and process messages. You might say that each endpoint is both a client of, and a server to, the other endpoint.
I am considering frameworks like Sails.js and LoopBack (implemented on both endpoints), as well as simply passing JSON messages over ws, but remain unclear what the most idiomatic approach would be.
Web Sockets have a lot of overhead for connecting to browsers and what not, since they try to remain compatible with HTTP. If you're just connecting a pair of servers, a simple TCP connection will suffice. You can use the net module for this.
Now, once you have that connection, how do you initiate communication? You could go through the trouble of making your own protocol, but I don't recommend it. I found that a simple RPC was easiest. You can use the rpc-stream package over any duplex stream (including your TCP socket).
For my own application, I actually installed socket.io-client and let my servers use it for RPC. Although if I were to do it again, I would use rpc-stream to skip all the overhead required for setting up a Web Socket connection.
I want to run a load test for a server recently developed in node.js .The problem is i am not sure if and how is it possible to establish multiple connections from one client to this one port of the server.Particularly,should there be different event listeners for every websocket that is going to be created,for example w[i].on('open',function(){....} or am i under the wrong impression?
If the websocket server was developed in nodejs, you can easily use loadtest tool.
Runs a load test on the selected HTTP or WebSockets URL. The API allows for easy integration in your own tests.
This lets you to test web sockets and http URLs. It is available as a package on NPM.
I'm working on an application that interfaces with embedded equipment via the SNMP protocol. To facilitate testing, I've written a simulator for the embedded equipment with Nodejs and the snmpjs library. The simulator responds to SNMP gets/sets and sends traps to the managing application. The trap messages are constructed by the snmpjs library, but sent manually using Node's standard UDP sockets.
This works well when simulating one equipment, but I've run into an issue when attempting to simulate multiple equipment. Specifically, the managing application identifies the source equipment of SNMP traps by analyzing the source IP/port of the UDP packet carrying the trap. This precludes my simulating multiple equipment simultaneously, which is the most common use case for the application.
So, my question is: Is there some way to control/spoof the source IP or port of the udp packet with Nodejs? Or, perhaps, would it be possible to use some kind of proxy to achieve the desired result?
(Note: Running the simulators on a single machine is a strict requirement. Also, it is not sufficient that I have unique IPs/ports for each simulator, I must be able to know their values ahead of time so that I can configure the managing application to interface with them correctly.)
The solution was simple. I overlooked this line from the node documentation for the send method of udp sockets, "If the socket has not been previously bound with a call to bind, it's assigned a random port number..." I just needed to bind the socket to a port first. I've verified this with a test script.