Skip to content

Commit

Permalink
[IT-rex tests] improve docker container startup ordering
Browse files Browse the repository at this point in the history
+ some small optimizations
  • Loading branch information
michalovjan committed Oct 24, 2023
1 parent 444bf2d commit dca9935
Show file tree
Hide file tree
Showing 15 changed files with 311 additions and 56 deletions.
10 changes: 9 additions & 1 deletion integration-test-rex/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
Setup
-----
Rex, Keycloak and BPM are services required to run the tests.
Rex (with ISPN), Keycloak and BPM are services required to run the tests.
Rex and Keycloak are running in TestContainers, BPM in mocked using WireMock.

Container strict start order:
1. Keycloak (IT tests wide) [Docker]
- 1 instance per entire IT tests run
2. ISPN (per IT test class) [Docker]
3. Rex (per IT test class) [Docker]
4. ORCH EAP container (per IT test class) [Local]
5. BPM Wiremock server (per IT test class) [Local]

Process of the test build:
- Orch get auth token from Keycloak (services are configured with auth and the token is passed between them)
- Orch sends the build tasks to Rex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@
import org.jboss.pnc.restclient.websocket.WebSocketClient;
import org.jboss.pnc.test.category.ContainerTest;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -88,14 +90,20 @@ public class BuildTest extends RemoteServices {

private BuildUtils buildUtils;

private static final String PNC_SOCKET_URL = "ws://localhost:8080" + NOTIFICATION_PATH;
WebSocketClient wsClient = new VertxWebSocketClient();
private static BPMWireMock bpm;

private BPMWireMock bpm;
@BeforeClass
public static void startBPM() {
bpm = new BPMWireMock(8088);
}

@AfterClass
public static void stopBPM() throws IOException {
bpm.close();
}

@Before
public void beforeEach() throws ExecutionException, InterruptedException {
bpm = new BPMWireMock(8088);

String token = KeycloakClient
.getAuthTokensBySecret(authServerUrl, keycloakRealm, "test-user", "test-pass", "pnc", "", false)
Expand All @@ -105,14 +113,6 @@ public void beforeEach() throws ExecutionException, InterruptedException {
buildConfigurationClient = new BuildConfigurationClient(withBearerToken(token));
groupConfigurationClient = new GroupConfigurationClient(withBearerToken(token));
buildUtils = new BuildUtils(buildClient, new GroupBuildClient(withBearerToken(token)));

wsClient.connect(PNC_SOCKET_URL).get();
}

@After
public void afterEach() throws IOException {
bpm.close();
wsClient.disconnect();
}

@Test
Expand Down Expand Up @@ -532,7 +532,7 @@ public BPMWireMock(int port) {
.withPostServeAction(
"webhook",
baseBPMWebhook().withBody(BPMResultsMock.mockBuildResultSuccess())
.withFixedDelay(500)));
.withFixedDelay(250)));
wireMockServer.start();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@
import org.jboss.pnc.restclient.websocket.WebSocketClient;
import org.jboss.pnc.test.category.ContainerTest;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -78,13 +80,21 @@ public class DependentBuildsTest extends RemoteServices {

private BuildUtils buildUtils;

private BPMWireMock bpm;
private static BPMWireMock bpm;

private static final String PNC_SOCKET_URL = "ws://localhost:8080" + NOTIFICATION_PATH;
WebSocketClient wsClient = new VertxWebSocketClient();
private BuildClient buildClient;
private BuildConfigurationClient buildConfigurationClient;

@BeforeClass
public static void startBPM() {
bpm = new BPMWireMock(8088);
}

@AfterClass
public static void stopBPM() throws IOException {
bpm.close();
}

@Before
public void beforeEach() throws ExecutionException, InterruptedException {
String token = KeycloakClient
Expand All @@ -95,17 +105,8 @@ public void beforeEach() throws ExecutionException, InterruptedException {
groupBuildClient = new GroupBuildClient(withBearerToken(token));
buildConfigurationClient = new BuildConfigurationClient(withBearerToken(token));

wsClient.connect(PNC_SOCKET_URL).get();

buildClient = new BuildClient(withBearerToken(token));
buildUtils = new BuildUtils(buildClient, new GroupBuildClient(withBearerToken(token)));
bpm = new BPMWireMock(8088);
}

@After
public void afterEach() throws IOException {
bpm.close();
wsClient.disconnect();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
import dasniko.testcontainers.keycloak.KeycloakContainer;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.pnc.integrationrex.setup.Deployments;
import org.jboss.pnc.integrationrex.setup.arquillian.AfterDeploy;
import org.jboss.pnc.integrationrex.setup.arquillian.AfterUnDeploy;
import org.jboss.pnc.integrationrex.setup.arquillian.BeforeDeploy;
import org.jboss.pnc.integrationrex.testcontainers.InfinispanContainer;
import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
import org.jboss.util.StringPropertyReplacer;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.Testcontainers;
Expand Down Expand Up @@ -73,34 +73,33 @@ public class RemoteServices {
authServerUrl = keycloakContainer.getAuthServerUrl();
}

@BeforeDeploy
public static void startContainers() throws IOException {
logger.info("Starting containers ...");
System.out.println("Starting containers");
startRemoteServices();
}

@Deployment(testable = false)
public static EnterpriseArchive deploy() throws IOException {
return Deployments.testEar();
}

@BeforeClass
public static void beforeAll() throws IOException {
logger.info("Starting containers ...");
startRemoteServices();
@AfterDeploy
public static void exposeHostPorts() {

// 8080 IS JBOSS CONTAINER
// 8088 IS BPM WIREMOCK MOCK
Testcontainers.exposeHostPorts(8080, 8088);
logger.info("Containers started.");
}

@AfterClass
public static void afterAll() throws InterruptedException {
@AfterUnDeploy
public static void stopContainers() throws InterruptedException {
logger.info("Stopping containers ...");
ispnContainer.stop();
rexContainer.stop();
logger.info("Containers stopped.");
Thread.sleep(1000L); // make sure all resources are released
}

@Before
public void w8() throws InterruptedException {
Thread.sleep(1000L);
}

private static Properties initTestProperties() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
import org.jboss.pnc.restclient.websocket.WebSocketClient;
import org.jboss.pnc.test.category.ContainerTest;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -77,14 +79,23 @@ public class WaitingBuildTest extends RemoteServices {
BuildUtils buildUtils;

private static final String PNC_SOCKET_URL = "ws://localhost:8080" + NOTIFICATION_PATH;
WebSocketClient wsClient = new VertxWebSocketClient();

private BPMWireMock bpm;
private final WebSocketClient wsClient = new VertxWebSocketClient();

@Before
public void beforeEach() throws ExecutionException, InterruptedException {
private static BPMWireMock bpm;

@BeforeClass
public static void startBPM() {
bpm = new BPMWireMock(8088);
}

@AfterClass
public static void stopBPM() throws IOException {
bpm.close();
}

@Before
public void beforeEach() throws ExecutionException, InterruptedException {
String token = KeycloakClient
.getAuthTokensBySecret(authServerUrl, keycloakRealm, "test-user", "test-pass", "pnc", "", false)
.getToken();
Expand All @@ -99,7 +110,6 @@ public void beforeEach() throws ExecutionException, InterruptedException {

@After
public void afterEach() throws IOException {
bpm.close();
wsClient.disconnect();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@
import org.jboss.pnc.restclient.websocket.WebSocketClient;
import org.jboss.pnc.test.category.ContainerTest;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -84,11 +86,20 @@ public class WebSocketClientTest extends RemoteServices {
private AdvancedBuildConfigurationClient buildConfigurationClient;
private AdvancedGroupConfigurationClient groupConfigurationClient;

private BuildTest.BPMWireMock bpm;
private static BuildTest.BPMWireMock bpm;

@BeforeClass
public static void startBPM() {
bpm = new BuildTest.BPMWireMock(8088);
}

@AfterClass
public static void stopBPM() throws IOException {
bpm.close();
}

@Before
public void beforeEach() {
bpm = new BuildTest.BPMWireMock(8088);
String token = KeycloakClient
.getAuthTokensBySecret(authServerUrl, keycloakRealm, "test-user", "test-pass", "pnc", "", false)
.getToken();
Expand All @@ -99,7 +110,6 @@ public void beforeEach() {

@After
public void afterEach() throws IOException {
bpm.close();
buildConfigurationClient.close();
groupConfigurationClient.close();
}
Expand Down Expand Up @@ -149,7 +159,7 @@ public void testBuildListener() throws Exception {
buildConfigurationClient.trigger(bc.getId(), new BuildParameters());

// then
Thread.sleep(1000);
Thread.sleep(500);
unsubscriber.run();
wsClient.disconnect().get();
assertThat(notificationCounter).hasValueGreaterThanOrEqualTo(1);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* JBoss, Home of Professional Open Source.
* Copyright 2014-2022 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.pnc.integrationrex.setup.arquillian;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Annotate methods that you want to trigger AFTER Orch EAP container finishes starting.
*
* Useful for running initialization tasks for Orch (functionally identical to @BeforeAll in JUnit)
*
* The method must be static.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface AfterDeploy {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* JBoss, Home of Professional Open Source.
* Copyright 2014-2022 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.pnc.integrationrex.setup.arquillian;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Annotate methods that you want to trigger AFTER Orch EAP container finishes (all tests in class are finished).
*
* Useful for stopping Orch's dependencies or cleaning of environment outside Arquillian.
*
* The method must be static.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface AfterUnDeploy {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* JBoss, Home of Professional Open Source.
* Copyright 2014-2022 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.pnc.integrationrex.setup.arquillian;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Annotate methods that you want to trigger BEFORE Arquillian starts to deploy Orch EAP.
*
* Useful for starting Orch's dependencies or preparing environment for EAP.
*
* The method must be static.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface BeforeDeploy {
}
Loading

0 comments on commit dca9935

Please sign in to comment.