package org.jboss.jopr.jsfunit.as5.ps;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import java.util.Set;
import org.jboss.deployers.spi.management.ManagementView;
import org.jboss.deployers.spi.management.deploy.DeploymentManager;
import org.jboss.deployers.spi.management.deploy.DeploymentProgress;
import org.jboss.deployers.spi.management.deploy.DeploymentStatus;
import org.jboss.logging.Logger;
import org.jboss.managed.api.ManagedDeployment;
import org.jboss.deployers.spi.management.deploy.ProgressListener;
import org.jboss.jopr.jsfunit.AppConstants;
import org.jboss.jopr.jsfunit.exceptions.EmbJoprTestException;
/**
* Mostly copied from
* jboss-as-5.x/testsuite/src/main/org/jboss/test/profileservice/test
*/
public class RepeatedDeploymentViaPSTest extends ProfileServiceTestUtils implements ProgressListener {
public void testRepeatedDeploymentViaProfileService() throws Exception {
final String DEPLOYABLE_NAME = AppConstants.BASIC_EAR;
int TURNS = 100;
String earFilePath = ejtt.getTestDataDir() + "/ear/"+DEPLOYABLE_NAME;
for (int i = TURNS; i > 0; i--) {
log.info("Remaining EAR deploys: "+i);
// Deploy and undeploy the EAR.
doDeployment(earFilePath, "ear", null);
}
}
public void progressEvent(org.jboss.deployers.spi.management.deploy.ProgressEvent eventInfo) {
getLog().debug(eventInfo);
}
public URL getDeployURL( String file ) throws MalformedURLException{
return new URL("file:///"+ System.getProperty(AppConstants.SYSPROP_DEPLOY_DIR)+'/'+file );
}
protected final Logger log = Logger.getLogger(this.getClass().getName());
Logger getLog(){ return log; }
@SuppressWarnings("deprecation")
protected void doDeployment(String name, String type, ManagedDeploymentTester tester) throws Exception
{
DeploymentManager deployMgr = getDeploymentManager();
URL contentURL = getDeployURL(name);
assertNotNull(contentURL);
getLog().debug(contentURL);
// TODO - hack to get off JDK's url handling
String urlString = contentURL.toExternalForm();
int p = urlString.indexOf(":/");
contentURL = new URL("vfszip" + urlString.substring(p));
getLog().debug(contentURL);
DeploymentStatus status;
DeploymentProgress progress = deployMgr.distribute(name, contentURL, true);
progress.addProgressListener(this);
progress.run();
String[] uploadedNames = {};
try
{
status = progress.getDeploymentStatus();
assertTrue("DeploymentStatus.isCompleted: " + status, status.isCompleted());
// It should not be running yet
assertFalse("DeploymentStatus.isRunning: " + status, status.isRunning());
assertFalse("DeploymentStatus.isFailed: " + status, status.isFailed());
// Get the unique deployment name
uploadedNames = progress.getDeploymentID().getRepositoryNames();
getLog().debug("Uploaded deployment names: "+Arrays.asList(uploadedNames));
// Now start the deployment
progress = deployMgr.start(uploadedNames);
progress.addProgressListener(this);
progress.run();
try
{
status = progress.getDeploymentStatus();
assertTrue("DeploymentStatus.isCompleted: " + status, status.isCompleted());
assertFalse("DeploymentStatus.isRunning: " + status, status.isRunning());
assertFalse("DeploymentStatus.isFailed: " + status, status.isFailed());
// Check for a
ManagementView mgtView = getManagementView();
ManagedDeployment deployment = mgtView.getDeployment(uploadedNames[0]);
assertNotNull(deployment);
getLog().info("Found " + type + " deployment: " + deployment);
Set<String> types = deployment.getTypes();
if (types != null && types.isEmpty() == false)
assertTrue("Missing type: " + type + ", available: " + types, types.contains(type));
if (tester != null)
{
tester.testManagedDeployment();
}
}
finally
{
//Thread.sleep(15 * 1000); // 15 secs >> more than it takes for reaper to run :-)
// Stop/remove the deployment
progress = deployMgr.stop(uploadedNames);
progress.addProgressListener(this);
progress.run();
status = progress.getDeploymentStatus();
assertTrue("DeploymentStatus.isCompleted: " + status, status.isCompleted());
assertFalse("DeploymentStatus.isFailed: " + status, status.isFailed());
}
}
finally
{
progress = deployMgr.remove(uploadedNames);
progress.addProgressListener(this);
progress.run();
status = progress.getDeploymentStatus();
assertTrue("DeploymentStatus.isCompleted: " + status, status.isCompleted());
assertFalse("DeploymentStatus.isFailed: " + status, status.isFailed());
}
}
private interface ManagedDeploymentTester
{
void testManagedDeployment() throws Exception;
}
}