brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From duncangrant <...@git.apache.org>
Subject [GitHub] brooklyn-server pull request #881: BROOKLYN-547: fix VanillaSoftwareProcess....
Date Mon, 06 Nov 2017 20:15:52 GMT
Github user duncangrant commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/881#discussion_r149190906
  
    --- Diff: software/base/src/test/java/org/apache/brooklyn/entity/software/base/VanillaSoftwareProcessTest.java
---
    @@ -294,4 +309,63 @@ public void testCmdNotInheritedFromParentOfSoftwareProcess() throws
Exception {
             assertExecHasOnlyOnce(RecordingSshTool.getExecCmds(), "preInstallCommand");
             assertExecHasOnlyOnce(RecordingSshTool.getExecCmds(), "launchCommand");
         }
    +    
    +    @Test
    +    public void testUseSshMonitoringDisabled() throws Exception {
    +        // Setup a custom health-check that returns true after launch is called, 
    +        // and false after stop is called.
    +        final AtomicBoolean customHealth = new AtomicBoolean(false);
    +        
    +        RecordingSshTool.setCustomResponse(".*launchCommand.*", new CustomResponseGenerator()
{
    +            @Override public CustomResponse generate(ExecParams execParams) throws Exception
{
    +                customHealth.set(true);
    +                return new CustomResponse(0, "", "");
    +            }});
    +        RecordingSshTool.setCustomResponse(".*stopCommand.*", new CustomResponseGenerator()
{
    +            @Override public CustomResponse generate(ExecParams execParams) throws Exception
{
    +                customHealth.set(false);
    +                return new CustomResponse(0, "", "");
    +            }});
    +        
    +        // The entity polls for the custom-health; it populates the service-up-indicators
using that.
    +        VanillaSoftwareProcess entity = app.createAndManageChild(EntitySpec.create(VanillaSoftwareProcess.class)
    +                .configure(VanillaSoftwareProcess.USE_SSH_MONITORING, false)
    +                .configure(VanillaSoftwareProcess.SERVICE_PROCESS_IS_RUNNING_POLL_PERIOD,
Duration.ONE_MILLISECOND)
    +                .configure(VanillaSoftwareProcess.LAUNCH_COMMAND, "launchCommand")
    +                .configure(VanillaSoftwareProcess.CHECK_RUNNING_COMMAND, "checkRunningCommand")
    +                .configure(VanillaSoftwareProcess.STOP_COMMAND, "stopCommand")
    +                .addInitializer(new FunctionSensor<Boolean>(ConfigBag.newInstance()
    +                        .configure(FunctionSensor.SENSOR_NAME, "myCustomHealth")
    +                        .configure(FunctionSensor.SUPPRESS_DUPLICATES, true)
    +                        .configure(FunctionSensor.SENSOR_PERIOD, Duration.ONE_MILLISECOND)
    +                        .configure(FunctionSensor.FUNCTION, new Callable<Boolean>()
{
    +                            public Boolean call() {
    +                                return customHealth.get();
    +                            }})
    +                        ))
    +                .enricher(EnricherSpec.create(UpdatingMap.class)
    +                        .configure(UpdatingMap.SOURCE_SENSOR, Sensors.newBooleanSensor("myCustomHealth"))
    +                        .configure(UpdatingMap.TARGET_SENSOR, Attributes.SERVICE_NOT_UP_INDICATORS)
    +                        .configure(UpdatingMap.COMPUTING, Functions.forMap(
    +                                MutableMap.of(true, null, false, "custom-health-is-false"),
    +                                "custom-health-unknown")))
    +                        );
    +        
    +        // Start the entity
    +        app.start(ImmutableList.of(loc));
    +        EntityAsserts.assertAttributeEqualsEventually(entity, Attributes.SERVICE_UP,
true);
    +
    +        // Expect to have ssh "checkRunningCommand" called once during startup, and not
again 
    +        assertExecHasAtLeastOnce(RecordingSshTool.getExecCmds(), "checkRunningCommand");
    +        
    +        RecordingSshTool.clearCmdHistory();
    +        Asserts.succeedsContinually(ImmutableMap.of("timeout", Duration.millis(100)),
new Runnable() {
    +            public void run() {
    +                assertExecHasNever(RecordingSshTool.getExecCmds(), "checkRunningCommand");
    +            }});
    +
    +        // Restart (see https://issues.apache.org/jira/browse/BROOKLYN-547)
    +        entity.restart();
    --- End diff --
    
    Should test SERVICE_UP false first?


---

Mime
View raw message