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
This commit is contained in:
parent
9cd9576b84
commit
faaa671fb6
|
@ -72,10 +72,12 @@ class ClusterConfiguration {
|
||||||
boolean useMinimumMasterNodes = true
|
boolean useMinimumMasterNodes = true
|
||||||
|
|
||||||
@Input
|
@Input
|
||||||
String jvmArgs = "-Xms" + System.getProperty('tests.heap.size', '512m') +
|
String jvmArgs = "-ea" +
|
||||||
|
" " + "-Xms" + System.getProperty('tests.heap.size', '512m') +
|
||||||
" " + "-Xmx" + System.getProperty('tests.heap.size', '512m') +
|
" " + "-Xmx" + System.getProperty('tests.heap.size', '512m') +
|
||||||
" " + System.getProperty('tests.jvm.argline', '')
|
" " + System.getProperty('tests.jvm.argline', '')
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A closure to call which returns the unicast host to connect to for cluster formation.
|
* A closure to call which returns the unicast host to connect to for cluster formation.
|
||||||
*
|
*
|
||||||
|
|
|
@ -592,15 +592,14 @@ public class InternalEngine extends Engine {
|
||||||
private boolean assertSequenceNumber(final Engine.Operation.Origin origin, final long seqNo) {
|
private boolean assertSequenceNumber(final Engine.Operation.Origin origin, final long seqNo) {
|
||||||
if (engineConfig.getIndexSettings().getIndexVersionCreated().before(Version.V_6_0_0_alpha1_UNRELEASED) && origin == Operation.Origin.LOCAL_TRANSLOG_RECOVERY) {
|
if (engineConfig.getIndexSettings().getIndexVersionCreated().before(Version.V_6_0_0_alpha1_UNRELEASED) && origin == Operation.Origin.LOCAL_TRANSLOG_RECOVERY) {
|
||||||
// legacy support
|
// legacy support
|
||||||
assert seqNo == SequenceNumbersService.UNASSIGNED_SEQ_NO : "old op recovering but it already has a seq no." +
|
assert seqNo == SequenceNumbersService.UNASSIGNED_SEQ_NO : "old op recovering but it already has a seq no.;" +
|
||||||
" index version: " + engineConfig.getIndexSettings().getIndexVersionCreated() + ". seq no: " + seqNo;
|
" index version: " + engineConfig.getIndexSettings().getIndexVersionCreated() + ", seqNo: " + seqNo;
|
||||||
} else if (origin == Operation.Origin.PRIMARY) {
|
} else if (origin == Operation.Origin.PRIMARY) {
|
||||||
// sequence number should not be set when operation origin is primary
|
// sequence number should not be set when operation origin is primary
|
||||||
assert seqNo == SequenceNumbersService.UNASSIGNED_SEQ_NO : "primary ops should never have an assigned seq no. got: " + seqNo;
|
assert seqNo == SequenceNumbersService.UNASSIGNED_SEQ_NO : "primary ops should never have an assigned seq no.; seqNo: " + seqNo;
|
||||||
} else {
|
} else if (engineConfig.getIndexSettings().getIndexVersionCreated().onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) {
|
||||||
// sequence number should be set when operation origin is not primary
|
// sequence number should be set when operation origin is not primary
|
||||||
assert seqNo >= 0 : "recovery or replica ops should have an assigned seq no. origin: " + origin +
|
assert seqNo >= 0 : "recovery or replica ops should have an assigned seq no.; origin: " + origin;
|
||||||
" index version: " + engineConfig.getIndexSettings().getIndexVersionCreated();
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,10 +89,11 @@ public class BytesRestResponse extends RestResponse {
|
||||||
this.content = BytesArray.EMPTY;
|
this.content = BytesArray.EMPTY;
|
||||||
this.contentType = TEXT_CONTENT_TYPE;
|
this.contentType = TEXT_CONTENT_TYPE;
|
||||||
} else {
|
} else {
|
||||||
XContentBuilder builder = convert(channel, status, e);
|
try (final XContentBuilder builder = convert(channel, status, e)) {
|
||||||
this.content = builder.bytes();
|
this.content = builder.bytes();
|
||||||
this.contentType = builder.contentType().mediaType();
|
this.contentType = builder.contentType().mediaType();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (e instanceof ElasticsearchException) {
|
if (e instanceof ElasticsearchException) {
|
||||||
copyHeaders(((ElasticsearchException) e));
|
copyHeaders(((ElasticsearchException) e));
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,8 +72,10 @@ public class RestGetMappingAction extends BaseRestHandler {
|
||||||
if (indices.length != 0 && types.length != 0) {
|
if (indices.length != 0 && types.length != 0) {
|
||||||
return new BytesRestResponse(OK, builder.startObject().endObject());
|
return new BytesRestResponse(OK, builder.startObject().endObject());
|
||||||
} else if (indices.length != 0) {
|
} else if (indices.length != 0) {
|
||||||
|
builder.close();
|
||||||
return new BytesRestResponse(channel, new IndexNotFoundException(indices[0]));
|
return new BytesRestResponse(channel, new IndexNotFoundException(indices[0]));
|
||||||
} else if (types.length != 0) {
|
} else if (types.length != 0) {
|
||||||
|
builder.close();
|
||||||
return new BytesRestResponse(channel, new TypeMissingException("_all", types[0]));
|
return new BytesRestResponse(channel, new TypeMissingException("_all", types[0]));
|
||||||
} else {
|
} else {
|
||||||
return new BytesRestResponse(OK, builder.startObject().endObject());
|
return new BytesRestResponse(OK, builder.startObject().endObject());
|
||||||
|
|
Loading…
Reference in New Issue