org.apache.brooklyn.core.test.entity.TestApplication Java Examples

The following examples show how to use org.apache.brooklyn.core.test.entity.TestApplication. 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: RebindEnricherTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testCombiningEnricher() throws Exception {
    origApp.enrichers().add(Enrichers.builder()
            .combining(METRIC1, METRIC2)
            .from(origEntity)
            .computing(StringFunctions.joiner(","))
            .publishing(METRIC2)
            .build());
    
    TestApplication newApp = rebind();
    TestEntity newEntity = (TestEntity) Iterables.find(newApp.getChildren(), Predicates.instanceOf(TestEntity.class));

    newEntity.sensors().set(METRIC1, "myval");
    newEntity.sensors().set(METRIC2, "myval2");
    EntityAsserts.assertAttributeEventually(newApp, METRIC2, Predicates.or(Predicates.equalTo("myval,myval2"), Predicates.equalTo("myval2,myval")));
}
 
Example #2
Source File: TestSensorTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
protected void assertStartFails(final TestApplication app, final Class<? extends Throwable> clazz, Duration execTimeout) throws Exception {
    Runnable task = new Runnable() {
        @Override
        public void run() {
            try {
                app.start(locs);
                Asserts.shouldHaveFailedPreviously();
            } catch (final PropagatedRuntimeException pre) {
                final Throwable throwable = Exceptions.getFirstThrowableOfType(pre, clazz);
                if (throwable == null) {
                    throw pre;
                }
            }
        }
    };

    if (execTimeout == null) {
        task.run();
    } else {
        Asserts.assertReturnsEventually(task, execTimeout);
    }

    Entity entity = Iterables.find(Entities.descendantsWithoutSelf(app), Predicates.instanceOf(TestSensor.class));
    assertTestSensorFails((TestSensor) entity);
}
 
Example #3
Source File: JBossServersMultiVersionWebAppFixtureIntegrationTest.java    From brooklyn-library with Apache License 2.0 6 votes vote down vote up
@Override
@DataProvider(name = "basicEntities")
public Object[][] basicEntities() {
    TestApplication jboss6App = newTestApplication();
    JBoss6Server jboss6 = jboss6App.createAndManageChild(EntitySpec.create(JBoss6Server.class)
            .configure(JBoss6Server.PORT_INCREMENT, PORT_INCREMENT));
    
    TestApplication jboss7App = newTestApplication();
    JBoss7Server jboss7 = jboss7App.createAndManageChild(EntitySpec.create(JBoss7Server.class)
            .configure(JBoss7Server.HTTP_PORT, PortRanges.fromString(DEFAULT_HTTP_PORT)));
    
    return new JavaWebAppSoftwareProcess[][] {
            new JavaWebAppSoftwareProcess[] {jboss6}, 
            new JavaWebAppSoftwareProcess[] {jboss7}
            
    };
}
 
Example #4
Source File: UsageResourceTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testListAndGetMachineUsage() throws Exception {
    Location location = getManagementContext().getLocationManager().createLocation(LocationSpec.create(DynamicLocalhostMachineProvisioningLocation.class));
    TestApplication app = getManagementContext().getEntityManager().createEntity(EntitySpec.create(TestApplication.class));
    SoftwareProcessEntityTest.MyService entity = app.createAndManageChild(org.apache.brooklyn.api.entity.EntitySpec.create(SoftwareProcessEntityTest.MyService.class));
    
    Calendar preStart = new GregorianCalendar();
    app.start(ImmutableList.of(location));
    Calendar postStart = new GregorianCalendar();
    Location machine = Iterables.getOnlyElement(entity.getLocations());

    // All machines
    Response response = client().path("/usage/machines").get();
    assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
    Iterable<UsageStatistics> usages = response.readEntity(new GenericType<List<UsageStatistics>>() {});
    UsageStatistics usage = Iterables.getOnlyElement(usages);
    assertMachineUsage(usage, app.getId(), machine.getId(), ImmutableList.of(Status.ACCEPTED), roundDown(preStart), postStart);

    // Specific machine
    response = client().path("/usage/machines/"+machine.getId()).get();
    assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
    assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
    usage = response.readEntity(new GenericType<UsageStatistics>() {});
    assertMachineUsage(usage, app.getId(), machine.getId(), ImmutableList.of(Status.ACCEPTED), roundDown(preStart), postStart);
}
 
