-
Notifications
You must be signed in to change notification settings - Fork 194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: create AbstractAggregationRequestIT class + fail with OpenS… #421
Merged
dblock
merged 12 commits into
opensearch-project:main
from
szczepanczykd:feature/flaky-test-aggregation-request-it
Apr 3, 2023
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
65ed8c3
refactor: create AbstractAggregationRequestIT class + fail with OpenS…
szczepanczykd d938d19
feature: upload IntegrationTests reports
szczepanczykd bf9b658
fix: fixed workflow file
szczepanczykd 51e0821
fix: upload reports on failure
szczepanczykd 11210c4
refactor: add more error details to tests
szczepanczykd e168d8d
feat: update github workflows with name and retention-days
szczepanczykd 5ee1c48
test: create index with manual mappings
szczepanczykd 986d6dc
refactor: change expDate type from Date to String
szczepanczykd 71944df
refactor: stability check
szczepanczykd c8f6e5e
refactor: stability check 2
szczepanczykd 26753a9
fix: change retention-days to 7 for uploaded artifacts
szczepanczykd bc4eaec
refactor: change expDate type to Long
szczepanczykd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
187 changes: 187 additions & 0 deletions
187
...rc/test/java/org/opensearch/client/opensearch/integTest/AbstractAggregationRequestIT.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,187 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.client.opensearch.integTest; | ||
|
||
import org.junit.Test; | ||
import org.opensearch.client.opensearch._types.Refresh; | ||
import org.opensearch.client.opensearch._types.aggregations.Aggregation; | ||
import org.opensearch.client.opensearch._types.aggregations.AggregationRange; | ||
import org.opensearch.client.opensearch._types.aggregations.DateRangeAggregation; | ||
import org.opensearch.client.opensearch._types.aggregations.DateRangeExpression; | ||
import org.opensearch.client.opensearch._types.aggregations.FieldDateMath; | ||
import org.opensearch.client.opensearch._types.aggregations.RangeAggregation; | ||
import org.opensearch.client.opensearch._types.mapping.Property; | ||
import org.opensearch.client.opensearch.core.SearchResponse; | ||
|
||
import java.io.IOException; | ||
import java.time.Instant; | ||
import java.time.LocalDateTime; | ||
import java.time.ZoneOffset; | ||
import java.util.List; | ||
|
||
public abstract class AbstractAggregationRequestIT extends OpenSearchJavaClientTestCase { | ||
|
||
@Test | ||
public void testValueRangeAggregation() throws Exception { | ||
var index = "test-value-range-aggregation"; | ||
createDateRangeDocuments(index); | ||
var searchResponse = sendAggregateRequest(index, "cost_ranges", getCostValueRangeAggregation()); | ||
var costRangesAggregations = searchResponse.aggregations().get("cost_ranges"); | ||
var buckets = costRangesAggregations._get() | ||
._toAggregate() | ||
.range() | ||
.buckets() | ||
.array(); | ||
|
||
assertEquals(3, buckets.size()); | ||
assertEquals(2, buckets.get(0).docCount()); | ||
assertEquals(2, buckets.get(1).docCount()); | ||
assertEquals(2, buckets.get(2).docCount()); | ||
} | ||
|
||
@Test | ||
public void testDateRangeAggregation() throws Exception { | ||
var index = "test-date-range-aggregation"; | ||
createDateRangeDocuments(index); | ||
var searchResponse = sendAggregateRequest(index, "expiry_ranges", getExpiryDateRangeAggregation()); | ||
var expiryRangesAggregations = searchResponse.aggregations().get("expiry_ranges"); | ||
var buckets = expiryRangesAggregations._get() | ||
._toAggregate() | ||
.dateRange() | ||
.buckets() | ||
.array(); | ||
|
||
assertEquals(3, buckets.size()); | ||
assertEquals(2, buckets.get(0).docCount()); | ||
assertEquals(2, buckets.get(1).docCount()); | ||
assertEquals(2, buckets.get(2).docCount()); | ||
} | ||
|
||
private Aggregation getExpiryDateRangeAggregation() { | ||
DateRangeAggregation expiryDateRangeAggregation = new DateRangeAggregation.Builder() | ||
.field("expDate") | ||
.ranges(getDateAggregationRanges()) | ||
.build(); | ||
return new Aggregation.Builder().dateRange(expiryDateRangeAggregation).build(); | ||
} | ||
|
||
private Aggregation getCostValueRangeAggregation() { | ||
RangeAggregation costValueRangeAggregation = new RangeAggregation.Builder() | ||
.field("cost") | ||
.ranges(getValueAggregationRanges()) | ||
.build(); | ||
return new Aggregation.Builder().range(costValueRangeAggregation).build(); | ||
} | ||
|
||
private SearchResponse<Void> sendAggregateRequest(String index, String key, Aggregation value) throws IOException { | ||
return javaClient().search( | ||
request -> request.index(index) | ||
.size(0) | ||
.aggregations(key, value), | ||
Void.class); | ||
} | ||
|
||
private List<DateRangeExpression> getDateAggregationRanges() { | ||
return List.of( | ||
new DateRangeExpression.Builder() | ||
.from(builder -> builder.value((double) getDatePlusDays(1).toEpochMilli())) | ||
.to(FieldDateMath.of( | ||
builder -> builder.value((double) getDatePlusDays(3).toEpochMilli() - 1000)) | ||
) | ||
.key("from-1-to-2-days") | ||
.build(), | ||
new DateRangeExpression.Builder() | ||
.from(builder -> builder.value((double) getDatePlusDays(3).toEpochMilli())) | ||
.to(FieldDateMath.of( | ||
builder -> builder.value((double) getDatePlusDays(5).toEpochMilli() - 1000)) | ||
) | ||
.key("from-3-to-4-days") | ||
.build(), | ||
new DateRangeExpression.Builder() | ||
.from(builder -> builder.value((double) getDatePlusDays(5).toEpochMilli())) | ||
.to(FieldDateMath.of( | ||
builder -> builder.value((double) getDatePlusDays(7).toEpochMilli() - 1000)) | ||
) | ||
.key("from-5-to-6-days") | ||
.build() | ||
); | ||
} | ||
|
||
private List<AggregationRange> getValueAggregationRanges() { | ||
return List.of( | ||
new AggregationRange.Builder().to("10").build(), | ||
new AggregationRange.Builder().from("10").to("30").build(), | ||
new AggregationRange.Builder().from("30").build() | ||
); | ||
} | ||
|
||
private void createDateRangeDocuments(String index) throws IOException { | ||
createIndex(index); | ||
javaClient().create(_1 -> _1.index(index).id("1").document(createProduct("egg", 2, 1)).refresh(Refresh.True)); | ||
javaClient().create(_1 -> _1.index(index).id("2").document(createProduct("meat", 15, 2)).refresh(Refresh.True)); | ||
javaClient().create(_1 -> _1.index(index).id("3").document(createProduct("ham", 30, 3)).refresh(Refresh.True)); | ||
javaClient().create(_1 -> _1.index(index).id("4").document(createProduct("cheese", 25, 4)).refresh(Refresh.True)); | ||
javaClient().create(_1 -> _1.index(index).id("5").document(createProduct("pasta", 8, 5)).refresh(Refresh.True)); | ||
javaClient().create(_1 -> _1.index(index).id("6").document(createProduct("oil", 50, 6)).refresh(Refresh.True)); | ||
} | ||
|
||
private void createIndex(String index) throws IOException { | ||
Property nameValueProp = new Property.Builder() | ||
.text(v -> v) | ||
.build(); | ||
Property costValueProp = new Property.Builder() | ||
.integer(v -> v) | ||
.build(); | ||
Property expDateKeywordProp = new Property.Builder() | ||
.date(v -> v) | ||
.build(); | ||
javaClient().indices().create(c -> c.index(index) | ||
.mappings(m -> m.properties("name", nameValueProp) | ||
.properties("cost", costValueProp) | ||
.properties("expDate", expDateKeywordProp) | ||
) | ||
); | ||
} | ||
|
||
private ProductDetails createProduct(String name, int cost, int plusDays) { | ||
return new ProductDetails(name, cost, getDatePlusDays(plusDays).toEpochMilli()); | ||
} | ||
|
||
private Instant getDatePlusDays(int plusDays) { | ||
return LocalDateTime.of(2023, 2, 20, 0, 0, 0, 0).plusDays(plusDays).toInstant(ZoneOffset.UTC); | ||
} | ||
|
||
public static class ProductDetails { | ||
private String name; | ||
private int cost; | ||
private Long expDate; | ||
|
||
public ProductDetails() { | ||
} | ||
|
||
public ProductDetails(String name, int cost, Long expDate) { | ||
this.name = name; | ||
this.cost = cost; | ||
this.expDate = expDate; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public int getCost() { | ||
return cost; | ||
} | ||
|
||
public Long getExpDate() { | ||
return expDate; | ||
} | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
...est/java/org/opensearch/client/opensearch/integTest/httpclient5/AggregationRequestIT.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,14 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.client.opensearch.integTest.httpclient5; | ||
|
||
import org.opensearch.client.opensearch.integTest.AbstractAggregationRequestIT; | ||
|
||
public class AggregationRequestIT extends AbstractAggregationRequestIT implements HttpClient5TransportSupport{ | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