Skip to content

Commit a88ae59

Browse files
committed
Enable assertions in integration tests
When starting a standalone cluster, we do not able assertions. This is problematic because it means that we miss opportunities to catch bugs. This commit enables assertions for standalone integration tests, and fixes a couple bugs that were uncovered by enabling these. Relates #22334
1 parent ee09172 commit a88ae59

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterConfiguration.groovy

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@ class ClusterConfiguration {
7272
boolean useMinimumMasterNodes = true
7373

7474
@Input
75-
String jvmArgs = "-Xms" + System.getProperty('tests.heap.size', '512m') +
76-
" " + "-Xmx" + System.getProperty('tests.heap.size', '512m') +
77-
" " + System.getProperty('tests.jvm.argline', '')
75+
String jvmArgs = "-ea" +
76+
" " + "-Xms" + System.getProperty('tests.heap.size', '512m') +
77+
" " + "-Xmx" + System.getProperty('tests.heap.size', '512m') +
78+
" " + System.getProperty('tests.jvm.argline', '')
79+
7880

7981
/**
8082
* A closure to call which returns the unicast host to connect to for cluster formation.

core/src/main/java/org/elasticsearch/rest/BytesRestResponse.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,10 @@ public BytesRestResponse(RestChannel channel, RestStatus status, Exception e) th
8989
this.content = BytesArray.EMPTY;
9090
this.contentType = TEXT_CONTENT_TYPE;
9191
} else {
92-
XContentBuilder builder = convert(channel, status, e);
93-
this.content = builder.bytes();
94-
this.contentType = builder.contentType().mediaType();
92+
try (final XContentBuilder builder = convert(channel, status, e)) {
93+
this.content = builder.bytes();
94+
this.contentType = builder.contentType().mediaType();
95+
}
9596
}
9697
if (e instanceof ElasticsearchException) {
9798
copyHeaders(((ElasticsearchException) e));

core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetMappingAction.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ public RestResponse buildResponse(GetMappingsResponse response, XContentBuilder
7575
if (indices.length != 0 && types.length != 0) {
7676
return new BytesRestResponse(OK, builder.startObject().endObject());
7777
} else if (indices.length != 0) {
78+
builder.close();
7879
return new BytesRestResponse(channel, new IndexNotFoundException(indices[0]));
7980
} else if (types.length != 0) {
81+
builder.close();
8082
return new BytesRestResponse(channel, new TypeMissingException("_all", types[0]));
8183
} else {
8284
return new BytesRestResponse(OK, builder.startObject().endObject());

0 commit comments

Comments
 (0)