-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Tests] Mutualize fixtures code in BaseHttpFixture
Many fixtures have similar code for writing the pid & ports files or for handling HTTP requests. This commit changes the current ExampleFixture in order to make it an abstract BaseHttpFixture class that can be extended for specific testing purposes. This class provides some simple Request and Response classes to represent the HTTP requests and responses and takes care of writing the pid and ports files and starting the HTTP server. It allows to remove lot of duplicated code and forbidden APIs invocations. The current AmazonS3Fixture, GoogleCloudStorageFixture, AzureStorageFixture, and URLFixture have been removed. The AmazonS3TestServer, , AzureStorageTestServer, GoogleCloudStorageTestServer have been renamed and now extend BaseHttpFixture. This commit also fixes an issue with the AntFixture that was expecting a false result for the waitCondition(), whereas it should expect `true`.
- Loading branch information
Showing
20 changed files
with
1,672 additions
and
2,039 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...ples/rest-handler/src/test/java/org/elasticsearch/example/resthandler/ExampleFixture.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.elasticsearch.example.resthandler; | ||
|
||
import basic.BaseHttpFixture; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
|
||
public class ExampleFixture extends BaseHttpFixture { | ||
|
||
private final String message; | ||
|
||
private ExampleFixture(final String workingDir, final String message) { | ||
super(workingDir); | ||
this.message = Objects.requireNonNull(message); | ||
} | ||
|
||
@Override | ||
protected Response handle(final Request request) throws IOException { | ||
if ("GET".equals(request.getMethod()) && "/".equals(request.getPath())) { | ||
return new Response(200, TEXT_PLAIN_CONTENT_TYPE, message.getBytes(UTF_8)); | ||
} | ||
return null; | ||
} | ||
|
||
public static void main(final String[] args) throws Exception { | ||
if (args == null || args.length != 2) { | ||
throw new IllegalArgumentException("ExampleFixture <working directory> <echo message>"); | ||
} | ||
|
||
final ExampleFixture fixture = new ExampleFixture(args[0], args[1]); | ||
fixture.listen(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.