Example #5
Source File: HotStandbyTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testHotStandbyDoesNotStartFeeds() throws Exception {
    HaMgmtNode n1 = createMaster(Duration.PRACTICALLY_FOREVER);
    TestApplication app = createFirstAppAndPersist(n1);
    TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class).impl(MyEntityWithFunctionFeedImpl.class));
    forcePersistNow(n1);
    Assert.assertTrue(entity.feeds().getFeeds().size() > 0, "Feeds: "+entity.feeds().getFeeds());
    for (Feed feed : entity.feeds().getFeeds()) {
        assertTrue(feed.isRunning(), "Feed expected running, but it is non-running");
    }

    HaMgmtNode n2 = createHotStandby(Duration.PRACTICALLY_FOREVER);
    TestEntity entityRO = (TestEntity) n2.mgmt.lookup(entity.getId(), Entity.class);
    Assert.assertTrue(entityRO.feeds().getFeeds().size() > 0, "Feeds: "+entity.feeds().getFeeds());
    for (Feed feedRO : entityRO.feeds().getFeeds()) {
        assertFalse(feedRO.isRunning(), "Feed expected non-active, but it is running");
    }
}
 
Example #6
Source File: ServerPoolTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddExistingMachineFromSpec() {
    TestApplication app = createAppWithChildren(getInitialPoolSize());
    app.start(ImmutableList.of(pool.getDynamicLocation()));
    assertAvailableCountEventuallyEquals(0);

    Collection<Entity> added = pool.addExistingMachinesFromSpec("byon:(hosts=\"localhost,localhost\")");
    assertEquals(added.size(), 2, "Added: " + Joiner.on(", ").join(added));
    Iterator<Entity> it = added.iterator();
    assertFalse(it.next().getConfig(ServerPoolImpl.REMOVABLE));
    assertFalse(it.next().getConfig(ServerPoolImpl.REMOVABLE));
    assertAvailableCountEventuallyEquals(2);

    TestApplication app2 = createAppWithChildren(2);
    app2.start(ImmutableList.of(pool.getDynamicLocation()));
    assertAvailableCountEventuallyEquals(0);
}
 
Example #7
Source File: RebindJcloudsLocationLiveTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test(groups={"Live", "WIP"}, enabled=false)
public void testRebindsToJcloudsMachineWithInvalidTemplate() throws Exception {
    ResourceUtils resourceUtils = ResourceUtils.create(this);
    FileUtils.write(
            new File(mementoDir, "locations/briByOel"),
            resourceUtils.getResourceAsString("classpath://org/apache/brooklyn/location/jclouds/persisted-azure-parent-briByOel"));
    FileUtils.write(
            new File(mementoDir, "locations/VNapYjwp"),
            resourceUtils.getResourceAsString("classpath://org/apache/brooklyn/location/jclouds/persisted-azure-machine-VNapYjwp"));
    
    TestApplication newApp = rebind();
    
    JcloudsLocation loc = (JcloudsLocation) newApp.getManagementContext().getLocationManager().getLocation("briByOel");
    JcloudsSshMachineLocation machine = (JcloudsSshMachineLocation) newApp.getManagementContext().getLocationManager().getLocation("VNapYjwp");
    assertEquals(ImmutableSet.of(loc.getChildren()), ImmutableSet.of(machine));
}
 
