-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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 (#31210)
Many fixtures have similar code for writing the pid & ports files or for handling HTTP requests. This commit adds an AbstractHttpFixture class in the test framework that can be extended for specific testing purposes.
- Loading branch information
Showing
17 changed files
with
1,632 additions
and
2,103 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
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 org.elasticsearch.test.fixture.AbstractHttpFixture; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
|
||
public class ExampleFixture extends AbstractHttpFixture { | ||
|
||
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
Oops, something went wrong.