Skip to content

Commit 47751a8

Browse files
committed
Rename tests, grab numShards differently
1 parent 93eddcc commit 47751a8

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

qa/smoke-test-http/src/internalClusterTest/java/org/elasticsearch/http/SearchErrorTraceIT.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import org.elasticsearch.action.search.MultiSearchRequest;
1717
import org.elasticsearch.action.search.SearchRequest;
1818
import org.elasticsearch.client.Request;
19-
import org.elasticsearch.cluster.metadata.IndexMetadata;
2019
import org.elasticsearch.common.settings.Settings;
2120
import org.elasticsearch.common.util.CollectionUtils;
2221
import org.elasticsearch.plugins.Plugin;
@@ -62,17 +61,14 @@ public void resetSettings() {
6261
updateClusterSettings(Settings.builder().putNull(SearchService.BATCHED_QUERY_PHASE.getKey()));
6362
}
6463

65-
private int setupIndexWithDocs() {
66-
int numShards = numberOfShards();
67-
createIndex("test1", Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, numShards).build());
68-
createIndex("test2", Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, numShards).build());
64+
private void setupIndexWithDocs() {
65+
createIndex("test1", "test2");
6966
indexRandom(
7067
true,
7168
prepareIndex("test1").setId("1").setSource("field", "foo"),
7269
prepareIndex("test2").setId("10").setSource("field", 5)
7370
);
7471
refresh();
75-
return numShards;
7672
}
7773

