From 8cbabde1f086795f7d31c6bf4fbf7c3b99e0ca60 Mon Sep 17 00:00:00 2001 From: Kabir Khan Date: Tue, 12 Mar 2024 11:24:33 +0000 Subject: [PATCH] [WFCORE-6728] Setup tasks to reload to a server stability level --- .../stability/StabilityServerSetupTasks.java | 21 +++++++- .../AbstractStabilityServerSetupTaskTest.java | 53 +++++++++++++++++++ ...StabilityCommunityServerSetupTestCase.java | 34 ++++++++++++ .../StabilityDefaultServerSetupTestCase.java | 35 ++++++++++++ ...bilityExperimentalServerSetupTestCase.java | 34 ++++++++++++ .../StabilityPreviewServerSetupTestCase.java | 34 ++++++++++++ 6 files changed, 209 insertions(+), 2 deletions(-) create mode 100644 testsuite/standalone/src/test/java/org/wildfly/core/test/standalone/stability/AbstractStabilityServerSetupTaskTest.java create mode 100644 testsuite/standalone/src/test/java/org/wildfly/core/test/standalone/stability/StabilityCommunityServerSetupTestCase.java create mode 100644 testsuite/standalone/src/test/java/org/wildfly/core/test/standalone/stability/StabilityDefaultServerSetupTestCase.java create mode 100644 testsuite/standalone/src/test/java/org/wildfly/core/test/standalone/stability/StabilityExperimentalServerSetupTestCase.java create mode 100644 testsuite/standalone/src/test/java/org/wildfly/core/test/standalone/stability/StabilityPreviewServerSetupTestCase.java diff --git a/testsuite/shared/src/main/java/org/wildfly/test/stability/StabilityServerSetupTasks.java b/testsuite/shared/src/main/java/org/wildfly/test/stability/StabilityServerSetupTasks.java index b0cd990aa4d..c0ac9448c5d 100644 --- a/testsuite/shared/src/main/java/org/wildfly/test/stability/StabilityServerSetupTasks.java +++ b/testsuite/shared/src/main/java/org/wildfly/test/stability/StabilityServerSetupTasks.java @@ -35,6 +35,8 @@ import java.util.Set; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.CORE_SERVICE; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.READ_OPERATION_DESCRIPTION_OPERATION; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.READ_OPERATION_NAMES_OPERATION; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RELOAD_ENHANCED; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.STABILITY; @@ -57,15 +59,23 @@ public StabilityServerSetupTasks(Stability desiredStability) { @Override public void setup(ManagementClient managementClient) throws Exception { + // Make sure the desired stability level is one of the ones supported by the server Set supportedStabilityLevels = getSupportedStabilityLevels(); Assume.assumeTrue( String.format("%s is not a supported stability level", desiredStability, supportedStabilityLevels), supportedStabilityLevels.contains(desiredStability)); + // Check the reload-enhanced operation exists in the current stability level Assume.assumeTrue( "The reload-enhanced operation is not registered at this stability level", checkReloadEnhancedOperationIsAvailable(managementClient)); + // Check the reload-enhanced operation exists in the stability level we want to load to so that + // we can reload back to the current one + Stability reloadOpStability = getReloadEnhancedOperationStabilityLevel(managementClient); + Assume.assumeTrue(desiredStability.enables(reloadOpStability)); + + // All good, let's do it! reloadToDesiredStability(managementClient.getControllerClient(), desiredStability); } @@ -85,6 +95,15 @@ private boolean checkReloadEnhancedOperationIsAvailable(ManagementClient managem return false; } + private Stability getReloadEnhancedOperationStabilityLevel(ManagementClient managementClient) throws Exception { + ModelNode op = Util.createOperation(READ_OPERATION_DESCRIPTION_OPERATION, PathAddress.EMPTY_ADDRESS); + op.get(NAME).set(RELOAD_ENHANCED); + + ModelNode result = ManagementOperations.executeOperation(managementClient.getControllerClient(), op); + String stability = result.get(STABILITY).asString(); + return Stability.fromString(stability); + + } private Set getSupportedStabilityLevels() { // TODO WFCORE-6731 - see https://github.com/wildfly/wildfly-core/pull/5895#discussion_r1520489808 // This information will be available in a management operation, For now just return a hardcoded set @@ -98,8 +117,6 @@ private Stability reloadToDesiredStability(ModelControllerClient client, Stabili originalStability = currentStability; } - // The stability parameter for the reload opration is only registered below the default level - Assume.assumeFalse("Can't reload to a different stability when server stability level is default", currentStability == Stability.DEFAULT && stability != Stability.DEFAULT); if (currentStability == stability) { return originalStability; diff --git a/testsuite/standalone/src/test/java/org/wildfly/core/test/standalone/stability/AbstractStabilityServerSetupTaskTest.java b/testsuite/standalone/src/test/java/org/wildfly/core/test/standalone/stability/AbstractStabilityServerSetupTaskTest.java new file mode 100644 index 00000000000..220fe12f3b7 --- /dev/null +++ b/testsuite/standalone/src/test/java/org/wildfly/core/test/standalone/stability/AbstractStabilityServerSetupTaskTest.java @@ -0,0 +1,53 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2024 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.wildfly.core.test.standalone.stability; + +import jakarta.inject.Inject; +import org.jboss.as.controller.PathAddress; +import org.jboss.as.controller.operations.common.Util; +import org.jboss.as.test.integration.management.ManagementOperations; +import org.jboss.as.version.Stability; +import org.jboss.dmr.ModelNode; +import org.junit.Assert; +import org.junit.Test; +import org.wildfly.core.testrunner.ManagementClient; + +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.CORE_SERVICE; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.STABILITY; +import static org.jboss.as.server.controller.descriptions.ServerDescriptionConstants.SERVER_ENVIRONMENT; + +public abstract class AbstractStabilityServerSetupTaskTest { + private final Stability desiredStability; + + @Inject + private ManagementClient managementClient; + + public AbstractStabilityServerSetupTaskTest(Stability desiredStability) { + this.desiredStability = desiredStability; + } + + @Test + public void testStabilityMatchesSetupTask() throws Exception { + ModelNode op = Util.getReadAttributeOperation(PathAddress.pathAddress(CORE_SERVICE, SERVER_ENVIRONMENT), STABILITY); + ModelNode result = ManagementOperations.executeOperation(managementClient.getControllerClient(), op); + Stability stability = Stability.fromString(result.asString()); + Assert.assertEquals(desiredStability, stability); + } +} diff --git a/testsuite/standalone/src/test/java/org/wildfly/core/test/standalone/stability/StabilityCommunityServerSetupTestCase.java b/testsuite/standalone/src/test/java/org/wildfly/core/test/standalone/stability/StabilityCommunityServerSetupTestCase.java new file mode 100644 index 00000000000..908f0967880 --- /dev/null +++ b/testsuite/standalone/src/test/java/org/wildfly/core/test/standalone/stability/StabilityCommunityServerSetupTestCase.java @@ -0,0 +1,34 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2024 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.wildfly.core.test.standalone.stability; + +import org.jboss.as.version.Stability; +import org.junit.runner.RunWith; +import org.wildfly.core.testrunner.ServerSetup; +import org.wildfly.core.testrunner.WildFlyRunner; +import org.wildfly.test.stability.StabilityServerSetupTasks; + +@ServerSetup(StabilityServerSetupTasks.Community.class) +@RunWith(WildFlyRunner.class) +public class StabilityCommunityServerSetupTestCase extends AbstractStabilityServerSetupTaskTest { + public StabilityCommunityServerSetupTestCase() { + super(Stability.COMMUNITY); + } +} diff --git a/testsuite/standalone/src/test/java/org/wildfly/core/test/standalone/stability/StabilityDefaultServerSetupTestCase.java b/testsuite/standalone/src/test/java/org/wildfly/core/test/standalone/stability/StabilityDefaultServerSetupTestCase.java new file mode 100644 index 00000000000..7f817551f29 --- /dev/null +++ b/testsuite/standalone/src/test/java/org/wildfly/core/test/standalone/stability/StabilityDefaultServerSetupTestCase.java @@ -0,0 +1,35 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2024 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.wildfly.core.test.standalone.stability; + +import org.jboss.as.version.Stability; +import org.junit.runner.RunWith; +import org.wildfly.core.testrunner.ServerSetup; +import org.wildfly.core.testrunner.WildFlyRunner; +import org.wildfly.test.stability.StabilityServerSetupTasks; + +@ServerSetup(StabilityServerSetupTasks.Default.class) +@RunWith(WildFlyRunner.class) +public class StabilityDefaultServerSetupTestCase extends AbstractStabilityServerSetupTaskTest { + public StabilityDefaultServerSetupTestCase() { + super(Stability.DEFAULT); + } + +} diff --git a/testsuite/standalone/src/test/java/org/wildfly/core/test/standalone/stability/StabilityExperimentalServerSetupTestCase.java b/testsuite/standalone/src/test/java/org/wildfly/core/test/standalone/stability/StabilityExperimentalServerSetupTestCase.java new file mode 100644 index 00000000000..ecbd1464336 --- /dev/null +++ b/testsuite/standalone/src/test/java/org/wildfly/core/test/standalone/stability/StabilityExperimentalServerSetupTestCase.java @@ -0,0 +1,34 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2024 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.wildfly.core.test.standalone.stability; + +import org.jboss.as.version.Stability; +import org.junit.runner.RunWith; +import org.wildfly.core.testrunner.ServerSetup; +import org.wildfly.core.testrunner.WildFlyRunner; +import org.wildfly.test.stability.StabilityServerSetupTasks; + +@ServerSetup(StabilityServerSetupTasks.Experimental.class) +@RunWith(WildFlyRunner.class) +public class StabilityExperimentalServerSetupTestCase extends AbstractStabilityServerSetupTaskTest { + public StabilityExperimentalServerSetupTestCase() { + super(Stability.EXPERIMENTAL); + } +} diff --git a/testsuite/standalone/src/test/java/org/wildfly/core/test/standalone/stability/StabilityPreviewServerSetupTestCase.java b/testsuite/standalone/src/test/java/org/wildfly/core/test/standalone/stability/StabilityPreviewServerSetupTestCase.java new file mode 100644 index 00000000000..26be97e0502 --- /dev/null +++ b/testsuite/standalone/src/test/java/org/wildfly/core/test/standalone/stability/StabilityPreviewServerSetupTestCase.java @@ -0,0 +1,34 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2024 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.wildfly.core.test.standalone.stability; + +import org.jboss.as.version.Stability; +import org.junit.runner.RunWith; +import org.wildfly.core.testrunner.ServerSetup; +import org.wildfly.core.testrunner.WildFlyRunner; +import org.wildfly.test.stability.StabilityServerSetupTasks; + +@ServerSetup(StabilityServerSetupTasks.Preview.class) +@RunWith(WildFlyRunner.class) +public class StabilityPreviewServerSetupTestCase extends AbstractStabilityServerSetupTaskTest { + public StabilityPreviewServerSetupTestCase() { + super(Stability.PREVIEW); + } +}