brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [5/7] git commit: Fix ElasticSearch test
Date Wed, 29 Oct 2014 16:19:46 GMT
Fix ElasticSearch test

- Support for OS X: don’t fail if can’t install latest Java
- Accept documentCount > 1 across all nodes.
  Is this because of a replica?
- Don’t expect the node where the put was executed to be the one
  with the document.


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/0f776372
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/0f776372
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/0f776372

Branch: refs/heads/master
Commit: 0f7763727b596ecdc0e03359821d3c8593464126
Parents: 25ac951
Author: Aled Sage <aled.sage@gmail.com>
Authored: Wed Oct 29 10:59:57 2014 +0000
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Wed Oct 29 16:02:00 2014 +0000

----------------------------------------------------------------------
 .../ElasticSearchNodeSshDriver.java             |  2 +-
 .../ElasticSearchClusterIntegrationTest.java    | 31 +++++++++++++++-----
 .../java/brooklyn/util/ssh/BashCommands.java    |  6 +++-
 3 files changed, 30 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0f776372/software/nosql/src/main/java/brooklyn/entity/nosql/elasticsearch/ElasticSearchNodeSshDriver.java
----------------------------------------------------------------------
diff --git a/software/nosql/src/main/java/brooklyn/entity/nosql/elasticsearch/ElasticSearchNodeSshDriver.java
b/software/nosql/src/main/java/brooklyn/entity/nosql/elasticsearch/ElasticSearchNodeSshDriver.java
index c2a31de..1fdb672 100644
--- a/software/nosql/src/main/java/brooklyn/entity/nosql/elasticsearch/ElasticSearchNodeSshDriver.java
+++ b/software/nosql/src/main/java/brooklyn/entity/nosql/elasticsearch/ElasticSearchNodeSshDriver.java
@@ -54,7 +54,7 @@ public class ElasticSearchNodeSshDriver extends AbstractSoftwareProcessSshDriver
         String saveAs = resolver.getFilename();
         
         List<String> commands = ImmutableList.<String>builder()
-            .add(BashCommands.installJavaLatestOrFail())
+            .add(BashCommands.installJavaLatestOrWarn())
             .addAll(BashCommands.commandsToDownloadUrlsAs(urls, saveAs))
             .add(String.format("tar zxvf %s", saveAs))
             .build();

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0f776372/software/nosql/src/test/java/brooklyn/entity/nosql/elasticsearch/ElasticSearchClusterIntegrationTest.java
----------------------------------------------------------------------
diff --git a/software/nosql/src/test/java/brooklyn/entity/nosql/elasticsearch/ElasticSearchClusterIntegrationTest.java
b/software/nosql/src/test/java/brooklyn/entity/nosql/elasticsearch/ElasticSearchClusterIntegrationTest.java
index efb17d6..232918a 100644
--- a/software/nosql/src/test/java/brooklyn/entity/nosql/elasticsearch/ElasticSearchClusterIntegrationTest.java
+++ b/software/nosql/src/test/java/brooklyn/entity/nosql/elasticsearch/ElasticSearchClusterIntegrationTest.java
@@ -19,12 +19,15 @@
 package brooklyn.entity.nosql.elasticsearch;
 
 import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
 
 import java.net.URI;
 import java.net.URISyntaxException;
 
 import org.apache.http.client.methods.HttpGet;
 import org.bouncycastle.util.Strings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
@@ -36,6 +39,7 @@ import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.entity.trait.Startable;
 import brooklyn.event.feed.http.HttpValueFunctions;
 import brooklyn.location.Location;
+import brooklyn.test.Asserts;
 import brooklyn.test.EntityTestUtils;
 import brooklyn.util.http.HttpTool;
 import brooklyn.util.http.HttpToolResponse;
@@ -47,11 +51,15 @@ public class ElasticSearchClusterIntegrationTest extends BrooklynAppLiveTestSupp
 
     // FIXME Exception in thread "main" java.lang.UnsupportedClassVersionError: org/elasticsearch/bootstrap/Elasticsearch
: Unsupported major.minor version 51.0
 
+    private static final Logger LOG = LoggerFactory.getLogger(ElasticSearchClusterIntegrationTest.class);
+
     protected Location testLocation;
     protected ElasticSearchCluster elasticSearchCluster;
 
     @BeforeMethod(alwaysRun = true)
