You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by sv...@apache.org on 2016/11/16 06:44:20 UTC
[5/6] brooklyn-server git commit: Fix
ServiceRestarterTest.testDoesNotSetOnFireOnFailure
Fix ServiceRestarterTest.testDoesNotSetOnFireOnFailure
The previous commit broke it, by changing FailingEntityImpl to
set itself as down/on-fire if restart() failed. Make that behaviour
configurable.
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/b968d7f9
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/b968d7f9
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/b968d7f9
Branch: refs/heads/master
Commit: b968d7f975be737c316a296e7f3547d5fd519283
Parents: 3e2cf87
Author: Aled Sage <al...@gmail.com>
Authored: Mon Nov 7 13:37:26 2016 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Mon Nov 14 11:09:54 2016 +0000
----------------------------------------------------------------------
.../core/entity/trait/FailingEntity.java | 2 ++
.../core/entity/trait/FailingEntityImpl.java | 28 ++++++++++++--------
.../policy/ha/ServiceRestarterTest.java | 22 ++++-----------
3 files changed, 24 insertions(+), 28 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b968d7f9/core/src/test/java/org/apache/brooklyn/core/entity/trait/FailingEntity.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/entity/trait/FailingEntity.java b/core/src/test/java/org/apache/brooklyn/core/entity/trait/FailingEntity.java
index 7845326..87182f1 100644
--- a/core/src/test/java/org/apache/brooklyn/core/entity/trait/FailingEntity.java
+++ b/core/src/test/java/org/apache/brooklyn/core/entity/trait/FailingEntity.java
@@ -50,6 +50,8 @@ public interface FailingEntity extends TestEntity {
@SetFromFlag("failOnRestart")
ConfigKey<Boolean> FAIL_ON_RESTART = ConfigKeys.newBooleanConfigKey("failOnRestart", "Whether to throw exception on call to restart", false);
+ ConfigKey<Boolean> SET_SERVICE_DOWN_ON_FAILURE = ConfigKeys.newBooleanConfigKey("setServiceDownOnFailure", "Whether to set service-down (i.e. service.isUp=false, and thus potentially state=on-fire), when simulating a failure", true);
+
@SetFromFlag("failOnStartCondition")
ConfigKey<Predicate<? super FailingEntity>> FAIL_ON_START_CONDITION = (ConfigKey) ConfigKeys.newConfigKey(Predicate.class, "failOnStartCondition", "Whether to throw exception on call to start", null);
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b968d7f9/core/src/test/java/org/apache/brooklyn/core/entity/trait/FailingEntityImpl.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/entity/trait/FailingEntityImpl.java b/core/src/test/java/org/apache/brooklyn/core/entity/trait/FailingEntityImpl.java
index 6327c65..c449c53 100644
--- a/core/src/test/java/org/apache/brooklyn/core/entity/trait/FailingEntityImpl.java
+++ b/core/src/test/java/org/apache/brooklyn/core/entity/trait/FailingEntityImpl.java
@@ -39,9 +39,11 @@ public class FailingEntityImpl extends TestEntityImpl implements FailingEntity {
public void start(Collection<? extends Location> locs) {
getConfig(LISTENER).onEvent(this, "start", new Object[] {locs});
if (getConfig(FAIL_ON_START) || (getConfig(FAIL_ON_START_CONDITION) != null && getConfig(FAIL_ON_START_CONDITION).apply(this))) {
- ServiceStateLogic.setExpectedState(this, Lifecycle.STARTING);
- sensors().set(SERVICE_UP, false);
- ServiceStateLogic.setExpectedState(this, Lifecycle.RUNNING);
+ if (Boolean.TRUE.equals(getConfig(SET_SERVICE_DOWN_ON_FAILURE))) {
+ ServiceStateLogic.setExpectedState(this, Lifecycle.STARTING);
+ sensors().set(SERVICE_UP, false);
+ ServiceStateLogic.setExpectedState(this, Lifecycle.RUNNING);
+ }
callHistory.add("start");
getConfig(EXEC_ON_FAILURE).apply(this);
@@ -54,9 +56,11 @@ public class FailingEntityImpl extends TestEntityImpl implements FailingEntity {
public void stop() {
getConfig(LISTENER).onEvent(this, "stop", new Object[0]);
if (getConfig(FAIL_ON_STOP) || (getConfig(FAIL_ON_STOP_CONDITION) != null && getConfig(FAIL_ON_STOP_CONDITION).apply(this))) {
- ServiceStateLogic.setExpectedState(this, Lifecycle.STOPPING);
- sensors().set(SERVICE_UP, false);
- ServiceStateLogic.setExpectedState(this, Lifecycle.STOPPED);
+ if (Boolean.TRUE.equals(getConfig(SET_SERVICE_DOWN_ON_FAILURE))) {
+ ServiceStateLogic.setExpectedState(this, Lifecycle.STOPPING);
+ sensors().set(SERVICE_UP, false);
+ ServiceStateLogic.setExpectedState(this, Lifecycle.STOPPED);
+ }
callHistory.add("stop");
getConfig(EXEC_ON_FAILURE).apply(this);
@@ -69,11 +73,13 @@ public class FailingEntityImpl extends TestEntityImpl implements FailingEntity {
public void restart() {
getConfig(LISTENER).onEvent(this, "restart", new Object[0]);
if (getConfig(FAIL_ON_RESTART) || (getConfig(FAIL_ON_RESTART_CONDITION) != null && getConfig(FAIL_ON_RESTART_CONDITION).apply(this))) {
- ServiceStateLogic.setExpectedState(this, Lifecycle.STOPPING);
- sensors().set(SERVICE_UP, false);
- ServiceStateLogic.setExpectedState(this, Lifecycle.STOPPED);
- ServiceStateLogic.setExpectedState(this, Lifecycle.STARTING);
- ServiceStateLogic.setExpectedState(this, Lifecycle.ON_FIRE);
+ if (Boolean.TRUE.equals(getConfig(SET_SERVICE_DOWN_ON_FAILURE))) {
+ ServiceStateLogic.setExpectedState(this, Lifecycle.STOPPING);
+ sensors().set(SERVICE_UP, false);
+ ServiceStateLogic.setExpectedState(this, Lifecycle.STOPPED);
+ ServiceStateLogic.setExpectedState(this, Lifecycle.STARTING);
+ ServiceStateLogic.setExpectedState(this, Lifecycle.RUNNING);
+ }
callHistory.add("restart");
getConfig(EXEC_ON_FAILURE).apply(this);
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b968d7f9/policy/src/test/java/org/apache/brooklyn/policy/ha/ServiceRestarterTest.java
----------------------------------------------------------------------
diff --git a/policy/src/test/java/org/apache/brooklyn/policy/ha/ServiceRestarterTest.java b/policy/src/test/java/org/apache/brooklyn/policy/ha/ServiceRestarterTest.java
index b987ed5..8d239da 100644
--- a/policy/src/test/java/org/apache/brooklyn/policy/ha/ServiceRestarterTest.java
+++ b/policy/src/test/java/org/apache/brooklyn/policy/ha/ServiceRestarterTest.java
@@ -27,37 +27,30 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.apache.brooklyn.api.entity.EntitySpec;
-import org.apache.brooklyn.api.mgmt.ManagementContext;
import org.apache.brooklyn.api.policy.PolicySpec;
import org.apache.brooklyn.api.sensor.SensorEvent;
import org.apache.brooklyn.api.sensor.SensorEventListener;
import org.apache.brooklyn.core.entity.Attributes;
-import org.apache.brooklyn.core.entity.Entities;
-import org.apache.brooklyn.core.entity.factory.ApplicationBuilder;
import org.apache.brooklyn.core.entity.lifecycle.Lifecycle;
import org.apache.brooklyn.core.entity.trait.FailingEntity;
-import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
-import org.apache.brooklyn.core.test.entity.TestApplication;
+import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
import org.apache.brooklyn.core.test.entity.TestEntity;
+import org.apache.brooklyn.policy.ha.HASensors.FailureDescriptor;
import org.apache.brooklyn.test.Asserts;
import org.apache.brooklyn.util.core.config.ConfigBag;
import org.apache.brooklyn.util.exceptions.Exceptions;
-import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import org.apache.brooklyn.policy.ha.HASensors.FailureDescriptor;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
-public class ServiceRestarterTest {
+public class ServiceRestarterTest extends BrooklynAppUnitTestSupport {
private static final int TIMEOUT_MS = 10*1000;
- private ManagementContext managementContext;
- private TestApplication app;
private TestEntity e1;
private ServiceRestarter policy;
private SensorEventListener<Object> eventListener;
@@ -65,8 +58,7 @@ public class ServiceRestarterTest {
@BeforeMethod(alwaysRun=true)
public void setUp() throws Exception {
- managementContext = new LocalManagementContextForTests();
- app = ApplicationBuilder.newManagedApp(TestApplication.class, managementContext);
+ super.setUp();
e1 = app.createAndManageChild(EntitySpec.create(TestEntity.class));
events = Lists.newCopyOnWriteArrayList();
eventListener = new SensorEventListener<Object>() {
@@ -76,11 +68,6 @@ public class ServiceRestarterTest {
};
}
- @AfterMethod(alwaysRun=true)
- public void tearDown() throws Exception {
- if (managementContext != null) Entities.destroyAll(managementContext);
- }
-
@Test
public void testRestartsOnFailure() throws Exception {
policy = new ServiceRestarter(new ConfigBag().configure(ServiceRestarter.FAILURE_SENSOR_TO_MONITOR, HASensors.ENTITY_FAILED));
@@ -131,6 +118,7 @@ public class ServiceRestarterTest {
@Test
public void testDoesNotSetOnFireOnFailure() throws Exception {
final FailingEntity e2 = app.createAndManageChild(EntitySpec.create(FailingEntity.class)
+ .configure(FailingEntity.SET_SERVICE_DOWN_ON_FAILURE, false)
.configure(FailingEntity.FAIL_ON_RESTART, true));
app.subscriptions().subscribe(e2, ServiceRestarter.ENTITY_RESTART_FAILED, eventListener);