brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rich...@apache.org
Subject [2/7] git commit: use `Os.tmp()` when we create temp dirs and files, and simplify creation and deletion, defaulting to delete on exit etc, use LocalManagementContextForTests in more places, and other misc test tidies
Date Wed, 11 Jun 2014 22:25:21 GMT
use `Os.tmp()` when we create temp dirs and files, and simplify creation and deletion, defaulting to delete on exit etc, use LocalManagementContextForTests in more places, and other misc test tidies


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/0ce9b0cf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/0ce9b0cf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/0ce9b0cf

Branch: refs/heads/master
Commit: 0ce9b0cf166f37847cfdd6bd11fa547a5ca6fdce
Parents: 7aa7526
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Tue Jun 10 20:28:23 2014 -0700
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Tue Jun 10 22:18:09 2014 -0700

----------------------------------------------------------------------
 .../brooklyn/config/BrooklynProperties.java     |   3 +
 .../brooklyn/config/BrooklynServerConfig.java   |   4 +
 .../BrooklynMementoPersisterInMemory.java       |   6 +-
 .../rebind/persister/FileBasedObjectStore.java  |  18 +---
 .../internal/ManagementContextInternal.java     |   6 +-
 .../main/java/brooklyn/util/ResourceUtils.java  |  11 +-
 .../util/task/ssh/SshFetchTaskWrapper.java      |   3 +-
 .../catalog/internal/CatalogDtoTest.java        |  13 +--
 .../config/BrooklynPropertiesBuilderTest.java   |   7 +-
 .../entity/EntityPreManagementTest.java         |   3 +-
 .../entity/basic/BasicStartableTest.java        |   3 +-
 .../brooklyn/entity/basic/DataEntityTest.java   |   3 +-
 .../brooklyn/entity/basic/EntityConfigTest.java |   3 +-
 .../entity/basic/EntitySubscriptionTest.groovy  |   2 +-
 .../drivers/EntityDriverRegistryTest.java       |   3 +-
 .../ApplicationBuilderOverridingTest.java       |   3 +-
 .../proxying/InternalEntityFactoryTest.java     |   3 +-
 .../entity/rebind/RebindTestFixture.java        |   7 +-
 .../BrooklynMementoPersisterFileBasedTest.java  |  14 ++-
 ...BrooklynMementoPersisterToMultiFileTest.java |   9 +-
 .../FileBasedStoreObjectAccessorWriterTest.java |   4 +-
 .../persister/MementoFileWriterSyncTest.java    |  14 +--
 .../rebind/persister/MementoFileWriterTest.java |   3 +-
 .../location/basic/AbstractLocationTest.java    |   3 +-
 ...stMachineProvisioningLocationRebindTest.java |   4 +-
 .../location/basic/LocationConfigTest.java      |   3 +-
 .../location/basic/LocationExtensionsTest.java  |   5 +-
 .../location/basic/MultiLocationRebindTest.java |   4 +-
 .../location/basic/SshMachineLocationTest.java  |   8 +-
 .../HighAvailabilityManagerFileBasedTest.java   |  14 ++-
 .../management/internal/AccessManagerTest.java  |   3 +-
 .../internal/LocalManagementContextTest.java    |   6 +-
 .../util/BrooklynMavenArtifactsTest.java        |   9 +-
 .../util/crypto/SecureKeysAndSignerTest.java    |   4 +-
 .../util/ssh/BashCommandsIntegrationTest.java   |  16 +--
 .../util/task/ScheduledExecutionTest.groovy     |   2 +-
 .../brooklyn/util/task/ssh/SshTasksTest.java    |   7 +-
 .../util/task/system/SystemTasksTest.java       |   8 +-
 .../ha/ConnectionFailureDetectorTest.java       |   3 +-
 ...ServiceFailureDetectorStabilizationTest.java |   3 +-
 .../policy/ha/ServiceFailureDetectorTest.java   |   3 +-
 .../brooklyn/policy/ha/ServiceReplacerTest.java |   3 +-
 .../policy/ha/ServiceRestarterTest.java         |   3 +-
 ...SoftwareProcessSshDriverIntegrationTest.java |   8 +-
 ...SoftwareProcessSshDriverIntegrationTest.java |  12 +--
 .../postgresql/PostgreSqlSshDriver.java         |  11 +-
 .../AbstractWebAppFixtureIntegrationTest.java   |   7 +-
 .../brooklyn/util/javalang/JavaClassNames.java  |  12 ++-
 .../src/main/java/brooklyn/util/os/Os.java      | 108 ++++++++++++++++---
 49 files changed, 272 insertions(+), 142 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/core/src/main/java/brooklyn/config/BrooklynProperties.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/config/BrooklynProperties.java b/core/src/main/java/brooklyn/config/BrooklynProperties.java
index ab56bd0..5696229 100644
--- a/core/src/main/java/brooklyn/config/BrooklynProperties.java
+++ b/core/src/main/java/brooklyn/config/BrooklynProperties.java
@@ -45,10 +45,13 @@ public class BrooklynProperties extends LinkedHashMap implements StringConfigMap
     private static final Logger LOG = LoggerFactory.getLogger(BrooklynProperties.class);
 
     public static class Factory {
+        /** creates a new empty {@link BrooklynProperties} */
         public static BrooklynProperties newEmpty() {
             return new BrooklynProperties();
         }
 
+        /** creates a new {@link BrooklynProperties} with contents loaded 
+         * from the usual places, including *.properties files and environment variables */
         public static BrooklynProperties newDefault() {
             return new Builder().build();
         }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/core/src/main/java/brooklyn/config/BrooklynServerConfig.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/config/BrooklynServerConfig.java b/core/src/main/java/brooklyn/config/BrooklynServerConfig.java
index 0eaf998..8a21d98 100644
--- a/core/src/main/java/brooklyn/config/BrooklynServerConfig.java
+++ b/core/src/main/java/brooklyn/config/BrooklynServerConfig.java
@@ -125,5 +125,9 @@ public class BrooklynServerConfig {
             throw e2;
         }
     }
+
+    public static final ConfigKey<String> BROOKLYN_CATALOG_URL = ConfigKeys.newStringConfigKey("brooklyn.catalog.url",
+        "The URL of a catalog.xml descriptor; absent for default (~/.brooklyn/catalog.xml), " +
+        "or empty for no URL (use default scanner)", "file://~/.brooklyn/catalog.xml");
     
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/core/src/main/java/brooklyn/entity/rebind/persister/BrooklynMementoPersisterInMemory.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/rebind/persister/BrooklynMementoPersisterInMemory.java b/core/src/main/java/brooklyn/entity/rebind/persister/BrooklynMementoPersisterInMemory.java
index 6593b33..053a92b 100644
--- a/core/src/main/java/brooklyn/entity/rebind/persister/BrooklynMementoPersisterInMemory.java
+++ b/core/src/main/java/brooklyn/entity/rebind/persister/BrooklynMementoPersisterInMemory.java
@@ -24,6 +24,7 @@ import brooklyn.policy.Policy;
 import brooklyn.util.collections.MutableList;
 import brooklyn.util.collections.MutableMap;
 import brooklyn.util.exceptions.Exceptions;
+import brooklyn.util.javalang.JavaClassNames;
 import brooklyn.util.javalang.Reflections;
 import brooklyn.util.os.Os;
 import brooklyn.util.time.Duration;
@@ -31,7 +32,6 @@ import brooklyn.util.time.Duration;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Optional;
 import com.google.common.base.Throwables;