Example #8
Source File: HotStandbyTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testHotStandbySeesChangesToNameConfigAndSensorValue() throws Exception {
    HaMgmtNode n1 = createMaster(Duration.PRACTICALLY_FOREVER);
    TestApplication app = createFirstAppAndPersist(n1);
    HaMgmtNode n2 = createHotStandby(Duration.PRACTICALLY_FOREVER);

    assertEquals(n2.mgmt.getApplications().size(), 1);
    Application appRO = n2.mgmt.lookup(app.getId(), Application.class);
    Assert.assertNotNull(appRO);
    assertEquals(appRO.getChildren().size(), 0);
    
    // test changes

    app.setDisplayName("First App Renamed");
    app.config().set(TestEntity.CONF_NAME, "first-app-renamed");
    app.sensors().set(TestEntity.SEQUENCE, 4);

    appRO = expectRebindSequenceNumber(n1, n2, app, 4, true);
    assertEquals(n2.mgmt.getEntityManager().getEntities().size(), 1);
    assertEquals(appRO.getDisplayName(), "First App Renamed");
    assertEquals(appRO.getConfig(TestEntity.CONF_NAME), "first-app-renamed");
    
    // and change again for good measure!

    app.setDisplayName("First App");
    app.config().set(TestEntity.CONF_NAME, "first-app-restored");
    app.sensors().set(TestEntity.SEQUENCE, 5);
    
    appRO = expectRebindSequenceNumber(n1, n2, app, 5, true);
    assertEquals(n2.mgmt.getEntityManager().getEntities().size(), 1);
    assertEquals(appRO.getDisplayName(), "First App");
    assertEquals(appRO.getConfig(TestEntity.CONF_NAME), "first-app-restored");
}
 
Example #9
Source File: AbstractSeaCloudsPoliciesLiveTests.java    From SeaCloudsPlatform with Apache License 2.0 5 votes vote down vote up
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception {
    app = ApplicationBuilder.newManagedApp(TestApplication.class);
    managementContext = app.getManagementContext();
    locationManager = managementContext.getLocationManager();
    loc = locationManager.createLocation(LocationSpec.create(SshMachineLocation.class)
            .configure("address", "localhost"));
}
 
Example #10
Source File: RebindLocationTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testIgnoresStaticFieldsSetFromFlag() throws Exception {
    MyLocation origLoc = new MyLocation(MutableMap.of("myStaticFieldSetFromFlag", "myval"));
    origApp.start(ImmutableList.of(origLoc));

    RebindTestUtils.stopPersistence(origApp);
    MyLocation.myStaticFieldSetFromFlag = "mynewval"; // not auto-checkpointed
    newApp = (TestApplication) RebindTestUtils.rebind(mementoDir, getClass().getClassLoader());
    MyLocation newLoc = (MyLocation) Iterables.get(newApp.getLocations(), 0);
    Assert.assertEquals(newLoc, origLoc);
    
    assertEquals(MyLocation.myStaticFieldSetFromFlag, "mynewval");
}
 
Example #11
Source File: ScalabilityPerformanceTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
private TestApplication newClusterApp(int suffix) {
    TestApplication app = mgmt.getEntityManager().createEntity(EntitySpec.create(EntitySpec.create(TestApplication.class)
            .displayName("app-"+suffix)
            .child(EntitySpec.create(DynamicCluster.class)
                    .configure(DynamicCluster.INITIAL_SIZE, 1)
                    .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(BasicStartable.class)))));
    app.start(ImmutableList.of(app.newLocalhostProvisioningLocation()));
    return app;
}
 
Example #12
Source File: OsgiTestingLeaksAndSpeedTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
void up() throws Exception {
        mgmt = LocalManagementContextForTests.builder(true)
            .enableOsgiReusable()
//            .disableOsgi()
//            .enableOsgiNonReusable()
            .build();
        app = TestApplication.Factory.newManagedInstanceForTests(mgmt);
    }
 
