@@ -69,19 +69,31 @@ public void testBasic() throws IOException {
69
69
try (RestClient local = buildLocalClusterClient (); RestClient remote = buildRemoteClusterClient ()) {
70
70
final int localGeometries = createIndex (local , "test" );
71
71
final int remoteGeometries = createIndex (remote , "test" );
72
- // check call in each cluster
73
- final Request mvtRequest = new Request (HttpPost .METHOD_NAME , "test/_mvt/location/0/0/0" );
74
- final VectorTile .Tile localTile = execute (local , mvtRequest );
75
- assertThat (getLayer (localTile , "hits" ).getFeaturesCount (), Matchers .equalTo (localGeometries ));
76
- final VectorTile .Tile remoteTile = execute (remote , mvtRequest );
77
- assertThat (getLayer (remoteTile , "hits" ).getFeaturesCount (), Matchers .equalTo (remoteGeometries ));
78
- // call to both clusters
79
- final Request mvtCCSRequest = new Request (HttpPost .METHOD_NAME , "/test,other:test/_mvt/location/0/0/0" );
80
- final VectorTile .Tile ccsTile = execute (local , mvtCCSRequest );
81
- assertThat (getLayer (ccsTile , "hits" ).getFeaturesCount (), Matchers .equalTo (localGeometries + remoteGeometries ));
72
+ // check with no params
73
+ assertLocalAndRemote (local , remote , localGeometries , remoteGeometries , "" );
74
+ // check with labels
75
+ assertLocalAndRemote (local , remote , 2 * localGeometries , 2 * remoteGeometries , "?with_labels=true" );
82
76
}
83
77
}
84
78
79
+ private void assertLocalAndRemote (RestClient local , RestClient remote , int localGeometries , int remoteGeometries , String param )
80
+ throws IOException {
81
+ // check call in each cluster
82
+ final Request mvtRequest = new Request (HttpPost .METHOD_NAME , "test/_mvt/location/0/0/0" + param );
83
+ final VectorTile .Tile localTile = execute (local , mvtRequest );
84
+ assertThat (getLayer (localTile , "hits" ).getFeaturesCount (), Matchers .equalTo (localGeometries ));
85
+ assertEquals (localGeometries , countFeaturesWithTag (getLayer (localTile , "hits" ), "_index" , "test" ));
86
+ final VectorTile .Tile remoteTile = execute (remote , mvtRequest );
87
+ assertThat (getLayer (remoteTile , "hits" ).getFeaturesCount (), Matchers .equalTo (remoteGeometries ));
88
+ assertEquals (remoteGeometries , countFeaturesWithTag (getLayer (remoteTile , "hits" ), "_index" , "test" ));
89
+ // call to both clusters
90
+ final Request mvtCCSRequest = new Request (HttpPost .METHOD_NAME , "/test,other:test/_mvt/location/0/0/0" + param );
91
+ final VectorTile .Tile ccsTile = execute (local , mvtCCSRequest );
92
+ assertThat (getLayer (ccsTile , "hits" ).getFeaturesCount (), Matchers .equalTo (localGeometries + remoteGeometries ));
93
+ assertEquals (localGeometries , countFeaturesWithTag (getLayer (ccsTile , "hits" ), "_index" , "test" ));
94
+ assertEquals (remoteGeometries , countFeaturesWithTag (getLayer (ccsTile , "hits" ), "_index" , "other:test" ));
95
+ }
96
+
85
97
private VectorTile .Tile .Layer getLayer (VectorTile .Tile tile , String layerName ) {
86
98
for (int i = 0 ; i < tile .getLayersCount (); i ++) {
87
99
final VectorTile .Tile .Layer layer = tile .getLayers (i );
@@ -117,4 +129,26 @@ private RestClient buildClient(final String url) throws IOException {
117
129
);
118
130
return buildClient (restAdminSettings (), new HttpHost [] { httpHost });
119
131
}
132
+
133
+ private int countFeaturesWithTag (VectorTile .Tile .Layer layer , String tag , String value ) {
134
+ int count = 0 ;
135
+ for (int i = 0 ; i < layer .getFeaturesCount (); i ++) {
136
+ VectorTile .Tile .Feature feature = layer .getFeatures (i );
137
+ if (hasLabel (layer , feature , tag , value )) {
138
+ count ++;
139
+ }
140
+ }
141
+ return count ;
142
+ }
143
+
144
+ private boolean hasLabel (VectorTile .Tile .Layer layer , VectorTile .Tile .Feature feature , String tag , String value ) {
145
+ for (int i = 0 ; i < feature .getTagsCount (); i += 2 ) {
146
+ String thisTag = layer .getKeys (feature .getTags (i ));
147
+ if (tag .equals (thisTag )) {
148
+ VectorTile .Tile .Value thisValue = layer .getValues (feature .getTags (i + 1 ));
149
+ return value .equals (thisValue .getStringValue ());
150
+ }
151
+ }
152
+ return false ;
153
+ }
120
154
}
0 commit comments