Repository: incubator-brooklyn Updated Branches: refs/heads/master cf4d77b1d -> faf08c116
BROOKLYN-193 Test skipping rebind failures for an entity config value - Exposed exceptions in RebindTestUtils Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/136663a4 Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/136663a4 Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/136663a4 Branch: refs/heads/master Commit: 136663a4b3f915763f1c0fff0abc80c7cb32dfea Parents: 15faad3 Author: Valentin Aitken <[email protected]> Authored: Mon Nov 23 02:50:40 2015 +0200 Committer: Valentin Aitken <[email protected]> Committed: Mon Nov 23 14:55:58 2015 +0200 ---------------------------------------------------------------------- .../RebindManagerExceptionHandlerTest.java | 86 ++++++++++++++++++++ 1 file changed, 86 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/136663a4/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindManagerExceptionHandlerTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindManagerExceptionHandlerTest.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindManagerExceptionHandlerTest.java new file mode 100644 index 0000000..d50ab55 --- /dev/null +++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindManagerExceptionHandlerTest.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.brooklyn.core.mgmt.rebind; + +import com.google.common.collect.ImmutableMap; +import org.apache.brooklyn.api.entity.EntitySpec; +import org.apache.brooklyn.api.mgmt.ManagementContext; +import org.apache.brooklyn.core.entity.factory.ApplicationBuilder; +import org.apache.brooklyn.core.internal.BrooklynProperties; +import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext; +import org.apache.brooklyn.core.test.entity.TestApplication; +import org.apache.brooklyn.core.test.entity.TestApplicationNoEnrichersImpl; +import org.apache.brooklyn.core.test.entity.TestEntity; +import org.apache.brooklyn.test.EntityTestUtils; +import org.apache.brooklyn.util.exceptions.Exceptions; +import org.testng.annotations.Test; + +public class RebindManagerExceptionHandlerTest extends RebindTestFixtureWithApp { + + @Test(expectedExceptions = {IllegalStateException.class, IllegalArgumentException.class}) + public void testAddConfigFailure() throws Throwable { + origApp.createAndManageChild(EntitySpec.create(TestEntity.class) + .configure("test.confMapThing", ImmutableMap.of("keyWithMapValue", ImmutableMap.of("minRam", 4)))); + + try { + RebindTestUtils.waitForPersisted(origApp); + RebindOptions rebindOptions = RebindOptions.create(); + // Use the original context with empty properties so the test doesn't depend on the local properties file + rebindOptions.newManagementContext = origManagementContext; + rebind(rebindOptions); + } catch (Exception e) { + throw Exceptions.getFirstInteresting(e); + } + } + + @Test + public void testAddConfigContinue() throws Throwable { + ManagementContext m = createManagementContextWithAddConfigContinue(); + origApp = ApplicationBuilder.newManagedApp(EntitySpec.create(TestApplication.class, TestApplicationNoEnrichersImpl.class), m); + origApp.createAndManageChild(EntitySpec.create(TestEntity.class) + .configure("test.confMapThing", ImmutableMap.of("keyWithMapValue", ImmutableMap.of("minRam", 4)))); + + RebindTestUtils.waitForPersisted(origApp); + RebindOptions rebindOptions = RebindOptions.create(); + rebindOptions.newManagementContext = m; + TestApplication rebindedApp = rebind(rebindOptions); + EntityTestUtils.assertConfigEquals(rebindedApp, TestEntity.CONF_MAP_THING, null); + } + + private LocalManagementContext createManagementContextWithAddConfigContinue() { + BrooklynProperties bp = BrooklynProperties.Factory.newEmpty(); + bp.putIfAbsent("rebind.failureMode.addConfig", "continue"); + return RebindTestUtils.managementContextBuilder(mementoDir, classLoader) + .properties(bp) + .persistPeriodMillis(getPersistPeriodMillis()) + .forLive(useLiveManagementContext()) + .emptyCatalog(useEmptyCatalog()) + .buildStarted(); + } + + @Override + protected LocalManagementContext createOrigManagementContext() { + return RebindTestUtils.managementContextBuilder(mementoDir, classLoader) + .properties(BrooklynProperties.Factory.newEmpty()) + .persistPeriodMillis(getPersistPeriodMillis()) + .forLive(useLiveManagementContext()) + .emptyCatalog(useEmptyCatalog()) + .buildStarted(); + } +}
