public static File getOsgiCacheDirCleanedIfNeeded(ManagementContext mgmt) { File cacheDirF = getOsgiCacheDir(mgmt); boolean clean = isOsgiCacheForCleaning(mgmt, cacheDirF); log.debug("OSGi cache dir computed as "+cacheDirF.getAbsolutePath()+" ("+ (cacheDirF.exists() ? "already exists" : "does not exist")+", "+ (clean ? "cleaning now (and on exit)" : "cleaning not requested")); if (clean) { Os.deleteRecursively(cacheDirF); Os.deleteOnExitRecursively(cacheDirF); } return cacheDirF; }
@Test(groups="Integration") // integration only because non-reusable OSGi takes ~200ms public void testOsgiPathDefault() { mgmt = LocalManagementContextForTests.builder(true).enableOsgiNonReusable().build(); String path = BrooklynServerPaths.getOsgiCacheDir(mgmt).getAbsolutePath(); Assert.assertTrue(path.startsWith(BrooklynServerPaths.getMgmtBaseDir(mgmt)), path); Assert.assertTrue(path.contains(mgmt.getManagementNodeId()), path); assertExistsThenIsCleaned(path); }
@Test(groups="Integration") // integration only because non-reusable OSGi takes ~200ms public void testOsgiPathCustomWithoutNodeIdNotCleaned() { BrooklynProperties bp = BrooklynProperties.Factory.newEmpty(); String randomSeg = "osgi-test-"+Identifiers.makeRandomId(4); bp.put(BrooklynServerConfig.OSGI_CACHE_DIR, "${brooklyn.os.tmpdir}"+"/"+randomSeg+"/"+"sample"); mgmt = LocalManagementContextForTests.builder(true).enableOsgiNonReusable().useProperties(bp).build(); String path = BrooklynServerPaths.getOsgiCacheDir(mgmt).getAbsolutePath(); Os.deleteOnExitRecursivelyAndEmptyParentsUpTo(new File(path), new File(Os.tmp()+"/"+randomSeg)); Assert.assertTrue(path.startsWith(Os.tmp()), path); Assert.assertFalse(path.contains(mgmt.getManagementNodeId()), path); assertExistsThenCorrectCleanedBehaviour(path, false); }
@Test(groups="Integration") // integration only because non-reusable OSGi takes ~200ms public void testOsgiPathCustom() { BrooklynProperties bp = BrooklynProperties.Factory.newEmpty(); String randomSeg = "osgi-test-"+Identifiers.makeRandomId(4); bp.put(BrooklynServerConfig.OSGI_CACHE_DIR, "${brooklyn.os.tmpdir}"+"/"+randomSeg+"/"+"${brooklyn.mgmt.node.id}"); mgmt = LocalManagementContextForTests.builder(true).enableOsgiNonReusable().useProperties(bp).build(); String path = BrooklynServerPaths.getOsgiCacheDir(mgmt).getAbsolutePath(); Os.deleteOnExitRecursivelyAndEmptyParentsUpTo(new File(path), new File(Os.tmp()+"/"+randomSeg)); Assert.assertTrue(path.startsWith(Os.tmp()), path); Assert.assertTrue(path.contains(mgmt.getManagementNodeId()), path); assertExistsThenIsCleaned(path); }