-import com.google.common.io.Files;
 
 /**
  * @deprecated since 0.7.0 for production use {@link BrooklynMementoPersisterToMultiFile} instead; class be moved to tests
@@ -82,7 +82,7 @@ public class BrooklynMementoPersisterInMemory extends AbstractBrooklynMementoPer
     private void reserializeMemento() {
         // To confirm always serializable
         try {
-            File tempDir = Files.createTempDir();
+            File tempDir = Os.newTempDir(JavaClassNames.cleanSimpleClassName(this));
             try {
                 // TODO Duplicate code for LookupContext in RebindManager
                 BrooklynMementoPersisterToMultiFile persister = new BrooklynMementoPersisterToMultiFile(tempDir , classLoader);
@@ -141,7 +141,7 @@ public class BrooklynMementoPersisterInMemory extends AbstractBrooklynMementoPer
                 // Not actually reconstituting, because need to use a real lookupContext to reconstitute all the entities
                 persister.loadMemento(dummyLookupContext, exceptionHandler);
             } finally {
-                Os.tryDeleteDirectory(tempDir.getAbsolutePath());
+                Os.deleteRecursively(tempDir);
             }
         } catch (IOException e) {
             throw Throwables.propagate(e);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/core/src/main/java/brooklyn/entity/rebind/persister/FileBasedObjectStore.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/rebind/persister/FileBasedObjectStore.java b/core/src/main/java/brooklyn/entity/rebind/persister/FileBasedObjectStore.java
index b468082..e9a12b5 100644
--- a/core/src/main/java/brooklyn/entity/rebind/persister/FileBasedObjectStore.java
+++ b/core/src/main/java/brooklyn/entity/rebind/persister/FileBasedObjectStore.java
@@ -23,6 +23,7 @@ import brooklyn.management.ManagementContext;
 import brooklyn.util.exceptions.Exceptions;
 import brooklyn.util.exceptions.FatalConfigurationRuntimeException;
 import brooklyn.util.os.Os;
+import brooklyn.util.os.Os.DeletionResult;
 
 import com.google.common.base.Function;
 import com.google.common.base.Objects;
@@ -293,22 +294,9 @@ public class FileBasedObjectStore implements PersistenceObjectStore {
     }
     
     public static void deleteCompletely(File d) {
-        try {
-            if (d==null) return;
-            String dp = d.getAbsolutePath();
-            if (dp.length()<=4) {
-                log.warn("Refusing instruction to delete base dir "+d+": name too short");
-                return;
-            }
-            if (Os.home().equals(dp)) {
-                log.warn("Refusing instruction to delete base dir "+d+": it's the home directory");
-                return;
-            }
-            FileUtils.deleteDirectory(d);
-        } catch (IOException e) {
-            Exceptions.propagateIfFatal(e);
+        DeletionResult result = Os.deleteRecursively(d);
+        if (!result.wasSuccessful())
             log.warn("Unable to delete persistence dir "+d);
-        }
     }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/core/src/main/java/brooklyn/management/internal/ManagementContextInternal.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/management/internal/ManagementContextInternal.java b/core/src/main/java/brooklyn/management/internal/ManagementContextInternal.java
index a10b185..2565b40 100644
--- a/core/src/main/java/brooklyn/management/internal/ManagementContextInternal.java
+++ b/core/src/main/java/brooklyn/management/internal/ManagementContextInternal.java
@@ -6,11 +6,11 @@ import java.util.Map;
 import java.util.concurrent.ExecutionException;
 
 import brooklyn.config.BrooklynProperties;
+import brooklyn.config.BrooklynServerConfig;
 import brooklyn.config.ConfigKey;
 import brooklyn.entity.Effector;
 import brooklyn.entity.Entity;
 import brooklyn.entity.basic.BrooklynTaskTags;
-import brooklyn.entity.basic.ConfigKeys;
 import brooklyn.entity.proxying.InternalEntityFactory;
 import brooklyn.entity.proxying.InternalLocationFactory;
 import brooklyn.entity.proxying.InternalPolicyFactory;
@@ -28,9 +28,7 @@ public interface ManagementContextInternal extends ManagementContext {
     public static final String NON_TRANSIENT_TASK_TAG = BrooklynTaskTags.NON_TRANSIENT_TASK_TAG;
     public static final String TRANSIENT_TASK_TAG = BrooklynTaskTags.TRANSIENT_TASK_TAG;
 
-    public static final ConfigKey<String> BROOKLYN_CATALOG_URL = ConfigKeys.newStringConfigKey("brooklyn.catalog.url",
-            "The URL of a catalog.xml descriptor; absent for default (~/.brooklyn/catalog.xml), " +
-            "or empty for no URL (use default scanner)", "file://~/.brooklyn/catalog.xml");
+    public static final ConfigKey<String> BROOKLYN_CATALOG_URL = BrooklynServerConfig.BROOKLYN_CATALOG_URL;
     
     ClassLoader getBaseClassLoader();
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/core/src/main/java/brooklyn/util/ResourceUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/util/ResourceUtils.java b/core/src/main/java/brooklyn/util/ResourceUtils.java
index e8a6632..2f68770 100644
--- a/core/src/main/java/brooklyn/util/ResourceUtils.java
+++ b/core/src/main/java/brooklyn/util/ResourceUtils.java
@@ -310,11 +310,16 @@ public class ResourceUtils {
                 .put("address", InetAddress.getByName(address))
                 .build());
         try {
-            File tempFile = File.createTempFile("brooklyn-sftp", ".tmp");
-            tempFile.deleteOnExit();
+            final File tempFile = Os.newTempFile("brooklyn-sftp", "tmp");
             tempFile.setReadable(true, true);
             machine.copyFrom(path, tempFile.getAbsolutePath());
-            return new FileInputStream(tempFile);
+            return new FileInputStream(tempFile) {
+                @Override
+                public void close() throws IOException {
+                    super.close();
+                    tempFile.delete();
+                }
+            };
         } finally {
             Streams.closeQuietly(machine);
         }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/core/src/main/java/brooklyn/util/task/ssh/SshFetchTaskWrapper.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/util/task/ssh/SshFetchTaskWrapper.java b/core/src/main/java/brooklyn/util/task/ssh/SshFetchTaskWrapper.java
index bda5bce..c3963e6 100644
--- a/core/src/main/java/brooklyn/util/task/ssh/SshFetchTaskWrapper.java
+++ b/core/src/main/java/brooklyn/util/task/ssh/SshFetchTaskWrapper.java
@@ -12,6 +12,7 @@ import brooklyn.management.Task;
 import brooklyn.management.TaskWrapper;
 import brooklyn.util.config.ConfigBag;
 import brooklyn.util.exceptions.Exceptions;
+import brooklyn.util.os.Os;
 import brooklyn.util.task.TaskBuilder;
 import brooklyn.util.task.Tasks;
 import brooklyn.util.task.system.ProcessTaskWrapper;
@@ -68,7 +69,7 @@ public class SshFetchTaskWrapper implements TaskWrapper<String> {
             int result = -1;
             try {
                 Preconditions.checkNotNull(getMachine(), "machine");
-                backingFile = File.createTempFile("brooklyn-ssh-fetch-", FilenameUtils.getName(remoteFile));
+                backingFile = Os.newTempFile("brooklyn-ssh-fetch-", FilenameUtils.getName(remoteFile));
                 backingFile.deleteOnExit();
                 
                 result = getMachine().copyFrom(config.getAllConfig(), remoteFile, backingFile.getPath());

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/core/src/test/java/brooklyn/catalog/internal/CatalogDtoTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/catalog/internal/CatalogDtoTest.java b/core/src/test/java/brooklyn/catalog/internal/CatalogDtoTest.java
index 6df8169..db94f46 100644
--- a/core/src/test/java/brooklyn/catalog/internal/CatalogDtoTest.java
+++ b/core/src/test/java/brooklyn/catalog/internal/CatalogDtoTest.java
@@ -10,6 +10,7 @@ import org.testng.annotations.Test;
 import brooklyn.catalog.internal.CatalogClasspathDo.CatalogScanningModes;
 import brooklyn.entity.basic.Entities;
 import brooklyn.management.internal.LocalManagementContext;
+import brooklyn.test.entity.LocalManagementContextForTests;
 
 public class CatalogDtoTest {
 
@@ -19,7 +20,7 @@ public class CatalogDtoTest {
     
     @BeforeMethod(alwaysRun = true)
     public void setUp() throws Exception {
-        managementContext = new LocalManagementContext();
+        managementContext = new LocalManagementContextForTests();
     }
     
     @AfterMethod(alwaysRun = true)
@@ -27,15 +28,15 @@ public class CatalogDtoTest {
         if (managementContext != null) Entities.destroyAll(managementContext);
     }
 
-    @Test
+    @Test(groups="Integration")
     public void testCatalogLookup() {
-        CatalogDto root = buildHadoopsExample();
+        CatalogDto root = buildExampleCatalog();
         checkHadoopsExample(root);
     }
     
-    @Test
+    @Test(groups="Integration")
     public void testCatalogSerializeAndLookup() {
-        CatalogDto root = buildHadoopsExample();
+        CatalogDto root = buildExampleCatalog();
         CatalogXmlSerializer seriailizer = new CatalogXmlSerializer();
         
         String xml = seriailizer.toString(root);
@@ -54,7 +55,7 @@ public class CatalogDtoTest {
         Assert.assertEquals(worker.getName(), "M3 Worker Node");
     }
 
-    public static CatalogDto buildHadoopsExample() {
+    public static CatalogDto buildExampleCatalog() {
         CatalogDo root = new CatalogDo(CatalogDto.newNamedInstance("My Local Catalog", 
                 "My favourite local settings, including remote catalogs -- " +
         		"intended partly as a teaching example for what can be expressed, and how"));

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/core/src/test/java/brooklyn/config/BrooklynPropertiesBuilderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/config/BrooklynPropertiesBuilderTest.java b/core/src/test/java/brooklyn/config/BrooklynPropertiesBuilderTest.java
index 43e17be..4cb8f12 100644
--- a/core/src/test/java/brooklyn/config/BrooklynPropertiesBuilderTest.java
+++ b/core/src/test/java/brooklyn/config/BrooklynPropertiesBuilderTest.java
@@ -8,8 +8,9 @@ import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
+import brooklyn.util.os.Os;
+
 import com.google.common.base.Charsets;
-import com.google.common.collect.ImmutableMap;
 import com.google.common.io.Files;
 
 @Test
@@ -20,8 +21,8 @@ public class BrooklynPropertiesBuilderTest {
 
     @BeforeMethod(alwaysRun=true)
     public void setUp() throws Exception {
-        globalPropertiesFile = File.createTempFile("global-brooklyn-properties-test", ".properties");
-        localPropertiesFile = File.createTempFile("local-brooklyn-properties-test", ".properties");
+        globalPropertiesFile = Os.newTempFile(getClass(), ".global.properties");
+        localPropertiesFile = Os.newTempFile(getClass(), "local.properties");
     }
     
     @AfterMethod(alwaysRun=true)

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/core/src/test/java/brooklyn/entity/EntityPreManagementTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/EntityPreManagementTest.java b/core/src/test/java/brooklyn/entity/EntityPreManagementTest.java
index 00b0a43..0803bf3 100644
--- a/core/src/test/java/brooklyn/entity/EntityPreManagementTest.java
+++ b/core/src/test/java/brooklyn/entity/EntityPreManagementTest.java
@@ -21,6 +21,7 @@ import brooklyn.management.EntityManager;
 import brooklyn.management.ManagementContext;
 import brooklyn.policy.basic.AbstractPolicy;
 import brooklyn.test.TestUtils;
+import brooklyn.test.entity.LocalManagementContextForTests;
 import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 
@@ -37,7 +38,7 @@ public class EntityPreManagementTest {
     
     @BeforeMethod(alwaysRun=true)
     public void setUp() throws Exception {
-        managementContext = Entities.newManagementContext();
+        managementContext = new LocalManagementContextForTests();
         entityManager = managementContext.getEntityManager();
     }
     

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/core/src/test/java/brooklyn/entity/basic/BasicStartableTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/basic/BasicStartableTest.java b/core/src/test/java/brooklyn/entity/basic/BasicStartableTest.java
index 71afa32..e7d59e8 100644
--- a/core/src/test/java/brooklyn/entity/basic/BasicStartableTest.java
+++ b/core/src/test/java/brooklyn/entity/basic/BasicStartableTest.java
@@ -17,6 +17,7 @@ import brooklyn.location.LocationSpec;
 import brooklyn.location.basic.Locations.LocationsFilter;
 import brooklyn.location.basic.SimulatedLocation;
 import brooklyn.management.ManagementContext;
+import brooklyn.test.entity.LocalManagementContextForTests;
 import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.collections.MutableSet;
@@ -38,7 +39,7 @@ public class BasicStartableTest {
     
     @BeforeMethod(alwaysRun=true)
     public void setUp() throws Exception {
-        managementContext = Entities.newManagementContext();
+        managementContext = new LocalManagementContextForTests();
         loc1 = managementContext.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class));
         loc2 = managementContext.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class));
         app = ApplicationBuilder.newManagedApp(TestApplication.class, managementContext);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/core/src/test/java/brooklyn/entity/basic/DataEntityTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/basic/DataEntityTest.java b/core/src/test/java/brooklyn/entity/basic/DataEntityTest.java
index 9c152ef..d3e3f17 100644
--- a/core/src/test/java/brooklyn/entity/basic/DataEntityTest.java
+++ b/core/src/test/java/brooklyn/entity/basic/DataEntityTest.java
@@ -17,6 +17,7 @@ import brooklyn.location.basic.SimulatedLocation;
 import brooklyn.management.ManagementContext;
 import brooklyn.test.Asserts;
 import brooklyn.test.EntityTestUtils;
+import brooklyn.test.entity.LocalManagementContextForTests;
 import brooklyn.test.entity.TestApplication;
 import brooklyn.util.collections.MutableMap;
 
@@ -42,7 +43,7 @@ public class DataEntityTest {
     
     @BeforeMethod(alwaysRun=true)
     public void setUp() throws Exception {
-        managementContext = Entities.newManagementContext();
+        managementContext = new LocalManagementContextForTests();
         loc = managementContext.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class));
         app = ApplicationBuilder.newManagedApp(TestApplication.class, managementContext);
     }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/core/src/test/java/brooklyn/entity/basic/EntityConfigTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/basic/EntityConfigTest.java b/core/src/test/java/brooklyn/entity/basic/EntityConfigTest.java
index 7c6c630..8ded5ef 100644
--- a/core/src/test/java/brooklyn/entity/basic/EntityConfigTest.java
+++ b/core/src/test/java/brooklyn/entity/basic/EntityConfigTest.java
@@ -9,6 +9,7 @@ import org.testng.annotations.Test;
 import brooklyn.config.ConfigKey;
 import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.management.ManagementContext;
+import brooklyn.test.entity.LocalManagementContextForTests;
 import brooklyn.util.flags.SetFromFlag;
 
 import com.google.common.collect.ImmutableMap;
@@ -19,7 +20,7 @@ public class EntityConfigTest {
 
     @BeforeMethod(alwaysRun=true)
     public void setUp() throws Exception {
-        managementContext = Entities.newManagementContext();
+        managementContext = new LocalManagementContextForTests();
     }
     
     @AfterMethod(alwaysRun=true)

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/core/src/test/java/brooklyn/entity/basic/EntitySubscriptionTest.groovy
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/basic/EntitySubscriptionTest.groovy b/core/src/test/java/brooklyn/entity/basic/EntitySubscriptionTest.groovy
index 9747e23..168da87 100644
--- a/core/src/test/java/brooklyn/entity/basic/EntitySubscriptionTest.groovy
+++ b/core/src/test/java/brooklyn/entity/basic/EntitySubscriptionTest.groovy
@@ -151,7 +151,7 @@ public class EntitySubscriptionTest {
         }
     }
     
-    @Test
+    @Test(groups="Integration")
     public void testSubscribeToMembersIgnoresEventsForDynamicallyRemovedMembers() {
         entity.subscribeToMembers(observedGroup, TestEntity.SEQUENCE, listener);
         

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/core/src/test/java/brooklyn/entity/drivers/EntityDriverRegistryTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/drivers/EntityDriverRegistryTest.java b/core/src/test/java/brooklyn/entity/drivers/EntityDriverRegistryTest.java
index 69026a2..022f0e1 100644
--- a/core/src/test/java/brooklyn/entity/drivers/EntityDriverRegistryTest.java
+++ b/core/src/test/java/brooklyn/entity/drivers/EntityDriverRegistryTest.java
@@ -12,6 +12,7 @@ import brooklyn.entity.drivers.ReflectiveEntityDriverFactoryTest.MyDriverDepende
 import brooklyn.entity.drivers.RegistryEntityDriverFactoryTest.MyOtherSshDriver;
 import brooklyn.location.basic.SshMachineLocation;
 import brooklyn.management.ManagementContext;
+import brooklyn.test.entity.LocalManagementContextForTests;
 import brooklyn.util.collections.MutableMap;
 
 public class EntityDriverRegistryTest {
@@ -21,7 +22,7 @@ public class EntityDriverRegistryTest {
 
     @BeforeMethod
     public void setUp() throws Exception {
-        managementContext = Entities.newManagementContext();
+        managementContext = new LocalManagementContextForTests();
         sshLocation = new SshMachineLocation(MutableMap.of("address", "localhost"));
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/core/src/test/java/brooklyn/entity/proxying/ApplicationBuilderOverridingTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/proxying/ApplicationBuilderOverridingTest.java b/core/src/test/java/brooklyn/entity/proxying/ApplicationBuilderOverridingTest.java
index bcbe683..8a33b32 100644
--- a/core/src/test/java/brooklyn/entity/proxying/ApplicationBuilderOverridingTest.java
+++ b/core/src/test/java/brooklyn/entity/proxying/ApplicationBuilderOverridingTest.java
@@ -27,6 +27,7 @@ import brooklyn.entity.basic.EntityInternal;
 import brooklyn.entity.basic.StartableApplication;
 import brooklyn.management.ManagementContext;
 import brooklyn.management.internal.LocalManagementContext;
+import brooklyn.test.entity.LocalManagementContextForTests;
 import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.exceptions.Exceptions;
@@ -45,7 +46,7 @@ public class ApplicationBuilderOverridingTest {
     
     @BeforeMethod(alwaysRun=true)
     public void setUp() throws Exception {
-        spareManagementContext = Entities.newManagementContext();
+        spareManagementContext = new LocalManagementContextForTests();
         executor = Executors.newCachedThreadPool();
     }
     

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/core/src/test/java/brooklyn/entity/proxying/InternalEntityFactoryTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/proxying/InternalEntityFactoryTest.java b/core/src/test/java/brooklyn/entity/proxying/InternalEntityFactoryTest.java
index d3a1f8b..35d86f4 100644
--- a/core/src/test/java/brooklyn/entity/proxying/InternalEntityFactoryTest.java
+++ b/core/src/test/java/brooklyn/entity/proxying/InternalEntityFactoryTest.java
@@ -14,6 +14,7 @@ import brooklyn.entity.Entity;
 import brooklyn.entity.basic.AbstractApplication;
 import brooklyn.entity.basic.Entities;
 import brooklyn.management.internal.ManagementContextInternal;
+import brooklyn.test.entity.LocalManagementContextForTests;
 import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestApplicationImpl;
 import brooklyn.test.entity.TestEntity;
@@ -26,7 +27,7 @@ public class InternalEntityFactoryTest {
 
     @BeforeMethod(alwaysRun=true)
     public void setUp() throws Exception {
-        managementContext = (ManagementContextInternal) Entities.newManagementContext();
+        managementContext = new LocalManagementContextForTests();
         InternalPolicyFactory policyFactory = new InternalPolicyFactory(managementContext);
         factory = new InternalEntityFactory(managementContext, managementContext.getEntityManager().getEntityTypeRegistry(), policyFactory);
     }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/core/src/test/java/brooklyn/entity/rebind/RebindTestFixture.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/rebind/RebindTestFixture.java b/core/src/test/java/brooklyn/entity/rebind/RebindTestFixture.java
index 383e4d3..c53983b 100644
--- a/core/src/test/java/brooklyn/entity/rebind/RebindTestFixture.java
+++ b/core/src/test/java/brooklyn/entity/rebind/RebindTestFixture.java
@@ -13,10 +13,9 @@ import brooklyn.internal.BrooklynFeatureEnablement;
 import brooklyn.management.ManagementContext;
 import brooklyn.management.internal.LocalManagementContext;
 import brooklyn.mementos.BrooklynMementoManifest;
+import brooklyn.util.os.Os;
 import brooklyn.util.time.Duration;
 
-import com.google.common.io.Files;
-
 public abstract class RebindTestFixture<T extends StartableApplication> {
 
     protected static final Duration TIMEOUT_MS = Duration.TEN_SECONDS;
@@ -37,7 +36,7 @@ public abstract class RebindTestFixture<T extends StartableApplication> {
         origPolicyPersistenceEnabled = BrooklynFeatureEnablement.enable(BrooklynFeatureEnablement.FEATURE_POLICY_PERSISTENCE_PROPERTY);
         origEnricherPersistenceEnabled = BrooklynFeatureEnablement.enable(BrooklynFeatureEnablement.FEATURE_ENRICHER_PERSISTENCE_PROPERTY);
         
-        mementoDir = Files.createTempDir();
+        mementoDir = Os.newTempDir(getClass());
         origManagementContext = RebindTestUtils.newPersistingManagementContext(mementoDir, classLoader, 1);
         origApp = createApp();
     }
@@ -56,7 +55,7 @@ public abstract class RebindTestFixture<T extends StartableApplication> {
             newManagementContext = null;
     
             if (origManagementContext != null) Entities.destroyAll(origManagementContext);
-            if (mementoDir != null) RebindTestUtils.deleteMementoDir(mementoDir);
+            if (mementoDir != null) FileBasedObjectStore.deleteCompletely(mementoDir);
             origManagementContext = null;
         } finally {
             BrooklynFeatureEnablement.setEnablement(BrooklynFeatureEnablement.FEATURE_POLICY_PERSISTENCE_PROPERTY, origPolicyPersistenceEnabled);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/core/src/test/java/brooklyn/entity/rebind/persister/BrooklynMementoPersisterFileBasedTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/rebind/persister/BrooklynMementoPersisterFileBasedTest.java b/core/src/test/java/brooklyn/entity/rebind/persister/BrooklynMementoPersisterFileBasedTest.java
index 5d5ede6..a419498 100644
--- a/core/src/test/java/brooklyn/entity/rebind/persister/BrooklynMementoPersisterFileBasedTest.java
+++ b/core/src/test/java/brooklyn/entity/rebind/persister/BrooklynMementoPersisterFileBasedTest.java
@@ -2,15 +2,15 @@ package brooklyn.entity.rebind.persister;
 
 import java.io.File;
 
+import org.testng.annotations.AfterMethod;
 import org.testng.annotations.Test;
 
 import brooklyn.entity.rebind.RebindTestUtils;
 import brooklyn.management.ManagementContext;
+import brooklyn.util.javalang.JavaClassNames;
 import brooklyn.util.os.Os;
 import brooklyn.util.time.Duration;
 
-import com.google.common.io.Files;
-
 /**
  * @author Andrea Turli
  */