Example #13
Source File: RebindEnricherTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testPropagatingAllEnricher() throws Exception {
    origApp.enrichers().add(Enrichers.builder()
            .propagatingAll()
            .from(origEntity)
            .build());
    
    TestApplication newApp = rebind();
    TestEntity newEntity = (TestEntity) Iterables.find(newApp.getChildren(), Predicates.instanceOf(TestEntity.class));

    newEntity.sensors().set(METRIC1, "myval");
    EntityAsserts.assertAttributeEqualsEventually(newApp, METRIC1, "myval");
}
 
Example #14
Source File: EntityAutomanagedTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testStartManagementIsNoop() throws Exception {
    TestApplication app2 = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class));
    assertTrue(Entities.isManaged(app2));
    
    Entities.startManagement(app2, mgmt);
    assertTrue(Entities.isManaged(app2));
    listener.assertEventsEqualsEventually(ImmutableList.of(new ChangeEvent(ChangeType.ADDED, app2)));
}
 
Example #15
Source File: EntityAutomanagedTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testNewApp() throws Exception {
    TestApplication app2 = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class));
    assertTrue(Entities.isManaged(app2));
    
    assertTrue(mgmt.getApplications().contains(app2), "app="+app2+"; apps="+mgmt.getApplications());
    app.addChild(app2);
    assertTrue(Entities.isManaged(app2));
    listener.assertEventsEqualsEventually(ImmutableList.of(new ChangeEvent(ChangeType.ADDED, app2)));
}
 
Example #16
Source File: RebindFeedWithHaTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test(retryAnalyzer = FlakyRetryAnalyser.class)
public void testHttpFeedCleansUpAfterHaDisabledAndRunsAtFailover() throws Exception {
    TestEntity origEntity = origApp.createAndManageChild(EntitySpec.create(TestEntity.class).impl(RebindFeedTest.MyEntityWithHttpFeedImpl.class)
            .configure(RebindFeedTest.MyEntityWithHttpFeedImpl.BASE_URL, baseUrl));
    EntityAsserts.assertAttributeEqualsEventually(origEntity, SENSOR_INT, 200);
    EntityAsserts.assertAttributeEqualsEventually(origEntity, SENSOR_STRING, "{\"foo\":\"myfoo\"}");
    assertEquals(origEntity.feeds().getFeeds().size(), 1);
    origManagementContext.getRebindManager().forcePersistNow(false, null);

    List<Task<?>> tasksBefore = ((BasicExecutionManager)origManagementContext.getExecutionManager()).getAllTasks();
    log.info("tasks before disabling HA, "+tasksBefore.size()+": "+tasksBefore);
    Assert.assertFalse(tasksBefore.isEmpty());
    origManagementContext.getHighAvailabilityManager().changeMode(HighAvailabilityMode.DISABLED);
    origApp = null;
    
    Repeater.create().every(Duration.millis(20)).backoffTo(Duration.ONE_SECOND).limitTimeTo(Duration.THIRTY_SECONDS).until(new Callable<Boolean>() {
        @Override
        public Boolean call() throws Exception {
            origManagementContext.getGarbageCollector().gcIteration();
            List<Task<?>> tasksAfter = removeSystemTasks( ((BasicExecutionManager)origManagementContext.getExecutionManager()).getAllTasks() );
            log.info("tasks after disabling HA, "+tasksAfter.size()+": "+tasksAfter);
            return tasksAfter.isEmpty();
        }

    }).runRequiringTrue();
    
    newManagementContext = createNewManagementContext();
    newApp = (TestApplication) RebindTestUtils.rebind(RebindOptions.create().newManagementContext(newManagementContext).classLoader(classLoader));

    TestEntity newEntity = (TestEntity) Iterables.getOnlyElement(newApp.getChildren());
    
    Collection<Feed> newFeeds = newEntity.feeds().getFeeds();
    assertEquals(newFeeds.size(), 1);
    
    // Expect the feed to still be polling
    newEntity.sensors().set(SENSOR_INT, null);
    newEntity.sensors().set(SENSOR_STRING, null);
    EntityAsserts.assertAttributeEqualsEventually(newEntity, SENSOR_INT, 200);
    EntityAsserts.assertAttributeEqualsEventually(newEntity, SENSOR_STRING, "{\"foo\":\"myfoo\"}");
}
 
