1919import static org .apache .solr .common .cloud .ZkStateReader .ALIASES ;
2020
2121import java .io .IOException ;
22+ import java .nio .charset .StandardCharsets ;
2223import java .util .List ;
2324import java .util .Locale ;
2425import java .util .Map ;
2526import java .util .concurrent .TimeUnit ;
2627import java .util .function .Consumer ;
2728import java .util .function .UnaryOperator ;
28- import org .apache .http .client .methods .CloseableHttpResponse ;
29- import org .apache .http .client .methods .HttpDelete ;
30- import org .apache .http .client .methods .HttpGet ;
31- import org .apache .http .client .methods .HttpPut ;
32- import org .apache .http .client .methods .HttpUriRequest ;
33- import org .apache .http .entity .ContentType ;
34- import org .apache .http .entity .StringEntity ;
35- import org .apache .http .impl .client .CloseableHttpClient ;
36- import org .apache .http .util .EntityUtils ;
3729import org .apache .solr .client .solrj .SolrClient ;
3830import org .apache .solr .client .solrj .SolrRequest ;
3931import org .apache .solr .client .solrj .SolrServerException ;
40- import org .apache .solr .client .solrj .apache .CloudLegacySolrClient ;
4132import org .apache .solr .client .solrj .cloud .SolrCloudManager ;
4233import org .apache .solr .client .solrj .impl .CloudSolrClient ;
4334import org .apache .solr .client .solrj .impl .ClusterStateProvider ;
6051import org .apache .solr .embedded .JettySolrRunner ;
6152import org .apache .solr .util .TimeOut ;
6253import org .apache .zookeeper .KeeperException ;
54+ import org .eclipse .jetty .client .ContentResponse ;
55+ import org .eclipse .jetty .client .HttpClient ;
56+ import org .eclipse .jetty .client .StringRequestContent ;
57+ import org .eclipse .jetty .http .HttpMethod ;
6358import org .junit .After ;
6459import org .junit .Before ;
6560import org .junit .BeforeClass ;
6661import org .junit .Test ;
6762
6863public class AliasIntegrationTest extends SolrCloudTestCase {
6964
70- private CloseableHttpClient httpClient ;
71-
7265 @ BeforeClass
7366 public static void setupCluster () throws Exception {
7467 configureCluster (2 ).addConfig ("conf" , configset ("cloud-minimal" )).configure ();
@@ -78,9 +71,6 @@ public static void setupCluster() throws Exception {
7871 @ Override
7972 public void setUp () throws Exception {
8073 super .setUp ();
81-
82- httpClient =
83- (CloseableHttpClient ) ((CloudLegacySolrClient ) cluster .getSolrClient ()).getHttpClient ();
8474 }
8575
8676 @ After
@@ -238,49 +228,53 @@ public void testProperties() throws Exception {
238228 public void testModifyPropertiesV2 () throws Exception {
239229 final String aliasName = getSaferTestName ();
240230 ZkStateReader zkStateReader = createColectionsAndAlias (aliasName );
241- final String baseUrl = cluster .getRandomJetty (random ()).getBaseURLV2 ().toString ();
231+ final JettySolrRunner runner = cluster .getRandomJetty (random ());
232+ final String baseUrl = runner .getBaseURLV2 ().toString ();
233+ final HttpClient httpClient = runner .getSolrClient ().getHttpClient ();
242234 String aliasApi = String .format (Locale .ENGLISH , "/aliases/%s/properties" , aliasName );
243235
244- HttpPut withoutBody = new HttpPut (baseUrl + aliasApi );
245- assertEquals (400 , httpClient .execute (withoutBody ).getStatusLine ().getStatusCode ());
246-
247- HttpPut update = new HttpPut (baseUrl + aliasApi );
248- update .setEntity (
249- new StringEntity (
250- "{\n "
251- + " \" properties\" :\n "
252- + " {\n "
253- + " \" foo\" : \" baz\" ,\n "
254- + " \" bar\" : \" bam\" \n "
255- + " }\n "
256- + "}" ,
257- ContentType .APPLICATION_JSON ));
258- assertSuccess (update );
236+ assertEquals (
237+ 400 , httpClient .newRequest (baseUrl + aliasApi ).method (HttpMethod .PUT ).send ().getStatus ());
238+
239+ String body =
240+ "{\n "
241+ + " \" properties\" :\n "
242+ + " {\n "
243+ + " \" foo\" : \" baz\" ,\n "
244+ + " \" bar\" : \" bam\" \n "
245+ + " }\n "
246+ + "}" ;
247+ assertSuccess (
248+ httpClient
249+ .newRequest (baseUrl + aliasApi )
250+ .method (HttpMethod .PUT )
251+ .body (new StringRequestContent ("application/json" , body , StandardCharsets .UTF_8 ))
252+ .send ());
259253 checkFooAndBarMeta (aliasName , zkStateReader , "baz" , "bam" );
260254
261255 String aliasPropertyApi =
262256 String .format (Locale .ENGLISH , "/aliases/%s/properties/%s" , aliasName , "foo" );
263- HttpPut updateByProperty = new HttpPut (baseUrl + aliasPropertyApi );
264- updateByProperty .setEntity (
265- new StringEntity ("{ \" value\" : \" zab\" }" , ContentType .APPLICATION_JSON ));
266- assertSuccess (updateByProperty );
257+ assertSuccess (
258+ httpClient
259+ .newRequest (baseUrl + aliasPropertyApi )
260+ .method (HttpMethod .PUT )
261+ .body (
262+ new StringRequestContent (
263+ "application/json" , "{ \" value\" : \" zab\" }" , StandardCharsets .UTF_8 ))
264+ .send ());
267265 checkFooAndBarMeta (aliasName , zkStateReader , "zab" , "bam" );
268266
269- HttpDelete deleteByProperty = new HttpDelete ( baseUrl + aliasPropertyApi );
270- assertSuccess ( deleteByProperty );
267+ assertSuccess (
268+ httpClient . newRequest ( baseUrl + aliasPropertyApi ). method ( HttpMethod . DELETE ). send () );
271269 checkFooAndBarMeta (aliasName , zkStateReader , null , "bam" );
272270
273- HttpPut deleteByEmptyValue = new HttpPut (baseUrl + aliasApi );
274- deleteByEmptyValue .setEntity (
275- new StringEntity (
276- "{\n "
277- + " \" properties\" :\n "
278- + " {\n "
279- + " \" bar\" : \" \" \n "
280- + " }\n "
281- + "}" ,
282- ContentType .APPLICATION_JSON ));
283- assertSuccess (deleteByEmptyValue );
271+ body = "{ \" properties\" : { \" bar\" : \" \" } }" ;
272+ assertSuccess (
273+ httpClient
274+ .newRequest (baseUrl + aliasApi )
275+ .method (HttpMethod .PUT )
276+ .body (new StringRequestContent ("application/json" , body , StandardCharsets .UTF_8 ))
277+ .send ());
284278 checkFooAndBarMeta (aliasName , zkStateReader , null , null );
285279 }
286280
@@ -289,29 +283,29 @@ public void testModifyPropertiesV1() throws Exception {
289283 // note we don't use TZ in this test, thus it's UTC
290284 final String aliasName = getSaferTestName ();
291285 ZkStateReader zkStateReader = createColectionsAndAlias (aliasName );
292- final String baseUrl = cluster .getRandomJetty (random ()).getBaseUrl ().toString ();
293- HttpGet get =
294- new HttpGet (
295- baseUrl
296- + "/admin/collections?action=ALIASPROP"
297- + "&wt=xml"
298- + "&name="
299- + aliasName
300- + "&property.foo=baz"
301- + "&property.bar=bam" );
302- assertSuccess (get );
286+ final JettySolrRunner runner = cluster .getRandomJetty (random ());
287+ final String baseUrl = runner .getBaseUrl ().toString ();
288+ final HttpClient httpClient = runner .getSolrClient ().getHttpClient ();
289+ String url =
290+ baseUrl
291+ + "/admin/collections?action=ALIASPROP"
292+ + "&wt=xml"
293+ + "&name="
294+ + aliasName
295+ + "&property.foo=baz"
296+ + "&property.bar=bam" ;
297+ assertSuccess (httpClient .GET (url ));
303298 checkFooAndBarMeta (aliasName , zkStateReader , "baz" , "bam" );
304299
305- HttpGet remove =
306- new HttpGet (
307- baseUrl
308- + "/admin/collections?action=ALIASPROP"
309- + "&wt=xml"
310- + "&name="
311- + aliasName
312- + "&property.foo="
313- + "&property.bar=bar" );
314- assertSuccess (remove );
300+ url =
301+ baseUrl
302+ + "/admin/collections?action=ALIASPROP"
303+ + "&wt=xml"
304+ + "&name="
305+ + aliasName
306+ + "&property.foo="
307+ + "&property.bar=bar" ;
308+ assertSuccess (httpClient .GET (url ));
315309 checkFooAndBarMeta (aliasName , zkStateReader , null , "bar" );
316310 }
317311
@@ -508,12 +502,10 @@ private ZkStateReader createColectionsAndAlias(String aliasName)
508502 return zkStateReader ;
509503 }
510504
511- private void assertSuccess (HttpUriRequest msg ) throws IOException {
512- try (CloseableHttpResponse response = httpClient .execute (msg )) {
513- if (200 != response .getStatusLine ().getStatusCode ()) {
514- System .err .println (EntityUtils .toString (response .getEntity ()));
515- fail ("Unexpected status: " + response .getStatusLine ());
516- }
505+ private void assertSuccess (ContentResponse response ) {
506+ if (200 != response .getStatus ()) {
507+ System .err .println (response .getContentAsString ());
508+ fail ("Unexpected status: " + response .getStatus ());
517509 }
518510 }
519511
0 commit comments