-    public void setup() throws Exception {
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
         testLocation = app.newLocalhostProvisioningLocation();
     }
 
@@ -75,8 +83,8 @@ public class ElasticSearchClusterIntegrationTest extends BrooklynAppLiveTestSupp
         app.start(ImmutableList.of(testLocation));
         
         EntityTestUtils.assertAttributeEqualsEventually(elasticSearchCluster, Startable.SERVICE_UP,
true);
-        
         assertEquals(elasticSearchCluster.getMembers().size(), 3);
+        assertEquals(clusterDocumentCount(), 0);
         
         ElasticSearchNode anyNode = (ElasticSearchNode)elasticSearchCluster.getMembers().iterator().next();
         
@@ -92,9 +100,7 @@ public class ElasticSearchClusterIntegrationTest extends BrooklynAppLiveTestSupp
                 ImmutableMap.<String, String>of(), 
                 Strings.toByteArray(document)); 
         assertEquals(putResponse.getResponseCode(), 201);
-        EntityTestUtils.assertAttributeEqualsEventually(anyNode, ElasticSearchNode.DOCUMENT_COUNT,
1);
         
-        int totalDocumentCount = 0;
         for (Entity entity : elasticSearchCluster.getMembers()) {
             ElasticSearchNode node = (ElasticSearchNode)entity;
             String getBaseUri = "http://" + node.getAttribute(Attributes.HOSTNAME) + ":"
+ node.getAttribute(Attributes.HTTP_PORT);
@@ -103,9 +109,20 @@ public class ElasticSearchClusterIntegrationTest extends BrooklynAppLiveTestSupp
                     new HttpGet(getBaseUri + "/mydocuments/docs/1/_source"));
             assertEquals(getResponse.getResponseCode(), 200);
             assertEquals(HttpValueFunctions.jsonContents("foo", String.class).apply(getResponse),
"bar");
-            
-            totalDocumentCount += node.getAttribute(ElasticSearchNode.DOCUMENT_COUNT);
         }
-        assertEquals(totalDocumentCount, 1);
+        Asserts.succeedsEventually(new Runnable() {
+            public void run() {
+                int count = clusterDocumentCount();
+                assertTrue(count >= 1, "count="+count);
+                LOG.debug("Document count is {}", count);
+            }});
+    }
+    
+    private int clusterDocumentCount() {
+        int result = 0;
+        for (Entity entity : elasticSearchCluster.getMembers()) {
+            result += entity.getAttribute(ElasticSearchNode.DOCUMENT_COUNT);
+        }
+        return result;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0f776372/utils/common/src/main/java/brooklyn/util/ssh/BashCommands.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/brooklyn/util/ssh/BashCommands.java b/utils/common/src/main/java/brooklyn/util/ssh/BashCommands.java
index 448e678..6f3b6cc 100644
--- a/utils/common/src/main/java/brooklyn/util/ssh/BashCommands.java
+++ b/utils/common/src/main/java/brooklyn/util/ssh/BashCommands.java
@@ -533,7 +533,7 @@ public class BashCommands {
      * @see #installJava7Or6OrFail()
      * @see #installJavaLatestOrFail()
      */
-    public static String installJava(Integer version) {
+    public static String installJava(int version) {
         Preconditions.checkArgument(version == 6 || version == 7 || version == 8, "Supported
Java versions are 6, 7, or 8");
         return installPackageOr(MutableMap.of("apt", "openjdk-" + version + "-jdk","yum",
"java-1." + version + ".0-openjdk-devel"), null,
                 ifExecutableElse1("zypper", chainGroup(
@@ -578,6 +578,10 @@ public class BashCommands {
         return alternatives(installJava8(), installJava7(), installJava6(), fail("java latest
install failed", 9));
     }
 
+    public static String installJavaLatestOrWarn() {
+        return alternatives(installJava8(), installJava7(), installJava6(), warn("java latest
install failed, entity may subsequently fail"));
+    }
+
     /** cats the given text to the given command, using bash << multi-line input syntax
*/
     public static String pipeTextTo(String text, String command) {
         String id = Identifiers.makeRandomId(8);


Mime
View raw message