Example #17
Source File: ServerPoolTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testAppCanBeDeployedToServerPool() {
    TestApplication app = createAppWithChildren(1);
    app.start(ImmutableList.of(pool.getDynamicLocation()));
    assertTrue(app.getAttribute(Attributes.SERVICE_UP));
    for (Entity child : app.getChildren()) {
        assertTrue(child.getAttribute(Attributes.SERVICE_UP));
    }
}
 
Example #18
Source File: RebindEnricherTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testRollingTimeWindowMeanEnricher() throws Exception {
    origApp.enrichers().add(EnricherSpec.create(RollingTimeWindowMeanEnricher.class)
            .configure("producer", origApp)
            .configure("source", INT_METRIC)
            .configure("target", DOUBLE_METRIC)
            .configure("timePeriod", Duration.millis(10)));
    
    TestApplication newApp = rebind();

    newApp.sensors().set(INT_METRIC, 10);
    Time.sleep(Duration.millis(10));
    newApp.sensors().set(INT_METRIC, 10);
    EntityAsserts.assertAttributeEqualsEventually(newApp, DOUBLE_METRIC, 10d);
}
 
Example #19
Source File: UsageResourceTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testListMachinesUsageForApp() throws Exception {
    Location location = getManagementContext().getLocationManager().createLocation(LocationSpec.create(DynamicLocalhostMachineProvisioningLocation.class));
    TestApplication app = getManagementContext().getEntityManager().createEntity(EntitySpec.create(TestApplication.class));
    SoftwareProcessEntityTest.MyService entity = app.createAndManageChild(org.apache.brooklyn.api.entity.EntitySpec.create(SoftwareProcessEntityTest.MyService.class));
    String appId = app.getId();
    
    Calendar preStart = new GregorianCalendar();
    app.start(ImmutableList.of(location));
    Calendar postStart = new GregorianCalendar();
    Location machine = Iterables.getOnlyElement(entity.getLocations());

    // For running machine
    Response response = client().path("/usage/machines").query("application", appId).get();
    assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
    Iterable<UsageStatistics> usages = response.readEntity(new GenericType<List<UsageStatistics>>() {});
    UsageStatistics usage = Iterables.getOnlyElement(usages);
    assertMachineUsage(usage, app.getId(), machine.getId(), ImmutableList.of(Status.ACCEPTED), roundDown(preStart), postStart);
    
    // Stop the machine
    Calendar preStop = new GregorianCalendar();
    app.stop();
    Calendar postStop = new GregorianCalendar();
    
    // Deleted machine still returned, if in time range
    response = client().path("/usage/machines").query("application", appId).get();
    assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
    usages = response.readEntity(new GenericType<List<UsageStatistics>>() {});
    usage = Iterables.getOnlyElement(usages);
    assertMachineUsage(usage, app.getId(), machine.getId(), ImmutableList.of(Status.ACCEPTED, Status.DESTROYED), roundDown(preStart), postStop);
    assertMachineUsage(ImmutableList.copyOf(usage.getStatistics()).subList(1,2), appId, machine.getId(), ImmutableList.of(Status.DESTROYED), roundDown(preStop), postStop);

    // Terminated machines ignored if terminated since start-time
    long futureTime = postStop.getTime().getTime()+1;
    waitForFuture(futureTime);
    response = client().path("/usage/applications").query("start", futureTime).get();
    assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
    usages = response.readEntity(new GenericType<List<UsageStatistics>>() {});
    assertTrue(Iterables.isEmpty(usages), "usages="+usages);
}
 
