// Integration test because requires ssh'ing (and takes about 5 seconds)
  // See also SoftwareProcessEntityTest.testCustomInstallDirX for a lot more mocked variants
  @Test(groups = "Integration")
  public void testCanInstallMultipleVersionsOnSameMachine() throws Exception {
    managementContext
        .getBrooklynProperties()
        .put(BrooklynConfigKeys.ONBOX_BASE_DIR, tempDataDir.getAbsolutePath());

    MyService entity =
        app.createAndManageChild(
            EntitySpec.create(MyService.class)
                .configure(SoftwareProcess.SUGGESTED_VERSION, "0.1.0"));
    MyService entity2 =
        app.createAndManageChild(
            EntitySpec.create(MyService.class)
                .configure(SoftwareProcess.SUGGESTED_VERSION, "0.2.0"));
    app.start(ImmutableList.of(machine127));

    String installDir1 = entity.getAttribute(SoftwareProcess.INSTALL_DIR);
    String installDir2 = entity2.getAttribute(SoftwareProcess.INSTALL_DIR);

    assertNotEquals(installDir1, installDir2);
    assertTrue(installDir1.contains("0.1.0"), "installDir1=" + installDir1);
    assertTrue(installDir2.contains("0.2.0"), "installDir2=" + installDir2);
    assertTrue(new File(new File(installDir1), "myfile").isFile());
    assertTrue(new File(new File(installDir2), "myfile").isFile());
  }
  @BeforeMethod(alwaysRun = true)
  public void setUp() throws Exception {
    tempDataDir = Files.createTempDir();
    managementContext = new LocalManagementContext();

    localhost =
        managementContext
            .getLocationManager()
            .createLocation(LocationSpec.create(LocalhostMachineProvisioningLocation.class));
    machine127 =
        managementContext
            .getLocationManager()
            .createLocation(
                LocationSpec.create(SshMachineLocation.class).configure("address", "localhost"));
    app = ApplicationBuilder.newManagedApp(TestApplication.class, managementContext);
  }
 // Note also called reflectively by BrooklynLeakListener
 @Beta
 public static int terminateAll() {
   int closed = 0, dangling = 0;
   for (LocalManagementContext context : getInstances()) {
     try {
       context.terminate();
       closed++;
     } catch (Throwable t) {
       Exceptions.propagateIfFatal(t);
       log.warn("Failed to terminate management context", t);
       dangling++;
     }
   }
   if (dangling > 0) return -dangling;
   return closed;
 }
 @BeforeMethod(alwaysRun = true)
 public void setUp() throws Exception {
   managementContext = new LocalManagementContext();
   host =
       managementContext
           .getLocationManager()
           .createLocation(
               LocationSpec.create(SshMachineLocation.class)
                   .configure("address", Networking.getLocalHost())
                   .configure(SshTool.PROP_TOOL_CLASS, RecordingSshjTool.class.getName()));
 }
  private void assertThrowsIllegalArgument(String val) {
    try {
      resolve(val);
      fail();
    } catch (IllegalArgumentException e) {
      // success
    }

    // and check the long form returns an Absent (not throwing)
    Assert.assertTrue(managementContext.getLocationRegistry().resolve(val, false, null).isAbsent());
  }
  @Test(groups = "Integration")
  @Deprecated
  public void testMachineInCustomFromDataDir() throws Exception {
    managementContext
        .getBrooklynProperties()
        .put(BrooklynConfigKeys.BROOKLYN_DATA_DIR, tempDataDir.getAbsolutePath());

    MyService entity = app.createAndManageChild(EntitySpec.create(MyService.class));
    app.start(ImmutableList.of(machine127));

    String installDir = entity.getAttribute(SoftwareProcess.INSTALL_DIR);
    assertTrue(
        installDir.startsWith(tempDataDir.getAbsolutePath() + "/installs/"),
        "installed in " + installDir);
  }
  @Test(groups = "Integration")
  public void testSshCacheExpiresEvenIfNotUsed() throws Exception {
    SshMachineLocation host2 =
        managementContext
            .getLocationManager()
            .createLocation(
                LocationSpec.create(SshMachineLocation.class)
                    .configure("address", InetAddress.getLocalHost())
                    .configure(SshMachineLocation.SSH_CACHE_EXPIRY_DURATION, Duration.ONE_SECOND)
                    .configure(SshTool.PROP_TOOL_CLASS, RecordingSshjTool.class.getName()));

    Map<String, Object> props = customSshConfigKeys();
    host2.execScript(props, "mysummary", ImmutableList.of("exit"));

    Asserts.succeedsEventually(
        new Runnable() {
          @Override
          public void run() {
            assertEquals(RecordingSshjTool.disconnectionCount.get(), 1);
          }
        });
  }
 @BeforeMethod(alwaysRun = true)
 public void setUp() throws Exception {
   managementContext = LocalManagementContextForTests.newInstance();
   brooklynProperties = managementContext.getBrooklynProperties();
 }
 private Location resolve(String val) {
   Location l = managementContext.getLocationRegistry().resolve(val);
   Assert.assertNotNull(l);
   return l;
 }
 private BasicLocationRegistry getLocationResolver() {
   return (BasicLocationRegistry) managementContext.getLocationRegistry();
 }
 @Test(expectedExceptions = {IllegalArgumentException.class})
 public void testDoesNotAcceptsListOLists() {
   ((BasicLocationRegistry) managementContext.getLocationRegistry())
       .resolve(ImmutableList.of(ImmutableList.of("localhost")));
 }