Skip to content

Commit

Permalink
Merge pull request wildfly#17849 from kabir/WFLY-19286-reload-stabili…
Browse files Browse the repository at this point in the history
…ty-level-tasks

[WFLY-19286] Add ServerSetupTasks to reload server to a desired stabi…
  • Loading branch information
kabir authored May 17, 2024
2 parents d753479 + 60ce0bd commit a5cedd8
Show file tree
Hide file tree
Showing 6 changed files with 431 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/

package org.jboss.as.test.smoke.stability;

import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.CORE_SERVICE;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.STABILITY;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SYSTEM_PROPERTY;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.VALUE;
import static org.jboss.as.server.controller.descriptions.ServerDescriptionConstants.SERVER_ENVIRONMENT;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.arquillian.container.ManagementClient;
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.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;

public abstract class AbstractStabilityServerSetupTaskTest {
private final Stability desiredStability;

@ArquillianResource
private ManagementClient managementClient;

public AbstractStabilityServerSetupTaskTest(Stability desiredStability) {
this.desiredStability = desiredStability;
}

@Deployment
public static JavaArchive createDeployment() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "stability-test.jar");
jar.add(EmptyAsset.INSTANCE, "dummy.txt");
return jar;
}


@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);
}

@Test
public void testSystemPropertyWasSetByDoSetupCalls() throws Exception {
ModelNode read = Util.getReadAttributeOperation(PathAddress.pathAddress(SYSTEM_PROPERTY, AbstractStabilityServerSetupTaskTest.class.getName()), VALUE);
ModelNode result = ManagementOperations.executeOperation(managementClient.getControllerClient(), read);
Assert.assertEquals(this.getClass().getName(), result.asString());
}


protected static <T extends AbstractStabilityServerSetupTaskTest> void addSystemProperty(ManagementClient client, Class<T> clazz) throws Exception {
ModelNode add = Util.createAddOperation(PathAddress.pathAddress(SYSTEM_PROPERTY, AbstractStabilityServerSetupTaskTest.class.getName()));
add.get(VALUE).set(clazz.getName());
ManagementOperations.executeOperation(client.getControllerClient(), add);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/

package org.jboss.as.test.smoke.stability;

import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.version.Stability;
import org.junit.runner.RunWith;
import org.wildfly.test.stabilitylevel.StabilityServerSetupSnapshotRestoreTasks;

@ServerSetup(StabilityCommunityServerSetupTestCase.CommunityStabilitySetupTask.class)
@RunWith(Arquillian.class)
@RunAsClient
public class StabilityCommunityServerSetupTestCase extends AbstractStabilityServerSetupTaskTest {
public StabilityCommunityServerSetupTestCase() {
super(Stability.COMMUNITY);
}


public static class CommunityStabilitySetupTask extends StabilityServerSetupSnapshotRestoreTasks.Community {
@Override
protected void doSetup(ManagementClient managementClient) throws Exception {
// Not really needed since the resulting written xml will be of a higher stability level
// than the server. Still we are doing it for experimental preview, so it doesn't hurt to
// do the same here.
AbstractStabilityServerSetupTaskTest.addSystemProperty(managementClient, StabilityCommunityServerSetupTestCase.class);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/

package org.jboss.as.test.smoke.stability;

import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.version.Stability;
import org.junit.runner.RunWith;
import org.wildfly.test.stabilitylevel.StabilityServerSetupSnapshotRestoreTasks;

@ServerSetup(StabilityDefaultServerSetupTestCase.DefaultStabilitySetupTask.class)
@RunWith(Arquillian.class)
@RunAsClient
public class StabilityDefaultServerSetupTestCase extends AbstractStabilityServerSetupTaskTest {
public StabilityDefaultServerSetupTestCase() {
super(Stability.DEFAULT);
}

public static class DefaultStabilitySetupTask extends StabilityServerSetupSnapshotRestoreTasks.Default {
@Override
protected void doSetup(ManagementClient managementClient) throws Exception {
// Not really needed since the resulting written xml will be of a higher stability level
// than the server. Still we are doing it for experimental preview, so it doesn't hurt to
// do the same here.
AbstractStabilityServerSetupTaskTest.addSystemProperty(managementClient, StabilityDefaultServerSetupTestCase.class);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/

package org.jboss.as.test.smoke.stability;

import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.version.Stability;
import org.junit.runner.RunWith;
import org.wildfly.test.stabilitylevel.StabilityServerSetupSnapshotRestoreTasks;

@ServerSetup(StabilityExperimentalServerSetupTestCase.ExperimentalStabilitySetupTask.class)
@RunWith(Arquillian.class)
@RunAsClient
public class StabilityExperimentalServerSetupTestCase extends AbstractStabilityServerSetupTaskTest {
public StabilityExperimentalServerSetupTestCase() {
super(Stability.EXPERIMENTAL);
}


public static class ExperimentalStabilitySetupTask extends StabilityServerSetupSnapshotRestoreTasks.Experimental {
@Override
protected void doSetup(ManagementClient managementClient) throws Exception {
// Write a system property so the model ges stored with a lower stability level.
// This is to make sure we can reload back to the higher level from the snapshot
AbstractStabilityServerSetupTaskTest.addSystemProperty(managementClient, StabilityExperimentalServerSetupTestCase.class);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/

package org.jboss.as.test.smoke.stability;

import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.version.Stability;
import org.junit.runner.RunWith;
import org.wildfly.test.stabilitylevel.StabilityServerSetupSnapshotRestoreTasks;

@ServerSetup(StabilityPreviewServerSetupTestCase.PreviewStabilitySetupTask.class)
@RunWith(Arquillian.class)
@RunAsClient
public class StabilityPreviewServerSetupTestCase extends AbstractStabilityServerSetupTaskTest {
public StabilityPreviewServerSetupTestCase() {
super(Stability.PREVIEW);
}


public static class PreviewStabilitySetupTask extends StabilityServerSetupSnapshotRestoreTasks.Preview {
@Override
protected void doSetup(ManagementClient managementClient) throws Exception {
// Write a system property so the model ges stored with a lower stability level.
// This is to make sure we can reload back to the higher level from the snapshot
AbstractStabilityServerSetupTaskTest.addSystemProperty(managementClient, StabilityPreviewServerSetupTestCase.class);
}
}

}
Loading

0 comments on commit a5cedd8

Please sign in to comment.