Example #20
Source File: TasksTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testResolvesMapWithAttributeWhenReady() throws Exception {
    app.sensors().set(TestApplication.MY_ATTRIBUTE, "myval");
    Map<?,?> orig = ImmutableMap.of("mykey", attributeWhenReady(app, TestApplication.MY_ATTRIBUTE));
    Map<String,String> expected = ImmutableMap.of("mykey", "myval");
    assertResolvesValue(orig, new TypeToken<Map<String,String>>() {}, expected);
}
 
Example #21
Source File: ExternalConfigYamlTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testExternalisedConfigFromSupplierWithoutMapArg() throws Exception {
    ConfigKey<String> MY_CONFIG_KEY = ConfigKeys.newStringConfigKey("my.config.key");

    String yaml = Joiner.on("\n").join(
        "services:",
        "- serviceType: org.apache.brooklyn.core.test.entity.TestApplication",
        "  brooklyn.config:",
        "    my.config.key: $brooklyn:external(\"myproviderWithoutMapArg\", \"mykey\")");

    TestApplication app = (TestApplication) createAndStartApplication(yaml);
    waitForApplicationTasks(app);

    assertEquals(app.getConfig(MY_CONFIG_KEY), "myHardcodedVal");
}
 
Example #22
Source File: ApplicationTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testAppInAppTest() throws IOException {
    ManagementContext mgmt = LocalManagementContextForTests.newInstance();
    try {
        TestApplication app = mgmt.getEntityManager().createEntity(org.apache.brooklyn.api.entity.EntitySpec.create(TestApplication.class));
        app.addChild(org.apache.brooklyn.api.entity.EntitySpec.create(TestApplication.class));
        Asserts.assertEqualsIgnoringOrder(mgmt.getApplications(), ImmutableList.of(app));
    } finally {
        Entities.destroyAll(mgmt);
    }
}
 
Example #23
Source File: ExternalConfigYamlTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testExternalisedConfigReferencedFromYaml() throws Exception {
    ConfigKey<String> MY_CONFIG_KEY = ConfigKeys.newStringConfigKey("my.config.key");

    String yaml = Joiner.on("\n").join(
        "services:",
        "- serviceType: org.apache.brooklyn.core.test.entity.TestApplication",
        "  brooklyn.config:",
        "    my.config.key: $brooklyn:external(\"myprovider\", \"mykey\")");

    TestApplication app = (TestApplication) createAndStartApplication(yaml);
    waitForApplicationTasks(app);

    assertEquals(app.getConfig(MY_CONFIG_KEY), "myval");
}
 
Example #24
Source File: TaskPredicatesTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testIsEffector() throws Exception {
    Task<?> task = app.invoke(TestApplication.START, ImmutableMap.of("locations", ImmutableList.<Location>of()));
    Task<?> otherTask = execManager.submit(TaskBuilder.<Object>builder()
            .body(Callables.<Object>returning("val"))
            .build());
    assertTrue(TaskPredicates.isEffector().apply(task));
    assertFalse(TaskPredicates.isEffector().apply(otherTask));
    
}
 
Example #25
Source File: ServerPoolTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testResizePoolDownSucceedsWhenEnoughMachinesAreFree() {
    TestApplication app = createAppWithChildren(1);
    app.start(ImmutableList.of(pool.getDynamicLocation()));
    assertAvailableCountEventuallyEquals(getInitialPoolSize() - 1);

    pool.resize(1);

    assertAvailableCountEventuallyEquals(0);
}
 
