@@ -511,7 +511,7 @@ public void testParseDoSectionExpectedWarnings() throws Exception {
511
511
"just one entry this time" )));
512
512
}
513
513
514
- public void testNodeSelector () throws IOException {
514
+ public void testNodeSelectorByVersion () throws IOException {
515
515
parser = createParser (YamlXContent .yamlXContent ,
516
516
"node_selector:\n " +
517
517
" version: 5.2.0-6.0.0\n " +
@@ -521,10 +521,10 @@ public void testNodeSelector() throws IOException {
521
521
522
522
DoSection doSection = DoSection .parse (parser );
523
523
assertNotSame (NodeSelector .ANY , doSection .getApiCallSection ().getNodeSelector ());
524
- Node v170 = nodeWithVersion ( " 1.7.0" );
525
- Node v521 = nodeWithVersion ( " 5.2.1" );
526
- Node v550 = nodeWithVersion ( " 5.5.0" );
527
- Node v612 = nodeWithVersion ( " 6.1.2" );
524
+ Node v170 = new Node ( new HttpHost ( "dummy" ), null , null , " 1.7.0", null );
525
+ Node v521 = new Node ( new HttpHost ( "dummy" ), null , null , " 5.2.1", null );
526
+ Node v550 = new Node ( new HttpHost ( "dummy" ), null , null , " 5.5.0", null );
527
+ Node v612 = new Node ( new HttpHost ( "dummy" ), null , null , " 6.1.2", null );
528
528
List <Node > nodes = new ArrayList <>();
529
529
nodes .add (v170 );
530
530
nodes .add (v521 );
@@ -541,8 +541,61 @@ public void testNodeSelector() throws IOException {
541
541
emptyList (), emptyMap (), doSection .getApiCallSection ().getNodeSelector ());
542
542
}
543
543
544
- private Node nodeWithVersion (String version ) {
545
- return new Node (new HttpHost ("dummy" ), null , null , version , null );
544
+ public void testNodeSelectorByName () throws IOException {
545
+ parser = createParser (YamlXContent .yamlXContent ,
546
+ "node_selector:\n " +
547
+ " name: cat\n " +
548
+ "indices.get_field_mapping:\n " +
549
+ " index: test_index"
550
+ );
551
+
552
+ DoSection doSection = DoSection .parse (parser );
553
+ assertNotSame (NodeSelector .ANY , doSection .getApiCallSection ().getNodeSelector ());
554
+ Node cat = new Node (new HttpHost ("dummy" ), null , "cat" , null , null );
555
+ Node dog = new Node (new HttpHost ("dummy" ), null , "dog" , null , null );
556
+ Node pig = new Node (new HttpHost ("dummy" ), null , "pig" , null , null );
557
+ List <Node > nodes = new ArrayList <>();
558
+ nodes .add (cat );
559
+ nodes .add (dog );
560
+ nodes .add (pig );
561
+ doSection .getApiCallSection ().getNodeSelector ().select (nodes );
562
+ assertEquals (Arrays .asList (cat ), nodes );
563
+ ClientYamlTestExecutionContext context = mock (ClientYamlTestExecutionContext .class );
564
+ ClientYamlTestResponse mockResponse = mock (ClientYamlTestResponse .class );
565
+ when (context .callApi ("indices.get_field_mapping" , singletonMap ("index" , "test_index" ),
566
+ emptyList (), emptyMap (), doSection .getApiCallSection ().getNodeSelector ())).thenReturn (mockResponse );
567
+ doSection .execute (context );
568
+ verify (context ).callApi ("indices.get_field_mapping" , singletonMap ("index" , "test_index" ),
569
+ emptyList (), emptyMap (), doSection .getApiCallSection ().getNodeSelector ());
570
+ }
571
+
572
+ public void testNodeSelectorByTwoThings () throws IOException {
573
+ parser = createParser (YamlXContent .yamlXContent ,
574
+ "node_selector:\n " +
575
+ " name: cat\n " +
576
+ " version: 5.2.0-6.0.0\n " +
577
+ "indices.get_field_mapping:\n " +
578
+ " index: test_index"
579
+ );
580
+
581
+ DoSection doSection = DoSection .parse (parser );
582
+ assertNotSame (NodeSelector .ANY , doSection .getApiCallSection ().getNodeSelector ());
583
+ Node cat = new Node (new HttpHost ("dummy" ), null , "cat" , "5.2.1" , null );
584
+ Node badName = new Node (new HttpHost ("dummy" ), null , "dog" , "5.2.1" , null );
585
+ Node badVersion = new Node (new HttpHost ("dummy" ), null , "cat" , "6.1.2" , null );
586
+ List <Node > nodes = new ArrayList <>();
587
+ nodes .add (cat );
588
+ nodes .add (badName );
589
+ nodes .add (badVersion );
590
+ doSection .getApiCallSection ().getNodeSelector ().select (nodes );
591
+ assertEquals (Arrays .asList (cat ), nodes );
592
+ ClientYamlTestExecutionContext context = mock (ClientYamlTestExecutionContext .class );
593
+ ClientYamlTestResponse mockResponse = mock (ClientYamlTestResponse .class );
594
+ when (context .callApi ("indices.get_field_mapping" , singletonMap ("index" , "test_index" ),
595
+ emptyList (), emptyMap (), doSection .getApiCallSection ().getNodeSelector ())).thenReturn (mockResponse );
596
+ doSection .execute (context );
597
+ verify (context ).callApi ("indices.get_field_mapping" , singletonMap ("index" , "test_index" ),
598
+ emptyList (), emptyMap (), doSection .getApiCallSection ().getNodeSelector ());
546
599
}
547
600
548
601
private void assertJsonEquals (Map <String , Object > actual , String expected ) throws IOException {
0 commit comments