7874
public void testSearchFailingQueryErrorTraceDefault() throws IOException {
@@ -131,8 +127,8 @@ public void testSearchFailingQueryErrorTraceFalse() throws IOException {
131127
assertFalse(hasStackTrace.getAsBoolean());
132128
}
133129

134-
public void testNoLoggingInSearchFailingQueryErrorTraceTrue() throws IOException {
135-
int numShards = setupIndexWithDocs();
130+
public void testDataNodeDoesNotLogStackTraceWhenErrorTraceTrue() throws IOException {
131+
setupIndexWithDocs();
136132

137133
Request searchRequest = new Request("POST", "/_search");
138134
searchRequest.setJsonEntity("""
@@ -147,6 +143,7 @@ public void testNoLoggingInSearchFailingQueryErrorTraceTrue() throws IOException
147143
""");
148144

149145
String errorTriggeringIndex = "test2";
146+
int numShards = getNumShards(errorTriggeringIndex).numPrimaries;
150147
try (var mockLog = MockLog.capture(SearchService.class)) {
151148
ErrorTraceHelper.addUnseenLoggingExpectations(numShards, mockLog, errorTriggeringIndex);
152149

@@ -156,8 +153,8 @@ public void testNoLoggingInSearchFailingQueryErrorTraceTrue() throws IOException
156153
}
157154
}
158155

159-
public void testLoggingInSearchFailingQueryErrorTraceFalse() throws IOException {
160-
int numShards = setupIndexWithDocs();
156+
public void testDataNodeLogsStackTraceWhenErrorTraceFalseOrEmpty() throws IOException {
157+
setupIndexWithDocs();
161158

162159
Request searchRequest = new Request("POST", "/_search");
163160
searchRequest.setJsonEntity("""
@@ -172,6 +169,7 @@ public void testLoggingInSearchFailingQueryErrorTraceFalse() throws IOException
172169
""");
173170

174171
String errorTriggeringIndex = "test2";
172+
int numShards = getNumShards(errorTriggeringIndex).numPrimaries;
175173
try (var mockLog = MockLog.capture(SearchService.class)) {
176174
ErrorTraceHelper.addSeenLoggingExpectations(numShards, mockLog, errorTriggeringIndex);
177175

@@ -235,8 +233,8 @@ public void testMultiSearchFailingQueryErrorTraceFalse() throws IOException {
235233
assertFalse(hasStackTrace.getAsBoolean());
236234
}
237235

238-
public void testLoggingInMultiSearchFailingQueryErrorTraceTrue() throws IOException {
239-
int numShards = setupIndexWithDocs();
236+
public void testDataNodeDoesNotLogStackTraceWhenErrorTraceTrueMultiSearch() throws IOException {
237+
setupIndexWithDocs();
240238

241239
XContentType contentType = XContentType.JSON;
242240
MultiSearchRequest multiSearchRequest = new MultiSearchRequest().add(
@@ -251,6 +249,7 @@ public void testLoggingInMultiSearchFailingQueryErrorTraceTrue() throws IOExcept
251249
searchRequest.addParameter("error_trace", "true");
252250

253251
String errorTriggeringIndex = "test2";
252+
int numShards = getNumShards(errorTriggeringIndex).numPrimaries;
254253
try (var mockLog = MockLog.capture(SearchService.class)) {
255254
ErrorTraceHelper.addUnseenLoggingExpectations(numShards, mockLog, errorTriggeringIndex);
256255

@@ -259,8 +258,8 @@ public void testLoggingInMultiSearchFailingQueryErrorTraceTrue() throws IOExcept
259258
}
260259
}
261260

262-
public void testLoggingInMultiSearchFailingQueryErrorTraceFalse() throws IOException {
263-
int numShards = setupIndexWithDocs();
261+
public void testDataNodeLogsStackTraceWhenErrorTraceFalseOrEmptyMultiSearch() throws IOException {
262+
setupIndexWithDocs();
264263

265264
XContentType contentType = XContentType.JSON;
266265
MultiSearchRequest multiSearchRequest = new MultiSearchRequest().add(
@@ -278,6 +277,7 @@ public void testLoggingInMultiSearchFailingQueryErrorTraceFalse() throws IOExcep
278277
}
279278

280279
String errorTriggeringIndex = "test2";
280+
int numShards = getNumShards(errorTriggeringIndex).numPrimaries;
281281
try (var mockLog = MockLog.capture(SearchService.class)) {
282282
ErrorTraceHelper.addSeenLoggingExpectations(numShards, mockLog, errorTriggeringIndex);
283283

x-pack/plugin/async-search/src/internalClusterTest/java/org/elasticsearch/xpack/search/AsyncSearchErrorTraceIT.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,14 @@ public void resetSettings() {
6363
updateClusterSettings(Settings.builder().putNull(SearchService.BATCHED_QUERY_PHASE.getKey()));
6464
}
6565

66-
private int setupIndexWithDocs() {
67-
int numShards = numberOfShards();
68-
createIndex("test1", Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, numShards).build());
69-
createIndex("test2", Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, numShards).build());
66+
private void setupIndexWithDocs() {
67+
createIndex("test1", "test2");
7068
indexRandom(
7169
true,
7270
prepareIndex("test1").setId("1").setSource("field", "foo"),
7371
prepareIndex("test2").setId("10").setSource("field", 5)
7472
);
7573
refresh();
76-
return numShards;
7774
}
7875

7976
public void testAsyncSearchFailingQueryErrorTraceDefault() throws IOException, InterruptedException {
@@ -158,8 +155,8 @@ public void testAsyncSearchFailingQueryErrorTraceFalse() throws IOException, Int
158155
assertFalse(transportMessageHasStackTrace.getAsBoolean());
159156
}
160157

161-
public void testLoggingInAsyncSearchFailingQueryErrorTraceTrue() throws IOException, InterruptedException {
162-
int numShards = setupIndexWithDocs();
158+
public void testDataNodeDoesNotLogStackTraceWhenErrorTraceTrue() throws IOException, InterruptedException {
159+
setupIndexWithDocs();
163160

164161
Request searchRequest = new Request("POST", "/_async_search");
165162
searchRequest.setJsonEntity("""
@@ -177,6 +174,7 @@ public void testLoggingInAsyncSearchFailingQueryErrorTraceTrue() throws IOExcept
177174
searchRequest.addParameter("wait_for_completion_timeout", "0ms");
178175

179176
String errorTriggeringIndex = "test2";
177+
int numShards = getNumShards(errorTriggeringIndex).numPrimaries;
180178
try (var mockLog = MockLog.capture(SearchService.class)) {
181179
ErrorTraceHelper.addUnseenLoggingExpectations(numShards, mockLog, errorTriggeringIndex);
182180

@@ -193,8 +191,9 @@ public void testLoggingInAsyncSearchFailingQueryErrorTraceTrue() throws IOExcept
193191
}
194192
}
195193

196-
public void testLoggingInAsyncSearchFailingQueryErrorTraceFalse() throws IOException, InterruptedException {
197-
int numShards = setupIndexWithDocs();
194+
public void testDataNodeLogsStackTraceWhenErrorTraceFalseOrEmpty() throws IOException, InterruptedException {
195+
setupIndexWithDocs();
196+
198197
// error_trace defaults to false so we can test both cases with some randomization
199198
final boolean defineErrorTraceFalse = randomBoolean();
200199

@@ -216,6 +215,7 @@ public void testLoggingInAsyncSearchFailingQueryErrorTraceFalse() throws IOExcep
216215
searchRequest.addParameter("wait_for_completion_timeout", "0ms");
217216

218217
String errorTriggeringIndex = "test2";
218+
int numShards = getNumShards(errorTriggeringIndex).numPrimaries;
219219
try (var mockLog = MockLog.capture(SearchService.class)) {
220220
ErrorTraceHelper.addSeenLoggingExpectations(numShards, mockLog, errorTriggeringIndex);
221221

0 commit comments

Comments
 (0)