0

I am trying to automate JMeter performance tests for my Jenkins PR-Build for a Hybris Platform.

In order to run my JMeter performance script obviously the hybrisserver needs to start first so that localhost is available.

My approach was to start the server the same way as its done for integration tests and then execute the performance tests. I can see that the server is starting up just the same way as in the integrationtests target but all my requests from jmeter script are failing as localhost is not available.

Can anyone help with that?

Edit: Approach to start the Hybris Server as its done for the integration test

Edit: Approach to start Hybris Server within my ANT Target which runs my JMeter Performance Test - it also starts Hybris Server but localhost is not reachable aswell

    <yrun>
         de.hybris.platform.core.Registry.setCurrentTenantByID("junit");

         de.hybris.platform.util.RedeployUtilities.shutdown();
     </yrun>
Theo
  • 57
  • 5
  • Hi @Theo - Please add up the commands and any related screenshots if possible. How you are trying to achieve it when you say `same way as its done for integration tests`?. Please add a little more info and you will attract more answers. Thanks – www.hybriscx.com Nov 20 '19 at 02:44
  • Hi thanks for the hint. I added more information – Theo Nov 20 '19 at 09:01
  • Hi @Theo, I think you also need to call `Registry.activateMasterTenant();` or `activateTenant` – www.hybriscx.com Nov 20 '19 at 10:06

4 Answers4

0

You can put your logic which will "wait" for server to become available under setUp Thread Group, something like:

however this way you will get extra negative results in your .jtl results file, I would go for JSR223 Sampler and the code like:

SampleResult.setIgnore()
def attempt = 1
def host = 'localhost'
def port = 8080
while (true) {
    try {
        def s = new Socket(host, port)
        if (s.isConnected()) {
            log.info('Server is available, starting the test')
            s.close()
            break
        }
    }
    catch (Exception ex) {
        log.info('Server is not available after ' + attempt + ' attempts, retrying...')
        attempt++
        sleep(5000)
    }
}

it will try to establish a Socket connection with the given endpoint and in case of failure wait for 5 seconds and retry. When the server becomes available it will exit the loop and start other "normal" Thread Groups.

enter image description here

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • Thanks Dmitri T The problem actually is not that JMeter is executed before the server is started. It looks like its a problem from Hybris side => the server is either started slimmed or localhost is on another port which I dont know. – Theo Nov 19 '19 at 15:40
0

Please try at 9001 or 9002 ports.

BNR
  • 89
  • 2
  • 13
  • Open the ports, if they are behind the firewall. what operating system you are using?. Hybris typically requires 80, 443, 9001, 9002 and 8983 ( for solr) – BNR Nov 20 '19 at 18:14
  • Hi @BNR, I am using mac os I think the port must be open because when I start my server like ./hybrisserver.sh localhost is available and everything is working – Theo Nov 21 '19 at 05:55
0

I think you will also need to activate your tenant using something like...
de.hybris.platform.core.Registry.activateTenant(); (please check for available functions you can use in Registery class)

<yrun>
         de.hybris.platform.core.Registry.activateTenant(de.hybris.platform.core.Registry.getTenantByID("junit"));
         de.hybris.platform.util.RedeployUtilities.shutdown();
</yrun>

Also, check for web=true in platform/build.xml if something triggers the web context loading.

<target name="allwebtests" description="">
        <callback extname="" target="before_yunitweb"/>
        <annotationtests annotations="unittests,demotests,integrationtests" web="true"/>
        <callback extname="" target="after_yunitweb"/>
    </target>
www.hybriscx.com
  • 1,129
  • 4
  • 22
  • 1
    I have started the server that way but still I cant access localhost :/ I used this lines to start the server de.hybris.platform.core.Registry.setCurrentTenantByID("master"); de.hybris.platform.core.Registry.activateMasterTenant(); – Theo Nov 20 '19 at 11:28
  • 1
    Oh, should check if with activateTanent, hybris loads the web context as well or simply loads spring application context only. If you don't shut it down using`de.hybris.platform.util.RedeployUtilities.shutdown()`, can you access site using browser? – www.hybriscx.com Nov 20 '19 at 13:14
  • Thats a very interesting point. I cant access the site using my browser. I tried with https://localhost:9002 and http://localhost:9001 both are not available – Theo Nov 20 '19 at 13:34
  • May be you can refer to the platform/build.xml for target `allwebtests`. You would see that there is an attribute `web=true` passed in that. – www.hybriscx.com Nov 21 '19 at 02:22
  • Even when I run allwebtests localhost is not available on my browser:/ – Theo Nov 21 '19 at 18:56
0

You can start an embedded server using the "@NeedsEmbeddedServer" annotation, this is for example used in the Spock (BDD) tests in the "ycommercewebservicestest" extension.

Please note that this will use the "junit" tenant and the embedded server runs on the ports 8001 (http) and 8002 (https) by default.

You can check the ports in your properties:

# specifies default http port for embedded server
embeddedserver.http.port=8001

# specifies default https port for embedded server
embeddedserver.ssl.port=8002

For Example:

@IntegrationTest
@NeedsEmbeddedServer(webExtensions = {"ycommercewebservices"})
public class ExampleWebTest extends ServicelayerTest {

    @Test
    public void exampleTest() {
        // YOUR IMPLEMENTATION
    }
}
Eike S.
  • 3
  • 1