From 5f7cf2330fcb4b5de7002582be61fe2fcffb5c99 Mon Sep 17 00:00:00 2001 From: Tomaz Cerar Date: Mon, 26 Oct 2015 16:22:31 +0100 Subject: [PATCH] WFLY-5571 remove ModelPersistenceTestCase from full - reanable ManagementOnlyModeTestCase --- .../api/ManagementOnlyModeTestCase.java | 56 ++-- .../api/ModelPersistenceTestCase.java | 258 ------------------ 2 files changed, 26 insertions(+), 288 deletions(-) delete mode 100644 testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/management/api/ModelPersistenceTestCase.java diff --git a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/management/api/ManagementOnlyModeTestCase.java b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/management/api/ManagementOnlyModeTestCase.java index 5c561b312d01..c7ecd52899e2 100644 --- a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/management/api/ManagementOnlyModeTestCase.java +++ b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/management/api/ManagementOnlyModeTestCase.java @@ -21,38 +21,36 @@ */ package org.jboss.as.test.integration.management.api; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADMIN_ONLY; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.READ_ATTRIBUTE_OPERATION; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.REMOVE; +import static org.jboss.as.test.integration.management.util.ModelUtil.createOpNode; + import java.net.URL; import java.util.concurrent.Callable; + import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.as.test.integration.management.base.ContainerResourceMgmtTestBase; +import org.jboss.as.test.integration.management.util.WebUtil; +import org.jboss.as.test.shared.RetryTaskExecutor; import org.jboss.dmr.ModelNode; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; -import org.junit.Assert; -import static org.jboss.as.test.integration.management.util.ModelUtil.createOpNode; -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD; -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADMIN_ONLY; -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.READ_ATTRIBUTE_OPERATION; -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.REMOVE; -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME; - -import org.jboss.as.test.integration.management.base.ContainerResourceMgmtTestBase; -import org.jboss.as.test.integration.management.util.WebUtil; -import org.jboss.as.test.shared.RetryTaskExecutor; -import org.junit.Ignore; /** - * * @author Dominik Pospisil */ @RunWith(Arquillian.class) @RunAsClient -@Ignore("ARQ-791") public class ManagementOnlyModeTestCase extends ContainerResourceMgmtTestBase { @ArquillianResource @@ -75,20 +73,20 @@ public void testManagementOnlyMode() throws Exception { ModelNode result = executeOperation(op); // wait until the server is admin-only mode - RetryTaskExecutor rte = new RetryTaskExecutor(); + RetryTaskExecutor rte = new RetryTaskExecutor<>(); rte.retryTask(new Callable() { public ModelNode call() throws Exception { ModelNode rop = createOpNode(null, READ_ATTRIBUTE_OPERATION); rop.get(NAME).set("running-mode"); ModelNode mode = executeOperation(rop); - if (! mode.asString().equals("ADMIN_ONLY")) throw new Exception ("Wrong mode."); + if (!mode.asString().equals("ADMIN_ONLY")) { throw new Exception("Wrong mode."); } return mode; } }); // check that the server is unreachable - Assert.assertFalse("Could not connect to created connector.",WebUtil.testHttpURL(new URL( + Assert.assertFalse("Could not connect to created connector.", WebUtil.testHttpURL(new URL( "http", url.getHost(), url.getPort(), "/").toString())); // update the model in admin-only mode - add a web connector @@ -97,7 +95,7 @@ public ModelNode call() throws Exception { op.get("port").set(TEST_PORT); result = executeOperation(op); - op = createOpNode("subsystem=undertow/listener=test", ADD); + op = createOpNode("subsystem=undertow/server=default-server/http-listener=test", ADD); op.get("socket-binding").set("test-binding"); result = executeOperation(op); @@ -107,28 +105,26 @@ public ModelNode call() throws Exception { result = executeOperation(op); // wait until the server is in normal mode - rte = new RetryTaskExecutor(); - rte.retryTask(new Callable() { - public ModelNode call() throws Exception { - ModelNode rop = createOpNode(null, READ_ATTRIBUTE_OPERATION); - rop.get(NAME).set("running-mode"); - ModelNode mode = executeOperation(rop); - if (! mode.asString().equals("NORMAL")) throw new Exception ("Wrong mode."); - return mode; - } + rte = new RetryTaskExecutor<>(); + rte.retryTask(() -> { + ModelNode rop = createOpNode(null, READ_ATTRIBUTE_OPERATION); + rop.get(NAME).set("running-mode"); + ModelNode mode = executeOperation(rop); + if (!mode.asString().equals("NORMAL")) { throw new Exception("Wrong mode."); } + return mode; }); // check that the server is up - Assert.assertTrue("Could not connect to created connector.",WebUtil.testHttpURL(new URL( + Assert.assertTrue("Could not connect to created connector.", WebUtil.testHttpURL(new URL( "http", url.getHost(), url.getPort(), "/").toString())); // check that the changes made in admin-only mode have been applied - test the connector - Assert.assertTrue("Could not connect to created connector.",WebUtil.testHttpURL(new URL( + Assert.assertTrue("Could not connect to created connector.", WebUtil.testHttpURL(new URL( "http", url.getHost(), TEST_PORT, "/").toString())); // remove the conector - op = createOpNode("subsystem=undertow/listener=test", REMOVE); + op = createOpNode("subsystem=undertow/server=default-server/http-listener=test", REMOVE); result = executeOperation(op); op = createOpNode("socket-binding-group=standard-sockets/socket-binding=test-binding", REMOVE); result = executeOperation(op); diff --git a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/management/api/ModelPersistenceTestCase.java b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/management/api/ModelPersistenceTestCase.java deleted file mode 100644 index 45017a88038e..000000000000 --- a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/management/api/ModelPersistenceTestCase.java +++ /dev/null @@ -1,258 +0,0 @@ -/* - * JBoss, Home of Professional Open Source. - * Copyright 2011, Red Hat, Inc., and individual contributors - * as indicated by the @author tags. See the copyright.txt file in the - * distribution for a full listing of individual contributors. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package org.jboss.as.test.integration.management.api; - -import java.io.File; -import java.io.IOException; -import java.util.List; - -import org.apache.commons.io.FileUtils; -import org.jboss.arquillian.container.test.api.RunAsClient; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.as.test.integration.management.base.ContainerResourceMgmtTestBase; -import org.jboss.as.test.integration.management.util.MgmtOperationException; -import org.jboss.as.test.integration.management.util.ModelUtil; -import org.jboss.dmr.ModelNode; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -import static org.jboss.as.test.integration.management.util.ModelUtil.createOpNode; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -/** - * Tests both automated and manual configuration model persistence snapshot generation. - * - * @author Dominik Pospisil - */ -@RunWith(Arquillian.class) -@RunAsClient -public class ModelPersistenceTestCase extends ContainerResourceMgmtTestBase { - - private class CfgFileDescription { - - public CfgFileDescription(int version, File file, long hash) { - this.version = version; - this.file = file; - this.hash = hash; - } - - public int version; - public File file; - public long hash; - - } - - private static final String SERVER_CONFIG_DIR = System.getProperty("jboss.inst") + "/standalone/configuration"; - private static final String HISTORY_DIR = "standalone_xml_history"; - private static final String CURRENT_DIR = "current"; - - private static File configDir; - private static File currentCfgDir; - private static File lastCfgFile; - - - - @Before - public void before() throws IOException, MgmtOperationException { - - if (configDir == null) { - configDir = new File(SERVER_CONFIG_DIR); - assertTrue("Server config dir " + SERVER_CONFIG_DIR + " does not exists.", configDir.exists()); - assertTrue(configDir.isDirectory()); - currentCfgDir = new File(configDir, HISTORY_DIR + File.separatorChar + CURRENT_DIR); - - // get server configuration name - ModelNode op = createOpNode("core-service=server-environment", "read-attribute"); - op.get("name").set("config-file"); - ModelNode result = executeOperation(op); - String configFile = result.asString(); - String configFileName = new File(configFile).getName(); - assertTrue(configFileName.endsWith(".xml")); - configFileName = configFileName.substring(0, configFileName.length() - 4); - - lastCfgFile = new File(configDir, HISTORY_DIR + File.separator + configFileName + ".last.xml"); - } - - } - - @Test - public void testSimpleOperation() throws Exception { - - CfgFileDescription lastBackupDesc = getLatestBackup(currentCfgDir); - - long lastFileHash = lastCfgFile.exists() ? FileUtils.checksumCRC32(lastCfgFile) : -1; - - // execute operation so the model gets updated - ModelNode op = createOpNode("system-property=test", "add"); - op.get("value").set("test"); - executeOperation(op); - - // check that the automated snapshat has been generated - CfgFileDescription newBackupDesc = getLatestBackup(currentCfgDir); - assertNotNull("Model snapshot not found.", newBackupDesc); - // check that the version is incremented by one - assertTrue(lastBackupDesc.version == newBackupDesc.version - 1); - - // check that the last cfg file has changed - assertTrue(lastFileHash != FileUtils.checksumCRC32(lastCfgFile)); - - // remove testing attribute - op = createOpNode("system-property=test", "remove"); - executeOperation(op); - - // check that the snapshot has been updated again - lastBackupDesc = newBackupDesc; - newBackupDesc = getLatestBackup(currentCfgDir); - assertNotNull("Model snapshot not found.", newBackupDesc); - // check that the version is incremented by one - assertTrue(lastBackupDesc.version == newBackupDesc.version - 1); - } - - @Test - public void testCompositeOperation() throws Exception { - - CfgFileDescription lastBackupDesc = getLatestBackup(currentCfgDir); - - // execute composite operation - ModelNode[] steps = new ModelNode[2]; - steps[0] = createOpNode("system-property=test", "add"); - steps[0].get("value").set("test"); - steps[1] = createOpNode("system-property=test", "write-attribute"); - steps[1].get("name").set("value"); - steps[1].get("value").set("test2"); - executeOperation(ModelUtil.createCompositeNode(steps)); - - // check that the automated snapshat has been generated - CfgFileDescription newBackupDesc = getLatestBackup(currentCfgDir); - // check that the version is incremented by one - assertTrue(lastBackupDesc.version == newBackupDesc.version - 1); - - - // remove testing attribute - ModelNode op = createOpNode("system-property=test", "remove"); - executeOperation(op); - - // check that the snapshot has been updated again - lastBackupDesc = newBackupDesc; - - newBackupDesc = getLatestBackup(currentCfgDir); - assertNotNull("Model snapshot not found.", newBackupDesc); - // check that the version is incremented by one - assertTrue(lastBackupDesc.version == newBackupDesc.version - 1); - } - - @Test - public void testCompositeOperationRollback() throws Exception { - - CfgFileDescription lastBackupDesc = getLatestBackup(currentCfgDir); - - // execute operation so the model gets updated - ModelNode op = createOpNode("system-property=test", "add"); - op.get("value").set("test"); - executeAndRollbackOperation(op); - - // check that the model has not been updated - CfgFileDescription newBackupDesc = getLatestBackup(currentCfgDir); - assertNotNull("Model snapshot not found.", newBackupDesc); - - // check that the config did not change - assertTrue(lastBackupDesc.version == newBackupDesc.version); - assertTrue(lastBackupDesc.hash == newBackupDesc.hash); - - } - - - @Test - public void testTakeAndDeleteSnapshot() throws Exception { - - // take snapshot - - ModelNode op = createOpNode(null, "take-snapshot"); - ModelNode result = executeOperation(op); - - // check that the snapshot file exists - String snapshotFileName = result.asString(); - File snapshotFile = new File(snapshotFileName); - assertTrue(snapshotFile.exists()); - - // compare with current cfg - long snapshotHash = FileUtils.checksumCRC32(snapshotFile); - long lastHash = FileUtils.checksumCRC32(lastCfgFile); - assertTrue(snapshotHash == lastHash); - - // delete snapshot - op = createOpNode(null, "delete-snapshot"); - op.get("name").set(snapshotFile.getName()); - result = executeOperation(op); - - // check that the file is deleted - assertFalse("Snapshot file stil exists.", snapshotFile.exists()); - - } - - @Test - public void testListSnapshots() throws Exception { - - // take snapshot - ModelNode op = createOpNode(null, "take-snapshot"); - ModelNode result = executeOperation(op); - - // check that the snapshot file exists - String snapshotFileName = result.asString(); - File snapshotFile = new File(snapshotFileName); - assertTrue(snapshotFile.exists()); - - // get the snapshot listing - op = createOpNode(null, "list-snapshots"); - result = executeOperation(op); - File snapshotDir = new File(result.get("directory").asString()); - assertTrue(snapshotDir.isDirectory()); - - List snapshotNames = ModelUtil.modelNodeAsStingList(result.get("names")); - assertTrue(snapshotNames.contains(snapshotFile.getName())); - - } - - private CfgFileDescription getLatestBackup(File dir) throws IOException { - - int lastVersion = 0; - File lastFile = null; - - if (dir.isDirectory()) - for (File file : dir.listFiles()) { - - String fileName = file.getName(); - String[] nameParts = fileName.split("\\."); - if (!nameParts[0].contains("standalone")) continue; - if (!nameParts[2].equals("xml")) continue; - int version = Integer.valueOf(nameParts[1].substring(1)); - if (version > lastVersion) { - lastVersion = version; - lastFile = file; - } - } - return new CfgFileDescription(lastVersion, lastFile, (lastFile != null) ? FileUtils.checksumCRC32(lastFile) : 0); - } -}