@Test
 public void testDistributeEjbApp() throws Exception {
   ProgressObject progress = jsr88Deploy(getEjbArchive());
   TargetModuleID[] targetModules = progress.getResultTargetModuleIDs();
   try {
     DeploymentStatus state = progress.getDeploymentStatus();
     assertEquals(StateType.COMPLETED, state.getState());
   } finally {
     jsr88Undeploy(targetModules);
   }
 }
 @Test
 public void testDistributeEARApp() throws Exception {
   ProgressObject progress = jsr88Deploy(getEarArchive());
   TargetModuleID[] targetModules = progress.getResultTargetModuleIDs();
   try {
     DeploymentStatus state = progress.getDeploymentStatus();
     assertEquals(StateType.COMPLETED, state.getState());
     assertServletAccess("custom-context");
   } finally {
     jsr88Undeploy(targetModules);
   }
   try {
     assertServletAccess("custom-context");
     fail("Test deployment not undeployed");
   } catch (Exception e) {
     // ignore
   }
 }
  private StateType awaitCompletion(ProgressObject progress, long timeout)
      throws InterruptedException {
    DeploymentStatus status = progress.getDeploymentStatus();
    if (status.isCompleted()) return null;

    final CountDownLatch latch = new CountDownLatch(1);
    progress.addProgressListener(
        new ProgressListener() {
          public void handleProgressEvent(ProgressEvent event) {
            DeploymentStatus status = event.getDeploymentStatus();
            if (status.isCompleted() || status.isFailed()) {
              latch.countDown();
            }
          }
        });

    if (latch.await(timeout, TimeUnit.MILLISECONDS) == false)
      throw new IllegalStateException("Deployment timeout: " + progress);

    return status.getState();
  }