Example #26
Source File: BrooklynEntityMirrorIntegrationTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test(groups="Integration")
public void testServiceMirroring() throws Exception {
    setUpServer();
    
    String catalogItemId = "test-catalog-item:1.0";
    String catalogItemIdGA = "test-catalog-item:1.0-GA";
    serverApp.sensors().set(TestApplication.MY_ATTRIBUTE, "austria");
    serverApp.setCatalogItemId(catalogItemId);

    String serviceId = serverApp.getId();
    Entity mirror = localApp.addChild(EntitySpec.create(BrooklynEntityMirror.class)
        .configure(BrooklynEntityMirror.POLL_PERIOD, Duration.millis(100))
        .configure(BrooklynEntityMirror.MIRRORED_ENTITY_ID, serviceId)
        .configure(BrooklynEntityMirror.MIRRORED_ENTITY_URL, 
            getBaseUri()+"/v1/applications/"+serviceId+"/entities/"+serviceId)
    );

    EntityAsserts.assertAttributeEqualsEventually(mirror, TestApplication.MY_ATTRIBUTE, "austria");
    EntityAsserts.assertAttributeEqualsEventually(mirror, BrooklynEntityMirror.MIRROR_CATALOG_ITEM_ID, catalogItemId);
    assertTrue(mirror.getAttribute(BrooklynEntityMirror.MIRROR_SUMMARY) != null, "entity summary is null");
    log.info("Sensors mirrored are: "+((EntityInternal)mirror).sensors().getAll());
    
    serverApp.sensors().set(TestApplication.MY_ATTRIBUTE, "bermuda");
    serverApp.setCatalogItemId(catalogItemIdGA);
    EntityAsserts.assertAttributeEqualsEventually(mirror, TestApplication.MY_ATTRIBUTE, "bermuda");
    EntityAsserts.assertAttributeEqualsEventually(mirror, BrooklynEntityMirror.MIRROR_CATALOG_ITEM_ID, catalogItemIdGA);

    serverApp.stop();
    assertUnmanagedEventually(mirror);
}
 
Example #27
Source File: InfrastructureDeploymentTestCaseTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@BeforeMethod
public void setup() {
    app = TestApplication.Factory.newManagedInstanceForTests();
    managementContext = app.getManagementContext();

    loc = managementContext.getLocationManager()
            .createLocation(LocationSpec.create(LocalhostMachineProvisioningLocation.class)
                    .configure("name", LOC_NAME));

    infrastructureLoc = managementContext.getLocationManager()
            .createLocation(LocationSpec.create(LocalhostMachineProvisioningLocation.class)
                    .configure("name", INFRASTRUCTURE_LOC_NAME));
}
 
Example #28
Source File: VanillaJavaAppTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception {
    if (BROOKLYN_THIS_CLASSPATH==null) {
        BROOKLYN_THIS_CLASSPATH = ResourceUtils.create(MAIN_CLASS).getClassLoaderDir();
    }
    app = TestApplication.Factory.newManagedInstanceForTests();
    loc = app.newLocalhostProvisioningLocation(MutableMap.of("address", "localhost"));
}
 
Example #29
Source File: HttpCommandEffectorHttpBinTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@BeforeMethod(alwaysRun=true)
public void setUp() throws Exception {
    app = TestApplication.Factory.newManagedInstanceForTests();
    entity = app.createAndManageChild(EntitySpec.create(TestEntity.class).location(TestApplication.LOCALHOST_MACHINE_SPEC));
    app.start(ImmutableList.<Location>of());
    server = createHttpBinServer();
    serverUrl = server.getUrl();
}
 
Example #30
Source File: ApplicationLifecycleStateTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testChildFailuresOnStartButWithQuorumCausesAppToSucceed() throws Exception {
    TestApplication app = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class)
            .configure(StartableApplication.UP_QUORUM_CHECK, QuorumCheck.QuorumChecks.atLeastOne())
            .configure(StartableApplication.RUNNING_QUORUM_CHECK, QuorumCheck.QuorumChecks.atLeastOne())
            .child(EntitySpec.create(TestEntity.class))
            .child(EntitySpec.create(FailingEntity.class)
                    .configure(FailingEntity.FAIL_ON_START, true)));
    
    startAndAssertException(app, ImmutableList.<Location>of());
    assertUpAndRunningEventually(app);
}