Browse Source

Merge pull request #13189 from nik9000/fix_nodeattrs_test

Fix test for _cat/nodeattrs
Nik Everett 10 years ago
parent
commit
60a2dd7020

+ 1 - 0
core/src/test/java/org/elasticsearch/test/rest/ESRestTestCase.java

@@ -155,6 +155,7 @@ public abstract class ESRestTestCase extends ESIntegTestCase {
         return Settings.builder()
             .putArray(URLRepository.ALLOWED_URLS_SETTING, "http://snapshot.test*")
             .put(Node.HTTP_ENABLED, true)
+            .put("node.testattr", "test")
             .put(super.nodeSettings(nodeOrdinal)).build();
     }
     

+ 1 - 1
dev-tools/Elasticsearch.launch

@@ -14,5 +14,5 @@
 <stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.elasticsearch.bootstrap.Elasticsearch"/>
 <stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="start"/>
 <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="elasticsearch"/>
-<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xms256m -Xmx1g -Djava.awt.headless=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=logs/heapdump.hprof -Delasticsearch -Des.foreground=yes -ea -Des.path.home=target/eclipse_run -Des.security.manager.enabled=false"/>
+<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xms256m -Xmx1g -Djava.awt.headless=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=logs/heapdump.hprof -Delasticsearch -Des.foreground=yes -ea -Des.path.home=target/eclipse_run -Des.security.manager.enabled=false&#10;-Des.node.attr=test"/>
 </launchConfiguration>

+ 3 - 1
dev-tools/src/main/resources/ant/integration-tests.xml

@@ -157,7 +157,7 @@
       <!-- run bin/elasticsearch with args -->
       <echo>Starting up external cluster...</echo>
 
-      <run-script script="@{home}/bin/elasticsearch" 
+      <run-script script="@{home}/bin/elasticsearch"
                   spawn="@{spawn}">
         <nested>
           <env key="JAVA_HOME" value="${java.home}"/>
@@ -172,6 +172,8 @@
           <arg value="-Des.path.shared_data=@{home}/../"/>
           <arg value="-Des.script.inline=on"/>
           <arg value="-Des.script.indexed=on"/>
+          <!-- Define a node attribute so we can test that it exists -->
+          <arg value="-Des.node.testattr=test"/>
           <arg value="-Des.repositories.url.allowed_urls=http://snapshot.test*"/>
           <additional-args/>
         </nested>

+ 47 - 13
rest-api-spec/src/main/resources/rest-api-spec/test/cat.nodeattrs/10_basic.yaml

@@ -1,30 +1,64 @@
 ---
-"Test cat nodes attrs output":
+"Help":
+  - do:
+      cat.nodeattrs:
+        help: true
 
-  - skip:
-      version:  "all"
-      reason:   "Waiting for #12558"
+  - match:
+      $body: |
+               /^  node   .+ \n
+                   id     .+ \n
+                   pid    .+ \n
+                   host   .+ \n
+                   ip     .+ \n
+                   port   .+ \n
+                   attr   .+ \n
+                   value  .+ \n
+               $/
 
+---
+"Test cat nodes attrs output":
   - do:
       cat.nodeattrs: {}
-
-  - match:
+  - match: # All attributes look good
+      $body: |
+               /^#  node\s+         host\s+ ip\s+                   attr\s+     value\s* \n
+                    (((\S+\s?){1,10})\s+(\S+)\s+(\d{1,3}\.){3}\d{1,3}\s+(\S+)\s+    (\S+)\s* \n)+
+               $/
+  - match: # A specific planted attribute is present and looks good
       $body: |
-               /((\S+)\s+(\S+)\s+(\d{1,3}\.){3}\d{1,3}\s+(\S+)\s+(\S+)\s*)+/
+               /#   node\s+         host\s+ ip\s+                   attr\s+     value\s* \n
+                    ((\S+\s?){1,10})\s+ (\S+)\s+(\d{1,3}\.){3}\d{1,3}\s+testattr\s+ test \s* \n
+               /
+  # Note for future editors: its quite possible to construct a regex with an
+  # intense amount of backtracking if you use something like (\S\s?)+ to match
+  # node name.
 
   - do:
       cat.nodeattrs:
         v: true
-
-  - match:
+  - match: # All attributes look good including the heading
       $body: |
-               /((\S+)\s+(\S+)\s+(\d{1,3}\.){3}\d{1,3}\s+(\S+)\s+(\S+)\s*)+/
+               /^   node\s+        host\s+ ip\s+                   attr\s+     value\s* \n
+                    (((\S+\s?){1,10})\s+(\S+)\s+(\d{1,3}\.){3}\d{1,3}\s+(\S+)\s+    (\S+)\s* \n)+
+               $/
+  - match: # A specific planted attribute is present and looks good
+      $body: |
+               /#   node\s+        host\s+ ip\s+                   attr\s+     value\s* \n
+                    ((\S+\s?){1,10})\s+ (\S+)\s+(\d{1,3}\.){3}\d{1,3}\s+testattr\s+ test \s* \n
+               /
 
   - do:
       cat.nodeattrs:
           h: attr,value
           v: true
-
-  - match:
+  - match: # All attributes look good
+      $body: |
+               /^   attr\s+     value\s*\n
+                    ((\S+)\s+   (\S+)\s*)+
+               $/
+  - match: # A specific planted attribute is present and looks good
       $body: |
-               /((\S+)\s+(\S+)\s*)+/
+               /#   attr\s+     value\s*\n
+                    testattr\s+ test\s*\n
+               /