s/w broker Emulation library for Unit testing in automated environment

snagpal
snagpal Member, Employee Posts: 4 Solace Employee
edited September 2022 in PubSub+ Event Broker #1

Is there a broker emulation library that helps developer unit test their code? Does not have to be full fledged supporting all the features of the Solace broker but basic functionality like publish/subscribe success/not-success. This allows developer to test their code in a automated testing environment like github/jenkins etc without reaching out to a real broker. Any suggestions?

Answers

  • amackenzie
    amackenzie Member, Employee Posts: 259 Solace Employee

    we do not have a mock broker but generally use a very lightweight PubSub+ Standard Edition broker containerized and automated with docker compose.

    Take a look at:

    SolaceLabs/solace-single-docker-compose: Set up single Solace PubSub+ Docker container using Docker Compose (github.com)

    SolaceLabs/solace-ha-docker-compose: Configure High-availability Groups Using Docker Compose (github.com)

    Rootless Podman for Ubuntu (solace.com)

    Using a containerized broker, you can stand up, test, and tear down brokers in minutes. This includes using rootless podman for environments where the devs don't have root access to their deployment machines.

  • snagpal
    snagpal Member, Employee Posts: 4 Solace Employee

    Thanks Andrew for your response!

    This option was suggested to the development team, but the problem is that their automation environment creates a container instance to run their automated unit tests. And, it would entail running a container inside a container if went this route.

  • amackenzie
    amackenzie Member, Employee Posts: 259 Solace Employee

    You could create 2 separate containers and have them communicate on a docker network. I don't think you would need a container in a container.

  • mousam
    mousam Member Posts: 2

    Hi Andrews, I am following this thread and have a similar requirement where I would like to unit test my publisher application against a message broker. I have spinned up the broker based on this:

    https://solace.community/discussion/867/integration-testing-with-solace
    

    When I run my test cases, they have passed using the docker container that is being created; but when I try to execute mvn install, I still see that the host, port, username and password are not resolved. Following is the error.

    Caused by: com.solacesystems.jcsmp.InvalidPropertiesException: All hosts in the host list: 'tcps://${SOLACE_HOST}.messaging.solace.cloud:55443' are not resolvable

    Can you please provide me a link to the maven dependency for the dockr image which I can use in my pom file so that the package gets built ?

    solace/solace-pubsub-standard:latest
    

    Thanks and Regards,

    Mousam

  • amackenzie
    amackenzie Member, Employee Posts: 259 Solace Employee

    @mousam I am not familiar with the test containers framework being used. Perhaps you can pursue this via some of the other contacts on the other threads (such as @swenhelge ).

    solace/solace-pubsub-standard:latest on it's own, without these external testing frameworks, has no Maven dependencies. It's a standalone container image and the broker is not written in Java and has no Java dependencies.

    Your port problem has to do with the way the test containers is configured.

  • swenhelge
    swenhelge Member, Employee Posts: 77 Solace Employee

    @mousam


    Did you follow the steps in one of these examples?

    The broker ports are randomly assigned so you need to pass host and port into the connection properties for your JCSMP connection.

    From your example it seems the properties picked up are some sort of defaults picked up by your code? I guess you started putting your code together from a code example. Wherever 'tcps://${SOLACE_HOST}.messaging.solace.cloud:55443' is deiofned is where you need to set the proper connection parameters.

    The url should be localhost plus the random port assigned by test containers e.g. tcp://localhost:12345



  • mousam
    mousam Member Posts: 2

    Thank you for your response @amackenzie and @swenhelge. I indeed tried with the same example.

    But somehow during testing, it is not taking the host:port from the docker container that is spinning up. I can share the source code if you want to check it. My test class is TestGcpEventSubscriber.java which extends AbstractPubSubPlusTestCase.java



  • swenhelge
    swenhelge Member, Employee Posts: 77 Solace Employee

    @mousam - have looked at your code and nothing jumps out at me.

    However the error you shared does hint at incorrect/incomplete properties passed into the client library.

    I think you need to steo through the code in debug mode and see if the right properties are set up and used.