Java Code Examples for org.apache.brooklyn.core.entity.Entities#start()
The following examples show how to use
org.apache.brooklyn.core.entity.Entities#start() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractWebAppFixtureIntegrationTest.java From brooklyn-library with Apache License 2.0 | 6 votes |
/** * Checks an entity can start, set SERVICE_UP to true and shutdown again. */ @Test(groups = "Integration", dataProvider = "basicEntities") public void testReportsServiceDownWhenKilled(final SoftwareProcess entity) throws Exception { this.entity = entity; log.info("test=testReportsServiceDownWithKilled; entity="+entity+"; app="+entity.getApplication()); Entities.start(entity.getApplication(), ImmutableList.of(loc)); EntityAsserts.assertAttributeEqualsEventually(MutableMap.of("timeout", 120*1000), entity, Startable.SERVICE_UP, true); // Stop the underlying entity, but without our entity instance being told! killEntityBehindBack(entity); log.info("Killed {} behind mgmt's back, waiting for service up false in mgmt context", entity); EntityAsserts.assertAttributeEqualsEventually(entity, Startable.SERVICE_UP, false); log.info("success getting service up false in primary mgmt universe"); }
Example 2
Source File: AbstractWebAppFixtureIntegrationTest.java From brooklyn-library with Apache License 2.0 | 6 votes |
/** * Tests that we get consecutive events with zero workrate, and with suitably small timestamps between them. */ @Test(groups = "Integration", dataProvider = "basicEntities") @SuppressWarnings("rawtypes") public void publishesZeroRequestsPerSecondMetricRepeatedly(final SoftwareProcess entity) { this.entity = entity; log.info("test=publishesZeroRequestsPerSecondMetricRepeatedly; entity="+entity+"; app="+entity.getApplication()); final int maxIntervalBetweenEvents = 4000; // TomcatServerImpl publishes events every 3000ms so this should be enough overhead final int consecutiveEvents = 3; Entities.start(entity.getApplication(), ImmutableList.of(loc)); SubscriptionHandle subscriptionHandle = null; final CopyOnWriteArrayList<SensorEvent<Double>> events = new CopyOnWriteArrayList<>(); try { subscriptionHandle = recordEvents(entity, WebAppService.REQUESTS_PER_SECOND_IN_WINDOW, events); Asserts.succeedsEventually(assertConsecutiveSensorEventsEqual( events, WebAppService.REQUESTS_PER_SECOND_IN_WINDOW, 0.0d, consecutiveEvents, maxIntervalBetweenEvents)); } finally { if (subscriptionHandle != null) entity.subscriptions().unsubscribe(subscriptionHandle); entity.stop(); } }
Example 3
Source File: AbstractWebAppFixtureIntegrationTest.java From brooklyn-library with Apache License 2.0 | 6 votes |
/** * Tests given entity can deploy the given war. Checks given httpURL to confirm success. */ @Test(groups = "Integration", dataProvider = "entitiesWithWarAndURL") public void initialRootWarDeployments(final SoftwareProcess entity, final String war, final String urlSubPathToWebApp, final String urlSubPathToPageToQuery) { this.entity = entity; log.info("test=initialRootWarDeployments; entity="+entity+"; app="+entity.getApplication()); URL resource = getClass().getClassLoader().getResource(war); assertNotNull(resource); entity.config().set(JavaWebAppService.ROOT_WAR, resource.toString()); Entities.start(entity.getApplication(), ImmutableList.of(loc)); //tomcat may need a while to unpack everything Asserts.succeedsEventually(MutableMap.of("timeout", 60*1000), new Runnable() { @Override public void run() { // TODO get this URL from a WAR file entity HttpTestUtils.assertHttpStatusCodeEquals(Urls.mergePaths(entity.getAttribute(WebAppService.ROOT_URL), urlSubPathToPageToQuery), 200); assertEquals(entity.getAttribute(JavaWebAppSoftwareProcess.DEPLOYED_WARS), ImmutableSet.of("/")); }}); }
Example 4
Source File: AbstractWebAppFixtureIntegrationTest.java From brooklyn-library with Apache License 2.0 | 6 votes |
@Test(groups = "Integration", dataProvider = "entitiesWithWarAndURL") public void initialNamedWarDeployments(final SoftwareProcess entity, final String war, final String urlSubPathToWebApp, final String urlSubPathToPageToQuery) { this.entity = entity; log.info("test=initialNamedWarDeployments; entity="+entity+"; app="+entity.getApplication()); URL resource = getClass().getClassLoader().getResource(war); assertNotNull(resource); entity.config().set(JavaWebAppService.NAMED_WARS, ImmutableList.of(resource.toString())); Entities.start(entity.getApplication(), ImmutableList.of(loc)); Asserts.succeedsEventually(MutableMap.of("timeout", 60*1000), new Runnable() { @Override public void run() { // TODO get this URL from a WAR file entity HttpTestUtils.assertHttpStatusCodeEquals(Urls.mergePaths(entity.getAttribute(WebAppService.ROOT_URL), urlSubPathToWebApp, urlSubPathToPageToQuery), 200); }}); }
Example 5
Source File: NodeJsWebAppFixtureIntegrationTest.java From brooklyn-library with Apache License 2.0 | 6 votes |
/** * Checks an entity can start, set SERVICE_UP to true and shutdown again. */ // Broken on Ubuntu 15.04 Vivid, no packages from ppa:chris-lea/node.js available @Test(groups = {"Integration","Broken"}) public void testCanStartAndStop() { LOG.info("test=canStartAndStop; entity="+entity+"; app="+entity.getApplication()); Entities.start(entity.getApplication(), ImmutableList.of(loc)); Asserts.succeedsEventually(MutableMap.of("timeout", 120*1000), new Runnable() { @Override public void run() { assertTrue(entity.getAttribute(Startable.SERVICE_UP)); }}); entity.stop(); assertFalse(entity.getAttribute(Startable.SERVICE_UP)); }
Example 6
Source File: NodeJsWebAppFixtureIntegrationTest.java From brooklyn-library with Apache License 2.0 | 6 votes |
/** * Checks an entity can start, set SERVICE_UP to true and shutdown again. */ // Broken on Ubuntu 15.04 Vivid, no packages from ppa:chris-lea/node.js available @Test(groups = {"Integration","Broken"}) public void testReportsServiceDownWhenKilled() throws Exception { LOG.info("test=testReportsServiceDownWithKilled; entity="+entity+"; app="+entity.getApplication()); Entities.start(entity.getApplication(), ImmutableList.of(loc)); EntityAsserts.assertAttributeEqualsEventually(MutableMap.of("timeout", Duration.minutes(2)), entity, Startable.SERVICE_UP, true); // Stop the underlying entity, but without our entity instance being told! killEntityBehindBack(entity); LOG.info("Killed {} behind mgmt's back, waiting for service up false in mgmt context", entity); EntityAsserts.assertAttributeEqualsEventually(entity, Startable.SERVICE_UP, false); LOG.info("success getting service up false in primary mgmt universe"); }
Example 7
Source File: NodeJsWebAppFixtureIntegrationTest.java From brooklyn-library with Apache License 2.0 | 6 votes |
@Test(groups = {"Integration","Broken"}) public void testInitialNamedDeployments() { final String urlSubPathToWebApp = APP_NAME; final String urlSubPathToPageToQuery = ""; LOG.info("test=testInitialNamedDeployments; entity="+entity+"; app="+entity.getApplication()); Entities.start(entity.getApplication(), ImmutableList.of(loc)); Asserts.succeedsEventually(MutableMap.of("timeout", Duration.minutes(1)), new Runnable() { @Override public void run() { // TODO get this URL from a web-app entity of some kind? String url = Urls.mergePaths(entity.getAttribute(WebAppService.ROOT_URL), urlSubPathToWebApp, urlSubPathToPageToQuery); HttpTestUtils.assertHttpStatusCodeEquals(url, 200); }}); }
Example 8
Source File: ScriptResourceTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testGroovy() { ManagementContext mgmt = LocalManagementContextForTests.newInstance(); Application app = mgmt.getEntityManager().createEntity( EntitySpec.create(Application.class, RestMockApp.class) ); try { Entities.start(app, Collections.<Location>emptyList()); ScriptResource s = new ScriptResource(); s.setManagementContext(mgmt); ScriptExecutionSummary result = s.groovy(null, "def apps = []; mgmt.applications.each { println 'app:'+it; apps << it.id }; apps"); Assert.assertEquals(Collections.singletonList(app.getId()).toString(), result.getResult()); Assert.assertTrue(result.getStdout().contains("app:RestMockApp")); } finally { Entities.destroyAll(mgmt); } }
Example 9
Source File: EntityLocationUtilsTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testCount() { @SuppressWarnings("unused") SoftwareProcess r1 = app.createAndManageChild(EntitySpec.create(SoftwareProcess.class, RestMockSimpleEntity.class)); SoftwareProcess r2 = app.createAndManageChild(EntitySpec.create(SoftwareProcess.class, RestMockSimpleEntity.class)); Entities.start(app, Arrays.<Location>asList(loc)); Entities.dumpInfo(app); log.info("r2loc: "+r2.getLocations()); log.info("props: "+((LocationInternal)r2.getLocations().iterator().next()).config().getInternalConfigMap().getAllConfigInheritedRawValuesIgnoringErrors()); Map<Location, Integer> counts = new EntityLocationUtils(mgmt).countLeafEntitiesByLocatedLocations(); log.info("count: "+counts); assertEquals(ImmutableList.copyOf(counts.values()), ImmutableList.of(2), "counts="+counts); }
Example 10
Source File: AbstractWebAppFixtureIntegrationTest.java From brooklyn-library with Apache License 2.0 | 5 votes |
/** * Checks an entity can start, set SERVICE_UP to true and shutdown again. */ @Test(groups = "Integration", dataProvider = "basicEntities") public void canStartAndStop(final SoftwareProcess entity) { this.entity = entity; log.info("test=canStartAndStop; entity="+entity+"; app="+entity.getApplication()); Entities.start(entity.getApplication(), ImmutableList.of(loc)); EntityAsserts.assertAttributeEqualsEventually( MutableMap.of("timeout", 120*1000), entity, Startable.SERVICE_UP, Boolean.TRUE); entity.stop(); assertFalse(entity.getAttribute(Startable.SERVICE_UP)); }
Example 11
Source File: AbstractWebAppFixtureIntegrationTest.java From brooklyn-library with Apache License 2.0 | 5 votes |
/** * Checks that an entity correctly sets request and error count metrics by * connecting to a non-existent URL several times. */ @Test(groups = "Integration", dataProvider = "basicEntities") public void publishesRequestAndErrorCountMetrics(final SoftwareProcess entity) throws Exception { this.entity = entity; log.info("test=publishesRequestAndErrorCountMetrics; entity="+entity+"; app="+entity.getApplication()); Entities.start(entity.getApplication(), ImmutableList.of(loc)); EntityAsserts.assertAttributeEqualsEventually( MutableMap.of("timeout", 120 * 1000), entity, Startable.SERVICE_UP, Boolean.TRUE); String url = entity.getAttribute(WebAppService.ROOT_URL) + "does_not_exist"; final int n = 10; for (int i = 0; i < n; i++) { URLConnection connection = HttpTestUtils.connectToUrl(url); int status = ((HttpURLConnection) connection).getResponseCode(); log.info("connection to {} gives {}", url, status); } Asserts.succeedsEventually(MutableMap.of("timeout", 20*1000), new Runnable() { @Override public void run() { Integer requestCount = entity.getAttribute(WebAppService.REQUEST_COUNT); Integer errorCount = entity.getAttribute(WebAppService.ERROR_COUNT); log.info("req={}, err={}", requestCount, errorCount); assertNotNull(errorCount, "errorCount not set yet ("+errorCount+")"); // AS 7 seems to take a very long time to report error counts, // hence not using ==. >= in case error pages include a favicon, etc. assertEquals(errorCount, (Integer)n); assertTrue(requestCount >= errorCount); }}); }
Example 12
Source File: AbstractWebAppFixtureIntegrationTest.java From brooklyn-library with Apache License 2.0 | 5 votes |
/** * Tests that requests/sec last and windowed decay when the entity can't be contacted for * up to date values. */ @Test(groups = "Integration", dataProvider = "basicEntities") public void testRequestCountContinuallyPublishedWhenEntityKilled(final SoftwareProcess entity) throws Exception { this.entity = entity; log.info("test=testRequestCountContinuallyPublishedWhenEntityKilled; entity="+entity+"; app="+entity.getApplication()); Entities.start(entity.getApplication(), ImmutableList.of(loc)); EntityAsserts.assertAttributeEqualsEventually(entity, SoftwareProcess.SERVICE_UP, Boolean.TRUE); String url = entity.getAttribute(WebAppService.ROOT_URL) + "does_not_exist"; // Apply load to entity. Assert enriched sensor values. HttpTestUtils.connectToUrl(url); EntityAsserts.assertAttributeEventually(entity, WebAppServiceMetrics.REQUEST_COUNT, new Predicate<Integer>() { @Override public boolean apply(Integer input) { return input > 0; }}); killEntityBehindBack(entity); final int requestCountAfterKilled = entity.sensors().get(WebAppServiceMetrics.REQUEST_COUNT); final int maxIntervalBetweenEvents = 4000; // TomcatServerImpl publishes events every 3000ms so this should be enough overhead final int consecutiveEvents = 3; // The entity should be configured to keep publishing request count, so SubscriptionHandle subscriptionHandle = null; final CopyOnWriteArrayList<SensorEvent<Integer>> events = new CopyOnWriteArrayList<>(); try { subscriptionHandle = recordEvents(entity, WebAppServiceMetrics.REQUEST_COUNT, events); Asserts.succeedsEventually(assertConsecutiveSensorEventsEqual( events, WebAppServiceMetrics.REQUEST_COUNT, requestCountAfterKilled, consecutiveEvents, maxIntervalBetweenEvents)); } finally { if (subscriptionHandle != null) entity.subscriptions().unsubscribe(subscriptionHandle); entity.stop(); } }
Example 13
Source File: AbstractWebAppFixtureIntegrationTest.java From brooklyn-library with Apache License 2.0 | 5 votes |
@Test(groups = "Integration", dataProvider = "entitiesWithWarAndURL") public void testWarDeployAndUndeploy(final JavaWebAppSoftwareProcess entity, final String war, final String urlSubPathToWebApp, final String urlSubPathToPageToQuery) { this.entity = entity; log.info("test=testWarDeployAndUndeploy; entity="+entity+"; app="+entity.getApplication()); URL resource = getClass().getClassLoader().getResource(war);; assertNotNull(resource); Entities.start(entity.getApplication(), ImmutableList.of(loc)); // Test deploying entity.deploy(resource.toString(), "myartifactname.war"); Asserts.succeedsEventually(MutableMap.of("timeout", 60*1000), new Runnable() { @Override public void run() { // TODO get this URL from a WAR file entity HttpTestUtils.assertHttpStatusCodeEquals(Urls.mergePaths(entity.getAttribute(WebAppService.ROOT_URL), "myartifactname/", urlSubPathToPageToQuery), 200); assertEquals(entity.getAttribute(JavaWebAppSoftwareProcess.DEPLOYED_WARS), ImmutableSet.of("/myartifactname")); }}); // And undeploying entity.undeploy("/myartifactname"); Asserts.succeedsEventually(MutableMap.of("timeout", 60*1000), new Runnable() { @Override public void run() { // TODO get this URL from a WAR file entity HttpTestUtils.assertHttpStatusCodeEquals(Urls.mergePaths(entity.getAttribute(WebAppService.ROOT_URL), "myartifactname", urlSubPathToPageToQuery), 404); assertEquals(entity.getAttribute(JavaWebAppSoftwareProcess.DEPLOYED_WARS), ImmutableSet.of()); }}); }