[jboss-cvs] JBossAS SVN: r93933 - in branches/JBPAPP_5_0: testsuite/src/main/org/jboss/test/deployers/test and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Sep 22 13:45:31 EDT 2009
Author: emuckenhuber
Date: 2009-09-22 13:45:31 -0400 (Tue, 22 Sep 2009)
New Revision: 93933
Added:
branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/deployers/test/AbstractDeployTestBase.java
Modified:
branches/JBPAPP_5_0/system/src/main/org/jboss/system/server/profileservice/repository/BasicDeploymentRepository.java
branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/deployers/test/DeploymentManagerUnitTestCase.java
Log:
[JBPAPP-2656]
Modified: branches/JBPAPP_5_0/system/src/main/org/jboss/system/server/profileservice/repository/BasicDeploymentRepository.java
===================================================================
--- branches/JBPAPP_5_0/system/src/main/org/jboss/system/server/profileservice/repository/BasicDeploymentRepository.java 2009-09-22 17:33:06 UTC (rev 93932)
+++ branches/JBPAPP_5_0/system/src/main/org/jboss/system/server/profileservice/repository/BasicDeploymentRepository.java 2009-09-22 17:45:31 UTC (rev 93933)
@@ -278,8 +278,8 @@
if(deleteFile && root != null)
{
- // Delete the file
- if(root.delete() == false)
+ // Delete the file, fail if it can't be deleted and still exists
+ if(root.delete() == false && root.exists())
throw new IOException("Failed to delete: " + root);
cleanUpRoot(root);
Added: branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/deployers/test/AbstractDeployTestBase.java
===================================================================
--- branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/deployers/test/AbstractDeployTestBase.java (rev 0)
+++ branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/deployers/test/AbstractDeployTestBase.java 2009-09-22 17:45:31 UTC (rev 93933)
@@ -0,0 +1,276 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.test.deployers.test;
+
+import javax.naming.InitialContext;
+
+import org.jboss.deployers.spi.management.ManagementView;
+import org.jboss.deployers.spi.management.deploy.DeploymentID;
+import org.jboss.deployers.spi.management.deploy.DeploymentManager;
+import org.jboss.deployers.spi.management.deploy.DeploymentProgress;
+import org.jboss.managed.api.DeploymentState;
+import org.jboss.managed.api.ManagedDeployment;
+import org.jboss.profileservice.spi.DeploymentOption;
+import org.jboss.profileservice.spi.NoSuchDeploymentException;
+import org.jboss.profileservice.spi.ProfileKey;
+import org.jboss.profileservice.spi.ProfileService;
+import org.jboss.test.JBossTestCase;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public abstract class AbstractDeployTestBase extends JBossTestCase
+{
+
+ /** A basic failing deployment. */
+ final static String FAILING_DEPLOYMENT = "deployers-failing-jboss-beans.xml";
+ /** A empty deployment, this will deploy ok. */
+ final static String EMTPY_DEPLOYMENT = "deployers-empty-jboss-beans.xml";
+ /** A simple nested deployment. */
+ final static String NESTED_DEPLOYMENT = "profileservice-datasource.ear";
+
+ /** The deployers target profile. */
+ final static ProfileKey deployersKey = new ProfileKey("deployers");
+
+ /** The deployment manager. */
+ private DeploymentManager deployMgr;
+ /** The management view. */
+ private ManagementView mgtView;
+
+ public AbstractDeployTestBase(String name)
+ {
+ super(name);
+ }
+
+ void deployFailed(boolean isCopyContent) throws Exception
+ {
+ DeploymentProgress start = distributeAndStart(FAILING_DEPLOYMENT, isCopyContent);
+ assertFailed(start);
+ assertDeploymentState(start.getDeploymentID(), DeploymentState.FAILED);
+ }
+
+ void deployEmpty(boolean isCopyContent) throws Exception
+ {
+ DeploymentProgress start = distributeAndStart(EMTPY_DEPLOYMENT, isCopyContent);
+ assertComplete(start);
+ assertDeploymentState(start.getDeploymentID(), DeploymentState.STARTED);
+ }
+
+ DeploymentProgress distributeAndStart(String deploymentName, boolean copyContent) throws Exception
+ {
+ return distributeAndStart(deploymentName, copyContent, true);
+ }
+
+ DeploymentProgress distributeAndStart(String deploymentName, boolean copyContent, boolean checkStopped) throws Exception
+ {
+ return distributeAndStart(deploymentName, deploymentName, copyContent, true);
+ }
+
+ /**
+ * Distribute and start a deployment.
+ *
+ * @param deployment the deployment
+ * @param deploymentName the new (server side) deployment name
+ * @param copyContent is copyContent
+ * @param checkStopped check the if the deployment is stopped after distribute
+ * @return the DeploymentProgress of the start operation
+ * @throws Exception
+ */
+ DeploymentProgress distributeAndStart(String deployment, String deploymentName, boolean copyContent, boolean checkStopped) throws Exception
+ {
+ // The deployment manager
+ DeploymentManager deployMgr = getDeploymentManager();
+
+ // Distribute
+ DeploymentProgress distribute = deployMgr.distribute(deploymentName,
+ getDeployURL(deployment), copyContent);
+ distribute.run();
+ // Distribute always has to complete
+ assertComplete(distribute);
+ // check if the app is stopped
+ if(checkStopped)
+ assertDeploymentState(distribute.getDeploymentID(), DeploymentState.STOPPED);
+
+ // Get the repository names
+ String[] uploadedNames = distribute.getDeploymentID().getRepositoryNames();
+ assertNotNull(uploadedNames);
+
+ // Start
+ DeploymentProgress start = deployMgr.start(uploadedNames);
+ start.run();
+ // Return the start deployment progress
+ return start;
+ }
+
+ DeploymentProgress distributeAndStart(String deploymentName, DeploymentOption... options) throws Exception
+ {
+ return distributeAndStart(deploymentName, deploymentName, options);
+ }
+
+ /**
+ * Distribute and start a deployment
+ *
+ * @param deployment the deployment
+ * @param deploymentName the new (server side) deployment name
+ * @param options the deployment options
+ * @return the DeploymentProgress of the start operation
+ * @throws Exception
+ */
+ DeploymentProgress distributeAndStart(String deployment, String deploymentName, DeploymentOption... options) throws Exception
+ {
+ // The deployment manager
+ DeploymentManager deployMgr = getDeploymentManager();
+
+ // Distribute
+ DeploymentProgress distribute = deployMgr.distribute(deploymentName,
+ getDeployURL(deployment), options);
+ distribute.run();
+ // Distribute always has to complete
+ assertComplete(distribute);
+ // check if the app is stopped
+ assertDeploymentState(distribute.getDeploymentID(), DeploymentState.STOPPED);
+
+ // Get the repository names
+ String[] uploadedNames = distribute.getDeploymentID().getRepositoryNames();
+ assertNotNull(uploadedNames);
+
+ // Start
+ DeploymentProgress start = deployMgr.start(uploadedNames);
+ start.run();
+ // Return the start deployment progress
+ return start;
+ }
+
+ void redeployCheckComplete(String name) throws Exception
+ {
+ // The deployment manager
+ DeploymentManager deployMgr = getDeploymentManager();
+
+ // Redeploy
+ DeploymentProgress redeploy = deployMgr.redeploy(name);
+ redeploy.run();
+ assertComplete(redeploy);
+ assertDeploymentState(redeploy.getDeploymentID(), DeploymentState.STARTED);
+ }
+
+ void prepareCheckComplete(String name) throws Exception
+ {
+ // The deployment manager
+ DeploymentManager deployMgr = getDeploymentManager();
+
+ // Prepare
+ DeploymentProgress prepare = deployMgr.prepare(name);
+ prepare.run();
+ assertComplete(prepare);
+ }
+
+ void stopAndRemove(String[] names) throws Exception
+ {
+ // The deployment manager
+ DeploymentManager deployMgr = getDeploymentManager();
+
+ try
+ {
+ DeploymentProgress stop = deployMgr.stop(names);
+ stop.run();
+ assertComplete(stop);
+ assertDeploymentState(stop.getDeploymentID(), DeploymentState.STOPPED);
+ }
+ catch(Exception e)
+ {
+ log.debug("stopAndRemove Failed ", e);
+ throw e;
+ }
+ finally
+ {
+ DeploymentProgress remove = deployMgr.remove(names);
+ remove.run();
+ assertComplete(remove);
+
+ String name = remove.getDeploymentID().getNames()[0];
+ ManagementView mgtView = getManagementView();
+ try
+ {
+ mgtView.getDeployment(name);
+ fail("Did not see NoSuchDeploymentException");
+ }
+ catch(NoSuchDeploymentException ok)
+ {
+ //
+ }
+ }
+ }
+
+ void assertFailed(DeploymentProgress progress) throws Exception
+ {
+ assertFalse(progress.getDeploymentStatus().isCompleted());
+ assertTrue(progress.getDeploymentStatus().isFailed());
+ }
+
+ void assertDeploymentState(DeploymentID DtID, DeploymentState state) throws Exception
+ {
+ String name = DtID.getNames()[0];
+ ManagementView mgtView = getManagementView();
+ ManagedDeployment md = mgtView.getDeployment(name);
+ assertNotNull(name, md);
+ assertEquals("deployment: " + name, state, md.getDeploymentState());
+ log.debug(md.getSimpleName() + " " + md.getTypes());
+ }
+
+ void assertComplete(DeploymentProgress progress) throws Exception
+ {
+ if(progress.getDeploymentStatus().isFailed())
+ {
+ throw new RuntimeException("deployment failed.", progress.getDeploymentStatus().getFailure());
+ }
+ //
+ assertTrue(progress.getDeploymentStatus().isCompleted());
+ }
+
+ DeploymentManager getDeploymentManager() throws Exception
+ {
+ if(this.deployMgr == null)
+ {
+ this.deployMgr = getProfileService().getDeploymentManager();
+ }
+ return deployMgr;
+ }
+
+ ManagementView getManagementView() throws Exception
+ {
+ if(this.mgtView == null)
+ {
+ this.mgtView = getProfileService().getViewManager();
+ }
+ this.mgtView.load();
+ return this.mgtView;
+ }
+
+ ProfileService getProfileService() throws Exception
+ {
+ InitialContext ctx = getInitialContext();
+ return (ProfileService) ctx.lookup("ProfileService");
+ }
+
+}
+
Modified: branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/deployers/test/DeploymentManagerUnitTestCase.java
===================================================================
--- branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/deployers/test/DeploymentManagerUnitTestCase.java 2009-09-22 17:33:06 UTC (rev 93932)
+++ branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/deployers/test/DeploymentManagerUnitTestCase.java 2009-09-22 17:45:31 UTC (rev 93933)
@@ -24,13 +24,10 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
+import java.net.URI;
import java.util.Collection;
-import javax.naming.InitialContext;
-
import org.jboss.deployers.spi.management.ManagementView;
-import org.jboss.deployers.spi.management.deploy.DeploymentID;
-import org.jboss.deployers.spi.management.deploy.DeploymentManager;
import org.jboss.deployers.spi.management.deploy.DeploymentProgress;
import org.jboss.managed.api.ComponentType;
import org.jboss.managed.api.DeploymentState;
@@ -41,8 +38,8 @@
import org.jboss.profileservice.spi.DeploymentOption;
import org.jboss.profileservice.spi.NoSuchDeploymentException;
import org.jboss.profileservice.spi.ProfileKey;
-import org.jboss.profileservice.spi.ProfileService;
-import org.jboss.test.JBossTestCase;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
/**
* Basic DeploymentManager test.
@@ -50,24 +47,12 @@
* @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
* @version $Revision$
*/
-public class DeploymentManagerUnitTestCase extends JBossTestCase
+public class DeploymentManagerUnitTestCase extends AbstractDeployTestBase
{
- /** A basic failing deployment. */
- final static String FAILING_DEPLOYMENT = "deployers-failing-jboss-beans.xml";
- /** A empty deployment, this will deploy ok. */
- final static String EMTPY_DEPLOYMENT = "deployers-empty-jboss-beans.xml";
- /** A simple nested deployment. */
- final static String NESTED_DEPLOYMENT = "profileservice-datasource.ear";
- /** A deployment picked up by the HDScanner. */
- final static String HD_DEPLOYMENT = "hd-jboss-beans.xml";
- /** The deployers target profile. */
- final static ProfileKey deployersKey = new ProfileKey("deployers");
-
- /** The deployment manager. */
- private DeploymentManager deployMgr;
- private ManagementView mgtView;
-
+ /** A deployment picked up by the HDScanner. */
+ private final static String HD_DEPLOYMENT = "hd-jboss-beans.xml";
+
public DeploymentManagerUnitTestCase(String name)
{
super(name);
@@ -95,21 +80,22 @@
*/
public void testDistributeOverride() throws Exception
{
+ final String deploymentName = getName() + ".ear";
try
{
for(int i = 0; i < 5; i++)
{
//
- DeploymentProgress start = distributeAndStart(NESTED_DEPLOYMENT, true, false);
+ DeploymentProgress start = distributeAndStart(NESTED_DEPLOYMENT, deploymentName, true, false);
assertComplete(start);
// disable stopped check, as it was started before
- start = distributeAndStart(NESTED_DEPLOYMENT, true, false);
+ start = distributeAndStart(NESTED_DEPLOYMENT, deploymentName, true, false);
assertComplete(start);
Thread.sleep(5);
- redeployCheckComplete(NESTED_DEPLOYMENT);
+ redeployCheckComplete(deploymentName);
}
}
catch(Exception e)
@@ -117,7 +103,7 @@
log.debug("Failed ", e);
throw e;
}
- stopAndRemove(new String[] { NESTED_DEPLOYMENT });
+ stopAndRemove(new String[] { deploymentName });
}
/**
@@ -183,14 +169,15 @@
*/
public void testDeploymentOptions() throws Exception
{
+ final String deploymentName = getName() + ".ear";
try
{
// Test exploded
- distributeAndStart(NESTED_DEPLOYMENT,
+ distributeAndStart(NESTED_DEPLOYMENT, deploymentName,
new DeploymentOption[] { DeploymentOption.Explode});
- // Test fail if exsits
- DeploymentProgress override = getDeploymentManager().distribute(NESTED_DEPLOYMENT,
+ // Test fail if exists
+ DeploymentProgress override = getDeploymentManager().distribute(deploymentName,
getDeployURL(NESTED_DEPLOYMENT),
new DeploymentOption[] { DeploymentOption.FailIfExists});
override.run();
@@ -201,7 +188,7 @@
log.error("Failed ", e);
throw e;
}
- stopAndRemove(new String[] { NESTED_DEPLOYMENT } );
+ stopAndRemove(new String[] { deploymentName } );
}
/**
@@ -238,6 +225,39 @@
}
/**
+ * Test some conflicts when deleting a file manually.
+ * This distributes a deployment into the deployers folder,
+ * where we don't perform HDScanning. We delete the file
+ * manually and then try to remove this file with the
+ * DeploymentManager.
+ *
+ * @throws Exception
+ */
+ public void testRemoveConflict() throws Exception
+ {
+ final String deploymentName = getName() + ".ear";
+ getDeploymentManager().loadProfile(deployersKey);
+ try
+ {
+ DeploymentProgress start = distributeAndStart(NESTED_DEPLOYMENT, deploymentName, true, false);
+ String deployed = start.getDeploymentID().getRepositoryNames()[0];
+
+ // Delete the file manually
+ VFS.init();
+ VirtualFile f = VFS.getRoot(new URI(deployed));
+ assertTrue(deployed, f.exists());
+ assertTrue("deleted " + deployed, f.delete());
+
+ stopAndRemove(new String[] { deploymentName });
+ }
+ finally
+ {
+ // Make sure that we release the profile
+ getDeploymentManager().releaseProfile();
+ }
+ }
+
+ /**
* Test the hd deployment. This deployment will get copied
* to the deploy folder after the server is started. This
* deployment needs to get picked up by the HDScanner and
@@ -259,7 +279,7 @@
// Manually copy the deployment
File output = copyFile(new File(homeDir, "deploy/"), HD_DEPLOYMENT);
// Wait for HDScanner
- Thread.sleep(10000);
+ Thread.sleep(8000);
// Reload mgtView
mgtView = getManagementView();
@@ -269,7 +289,7 @@
output.delete();
// Wait for HDScanner
- Thread.sleep(10000);
+ Thread.sleep(8000);
try
{
getManagementView().getDeployment(HD_DEPLOYMENT);
@@ -310,186 +330,5 @@
}
return output;
}
-
- void deployFailed(boolean isCopyContent) throws Exception
- {
- DeploymentProgress start = distributeAndStart(FAILING_DEPLOYMENT, isCopyContent);
- assertFailed(start);
- assertDeploymentState(start.getDeploymentID(), DeploymentState.FAILED);
- }
- void deployEmpty(boolean isCopyContent) throws Exception
- {
- DeploymentProgress start = distributeAndStart(EMTPY_DEPLOYMENT, isCopyContent);
- assertComplete(start);
- assertDeploymentState(start.getDeploymentID(), DeploymentState.STARTED);
- }
-
- DeploymentProgress distributeAndStart(String deploymentName, boolean copyContent) throws Exception
- {
- return distributeAndStart(deploymentName, copyContent, true);
- }
-
- DeploymentProgress distributeAndStart(String deploymentName, boolean copyContent, boolean checkStopped) throws Exception
- {
- // The deployment manager
- DeploymentManager deployMgr = getDeploymentManager();
-
- // Distribute
- DeploymentProgress distribute = deployMgr.distribute(deploymentName,
- getDeployURL(deploymentName), copyContent);
- distribute.run();
- // Distribute always has to complete
- assertComplete(distribute);
- // check if the app is stopped
- if(checkStopped)
- assertDeploymentState(distribute.getDeploymentID(), DeploymentState.STOPPED);
-
- // Get the repository names
- String[] uploadedNames = distribute.getDeploymentID().getRepositoryNames();
- assertNotNull(uploadedNames);
-
- // Start
- DeploymentProgress start = deployMgr.start(uploadedNames);
- start.run();
- // Return the start deployment progress
- return start;
- }
-
- DeploymentProgress distributeAndStart(String deploymentName, DeploymentOption... options) throws Exception
- {
- // The deployment manager
- DeploymentManager deployMgr = getDeploymentManager();
-
- // Distribute
- DeploymentProgress distribute = deployMgr.distribute(deploymentName,
- getDeployURL(deploymentName), options);
- distribute.run();
- // Distribute always has to complete
- assertComplete(distribute);
- // check if the app is stopped
- assertDeploymentState(distribute.getDeploymentID(), DeploymentState.STOPPED);
-
- // Get the repository names
- String[] uploadedNames = distribute.getDeploymentID().getRepositoryNames();
- assertNotNull(uploadedNames);
-
- // Start
- DeploymentProgress start = deployMgr.start(uploadedNames);
- start.run();
- // Return the start deployment progress
- return start;
- }
-
- void redeployCheckComplete(String name) throws Exception
- {
- // The deployment manager
- DeploymentManager deployMgr = getDeploymentManager();
-
- // Redeploy
- DeploymentProgress redeploy = deployMgr.redeploy(name);
- redeploy.run();
- assertComplete(redeploy);
- assertDeploymentState(redeploy.getDeploymentID(), DeploymentState.STARTED);
- }
-
- void prepareCheckComplete(String name) throws Exception
- {
- // The deployment manager
- DeploymentManager deployMgr = getDeploymentManager();
-
- // Prepare
- DeploymentProgress prepare = deployMgr.prepare(name);
- prepare.run();
- assertComplete(prepare);
- }
-
- void stopAndRemove(String[] names) throws Exception
- {
- // The deployment manager
- DeploymentManager deployMgr = getDeploymentManager();
-
- try
- {
- DeploymentProgress stop = deployMgr.stop(names);
- stop.run();
- assertComplete(stop);
- assertDeploymentState(stop.getDeploymentID(), DeploymentState.STOPPED);
- }
- catch(Exception e)
- {
- log.debug("stopAndRemove Failed ", e);
- throw e;
- }
- finally
- {
- DeploymentProgress remove = deployMgr.remove(names);
- remove.run();
- assertComplete(remove);
-
- String name = remove.getDeploymentID().getNames()[0];
- ManagementView mgtView = getManagementView();
- try
- {
- mgtView.getDeployment(name);
- fail("Did not see NoSuchDeploymentException");
- }
- catch(NoSuchDeploymentException ok)
- {
- //
- }
- }
- }
-
- void assertFailed(DeploymentProgress progress) throws Exception
- {
- assertFalse(progress.getDeploymentStatus().isCompleted());
- assertTrue(progress.getDeploymentStatus().isFailed());
- }
-
- void assertDeploymentState(DeploymentID DtID, DeploymentState state) throws Exception
- {
- String name = DtID.getNames()[0];
- ManagementView mgtView = getManagementView();
- ManagedDeployment md = mgtView.getDeployment(name);
- assertNotNull(name, md);
- assertEquals("deployment: " + name, state, md.getDeploymentState());
- log.debug(md.getSimpleName() + " " + md.getTypes());
- }
-
- void assertComplete(DeploymentProgress progress) throws Exception
- {
- if(progress.getDeploymentStatus().isFailed())
- {
- throw new RuntimeException("deployment failed.", progress.getDeploymentStatus().getFailure());
- }
- //
- assertTrue(progress.getDeploymentStatus().isCompleted());
- }
-
- DeploymentManager getDeploymentManager() throws Exception
- {
- if(this.deployMgr == null)
- {
- this.deployMgr = getProfileService().getDeploymentManager();
- }
- return deployMgr;
- }
-
- ManagementView getManagementView() throws Exception
- {
- if(this.mgtView == null)
- {
- this.mgtView = getProfileService().getViewManager();
- }
- this.mgtView.load();
- return this.mgtView;
- }
-
- ProfileService getProfileService() throws Exception
- {
- InitialContext ctx = getInitialContext();
- return (ProfileService) ctx.lookup("ProfileService");
- }
-
}
More information about the jboss-cvs-commits
mailing list