You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by gr...@apache.org on 2014/11/04 22:13:43 UTC
[2/7] git commit: Convert KarafContainerTest from groovy to java
Convert KarafContainerTest from groovy to java
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/0826dfcc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/0826dfcc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/0826dfcc
Branch: refs/heads/master
Commit: 0826dfcceb9543c094fc0aa6def1ddedcebc5452
Parents: 374a087
Author: Aled Sage <al...@gmail.com>
Authored: Tue Nov 4 13:55:53 2014 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Tue Nov 4 14:37:18 2014 +0000
----------------------------------------------------------------------
.../entity/osgi/karaf/KarafContainerTest.groovy | 157 -------------------
.../entity/osgi/karaf/KarafContainerTest.java | 143 +++++++++++++++++
2 files changed, 143 insertions(+), 157 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0826dfcc/software/osgi/src/test/java/brooklyn/entity/osgi/karaf/KarafContainerTest.groovy
----------------------------------------------------------------------
diff --git a/software/osgi/src/test/java/brooklyn/entity/osgi/karaf/KarafContainerTest.groovy b/software/osgi/src/test/java/brooklyn/entity/osgi/karaf/KarafContainerTest.groovy
deleted file mode 100644
index f2c5585..0000000
--- a/software/osgi/src/test/java/brooklyn/entity/osgi/karaf/KarafContainerTest.groovy
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * 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 brooklyn.entity.osgi.karaf
-
-import static brooklyn.test.TestUtils.*
-import static java.util.concurrent.TimeUnit.*
-import static org.testng.Assert.*
-
-import java.util.concurrent.TimeUnit
-
-import org.testng.Assert;
-import org.testng.annotations.AfterMethod
-import org.testng.annotations.BeforeMethod
-import org.testng.annotations.Test
-
-import brooklyn.entity.basic.ApplicationBuilder
-import brooklyn.entity.basic.Entities
-import brooklyn.entity.proxying.EntitySpec
-import brooklyn.entity.software.SshEffectorTasks;
-import brooklyn.entity.trait.Startable
-import brooklyn.location.MachineProvisioningLocation
-import brooklyn.location.basic.LocalhostMachineProvisioningLocation
-import brooklyn.test.entity.TestApplication
-import brooklyn.util.internal.TimeExtras
-import brooklyn.util.text.Identifiers
-
-public class KarafContainerTest {
- static { TimeExtras.init() }
-
- MachineProvisioningLocation localhost;
- TestApplication app
- KarafContainer karaf
-
- @BeforeMethod(alwaysRun=true)
- public void setup() {
- app = ApplicationBuilder.newManagedApp(TestApplication.class);
- localhost = app.newLocalhostProvisioningLocation();
- }
-
- @AfterMethod(alwaysRun=true)
- public void shutdown() {
- if (app != null) Entities.destroyAll(app.getManagementContext());
- app = null;
- }
-
- // FIXME Test failing in jenkins; not sure why. The karaf log shows the mbeans never being
- // registered so we are never able to connect to them over jmx.
- @Test(groups = ["Integration", "WIP"])
- public void canStartupAndShutdown() {
- karaf = app.createAndManageChild(EntitySpec.create(KarafContainer.class)
- .configure("name", Identifiers.makeRandomId(8))
- .configure("displayName", "Karaf Test"));
-
- app.start([ localhost ]);
- executeUntilSucceeds(timeout:30 * SECONDS) {
- assertNotNull karaf.getAttribute(Startable.SERVICE_UP)
- assertTrue karaf.getAttribute(Startable.SERVICE_UP)
- }
-
- Entities.dumpInfo(karaf);
- int pid = karaf.getAttribute(KarafContainer.KARAF_PID);
- Entities.submit(app, SshEffectorTasks.requirePidRunning(pid).machine(localhost.obtain())).get();
-
- karaf.stop();
- executeUntilSucceeds(timeout:10 * SECONDS) {
- assertFalse karaf.getAttribute(Startable.SERVICE_UP)
- }
-
- Assert.assertFalse(Entities.submit(app, SshEffectorTasks.isPidRunning(pid).machine(localhost.obtain())).get());
- }
-
- @Test(groups = ["Integration", "WIP"])
- public void canStartupAndShutdownExplicitJmx() {
- karaf = app.createAndManageChild(EntitySpec.create(KarafContainer.class)
- .configure("name", Identifiers.makeRandomId(8))
- .configure("displayName", "Karaf Test")
- .configure("rmiRegistryPort", "8099+")
- .configure("jmxPort", "9099+"));
-
- app.start([ localhost ]);
- executeUntilSucceeds(timeout:30 * SECONDS) {
- assertNotNull karaf.getAttribute(Startable.SERVICE_UP)
- assertTrue karaf.getAttribute(Startable.SERVICE_UP)
- }
-
- karaf.stop();
- executeUntilSucceeds(timeout:10 * SECONDS) {
- assertFalse karaf.getAttribute(Startable.SERVICE_UP)
- }
- }
-
- @Test(groups = ["Integration", "WIP"])
- public void canStartupAndShutdownLegacyJmx() {
- karaf = app.createAndManageChild(EntitySpec.create(KarafContainer.class)
- .configure("name", Identifiers.makeRandomId(8))
- .configure("displayName", "Karaf Test")
- .configure("jmxPort", "8099+")
- .configure("rmiRegistryPort", "9099+"));
- // NB: now the above parameters have the opposite semantics to before
-
- app.start([ localhost ]);
- executeUntilSucceeds(timeout:30 * SECONDS) {
- assertNotNull karaf.getAttribute(Startable.SERVICE_UP)
- assertTrue karaf.getAttribute(Startable.SERVICE_UP)
- }
-
- karaf.stop();
- executeUntilSucceeds(timeout:10 * SECONDS) {
- assertFalse karaf.getAttribute(Startable.SERVICE_UP)
- }
- }
-
- // FIXME Test failing in jenkins; not sure why. The karaf log shows the mbeans never being
- // registered so we are never able to connect to them over jmx.
- @Test(groups = ["Integration", "WIP"])
- public void testCanInstallAndUninstallBundle() {
- karaf = app.createAndManageChild(EntitySpec.create(KarafContainer.class)
- .configure("name", Identifiers.makeRandomId(8))
- .configure("displayName", "Karaf Test")
- .configure("jmxPort", "8099+")
- .configure("rmiRegistryPort", "9099+"));
-
- app.start([ localhost ]);
-
- URL jarUrl = getClass().getClassLoader().getResource("hello-world.jar");
- assertNotNull(jarUrl);
-
- long bundleId = karaf.installBundle("wrap:"+jarUrl.toString());
-
- Map<Long, Map<String,?>> bundles = karaf.listBundles();
- Map<String,?> bundle = bundles.get(bundleId);
- assertNotNull(bundle, "expected="+bundleId+"; actual="+bundles.keySet());
-
- // Undeploy: expect bundle to no longer be listed
- karaf.uninstallBundle(bundleId);
-
- Map<Long, Map<String,?>> bundles2 = karaf.listBundles();
- Map<String,?> bundle2 = bundles2.get(bundleId);
- assertNull(bundle2, "expectedAbsent="+bundleId+"; actual="+bundles2.keySet());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0826dfcc/software/osgi/src/test/java/brooklyn/entity/osgi/karaf/KarafContainerTest.java
----------------------------------------------------------------------
diff --git a/software/osgi/src/test/java/brooklyn/entity/osgi/karaf/KarafContainerTest.java b/software/osgi/src/test/java/brooklyn/entity/osgi/karaf/KarafContainerTest.java
new file mode 100644
index 0000000..f43255d
--- /dev/null
+++ b/software/osgi/src/test/java/brooklyn/entity/osgi/karaf/KarafContainerTest.java
@@ -0,0 +1,143 @@
+/*
+ * 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 brooklyn.entity.osgi.karaf;
+
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+
+import java.net.URL;
+import java.util.Map;
+
+import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import brooklyn.entity.BrooklynAppLiveTestSupport;
+import brooklyn.entity.basic.Attributes;
+import brooklyn.entity.basic.Entities;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.entity.software.SshEffectorTasks;
+import brooklyn.location.NoMachinesAvailableException;
+import brooklyn.location.basic.LocalhostMachineProvisioningLocation;
+import brooklyn.test.Asserts;
+import brooklyn.test.EntityTestUtils;
+import brooklyn.util.exceptions.Exceptions;
+import brooklyn.util.text.Identifiers;
+
+import com.google.common.collect.ImmutableList;
+
+public class KarafContainerTest extends BrooklynAppLiveTestSupport {
+
+ LocalhostMachineProvisioningLocation localhost;
+ KarafContainer karaf;
+
+ @BeforeMethod(alwaysRun=true)
+ public void setUp() throws Exception {
+ super.setUp();
+ localhost = app.newLocalhostProvisioningLocation();
+ }
+
+ // FIXME Test failing in jenkins; not sure why. The karaf log shows the mbeans never being
+ // registered so we are never able to connect to them over jmx.
+ @Test(groups = {"Integration", "WIP"})
+ public void canStartupAndShutdown() throws Exception {
+ karaf = app.createAndManageChild(EntitySpec.create(KarafContainer.class)
+ .configure("name", Identifiers.makeRandomId(8))
+ .configure("displayName", "Karaf Test"));
+
+ app.start(ImmutableList.of(localhost));
+ EntityTestUtils.assertAttributeEqualsEventually(karaf, Attributes.SERVICE_UP, true);
+
+ Entities.dumpInfo(karaf);
+ final int pid = karaf.getAttribute(KarafContainer.KARAF_PID);
+ Entities.submit(app, SshEffectorTasks.requirePidRunning(pid).machine(localhost.obtain())).get();
+
+ karaf.stop();
+ EntityTestUtils.assertAttributeEqualsEventually(karaf, Attributes.SERVICE_UP, false);
+
+ Asserts.succeedsEventually(new Runnable() {
+ public void run() {
+ try {
+ Assert.assertFalse(Entities.submit(app, SshEffectorTasks.isPidRunning(pid).machine(localhost.obtain())).get());
+ } catch (NoMachinesAvailableException e) {
+ throw Exceptions.propagate(e);
+ }
+ }});
+ }
+
+ @Test(groups = {"Integration", "WIP"})
+ public void canStartupAndShutdownExplicitJmx() throws Exception {
+ karaf = app.createAndManageChild(EntitySpec.create(KarafContainer.class)
+ .configure("name", Identifiers.makeRandomId(8))
+ .configure("displayName", "Karaf Test")
+ .configure("rmiRegistryPort", "8099+")
+ .configure("jmxPort", "9099+"));
+
+ app.start(ImmutableList.of(localhost));
+ EntityTestUtils.assertAttributeEqualsEventually(karaf, Attributes.SERVICE_UP, true);
+
+ karaf.stop();
+ EntityTestUtils.assertAttributeEqualsEventually(karaf, Attributes.SERVICE_UP, false);
+ }
+
+ @Test(groups = {"Integration", "WIP"})
+ public void canStartupAndShutdownLegacyJmx() throws Exception {
+ karaf = app.createAndManageChild(EntitySpec.create(KarafContainer.class)
+ .configure("name", Identifiers.makeRandomId(8))
+ .configure("displayName", "Karaf Test")
+ .configure("jmxPort", "8099+")
+ .configure("rmiRegistryPort", "9099+"));
+ // NB: now the above parameters have the opposite semantics to before
+
+ app.start(ImmutableList.of(localhost));
+ EntityTestUtils.assertAttributeEqualsEventually(karaf, Attributes.SERVICE_UP, true);
+
+ karaf.stop();
+ EntityTestUtils.assertAttributeEqualsEventually(karaf, Attributes.SERVICE_UP, false);
+ }
+
+ // FIXME Test failing in jenkins; not sure why. The karaf log shows the mbeans never being
+ // registered so we are never able to connect to them over jmx.
+ @Test(groups = {"Integration", "WIP"})
+ public void testCanInstallAndUninstallBundle() throws Exception {
+ karaf = app.createAndManageChild(EntitySpec.create(KarafContainer.class)
+ .configure("name", Identifiers.makeRandomId(8))
+ .configure("displayName", "Karaf Test")
+ .configure("jmxPort", "8099+")
+ .configure("rmiRegistryPort", "9099+"));
+
+ app.start(ImmutableList.of(localhost));
+
+ URL jarUrl = getClass().getClassLoader().getResource("hello-world.jar");
+ assertNotNull(jarUrl);
+
+ long bundleId = karaf.installBundle("wrap:"+jarUrl.toString());
+
+ Map<Long, Map<String,?>> bundles = karaf.listBundles();
+ Map<String,?> bundle = bundles.get(bundleId);
+ assertNotNull(bundle, "expected="+bundleId+"; actual="+bundles.keySet());
+
+ // Undeploy: expect bundle to no longer be listed
+ karaf.uninstallBundle(bundleId);
+
+ Map<Long, Map<String,?>> bundles2 = karaf.listBundles();
+ Map<String,?> bundle2 = bundles2.get(bundleId);
+ assertNull(bundle2, "expectedAbsent="+bundleId+"; actual="+bundles2.keySet());
+ }
+}