@Override public void run() { Entities.destroy(entity); } }).build();
@AfterMethod(alwaysRun=true) public void tearDown() throws Exception { // Kills the apps before terminating the pool for (TestApplication app : createdApps) { Entities.destroy(app); } if (mgmt != null) { Entities.destroyAll(mgmt); mgmt = null; } }
/** Same as {@link #destroy(Entity)} but catching all errors. */ public static void destroyCatching(Entity entity) { try { destroy(entity); } catch (Exception e) { log.warn("ERROR destroying "+entity+" (ignoring): "+e, e); Exceptions.propagateIfFatal(e); } }
@AfterMethod(alwaysRun=true) public void tearDown() throws Exception { try { if (mgmt != null) { for (Application app: mgmt.getApplications()) { LOG.debug("destroying app "+app+" (managed? "+Entities.isManaged(app)+"; mgmt is "+mgmt+")"); try { Entities.destroy(app); LOG.debug("destroyed app "+app+"; mgmt now "+mgmt); } catch (Exception e) { LOG.error("problems destroying app "+app, e); } } } if (launcher != null) launcher.destroyAll(); if (viewer != null) viewer.terminate(); if (mgmt != null) Entities.destroyAll(mgmt); if (mementoDir != null) FileBasedObjectStore.deleteCompletely(mementoDir); } catch (Throwable t) { LOG.error("Caught exception in tearDown method", t); } finally { mgmt = null; launcher = null; } }
/** Same as {@link #destroy(Location)} but catching all errors. */ public static void destroyCatching(Location loc) { try { destroy(loc); } catch (Exception e) { log.warn("ERROR destroying "+loc+" (ignoring): "+e, e); Exceptions.propagateIfFatal(e); } }
@Override public void run() { log.debug("destroying app "+app+" (managed? "+isManaged(app)+"; mgmt is "+mgmt+")"); try { destroy(app); log.debug("destroyed app "+app+"; mgmt now "+mgmt); } catch (Exception e) { log.warn("problems destroying app "+app+" (mgmt now "+mgmt+", will rethrow at least one exception): "+e); error.compareAndSet(null, e); } }})); }
@Override public Void call() { Entities.destroy(app); return null; } }, Asserts.DEFAULT_LONG_TIMEOUT.toMilliseconds(), TimeUnit.MILLISECONDS);
@AfterMethod(alwaysRun=true) public void tearDown() throws Exception { try { try { if (app != null) Entities.destroy(app); } catch (Throwable t) { LOG.error("Caught exception in tearDown method", t); } } finally { app = null; } }
@AfterMethod(alwaysRun = true) @Override public void tearDown() { try { if (app != null) Entities.destroy(app); } catch (Throwable t) { log.error("Caught exception in tearDown method", t); } finally { app = null; } }
try { log.warn("Call to invokeStopOnShutdown for "+entity+" while system already shutting down; invoking stop now and throwing exception"); Entities.destroy(entity); throw new IllegalStateException("Call to invokeStopOnShutdown for "+entity+" while system already shutting down"); } catch (Exception e) {
@AfterMethod(alwaysRun = true) @Override public void tearDown() throws Exception { try { if (app != null) Entities.destroy(app); } catch (Throwable t) { LOG.error("Caught exception in tearDown method", t); } finally { app = null; } }
@AfterMethod(alwaysRun = true) public void tearDown() throws Exception { try { try { if (app != null) Entities.destroy(app); } catch (Throwable t) { LOG.error("Caught exception in tearDown method", t); } } finally { app = null; } }
@AfterMethod(alwaysRun=true) public void shutdownApp() { if (entity != null) { Application app = entity.getApplication(); if (app != null) Entities.destroy(app); } }
@Override public void run() { ManagementContext mgmt = app.getManagementContext(); LOG.debug("destroying app "+app+" (managed? "+Entities.isManaged(app)+"; mgmt is "+mgmt+")"); try { Entities.destroy(app); LOG.debug("destroyed app "+app+"; mgmt now "+mgmt); } catch (Exception e) { LOG.warn("problems destroying app "+app+" (mgmt now "+mgmt+", will rethrow at least one exception): "+e); error.compareAndSet(null, e); } }})); }
@BeforeClass(alwaysRun = true) public void setUpClass() throws Exception { super.setUp(); if (app != null) Entities.destroy(app); location = WindowsTestFixture.setUpWindowsLocation(mgmt); machine = location.obtain(ImmutableMap.of()); }
@Test public void testDeleteAndLoadMemento() throws Exception { Entities.destroy(entity); BrooklynMemento reloadedMemento = loadMemento(); assertNotNull(reloadedMemento); assertFalse(Iterables.contains(reloadedMemento.getEntityIds(), entity.getId())); assertEquals(Iterables.getOnlyElement(reloadedMemento.getLocationIds()), location.getId()); // Destroying the app should also unmanage its owned location, and adjuncts Entities.destroy(app); reloadedMemento = loadMemento(); assertFalse(Iterables.contains(reloadedMemento.getEntityIds(), entity.getId())); assertFalse(Iterables.contains(reloadedMemento.getPolicyIds(), policy.getId())); assertFalse(Iterables.contains(reloadedMemento.getEnricherIds(), enricher.getId())); assertFalse(Iterables.contains(reloadedMemento.getLocationIds(), location.getId())); }
@Override public void run() { try { Time.sleep(Duration.FIVE_SECONDS); // error, loop wasn't interrupted or detected LOG.warn("Timeout elapsed, destroying items; usage: "+ ((LocalManagementContext)mgmt()).getGarbageCollector().getUsageString()); Entities.destroy(app); } catch (RuntimeInterruptedException e) { // expected on normal execution; clear the interrupted flag to prevent ugly further warnings being logged Thread.interrupted(); } } });
public void testUnmanagedEntityCanBeGcedEvenIfPreviouslyTagged() throws Exception { TestEntity e = app.createAndManageChild(EntitySpec.create(TestEntity.class)); String eId = e.getId(); e.invoke(TestEntity.MY_EFFECTOR, ImmutableMap.<String,Object>of()).get(); Set<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(app.getManagementContext().getExecutionManager(), e); Task<?> task = Iterables.get(tasks, 0); assertTrue(task.getTags().contains(BrooklynTaskTags.tagForContextEntity(e))); Set<Object> tags = app.getManagementContext().getExecutionManager().getTaskTags(); assertTrue(tags.contains(BrooklynTaskTags.tagForContextEntity(e)), "tags="+tags); Entities.destroy(e); forceGc(); Set<Object> tags2 = app.getManagementContext().getExecutionManager().getTaskTags(); for (Object tag : tags2) { if (tag instanceof Entity && ((Entity)tag).getId().equals(eId)) { fail("tags contains unmanaged entity "+tag); } if ((tag instanceof WrappedEntity) && ((WrappedEntity)tag).entity.getId().equals(eId) && ((WrappedEntity)tag).wrappingType.equals(BrooklynTaskTags.CONTEXT_ENTITY)) { fail("tags contains unmanaged entity (wrapped) "+tag); } } return; }
@Test(groups="Integration") public void testSubscriptionAndEffectorTasksGced() throws Exception { BasicExecutionManager em = (BasicExecutionManager) app.getManagementContext().getExecutionManager(); // allow background enrichers to complete Time.sleep(Duration.ONE_SECOND); forceGc(); List<Task<?>> t1 = em.getAllTasks(); TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class)); entity.sensors().set(TestEntity.NAME, "bob"); entity.invoke(TestEntity.MY_EFFECTOR, ImmutableMap.<String,Object>of()).get(); Entities.destroy(entity); Time.sleep(Duration.ONE_SECOND); forceGc(); List<Task<?>> t2 = em.getAllTasks(); Assert.assertEquals(t1.size(), t2.size(), "lists are different:\n"+t1+"\n"+t2+"\n"); }
@AfterMethod(alwaysRun = true) public void cleanUpButKeepMgmt() throws Exception { for (Application app: MutableList.copyOf(mgmt().getApplications())) { Entities.destroy(app); } for (Bundle b: bundlesToRemove) { ((ManagementContextInternal)mgmt()).getOsgiManager().get().uninstallUploadedBundle( ((ManagementContextInternal)mgmt()).getOsgiManager().get().getManagedBundle(new VersionedName(b))); } bundlesToRemove.clear(); }