Skip to content

Commit

Permalink
Maybe fix JDBC tests
Browse files Browse the repository at this point in the history
  • Loading branch information
michalxo committed Oct 18, 2024
1 parent 4af414e commit 2c333a4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,17 @@ public static ArtemisCloudClusterOperator getArtemisClusterOperator(String names
* ActiveMQArtemis Usage of generated typed API
******************************************************************************************************************/

public static long calculateWaitTime(ActiveMQArtemis artemisBroker) {
long waitTime = Constants.DURATION_1_MINUTE + Constants.DURATION_30_SECONDS;
if (artemisBroker.getSpec() != null && artemisBroker.getSpec().getDeploymentPlan() != null && artemisBroker.getSpec().getDeploymentPlan().getSize() != null) {
int size = artemisBroker.getSpec().getDeploymentPlan().getSize();
if (size > 1) {
waitTime += Constants.DURATION_1_MINUTE * size;
}
}
return waitTime;
}

public static ActiveMQArtemis createArtemis(String namespace, String name) {
return createArtemis(namespace, name, 1);
}
Expand Down Expand Up @@ -254,12 +265,7 @@ public static ActiveMQArtemis createArtemis(String namespace, String name, int s
.endConsole()
.endSpec()
.build();

long waitTime = Constants.DURATION_1_MINUTE + Constants.DURATION_30_SECONDS;
if (size > 1) {
waitTime += Constants.DURATION_1_MINUTE * size;
}
return createArtemis(namespace, broker, true, waitTime);
return createArtemis(namespace, broker, true, calculateWaitTime(broker));
}

public static ActiveMQArtemis createArtemis(String namespace, Path filePath) {
Expand Down Expand Up @@ -313,11 +319,11 @@ public static ActiveMQArtemis updateArtemis(ActiveMQArtemis broker, boolean rest
}

public static void deleteArtemis(ActiveMQArtemis broker) {
deleteArtemis(broker.getMetadata().getNamespace(), broker, true, Constants.DURATION_1_MINUTE);
deleteArtemis(broker.getMetadata().getNamespace(), broker, true, calculateWaitTime(broker));
}

public static void deleteArtemis(String namespace, ActiveMQArtemis broker) {
deleteArtemis(namespace, broker, true, Constants.DURATION_1_MINUTE);
deleteArtemis(namespace, broker, true, calculateWaitTime(broker));
}

public static void deleteArtemis(String namespace, ActiveMQArtemis broker, boolean waitForDeletion, long maxTimeout) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.fabric8.kubernetes.api.model.apps.StatefulSet;
import io.fabric8.kubernetes.api.model.apps.StatefulSetBuilder;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
Expand Down Expand Up @@ -63,6 +64,13 @@ void teardownClusterOperator() {
ResourceManager.deleteArtemis(testNamespace, broker);
teardownDefaultClusterOperator(testNamespace);
postgres.undeployPostgres();

}

@AfterEach
void undeployBrokerWithDB() {
ResourceManager.deleteArtemis(testNamespace, broker);
getClient().deleteSecret(testNamespace, LOGGER_SECRET_NAME);
}

protected void deployPostgres() {
Expand Down Expand Up @@ -137,11 +145,6 @@ void deployBrokerWithDB(int brokerSize, boolean waitForDeployment) {
ResourceManager.createArtemis(testNamespace, broker, waitForDeployment, Constants.DURATION_3_MINUTES);
}

void undeployBrokerWithDB() {
ResourceManager.deleteArtemis(testNamespace, broker);
getClient().deleteSecret(testNamespace, LOGGER_SECRET_NAME);
}

@Test
void testSingleBrokerMessaging() {
deployBrokerWithDB(1, true);
Expand All @@ -166,7 +169,6 @@ void testSingleBrokerMessaging() {
assertThat("Send & received messages are not same!", sent, equalTo(recv));

ResourceManager.deleteArtemisAddress(testNamespace, myAddress);
undeployBrokerWithDB();
}

@Test
Expand Down Expand Up @@ -213,12 +215,10 @@ void testJdbcLock() {
LOGGER.info("[{}] Delete pod 0 and check DB lock on pod 1", testNamespace);
getClient().deletePod(testNamespace, getClient().getPod(testNamespace, brokerName + "-ss-0"), false);
TestUtils.threadSleep(Constants.DURATION_5_SECONDS);
TestUtils.waitFor(acquiredLockLog + " to show up", Constants.DURATION_5_SECONDS, Constants.DURATION_2_MINUTES, () -> {
TestUtils.waitFor(acquiredLockLog + " to show up on " + brokerName + "-ss-1", Constants.DURATION_5_SECONDS, Constants.DURATION_2_MINUTES, () -> {
Pod brokerPod1 = getClient().getPod(testNamespace, brokerName + "-ss-1");
return getClient().getLogsFromPod(brokerPod1).contains(acquiredLockLog);
});

undeployBrokerWithDB();
}

}

0 comments on commit 2c333a4

Please sign in to comment.