@@ -20,10 +20,16 @@ public class BrooklynMementoPersisterFileBasedTest extends BrooklynMementoPersis
     protected File mementoDir;
     
     protected ManagementContext newPersistingManagementContext() {
-        mementoDir = Files.createTempDir();
+        mementoDir = Os.newTempDir(JavaClassNames.cleanSimpleClassName(this));
         Os.deleteOnExitRecursively(mementoDir);
         return RebindTestUtils.managementContextBuilder(classLoader, new FileBasedObjectStore(mementoDir))
             .persistPeriod(Duration.millis(10)).buildStarted();
     }
-    
+
+    @AfterMethod(alwaysRun=true)
+    public void tearDown() throws Exception {
+        mementoDir = Os.deleteRecursively(mementoDir).asNullOrThrowing();
+        super.tearDown();
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/core/src/test/java/brooklyn/entity/rebind/persister/BrooklynMementoPersisterToMultiFileTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/rebind/persister/BrooklynMementoPersisterToMultiFileTest.java b/core/src/test/java/brooklyn/entity/rebind/persister/BrooklynMementoPersisterToMultiFileTest.java
index 639e3cc..72840ae 100644
--- a/core/src/test/java/brooklyn/entity/rebind/persister/BrooklynMementoPersisterToMultiFileTest.java
+++ b/core/src/test/java/brooklyn/entity/rebind/persister/BrooklynMementoPersisterToMultiFileTest.java
@@ -5,14 +5,12 @@ import java.io.File;
 import org.testng.annotations.AfterMethod;
 
 import brooklyn.entity.rebind.RebindManagerImpl;
-import brooklyn.entity.rebind.RebindTestUtils;
 import brooklyn.management.internal.LocalManagementContext;
 import brooklyn.test.entity.LocalManagementContextForTests;
+import brooklyn.util.javalang.JavaClassNames;
 import brooklyn.util.os.Os;
 import brooklyn.util.time.Duration;
 
-import com.google.common.io.Files;
-
 /**
  * @author Andrea Turli
  * @deprecated just tests the deprecated {@link BrooklynMementoPersisterToMultiFile}
@@ -21,10 +19,9 @@ public class BrooklynMementoPersisterToMultiFileTest extends BrooklynMementoPers
 
     protected File mementoDir;
     
-    @SuppressWarnings("deprecation")
     @Override
     protected LocalManagementContext newPersistingManagementContext() {
-        mementoDir = Files.createTempDir();
+        mementoDir = Os.newTempDir(JavaClassNames.cleanSimpleClassName(this));
         Os.deleteOnExitRecursively(mementoDir);
         
         LocalManagementContext mgmt = new LocalManagementContextForTests();
@@ -38,7 +35,7 @@ public class BrooklynMementoPersisterToMultiFileTest extends BrooklynMementoPers
 
     @AfterMethod(alwaysRun=true)
     public void tearDown() throws Exception {
-        if (mementoDir != null) RebindTestUtils.deleteMementoDir(mementoDir);
+        mementoDir = Os.deleteRecursively(mementoDir).asNullOrThrowing();
         super.tearDown();
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/core/src/test/java/brooklyn/entity/rebind/persister/FileBasedStoreObjectAccessorWriterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/rebind/persister/FileBasedStoreObjectAccessorWriterTest.java b/core/src/test/java/brooklyn/entity/rebind/persister/FileBasedStoreObjectAccessorWriterTest.java
index 5d6f9a4..55b41a4 100644
--- a/core/src/test/java/brooklyn/entity/rebind/persister/FileBasedStoreObjectAccessorWriterTest.java
+++ b/core/src/test/java/brooklyn/entity/rebind/persister/FileBasedStoreObjectAccessorWriterTest.java
@@ -6,13 +6,13 @@ import java.io.IOException;
 import org.testng.annotations.Test;
 
 import brooklyn.entity.rebind.persister.PersistenceObjectStore.StoreObjectAccessorWithLock;
+import brooklyn.util.os.Os;
 
 @Test
 public class FileBasedStoreObjectAccessorWriterTest extends PersistenceStoreObjectAccessorWriterTestFixture {
 
     protected StoreObjectAccessorWithLock newPersistenceStoreObjectAccessor() throws IOException {
-        File file = File.createTempFile("objectAccessorWriterTest", ".txt");
-        file.deleteOnExit();
+        File file = Os.newTempFile(getClass(), "txt");
         return new StoreObjectAccessorLocking(new FileBasedStoreObjectAccessor(file, ".tmp"));
     }
     

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/core/src/test/java/brooklyn/entity/rebind/persister/MementoFileWriterSyncTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/rebind/persister/MementoFileWriterSyncTest.java b/core/src/test/java/brooklyn/entity/rebind/persister/MementoFileWriterSyncTest.java
index c6ca337..86f5c5e 100644
--- a/core/src/test/java/brooklyn/entity/rebind/persister/MementoFileWriterSyncTest.java
+++ b/core/src/test/java/brooklyn/entity/rebind/persister/MementoFileWriterSyncTest.java
@@ -10,13 +10,14 @@ import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
-import com.google.common.base.Charsets;
-import com.google.common.io.Files;
-
 import brooklyn.mementos.BrooklynMementoPersister.LookupContext;
+import brooklyn.util.javalang.JavaClassNames;
 import brooklyn.util.os.Os;
 import brooklyn.util.text.Identifiers;
 
+import com.google.common.base.Charsets;
+import com.google.common.io.Files;
+
 public class MementoFileWriterSyncTest {
 
     private File file;
@@ -27,8 +28,8 @@ public class MementoFileWriterSyncTest {
     
     @BeforeMethod(alwaysRun=true)
     public void setUp() throws Exception {
-        dir = Files.createTempDir();
-        file = File.createTempFile("mementoFileWriterSyncTest", "txt");
+        dir = Os.newTempDir(JavaClassNames.cleanSimpleClassName(this));
+        file = Os.newTempFile(getClass(), "txt");
         serializer = new MementoSerializer<String>() {
             @Override public String toString(String memento) {
                 return memento;
@@ -47,8 +48,7 @@ public class MementoFileWriterSyncTest {
     @AfterMethod(alwaysRun=true)
     public void tearDown() throws Exception {
         if (file != null) file.delete();
-        if (dir != null) Os.tryDeleteDirectory(dir);
-        
+        dir = Os.deleteRecursively(dir).asNullOrThrowing();
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/core/src/test/java/brooklyn/entity/rebind/persister/MementoFileWriterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/rebind/persister/MementoFileWriterTest.java b/core/src/test/java/brooklyn/entity/rebind/persister/MementoFileWriterTest.java
index aded679..db178a2 100644
--- a/core/src/test/java/brooklyn/entity/rebind/persister/MementoFileWriterTest.java
+++ b/core/src/test/java/brooklyn/entity/rebind/persister/MementoFileWriterTest.java
@@ -11,6 +11,7 @@ import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 import brooklyn.mementos.BrooklynMementoPersister.LookupContext;
+import brooklyn.util.os.Os;
 import brooklyn.util.time.Duration;
 
 import com.google.common.base.Charsets;
@@ -29,7 +30,7 @@ public class MementoFileWriterTest {
     
     @BeforeMethod(alwaysRun=true)
     public void setUp() throws Exception {
-        file = File.createTempFile("mementoFileWriterTest", "txt");
+        file = Os.newTempFile(getClass(), "txt");
         executor = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());
         serializer = new MementoSerializer<String>() {
             @Override public String toString(String memento) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/core/src/test/java/brooklyn/location/basic/AbstractLocationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/location/basic/AbstractLocationTest.java b/core/src/test/java/brooklyn/location/basic/AbstractLocationTest.java
index 3614089..020ff07 100644
--- a/core/src/test/java/brooklyn/location/basic/AbstractLocationTest.java
+++ b/core/src/test/java/brooklyn/location/basic/AbstractLocationTest.java
@@ -16,6 +16,7 @@ import brooklyn.entity.basic.Entities;
 import brooklyn.location.Location;
 import brooklyn.location.LocationSpec;
 import brooklyn.management.ManagementContext;
+import brooklyn.test.entity.LocalManagementContextForTests;
 import brooklyn.util.collections.MutableMap;
 import brooklyn.util.flags.SetFromFlag;
 
@@ -42,7 +43,7 @@ public class AbstractLocationTest {
 
     @BeforeMethod(alwaysRun=true)
     public void setUp() throws Exception {
-        mgmt = Entities.newManagementContext();
+        mgmt = new LocalManagementContextForTests();
     }
     
     @AfterMethod(alwaysRun = true)

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/core/src/test/java/brooklyn/location/basic/FixedListMachineProvisioningLocationRebindTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/location/basic/FixedListMachineProvisioningLocationRebindTest.java b/core/src/test/java/brooklyn/location/basic/FixedListMachineProvisioningLocationRebindTest.java
index 72ef051..bd2e796 100644
--- a/core/src/test/java/brooklyn/location/basic/FixedListMachineProvisioningLocationRebindTest.java
+++ b/core/src/test/java/brooklyn/location/basic/FixedListMachineProvisioningLocationRebindTest.java
@@ -18,11 +18,11 @@ import brooklyn.location.Location;
 import brooklyn.management.ManagementContext;
 import brooklyn.test.entity.TestApplication;
 import brooklyn.util.collections.MutableSet;
+import brooklyn.util.os.Os;
 
 import com.google.common.base.Function;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
-import com.google.common.io.Files;
 
 public class FixedListMachineProvisioningLocationRebindTest {
 
@@ -35,7 +35,7 @@ public class FixedListMachineProvisioningLocationRebindTest {
     
     @BeforeMethod(alwaysRun=true)
     public void setUp() throws Exception {
-        mementoDir = Files.createTempDir();
+        mementoDir = Os.newTempDir(getClass());
         origManagementContext = RebindTestUtils.newPersistingManagementContext(mementoDir, classLoader, 1);
         
     	origLoc = new FixedListMachineProvisioningLocation.Builder(origManagementContext.getLocationManager())

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/core/src/test/java/brooklyn/location/basic/LocationConfigTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/location/basic/LocationConfigTest.java b/core/src/test/java/brooklyn/location/basic/LocationConfigTest.java
index 53bbba7..059253e 100644
--- a/core/src/test/java/brooklyn/location/basic/LocationConfigTest.java
+++ b/core/src/test/java/brooklyn/location/basic/LocationConfigTest.java
@@ -11,6 +11,7 @@ import brooklyn.entity.basic.ConfigKeys;
 import brooklyn.entity.basic.Entities;
 import brooklyn.location.LocationSpec;
 import brooklyn.management.ManagementContext;
+import brooklyn.test.entity.LocalManagementContextForTests;
 import brooklyn.util.flags.SetFromFlag;
 
 import com.google.common.collect.ImmutableMap;
@@ -23,7 +24,7 @@ public class LocationConfigTest {
 
     @BeforeMethod(alwaysRun=true)
     public void setUp() throws Exception {
-        managementContext = Entities.newManagementContext();
+        managementContext = new LocalManagementContextForTests();
     }
     
     @AfterMethod(alwaysRun=true)

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/core/src/test/java/brooklyn/location/basic/LocationExtensionsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/location/basic/LocationExtensionsTest.java b/core/src/test/java/brooklyn/location/basic/LocationExtensionsTest.java
index 30942f4..c83d33b 100644
--- a/core/src/test/java/brooklyn/location/basic/LocationExtensionsTest.java
+++ b/core/src/test/java/brooklyn/location/basic/LocationExtensionsTest.java
@@ -4,11 +4,12 @@ import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertTrue;
 import static org.testng.Assert.fail;
-
 import brooklyn.entity.basic.Entities;
 import brooklyn.location.Location;
 import brooklyn.location.LocationSpec;
 import brooklyn.management.ManagementContext;
+import brooklyn.test.entity.LocalManagementContextForTests;
+
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
@@ -33,7 +34,7 @@ public class LocationExtensionsTest {
 
     @BeforeMethod(alwaysRun=true)
     public void setUp() throws Exception {
-        mgmt = Entities.newManagementContext();
+        mgmt = new LocalManagementContextForTests();
     }
     
     @AfterMethod(alwaysRun = true)

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/core/src/test/java/brooklyn/location/basic/MultiLocationRebindTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/location/basic/MultiLocationRebindTest.java b/core/src/test/java/brooklyn/location/basic/MultiLocationRebindTest.java
index 5958e78..5b0f5a3 100644
--- a/core/src/test/java/brooklyn/location/basic/MultiLocationRebindTest.java
+++ b/core/src/test/java/brooklyn/location/basic/MultiLocationRebindTest.java
@@ -19,12 +19,12 @@ import brooklyn.test.Asserts;
 import brooklyn.test.entity.TestApplication;
 import brooklyn.util.collections.MutableSet;
 import brooklyn.util.net.Networking;
+import brooklyn.util.os.Os;
 
 import com.google.common.base.Function;
 import com.google.common.base.Predicates;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
-import com.google.common.io.Files;
 
 public class MultiLocationRebindTest {
 
@@ -43,7 +43,7 @@ public class MultiLocationRebindTest {
     
     @BeforeMethod(alwaysRun=true)
     public void setUp() throws Exception {
-        mementoDir = Files.createTempDir();
+        mementoDir = Os.newTempDir(getClass());
         origManagementContext = RebindTestUtils.newPersistingManagementContext(mementoDir, classLoader, 1);
         origApp = ApplicationBuilder.newManagedApp(EntitySpec.create(TestApplication.class), origManagementContext);
     }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/core/src/test/java/brooklyn/location/basic/SshMachineLocationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/location/basic/SshMachineLocationTest.java b/core/src/test/java/brooklyn/location/basic/SshMachineLocationTest.java
index e98bcc6..f4fa966 100644
--- a/core/src/test/java/brooklyn/location/basic/SshMachineLocationTest.java
+++ b/core/src/test/java/brooklyn/location/basic/SshMachineLocationTest.java
@@ -1,6 +1,8 @@
 package brooklyn.location.basic;
 
-import static org.testng.Assert.*;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
 
 import java.io.ByteArrayOutputStream;
 import java.io.File;
@@ -87,8 +89,8 @@ public class SshMachineLocationTest {
     // Note: requires `ssh localhost` to be setup such that no password is required    
     @Test(groups = "Integration")
     public void testCopyFileTo() throws Exception {
-        File dest = new File(Os.tmp(), "sssMachineLocationTest_dest.tmp");
-        File src = File.createTempFile("sssMachineLocationTest_src", "tmp");
+        File dest = Os.newTempFile(getClass(), ".dest.tmp");
+        File src = Os.newTempFile(getClass(), ".src.tmp");
         try {
             Files.write("abc", src, Charsets.UTF_8);
             host.copyTo(src, dest);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/core/src/test/java/brooklyn/management/ha/HighAvailabilityManagerFileBasedTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/management/ha/HighAvailabilityManagerFileBasedTest.java b/core/src/test/java/brooklyn/management/ha/HighAvailabilityManagerFileBasedTest.java
index 5ecf37a..c13f00b 100644
--- a/core/src/test/java/brooklyn/management/ha/HighAvailabilityManagerFileBasedTest.java
+++ b/core/src/test/java/brooklyn/management/ha/HighAvailabilityManagerFileBasedTest.java
@@ -7,15 +7,19 @@ import org.testng.annotations.Test;
 import brooklyn.entity.rebind.persister.FileBasedObjectStore;
 import brooklyn.util.os.Os;
 
-import com.google.common.io.Files;
-
 @Test
 public class HighAvailabilityManagerFileBasedTest extends HighAvailabilityManagerTestFixture {
 
+    private File dir;
+
     protected FileBasedObjectStore newPersistenceObjectStore() {
-        File dir = Files.createTempDir();
-        Os.deleteOnExitRecursively(dir);
+        dir = Os.newTempDir(getClass());
         return new FileBasedObjectStore(dir);
     }
-    
+
+    @Override
+    public void tearDown() throws Exception {
+        super.tearDown();
+        dir = Os.deleteRecursively(dir).asNullOrThrowing();
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/core/src/test/java/brooklyn/management/internal/AccessManagerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/management/internal/AccessManagerTest.java b/core/src/test/java/brooklyn/management/internal/AccessManagerTest.java
index 9987b59..c429072 100644
--- a/core/src/test/java/brooklyn/management/internal/AccessManagerTest.java
+++ b/core/src/test/java/brooklyn/management/internal/AccessManagerTest.java
@@ -15,6 +15,7 @@ import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.location.Location;
 import brooklyn.location.LocationSpec;
 import brooklyn.location.basic.SimulatedLocation;
+import brooklyn.test.entity.LocalManagementContextForTests;
 import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.exceptions.Exceptions;
@@ -28,7 +29,7 @@ public class AccessManagerTest {
     
     @BeforeMethod(alwaysRun=true)
     public void setUp() throws Exception {
-        managementContext = new LocalManagementContext();
+        managementContext = new LocalManagementContextForTests();
         app = ApplicationBuilder.newManagedApp(TestApplication.class, managementContext);
     }
     

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/core/src/test/java/brooklyn/management/internal/LocalManagementContextTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/management/internal/LocalManagementContextTest.java b/core/src/test/java/brooklyn/management/internal/LocalManagementContextTest.java
index 3404e23..69095c5 100644
--- a/core/src/test/java/brooklyn/management/internal/LocalManagementContextTest.java
+++ b/core/src/test/java/brooklyn/management/internal/LocalManagementContextTest.java
@@ -1,13 +1,10 @@
 package brooklyn.management.internal;
 
 import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertNotEquals;
-import static org.testng.Assert.assertTrue;
 
 import java.io.File;
 import java.io.IOException;
-import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import org.testng.annotations.AfterMethod;
@@ -18,6 +15,7 @@ import brooklyn.config.BrooklynProperties;
 import brooklyn.config.BrooklynProperties.Factory.Builder;
 import brooklyn.location.Location;
 import brooklyn.management.ManagementContext.PropertiesReloadListener;
+import brooklyn.util.os.Os;
 
 import com.google.common.base.Charsets;
 import com.google.common.io.Files;
@@ -28,7 +26,7 @@ public class LocalManagementContextTest {
     
     @BeforeMethod(alwaysRun=true)
     public void setUp() throws Exception {
-        globalPropertiesFile = File.createTempFile("local-brooklyn-properties-test", ".properties");
+        globalPropertiesFile = Os.newTempFile(getClass(), "global.properties");
     }
     
     @AfterMethod(alwaysRun=true)

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/core/src/test/java/brooklyn/util/BrooklynMavenArtifactsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/util/BrooklynMavenArtifactsTest.java b/core/src/test/java/brooklyn/util/BrooklynMavenArtifactsTest.java
index 97fcca3..6aaf957 100644
--- a/core/src/test/java/brooklyn/util/BrooklynMavenArtifactsTest.java
+++ b/core/src/test/java/brooklyn/util/BrooklynMavenArtifactsTest.java
@@ -8,7 +8,10 @@ import org.testng.annotations.Test;
 import brooklyn.util.exceptions.Exceptions;
 import brooklyn.util.maven.MavenArtifact;
 import brooklyn.util.maven.MavenRetriever;
+import brooklyn.util.stream.Streams;
 import brooklyn.util.text.Strings;
+import brooklyn.util.time.Duration;
+import brooklyn.util.time.Time;
 
 @Test
 public class BrooklynMavenArtifactsTest {
@@ -27,7 +30,11 @@ public class BrooklynMavenArtifactsTest {
         log.info("found example war at: "+url);
     }
 
+    @Test(groups="Integration")
+    // runs without internet but doesn't assert what it should, and can take a long time, so integration
     public void testBadExampleWar() {
+        Time.sleep(Duration.FIVE_SECONDS);
+        log.info("boo!");
         String url = BrooklynMavenArtifacts.localUrl("example", "brooklyn-example-GOODBYE-world-sql-webapp", "war");
         Assert.assertFalse(ResourceUtils.create(this).doesUrlExist(url), "should not exist: "+url);
     }
@@ -54,7 +61,7 @@ public class BrooklynMavenArtifactsTest {
 
     private void checkValidArchive(String url) {
         try {
-            byte[] bytes = ResourceUtils.readFullyBytes(ResourceUtils.create(this).getResourceFromUrl(url));
+            byte[] bytes = Streams.readFully(ResourceUtils.create(this).getResourceFromUrl(url));
             // confirm this follow redirects!
             Assert.assertTrue(bytes.length > 100*1000, "download of "+url+" is suspect ("+Strings.makeSizeString(bytes.length)+")");
             // (could also check it is a zip etc)

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/core/src/test/java/brooklyn/util/crypto/SecureKeysAndSignerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/util/crypto/SecureKeysAndSignerTest.java b/core/src/test/java/brooklyn/util/crypto/SecureKeysAndSignerTest.java
index 0902139..cb4203f 100644
--- a/core/src/test/java/brooklyn/util/crypto/SecureKeysAndSignerTest.java
+++ b/core/src/test/java/brooklyn/util/crypto/SecureKeysAndSignerTest.java
@@ -11,6 +11,7 @@ import org.testng.Assert;
 import org.testng.annotations.Test;
 
 import brooklyn.util.ResourceUtils;
+import brooklyn.util.os.Os;
 
 import com.google.common.io.Files;
 
@@ -90,8 +91,7 @@ public class SecureKeysAndSignerTest {
     public void testReadRsaPassphraseKeyAndWriteWithoutPassphrase() throws Exception {
         KeyPair key = SecureKeys.readPem(ResourceUtils.create(this).getResourceFromUrl("classpath://brooklyn/util/crypto/sample_rsa_passphrase.pem"), "passphrase");
         checkNonTrivial(key);
-        File f = File.createTempFile("brooklyn-sample_rsa_passphrase_without_passphrase", "pem");
-        f.deleteOnExit();
+        File f = Os.newTempFile(getClass(), "brooklyn-sample_rsa_passphrase_without_passphrase.pem");
         Files.write(SecureKeys.stringPem(key), f, Charset.defaultCharset());
         KeyPair key2 = SecureKeys.readPem(new FileInputStream(f), null);
         checkNonTrivial(key2);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/core/src/test/java/brooklyn/util/ssh/BashCommandsIntegrationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/util/ssh/BashCommandsIntegrationTest.java b/core/src/test/java/brooklyn/util/ssh/BashCommandsIntegrationTest.java
index f7f9213..5a4eadd 100644
--- a/core/src/test/java/brooklyn/util/ssh/BashCommandsIntegrationTest.java
+++ b/core/src/test/java/brooklyn/util/ssh/BashCommandsIntegrationTest.java
@@ -25,8 +25,10 @@ import brooklyn.entity.basic.Entities;
 import brooklyn.location.basic.LocalhostMachineProvisioningLocation;
 import brooklyn.location.basic.SshMachineLocation;
 import brooklyn.management.ManagementContext;
+import brooklyn.test.entity.LocalManagementContextForTests;
 import brooklyn.util.javalang.JavaClassNames;
 import brooklyn.util.net.Networking;
+import brooklyn.util.os.Os;
 import brooklyn.util.task.BasicExecutionContext;
 import brooklyn.util.task.ssh.SshTasks;
 import brooklyn.util.task.system.ProcessTaskWrapper;
@@ -63,19 +65,19 @@ public class BashCommandsIntegrationTest {
     
     @BeforeMethod(alwaysRun=true)
     public void setUp() throws Exception {
-        mgmt = Entities.newManagementContext();
+        mgmt = new LocalManagementContextForTests();
         exec = new BasicExecutionContext(mgmt.getExecutionManager());
         
-        destFile = java.io.File.createTempFile("commoncommands-test-dest", "txt");
+        destFile = Os.newTempFile(getClass(), "commoncommands-test-dest.txt");
         
         sourceNonExistantFile = new File("/this/does/not/exist/ERQBETJJIG1234");
         sourceNonExistantFileUrl = sourceNonExistantFile.toURI().toString();
         
-        sourceFile1 = java.io.File.createTempFile("commoncommands-test", "txt");
+        sourceFile1 = Os.newTempFile(getClass(), "commoncommands-test.txt");
         sourceFileUrl1 = sourceFile1.toURI().toString();
         Files.write("mysource1".getBytes(), sourceFile1);
         
-        sourceFile2 = java.io.File.createTempFile("commoncommands-test2", "txt");
+        sourceFile2 = Os.newTempFile(getClass(), "commoncommands-test2.txt");
         sourceFileUrl2 = sourceFile2.toURI().toString();
         Files.write("mysource2".getBytes(), sourceFile2);
 
@@ -281,7 +283,7 @@ public class BashCommandsIntegrationTest {
         assertFalse(output.contains("Couldn't find"), "output="+output);
     }
     
-    @Test(groups="Integration")
+    @Test(groups="Integration", dependsOnMethods="testSudo")
     public void testWaitForPortFreeWhenAbortingOnTimeout() throws Exception {
         ServerSocket serverSocket = openServerSocket();
         try {
@@ -300,7 +302,7 @@ public class BashCommandsIntegrationTest {
         }
     }
 
-    @Test(groups="Integration")
+    @Test(groups="Integration", dependsOnMethods="testSudo")
     public void testWaitForPortFreeWhenNotAbortingOnTimeout() throws Exception {
         ServerSocket serverSocket = openServerSocket();
         try {
@@ -319,7 +321,7 @@ public class BashCommandsIntegrationTest {
         }
     }
     
-    @Test(groups="Integration")
+    @Test(groups="Integration", dependsOnMethods="testSudo")
     public void testWaitForPortFreeWhenFreedAfterStart() throws Exception {
         ServerSocket serverSocket = openServerSocket();
         try {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/core/src/test/java/brooklyn/util/task/ScheduledExecutionTest.groovy
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/util/task/ScheduledExecutionTest.groovy b/core/src/test/java/brooklyn/util/task/ScheduledExecutionTest.groovy
index f4aca60..57b59e8 100644
--- a/core/src/test/java/brooklyn/util/task/ScheduledExecutionTest.groovy
+++ b/core/src/test/java/brooklyn/util/task/ScheduledExecutionTest.groovy
@@ -93,7 +93,7 @@ public class ScheduledExecutionTest {
 		assertEquals(i, 5)
 	}
 
-    @Test
+    @Test(groups="Integration")
     public void testScheduledTaskTakesLongerThanPeriod() {
         final int PERIOD = 1;
         final int SLEEP_TIME = 100;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/core/src/test/java/brooklyn/util/task/ssh/SshTasksTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/util/task/ssh/SshTasksTest.java b/core/src/test/java/brooklyn/util/task/ssh/SshTasksTest.java
index f0e8a40..20096e2 100644
--- a/core/src/test/java/brooklyn/util/task/ssh/SshTasksTest.java
+++ b/core/src/test/java/brooklyn/util/task/ssh/SshTasksTest.java
@@ -19,12 +19,11 @@ import brooklyn.location.basic.SshMachineLocation;
 import brooklyn.management.ManagementContext;
 import brooklyn.management.internal.LocalManagementContext;
 import brooklyn.util.net.Urls;
+import brooklyn.util.os.Os;
 import brooklyn.util.ssh.BashCommandsIntegrationTest;
 import brooklyn.util.task.system.ProcessTaskFactory;
 import brooklyn.util.task.system.ProcessTaskWrapper;
 
-import com.google.common.io.Files;
-
 /**
  * Some tests for {@link SshTasks}. Note more tests in {@link BashCommandsIntegrationTest}, 
  * {@link SshEffectorTasksTest}, and {@link SoftwareEffectorTest}.
@@ -46,14 +45,14 @@ public class SshTasksTest {
         LocalhostMachineProvisioningLocation lhc = mgmt.getLocationManager().createLocation(LocationSpec.create(LocalhostMachineProvisioningLocation.class));
         host = lhc.obtain();
         clearExpectedFailure();
-        tempDir = Files.createTempDir();
+        tempDir = Os.newTempDir(getClass());
     }
     
     @AfterMethod(alwaysRun=true)
     public void tearDown() throws Exception {
         if (mgmt != null) Entities.destroyAll(mgmt);
         mgmt = null;
-        FileUtils.deleteDirectory(tempDir);
+        tempDir = Os.deleteRecursively(tempDir).asNullOrThrowing();
         checkExpectedFailure();
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/core/src/test/java/brooklyn/util/task/system/SystemTasksTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/util/task/system/SystemTasksTest.java b/core/src/test/java/brooklyn/util/task/system/SystemTasksTest.java
index 3e99c93..d4b18f1 100644
--- a/core/src/test/java/brooklyn/util/task/system/SystemTasksTest.java
+++ b/core/src/test/java/brooklyn/util/task/system/SystemTasksTest.java
@@ -2,7 +2,6 @@ package brooklyn.util.task.system;
 
 import java.io.File;
 
-import org.apache.commons.io.FileUtils;
 import org.testng.Assert;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
@@ -11,10 +10,9 @@ import org.testng.annotations.Test;
 import brooklyn.entity.basic.Entities;
 import brooklyn.management.ManagementContext;
 import brooklyn.management.internal.LocalManagementContext;
+import brooklyn.util.os.Os;
 import brooklyn.util.task.ssh.SshTasks;
 
-import com.google.common.io.Files;
-
 /**
  * Some tests for {@link SystemTasks}. See {@link SshTasks}.
  */
@@ -30,14 +28,14 @@ public class SystemTasksTest {
         mgmt = new LocalManagementContext();
         
         clearExpectedFailure();
-        tempDir = Files.createTempDir();
+        tempDir = Os.newTempDir(getClass());
     }
     
     @AfterMethod(alwaysRun=true)
     public void tearDown() throws Exception {
         if (mgmt != null) Entities.destroyAll(mgmt);
         mgmt = null;
-        FileUtils.deleteDirectory(tempDir);
+        tempDir = Os.deleteRecursively(tempDir).asNullOrThrowing();
         checkExpectedFailure();
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/policy/src/test/java/brooklyn/policy/ha/ConnectionFailureDetectorTest.java
----------------------------------------------------------------------
diff --git a/policy/src/test/java/brooklyn/policy/ha/ConnectionFailureDetectorTest.java b/policy/src/test/java/brooklyn/policy/ha/ConnectionFailureDetectorTest.java
index 7257608..6c76dd6 100644
--- a/policy/src/test/java/brooklyn/policy/ha/ConnectionFailureDetectorTest.java
+++ b/policy/src/test/java/brooklyn/policy/ha/ConnectionFailureDetectorTest.java
@@ -23,6 +23,7 @@ import brooklyn.management.ManagementContext;
 import brooklyn.policy.PolicySpec;
 import brooklyn.policy.ha.HASensors.FailureDescriptor;
 import brooklyn.test.Asserts;
+import brooklyn.test.entity.LocalManagementContextForTests;
 import brooklyn.test.entity.TestApplication;
 import brooklyn.util.collections.MutableMap;
 import brooklyn.util.time.Duration;
@@ -50,7 +51,7 @@ public class ConnectionFailureDetectorTest {
     public void setUp() throws Exception {
         events = new CopyOnWriteArrayList<SensorEvent<FailureDescriptor>>();
         
-        managementContext = Entities.newManagementContext();
+        managementContext = new LocalManagementContextForTests();
         app = ApplicationBuilder.newManagedApp(TestApplication.class, managementContext);
         
         app.getManagementContext().getSubscriptionManager().subscribe(

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/policy/src/test/java/brooklyn/policy/ha/ServiceFailureDetectorStabilizationTest.java
----------------------------------------------------------------------
diff --git a/policy/src/test/java/brooklyn/policy/ha/ServiceFailureDetectorStabilizationTest.java b/policy/src/test/java/brooklyn/policy/ha/ServiceFailureDetectorStabilizationTest.java
index 2e108cb..a6dd861 100644
--- a/policy/src/test/java/brooklyn/policy/ha/ServiceFailureDetectorStabilizationTest.java
+++ b/policy/src/test/java/brooklyn/policy/ha/ServiceFailureDetectorStabilizationTest.java
@@ -21,6 +21,7 @@ import brooklyn.management.ManagementContext;
 import brooklyn.policy.PolicySpec;
 import brooklyn.policy.ha.HASensors.FailureDescriptor;
 import brooklyn.test.Asserts;
+import brooklyn.test.entity.LocalManagementContextForTests;
 import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.collections.MutableMap;
@@ -45,7 +46,7 @@ public class ServiceFailureDetectorStabilizationTest {
     public void setUp() throws Exception {
         events = new CopyOnWriteArrayList<SensorEvent<FailureDescriptor>>();
         
-        managementContext = Entities.newManagementContext();
+        managementContext = new LocalManagementContextForTests();
         app = ApplicationBuilder.newManagedApp(TestApplication.class, managementContext);
         e1 = app.createAndManageChild(EntitySpec.create(TestEntity.class));
         e1.setAttribute(TestEntity.SERVICE_STATE, Lifecycle.RUNNING);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/policy/src/test/java/brooklyn/policy/ha/ServiceFailureDetectorTest.java
----------------------------------------------------------------------
diff --git a/policy/src/test/java/brooklyn/policy/ha/ServiceFailureDetectorTest.java b/policy/src/test/java/brooklyn/policy/ha/ServiceFailureDetectorTest.java
index d9ab80e..3130ef3 100644
--- a/policy/src/test/java/brooklyn/policy/ha/ServiceFailureDetectorTest.java
+++ b/policy/src/test/java/brooklyn/policy/ha/ServiceFailureDetectorTest.java
@@ -22,6 +22,7 @@ import brooklyn.management.ManagementContext;
 import brooklyn.policy.ha.HASensors.FailureDescriptor;
 import brooklyn.test.Asserts;
 import brooklyn.test.EntityTestUtils;
+import brooklyn.test.entity.LocalManagementContextForTests;
 import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.collections.MutableMap;
@@ -51,7 +52,7 @@ public class ServiceFailureDetectorTest {
             }
         };
         
-        managementContext = Entities.newManagementContext();
+        managementContext = new LocalManagementContextForTests();
         app = ApplicationBuilder.newManagedApp(TestApplication.class, managementContext);
         e1 = app.createAndManageChild(EntitySpec.create(TestEntity.class));
         

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/policy/src/test/java/brooklyn/policy/ha/ServiceReplacerTest.java
----------------------------------------------------------------------
diff --git a/policy/src/test/java/brooklyn/policy/ha/ServiceReplacerTest.java b/policy/src/test/java/brooklyn/policy/ha/ServiceReplacerTest.java
index 726914c..32cc223 100644
--- a/policy/src/test/java/brooklyn/policy/ha/ServiceReplacerTest.java
+++ b/policy/src/test/java/brooklyn/policy/ha/ServiceReplacerTest.java
@@ -32,6 +32,7 @@ import brooklyn.policy.PolicySpec;
 import brooklyn.policy.ha.HASensors.FailureDescriptor;
 import brooklyn.test.Asserts;
 import brooklyn.test.EntityTestUtils;
+import brooklyn.test.entity.LocalManagementContextForTests;
 import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.config.ConfigBag;
@@ -54,7 +55,7 @@ public class ServiceReplacerTest {
     
     @BeforeMethod(alwaysRun=true)
     public void setUp() throws Exception {
-        managementContext = Entities.newManagementContext();
+        managementContext = new LocalManagementContextForTests();
         app = ApplicationBuilder.newManagedApp(TestApplication.class, managementContext);
         loc = managementContext.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class));
         events = Lists.newCopyOnWriteArrayList();

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/policy/src/test/java/brooklyn/policy/ha/ServiceRestarterTest.java
----------------------------------------------------------------------
diff --git a/policy/src/test/java/brooklyn/policy/ha/ServiceRestarterTest.java b/policy/src/test/java/brooklyn/policy/ha/ServiceRestarterTest.java
index e32bb90..d109e82 100644
--- a/policy/src/test/java/brooklyn/policy/ha/ServiceRestarterTest.java
+++ b/policy/src/test/java/brooklyn/policy/ha/ServiceRestarterTest.java
@@ -24,6 +24,7 @@ import brooklyn.management.ManagementContext;
 import brooklyn.policy.PolicySpec;
 import brooklyn.policy.ha.HASensors.FailureDescriptor;
 import brooklyn.test.Asserts;
+import brooklyn.test.entity.LocalManagementContextForTests;
 import brooklyn.test.entity.TestApplication;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.config.ConfigBag;
@@ -47,7 +48,7 @@ public class ServiceRestarterTest {
     
     @BeforeMethod(alwaysRun=true)
     public void setUp() throws Exception {
-        managementContext = Entities.newManagementContext();
+        managementContext = new LocalManagementContextForTests();
         app = ApplicationBuilder.newManagedApp(TestApplication.class, managementContext);
         e1 = app.createAndManageChild(EntitySpec.create(TestEntity.class));
         events = Lists.newCopyOnWriteArrayList();

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/software/base/src/test/java/brooklyn/entity/basic/SoftwareProcessSshDriverIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/base/src/test/java/brooklyn/entity/basic/SoftwareProcessSshDriverIntegrationTest.java b/software/base/src/test/java/brooklyn/entity/basic/SoftwareProcessSshDriverIntegrationTest.java
index f177b9e..f812bb9 100644
--- a/software/base/src/test/java/brooklyn/entity/basic/SoftwareProcessSshDriverIntegrationTest.java
+++ b/software/base/src/test/java/brooklyn/entity/basic/SoftwareProcessSshDriverIntegrationTest.java
@@ -55,7 +55,7 @@ public class SoftwareProcessSshDriverIntegrationTest {
     @AfterMethod(alwaysRun=true)
     public void tearDown() throws Exception {
         if (app != null) Entities.destroyAll(app.getManagementContext());
-        if (tempDataDir != null) Os.tryDeleteDirectory(tempDataDir);
+        if (tempDataDir != null) Os.deleteRecursively(tempDataDir);
     }
 
     // Integration test because requires ssh'ing (and takes about 5 seconds)
@@ -180,7 +180,7 @@ public class SoftwareProcessSshDriverIntegrationTest {
         } catch (SshException e) {
             // success
         } finally {
-            Os.tryDeleteDirectory(tempDataDirSub);
+            Os.deleteRecursively(tempDataDirSub);
         }
         
         // Copy to absolute path
@@ -188,7 +188,7 @@ public class SoftwareProcessSshDriverIntegrationTest {
             entity.getDriver().copyResource(tempLocal.toURI().toString(), tempDest.getAbsolutePath(), true);
             assertEquals(Files.readLines(tempDest, Charsets.UTF_8), ImmutableList.of(tempLocalContent));
         } finally {
-            Os.tryDeleteDirectory(tempDataDirSub);
+            Os.deleteRecursively(tempDataDirSub);
         }
         
         // Copy to absolute path
@@ -200,7 +200,7 @@ public class SoftwareProcessSshDriverIntegrationTest {
             entity.getDriver().copyResource(tempLocal.toURI().toString(), tempDestRelativeToRunDir, true);
             assertEquals(Files.readLines(tempDestInRunDir, Charsets.UTF_8), ImmutableList.of(tempLocalContent));
         } finally {
-            Os.tryDeleteDirectory(new File(runDir, tempDataDirRelativeToRunDir));
+            Os.deleteRecursively(new File(runDir, tempDataDirRelativeToRunDir));
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/software/base/src/test/java/brooklyn/entity/java/JavaSoftwareProcessSshDriverIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/base/src/test/java/brooklyn/entity/java/JavaSoftwareProcessSshDriverIntegrationTest.java b/software/base/src/test/java/brooklyn/entity/java/JavaSoftwareProcessSshDriverIntegrationTest.java
index f6726fa..2a16d09 100644
--- a/software/base/src/test/java/brooklyn/entity/java/JavaSoftwareProcessSshDriverIntegrationTest.java
+++ b/software/base/src/test/java/brooklyn/entity/java/JavaSoftwareProcessSshDriverIntegrationTest.java
@@ -103,7 +103,7 @@ public class JavaSoftwareProcessSshDriverIntegrationTest {
         setup(mgmt);
         
         doTestSpecifiedDirectory(dir, dir);
-        Os.tryDeleteDirectory(dir);
+        Os.deleteRecursively(dir);
     }
     
     @Test(groups = "Integration")
@@ -113,7 +113,7 @@ public class JavaSoftwareProcessSshDriverIntegrationTest {
             app.setConfig(BrooklynConfigKeys.ONBOX_BASE_DIR, dir);
             doTestSpecifiedDirectory(dir, dir);
         } finally {
-            Os.tryDeleteDirectory(dir);
+            Os.deleteRecursively(dir);
         }
     }
     
@@ -124,8 +124,8 @@ public class JavaSoftwareProcessSshDriverIntegrationTest {
         app.setConfig(BrooklynConfigKeys.INSTALL_DIR, dir1);
         app.setConfig(BrooklynConfigKeys.RUN_DIR, dir2);
         doTestSpecifiedDirectory(dir1, dir2);
-        Os.tryDeleteDirectory(dir1);
-        Os.tryDeleteDirectory(dir2);
+        Os.deleteRecursively(dir1);
+        Os.deleteRecursively(dir2);
     }
     
     @Test(groups = "Integration")
@@ -140,8 +140,8 @@ public class JavaSoftwareProcessSshDriverIntegrationTest {
         
         app.setConfig(BrooklynConfigKeys.RUN_DIR, dir2);
         doTestSpecifiedDirectory(dir1, dir2);
-        Os.tryDeleteDirectory(dir1);
-        Os.tryDeleteDirectory(dir2);
+        Os.deleteRecursively(dir1);
+        Os.deleteRecursively(dir2);
     }
     
     protected void doTestSpecifiedDirectory(final String installDirPrefix, final String runDirPrefix) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/software/database/src/main/java/brooklyn/entity/database/postgresql/PostgreSqlSshDriver.java
----------------------------------------------------------------------
diff --git a/software/database/src/main/java/brooklyn/entity/database/postgresql/PostgreSqlSshDriver.java b/software/database/src/main/java/brooklyn/entity/database/postgresql/PostgreSqlSshDriver.java
index 49740b5..f97f279 100644
--- a/software/database/src/main/java/brooklyn/entity/database/postgresql/PostgreSqlSshDriver.java
+++ b/software/database/src/main/java/brooklyn/entity/database/postgresql/PostgreSqlSshDriver.java
@@ -49,6 +49,7 @@ import brooklyn.util.collections.MutableList;
 import brooklyn.util.collections.MutableMap;
 import brooklyn.util.exceptions.Exceptions;
 import brooklyn.util.net.Urls;
+import brooklyn.util.os.Os;
 import brooklyn.util.stream.Streams;
 import brooklyn.util.task.DynamicTasks;
 import brooklyn.util.task.ssh.SshTasks;
@@ -292,7 +293,7 @@ public class PostgreSqlSshDriver extends AbstractSoftwareProcessSshDriver implem
         try {
             executeDatabaseCreationScript();
         } catch (RuntimeException r) {
-            copyLogFileContents();
+            logTailOfPostgresLog();
             throw Exceptions.propagate(r);
         }
 
@@ -346,13 +347,17 @@ public class PostgreSqlSshDriver extends AbstractSoftwareProcessSshDriver implem
         return getRunDir() + "/postgresql.pid";
     }
 
-    public void copyLogFileContents() {
+    /** @deprecated since 0.7.0 renamed {@link #logTailOfPostgresLog()} */
+    @Deprecated
+    public void copyLogFileContents() { logTailOfPostgresLog(); }
+    public void logTailOfPostgresLog() {
         try {
-            File file = File.createTempFile("postgresql-log", getEntity().getId());
+            File file = Os.newTempFile("postgresql-"+getEntity().getId(), "log");
             int result = getMachine().copyFrom(getLogFile(), file.getAbsolutePath());
             if (result != 0) throw new IllegalStateException("Could not access log file " + getLogFile());
             log.info("Saving {} contents as {}", getLogFile(), file);
             Streams.logStreamTail(log, "postgresql.log", Streams.byteArrayOfString(Files.toString(file, Charsets.UTF_8)), 1024);
+            file.delete();
         } catch (IOException ioe) {
             log.debug("Error reading copied log file: {}", ioe);
         }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/software/webapp/src/test/java/brooklyn/entity/webapp/AbstractWebAppFixtureIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/test/java/brooklyn/entity/webapp/AbstractWebAppFixtureIntegrationTest.java b/software/webapp/src/test/java/brooklyn/entity/webapp/AbstractWebAppFixtureIntegrationTest.java
index f9ff189..3c61ab8 100644
--- a/software/webapp/src/test/java/brooklyn/entity/webapp/AbstractWebAppFixtureIntegrationTest.java
+++ b/software/webapp/src/test/java/brooklyn/entity/webapp/AbstractWebAppFixtureIntegrationTest.java
@@ -46,6 +46,7 @@ import brooklyn.mementos.BrooklynMemento;
 import brooklyn.test.Asserts;
 import brooklyn.test.EntityTestUtils;
 import brooklyn.test.HttpTestUtils;
+import brooklyn.test.entity.LocalManagementContextForTests;
 import brooklyn.test.entity.TestApplication;
 import brooklyn.util.collections.MutableMap;
 import brooklyn.util.os.Os;
@@ -194,7 +195,7 @@ public abstract class AbstractWebAppFixtureIntegrationTest {
     protected void killEntityBehindBack(Entity tokill) throws Exception {
         // Previously was calling entity.getDriver().kill(); but now our entity instance is a proxy so can't do that
         ManagementContext newManagementContext = null;
-        File tempDir = Files.createTempDir();
+        File tempDir = Os.newTempDir(getClass());
         try {
             ManagementContext managementContext = ((EntityInternal)tokill).getManagementContext();
             BrooklynMemento brooklynMemento = MementosGenerators.newBrooklynMemento(managementContext);
@@ -204,7 +205,7 @@ public abstract class AbstractWebAppFixtureIntegrationTest {
             oldPersister.waitForWritesCompleted(30*1000, TimeUnit.MILLISECONDS);
 
             BrooklynMementoPersisterToMultiFile newPersister = new BrooklynMementoPersisterToMultiFile(tempDir , getClass().getClassLoader());
-            newManagementContext = Entities.newManagementContext();
+            newManagementContext = new LocalManagementContextForTests();
             newManagementContext.getRebindManager().setPersister(newPersister);
             newManagementContext.getRebindManager().rebind(getClass().getClassLoader());
             newManagementContext.getRebindManager().start();
@@ -212,7 +213,7 @@ public abstract class AbstractWebAppFixtureIntegrationTest {
             entity2.stop();
         } finally {
             if (newManagementContext != null) ((ManagementContextInternal)newManagementContext).terminate();
-            Os.tryDeleteDirectory(tempDir.getAbsolutePath());
+            Os.deleteRecursively(tempDir.getAbsolutePath());
         }
         log.info("called to stop {} in parallel mgmt universe", entity);
     }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/utils/common/src/main/java/brooklyn/util/javalang/JavaClassNames.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/brooklyn/util/javalang/JavaClassNames.java b/utils/common/src/main/java/brooklyn/util/javalang/JavaClassNames.java
index 2cdf96d..9d716b0 100644
--- a/utils/common/src/main/java/brooklyn/util/javalang/JavaClassNames.java
+++ b/utils/common/src/main/java/brooklyn/util/javalang/JavaClassNames.java
@@ -66,7 +66,17 @@ public class JavaClassNames {
             return className.substring(lastDot+1);
         return className;
     }
- 
+
+    /** as {@link #simpleClassName(Object)} but making the result clean for use on filesystems and as java identifiers */
+    public static String cleanSimpleClassName(Object x) {
+        return Strings.makeValidFilename(simpleClassName(x));
+    }
+    
+    /** as {@link #simpleClassName(Object)} but making the result clean for use on filesystems and as java identifiers */
+    public static String cleanSimpleClassName(Class<?> x) {
+        return Strings.makeValidFilename(simpleClassName(x));
+    }
+    
     public static String packageName(Object x) {
         return componentType(x).getPackage().getName();
     }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0ce9b0cf/utils/common/src/main/java/brooklyn/util/os/Os.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/brooklyn/util/os/Os.java b/utils/common/src/main/java/brooklyn/util/os/Os.java
index 9257452..6e76724 100644
--- a/utils/common/src/main/java/brooklyn/util/os/Os.java
+++ b/utils/common/src/main/java/brooklyn/util/os/Os.java
@@ -18,8 +18,10 @@ import org.slf4j.LoggerFactory;
 
 import brooklyn.util.exceptions.Exceptions;
 import brooklyn.util.guava.Maybe;
+import brooklyn.util.javalang.JavaClassNames;
 import brooklyn.util.net.Urls;
 import brooklyn.util.stream.Streams;
+import brooklyn.util.text.Identifiers;
 import brooklyn.util.text.Strings;
 
 import com.google.common.annotations.Beta;
@@ -186,28 +188,71 @@ public class Os {
 
     /** tries to delete a directory recursively;
      * use with care - see http://stackoverflow.com/questions/8320376/why-is-files-deletedirectorycontents-deprecated-in-guava.
-     * @return true if there are no errors (but the directory may still exist if a file is created there in parallel),
-     * false if there are errors (without reporting the errors)
      * <p>
-     * NB: this method might change, based on Guava choosing to deprecate it;
-     * also the return type might be modified in future to supply more information;
-     * thus it is marked beta */
+     * also note this implementation refuses to delete / or ~, it needs length at least 4 for safety.
+     * if you might really want to delete something like that, use {@link #deleteRecursively(File, boolean)}.
+     */
+    @Beta
+    public static DeletionResult deleteRecursively(File dir) {
+        return deleteRecursively(dir, false);
+    }
+    
+    /** 
+     * as {@link #deleteRecursively(File)} but includes safety checks to prevent deletion of / or ~
+     * or any path of length 4 or less.
+     */
     @Beta
-    public static boolean tryDeleteDirectory(File dir) {
+    public static DeletionResult deleteRecursively(File dir, boolean skipSafetyChecks) {
         try {
+            if (dir==null) return new DeletionResult(null, true, null);
+            
+            if (!skipSafetyChecks) {
+                String dp = dir.getAbsolutePath();
+                if (dp.length()<=4)
+                    throw new IOException("Refusing instruction to delete "+dir+": name too short");
+
+                if (Os.home().equals(dp))
+                    throw new IOException("Refusing instruction to delete "+dir+": it's the home directory");
+            }
+
             FileUtils.deleteDirectory(dir);
-            return true;
+            return new DeletionResult(dir, true, null);
         } catch (IOException e) {
-            return false;
+            return new DeletionResult(dir, false, e);
         }
     }
     
     /**
-     * @see {@link #tryDeleteDirectory(File)}
+     * @see {@link #deleteRecursively(File)}
      */
     @Beta
-    public static boolean tryDeleteDirectory(String dir) {
-        return tryDeleteDirectory(new File(dir));
+    public static DeletionResult deleteRecursively(String dir) {
+        if (dir==null) return new DeletionResult(null, true, null);
+        return deleteRecursively(new File(dir));
+    }
+    
+    public static class DeletionResult {
+        private final File file;
+        private final boolean successful;
+        private final Throwable throwable;
+        public DeletionResult(File file, boolean successful, Throwable throwable) {
+            this.file = file;
+            this.successful = successful;
+            this.throwable = throwable;
+        }
+        public boolean wasSuccessful() { return successful; }
+        public DeletionResult throwIfFailed() {
+            if (!successful)
+                throw Exceptions.propagate(new IOException("Unable to delete '"+file+"': delete returned false", throwable));
+            return this; 
+        }
+        public File getFile() { return file; }
+        public Throwable getThrowable() { return throwable; }
+        public <T> T asNullIgnoringError() { return null; }
+        public <T> T asNullOrThrowing() {
+            throwIfFailed();
+            return null; 
+        }
     }
 
     private static class FileDeletionHook {
@@ -221,7 +266,7 @@ public class Os {
         public void run() throws IOException {
             if (path.exists()) {
                 if (recursively && path.isDirectory()) {
-                    FileUtils.deleteDirectory(path);
+                    Os.deleteRecursively(path);
                 } else {
                     path.delete();
                 }
@@ -415,4 +460,43 @@ public class Os {
         return false;
     }
 
+    /** creates a private temp file which will be deleted on exit;
+     * either prefix or ext may be null; 
+     * if ext does not start with a . and is <= 4 chars in length, a dot will be inserted */
+    public static File newTempFile(String prefix, String ext) {
+        String baseName = (prefix!=null ? prefix + "-" : "") + Identifiers.makeRandomId(4) + 
+            (ext!=null ? ext.startsWith(".") || ext.length()>4 ? ext : "."+ext : "");
+        File tempFile = new File(tmp(), baseName);
+        try {
+            if (tempFile.createNewFile()) {
+                tempFile.deleteOnExit();
+                return tempFile;
+            }
+            throw new IllegalStateException("cannot create temp file "+tempFile+", call returned false");
+        } catch (IOException e) {
+            throw new IllegalStateException("cannot create temp file "+tempFile+", error: "+e, e);
+        }
+    }
+    
+    /** as {@link #newTempFile(String, String)} using the class as the basis for a prefix */
+    public static File newTempFile(Class<?> clazz, String ext) {
+        return newTempFile(JavaClassNames.cleanSimpleClassName(clazz), ext);
+    }
+
+    /** creates a temp dir which will be deleted on exit */
+    public static File newTempDir(String prefix) {
+        String baseName = (prefix==null ? "" : prefix + "-") + "-" + Identifiers.makeRandomId(4);
+        File tempDir = new File(tmp(), baseName);
+        if (tempDir.mkdir()) {
+            Os.deleteOnExitRecursively(tempDir);
+            return tempDir;
+        }
+        throw new IllegalStateException("cannot write to temp dir, making directory "+tempDir);
+    }
+    
+    /** as {@link #newTempDir(String)}, using the class as the basis for a prefix */
+    public static File newTempDir(Class<?> clazz) {
+        return newTempDir(JavaClassNames.cleanSimpleClassName(clazz));
+    }
+
 }


Mime
View raw message