Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/443#discussion_r89776930
  
    --- Diff: 
core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterTest.java ---
    @@ -1225,4 +1235,93 @@ private void 
assertFirstAndNonFirstCounts(Collection<Entity> members, int expect
             assertEquals(found.size(), expectedNonFirstCount);
         }
     
    +    @DataProvider
    +    public Object[][] maxConcurrentCommandsTestProvider() {
    +        return new Object[][]{{1}, {2}, {3}};
    +    }
    +
    +    @Test(dataProvider = "maxConcurrentCommandsTestProvider")
    +    public void 
testEntitiesStartAndStopSequentiallyWhenMaxConcurrentCommandsIsOne(int 
maxConcurrentCommands) {
    +        EntitySpec<ThrowOnAsyncStartEntity> memberSpec = 
EntitySpec.create(ThrowOnAsyncStartEntity.class)
    +                .configure(ThrowOnAsyncStartEntity.MAX_CONCURRENCY, 
maxConcurrentCommands)
    +                .configure(ThrowOnAsyncStartEntity.COUNTER, new 
AtomicInteger());
    +        DynamicCluster cluster = 
app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
    +                .configure(DynamicCluster.MAX_CONCURRENT_CHILD_COMMANDS, 
maxConcurrentCommands)
    +                .configure(DynamicCluster.INITIAL_SIZE, 10)
    +                .configure(DynamicCluster.MEMBER_SPEC, memberSpec));
    +        app.start(ImmutableList.of(app.newSimulatedLocation()));
    +        
assertEquals(cluster.sensors().get(Attributes.SERVICE_STATE_ACTUAL), 
Lifecycle.RUNNING);
    +    }
    +
    +    @Test
    +    public void 
testFirstMemberStartsFirstWhenMaxConcurrentCommandsIsGiven() {
    +        final AtomicInteger counter = new AtomicInteger();
    +
    +        final DynamicCluster cluster = 
app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
    +                .configure(DynamicCluster.MAX_CONCURRENT_CHILD_COMMANDS, 1)
    +                .configure(DynamicCluster.INITIAL_SIZE, 10));
    +
    +        Task<Boolean> firstMemberUp = Tasks.<Boolean>builder()
    +                .body(new Callable<Boolean>() {
    +                    @Override
    +                    public Boolean call() throws Exception {
    +                        Task<Entity> first = 
DependentConfiguration.attributeWhenReady(cluster, DynamicCluster.FIRST);
    +                        
DynamicTasks.queueIfPossible(first).orSubmitAsync();
    +                        final Entity source = first.get();
    +                        final Task<Boolean> booleanTask = 
DependentConfiguration.attributeWhenReady(source, Attributes.SERVICE_UP);
    +                        
DynamicTasks.queueIfPossible(booleanTask).orSubmitAsync();
    +                        return booleanTask.get();
    +                    }
    +                })
    +                .build();
    +
    +        EntitySpec<ThrowOnAsyncStartEntity> firstMemberSpec = 
EntitySpec.create(ThrowOnAsyncStartEntity.class)
    +                .configure(ThrowOnAsyncStartEntity.COUNTER, counter)
    +                .configure(ThrowOnAsyncStartEntity.START_LATCH, true);
    +
    +        EntitySpec<ThrowOnAsyncStartEntity> memberSpec = 
EntitySpec.create(ThrowOnAsyncStartEntity.class)
    +                .configure(ThrowOnAsyncStartEntity.COUNTER, counter)
    +                .configure(ThrowOnAsyncStartEntity.START_LATCH, 
firstMemberUp);
    +
    +        cluster.config().set(DynamicCluster.FIRST_MEMBER_SPEC, 
firstMemberSpec);
    +        cluster.config().set(DynamicCluster.MEMBER_SPEC, memberSpec);
    +
    +        // app.start blocks so in the failure case this test would block 
forever.
    +        Thread t = new Thread() {
    --- End diff --
    
    Very minor - you could use `Asserts.assertReturnsEventually` to do the 
thread interrupt for you. For example, something like:
    ```
    Asserts.assertReturnsEventually(new Runnable() {
        public void run() {
            app.start(ImmutableList.of(app.newSimulatedLocation()));
        }});
    ```
    
    Also, I don't think you need to do `Entities.unmanage(cluster)` - will that 
not happen automatically in `tearDown` anyway?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to