This is an automated email from the ASF dual-hosted git repository. tbouron pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git
The following commit(s) were added to refs/heads/master by this push: new 84b6966 Move testErrorsCaughtByApiAndRestApiWorks to its own class new 71eb696 Merge pull request #1050 from geomacy/brooklyn-611-testErrorsCaughtByApiAndRestApiWorks 84b6966 is described below commit 84b696611695c9d1db731049bb187b53e96ecc3e Author: Geoff Macartney <geoff.macart...@gmail.com> AuthorDate: Tue Mar 12 22:49:56 2019 +0000 Move testErrorsCaughtByApiAndRestApiWorks to its own class This is a workaround to avoid the initialisation error described in https://issues.apache.org/jira/browse/BROOKLYN-611 --- .../launcher/BrooklynLauncherErrorTest.java | 78 ++++++++++++++++++++++ .../brooklyn/launcher/BrooklynLauncherTest.java | 22 ------ 2 files changed, 78 insertions(+), 22 deletions(-) diff --git a/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherErrorTest.java b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherErrorTest.java new file mode 100644 index 0000000..444be99 --- /dev/null +++ b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherErrorTest.java @@ -0,0 +1,78 @@ +/* + * 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.launcher; + +import com.google.common.base.Preconditions; +import org.apache.brooklyn.api.mgmt.ManagementContext; +import org.apache.brooklyn.core.catalog.internal.CatalogInitialization; +import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal; +import org.apache.brooklyn.core.mgmt.persist.PersistMode; +import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests; +import org.apache.brooklyn.test.support.FlakyRetryAnalyser; +import org.apache.brooklyn.util.http.HttpAsserts; +import org.apache.brooklyn.util.net.Urls; +import org.testng.Assert; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.Test; + + +// TODO Fix https://issues.apache.org/jira/browse/BROOKLYN-611 +// until then test testErrorsCaughtByApiAndRestApiWorks is moved to its own class to avoid the initialisation +// error described in that issue +public class BrooklynLauncherErrorTest { + + private BrooklynLauncher launcher; + + @AfterMethod(alwaysRun=true) + public void tearDown() throws Exception { + if (launcher != null) launcher.terminate(); + launcher = null; + } + + @Test(retryAnalyzer = FlakyRetryAnalyser.class) // takes a bit of time because starts webapp, but also tests rest api so useful + public void testErrorsCaughtByApiAndRestApiWorks() throws Exception { + launcher = newLauncherForTests(true) + .catalogInitialization(new CatalogInitialization(null) { + @Override public void populateInitialCatalogOnly() { + throw new RuntimeException("deliberate-exception-for-testing"); + }}) + .persistMode(PersistMode.DISABLED) + .installSecurityFilter(false) + .start(); + // 'deliberate-exception' error above should be thrown, then caught in this calling thread + ManagementContext mgmt = launcher.getServerDetails().getManagementContext(); + Assert.assertFalse( ((ManagementContextInternal)mgmt).errors().isEmpty() ); + Assert.assertTrue( ((ManagementContextInternal)mgmt).errors().get(0).toString().contains("deliberate"), ""+((ManagementContextInternal)mgmt).errors() ); + HttpAsserts.assertContentMatches( + Urls.mergePaths(launcher.getServerDetails().getWebServerUrl(), "v1/server/up"), + "true"); + HttpAsserts.assertContentMatches( + Urls.mergePaths(launcher.getServerDetails().getWebServerUrl(), "v1/server/healthy"), + "false"); + // TODO test errors api? + } + + private BrooklynLauncher newLauncherForTests(boolean minimal) { + Preconditions.checkArgument(launcher == null, "can only be used if no launcher yet"); + BrooklynLauncher launcher = BrooklynLauncher.newInstance(); + if (minimal) + launcher.brooklynProperties(LocalManagementContextForTests.builder(true).buildProperties()); + return launcher; + } +} diff --git a/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherTest.java b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherTest.java index 024ef4e..7a88d42 100644 --- a/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherTest.java +++ b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherTest.java @@ -270,28 +270,6 @@ public class BrooklynLauncherTest { } } - @Test(retryAnalyzer = FlakyRetryAnalyser.class) // takes a bit of time because starts webapp, but also tests rest api so useful - public void testErrorsCaughtByApiAndRestApiWorks() throws Exception { - launcher = newLauncherForTests(true) - .catalogInitialization(new CatalogInitialization(null) { - @Override public void populateInitialCatalogOnly() { - throw new RuntimeException("deliberate-exception-for-testing"); - }}) - .persistMode(PersistMode.DISABLED) - .installSecurityFilter(false) - .start(); - // 'deliberate-exception' error above should be thrown, then caught in this calling thread - ManagementContext mgmt = launcher.getServerDetails().getManagementContext(); - Assert.assertFalse( ((ManagementContextInternal)mgmt).errors().isEmpty() ); - Assert.assertTrue( ((ManagementContextInternal)mgmt).errors().get(0).toString().contains("deliberate"), ""+((ManagementContextInternal)mgmt).errors() ); - HttpAsserts.assertContentMatches( - Urls.mergePaths(launcher.getServerDetails().getWebServerUrl(), "v1/server/up"), - "true"); - HttpAsserts.assertContentMatches( - Urls.mergePaths(launcher.getServerDetails().getWebServerUrl(), "v1/server/healthy"), - "false"); - // TODO test errors api? - } private BrooklynLauncher newLauncherForTests(boolean minimal) { Preconditions.checkArgument(launcher == null, "can only be used if no launcher yet");