Skip to content

Commit 144882b

Browse files
committed
Merge remote-tracking branch 'es/6.x' into ccr-6.x
* es/6.x: (48 commits) Update bucket-sort-aggregation.asciidoc (#28937) [Docs] REST high-level client: Fix code for most basic search request (#28916) Improved percolator's random candidate query duel test and fixed bugs that were exposed by this: Revert "Rescore collapsed documents (#28521)" Build: Fix test logger NPE when no tests are run (#28929) [TEST] AwaitsFix QueryRescorerIT.testRescoreAfterCollapse Decouple XContentType from StreamInput/Output (#28927) Remove BytesRef usage from XContentParser and its subclasses (#28792) Add doc note for -server flag on Windows service [DOCS] Correct typo in configuration (#28903) Fix incorrect datemath example (#28904) Add a usage example of the JLH score (#28905) Limit analyzed text for highlighting (improvements) (#28907) Wrap stream passed to createParser in try-with-resources (#28897) [Docs] Fix typo in composite aggregation (#28891) Rescore collapsed documents (#28521) Fix (simple)_query_string to ignore removed terms (#28871) Missing `timeout` parameter from the REST API spec JSON files (#28328) Clarifies how query_string splits textual part (#28798) Update outdated java version reference (#28870) ...
2 parents 5d59f91 + 6ab93f3 commit 144882b

File tree

157 files changed

+2355
-1086
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

157 files changed

+2355
-1086
lines changed

buildSrc/src/main/groovy/com/carrotsearch/gradle/junit4/TestProgressLogger.groovy

+8-5
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,15 @@ class TestProgressLogger implements AggregatedEventListener {
100100

101101
@Subscribe
102102
void onQuit(AggregatedQuitEvent e) throws IOException {
103-
suiteLogger.completed()
104-
testLogger.completed()
105-
for (ProgressLogger slaveLogger : slaveLoggers) {
106-
slaveLogger.completed()
103+
// if onStart was never called (eg no matching tests), suiteLogger and all the other loggers will be null
104+
if (suiteLogger != null) {
105+
suiteLogger.completed()
106+
testLogger.completed()
107+
for (ProgressLogger slaveLogger : slaveLoggers) {
108+
slaveLogger.completed()
109+
}
110+
parentProgressLogger.completed()
107111
}
108-
parentProgressLogger.completed()
109112
}
110113

111114
@Subscribe

buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ class BuildPlugin implements Plugin<Project> {
430430
// we fork because compiling lots of different classes in a shared jvm can eventually trigger GC overhead limitations
431431
options.fork = true
432432
options.forkOptions.javaHome = new File(project.compilerJavaHome)
433-
options.forkOptions.memoryMaximumSize = "1g"
433+
options.forkOptions.memoryMaximumSize = "512m"
434434
if (targetCompatibilityVersion == JavaVersion.VERSION_1_8) {
435435
// compile with compact 3 profile by default
436436
// NOTE: this is just a compile time check: does not replace testing with a compact3 JRE

buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ public class PluginBuildPlugin extends BuildPlugin {
106106
private static void createIntegTestTask(Project project) {
107107
RestIntegTestTask integTest = project.tasks.create('integTest', RestIntegTestTask.class)
108108
integTest.mustRunAfter(project.precommit, project.test)
109+
project.integTestCluster.distribution = 'integ-test-zip'
109110
project.check.dependsOn(integTest)
110111
}
111112

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ClusterConfiguration {
2828
private final Project project
2929

3030
@Input
31-
String distribution = 'integ-test-zip'
31+
String distribution = 'zip'
3232

3333
@Input
3434
int numNodes = 1

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

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public class RestTestPlugin implements Plugin<Project> {
4646
RestIntegTestTask integTest = project.tasks.create('integTest', RestIntegTestTask.class)
4747
integTest.description = 'Runs rest tests against an elasticsearch cluster.'
4848
integTest.group = JavaBasePlugin.VERIFICATION_GROUP
49-
integTest.clusterConfig.distribution = 'zip' // rest tests should run with the real zip
5049
integTest.mustRunAfter(project.precommit)
5150
project.check.dependsOn(integTest)
5251
}

buildSrc/src/main/groovy/org/elasticsearch/gradle/vagrant/VagrantTestPlugin.groovy

+27-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package org.elasticsearch.gradle.vagrant
33
import com.carrotsearch.gradle.junit4.RandomizedTestingPlugin
44
import org.apache.tools.ant.taskdefs.condition.Os
55
import org.elasticsearch.gradle.FileContentsTask
6+
import org.elasticsearch.gradle.LoggedExec
67
import org.gradle.api.*
78
import org.gradle.api.artifacts.dsl.RepositoryHandler
89
import org.gradle.api.execution.TaskExecutionAdapter
@@ -309,15 +310,35 @@ class VagrantTestPlugin implements Plugin<Project> {
309310
}
310311
update.mustRunAfter(setupBats)
311312

313+
/*
314+
* Destroying before every execution can be annoying while iterating on tests locally. Therefore, we provide a flag
315+
* vagrant.destroy that defaults to true that can be used to control whether or not to destroy any test boxes before test
316+
* execution.
317+
*/
318+
final String vagrantDestroyProperty = project.getProperties().get('vagrant.destroy', 'true')
319+
final boolean vagrantDestroy
320+
if ("true".equals(vagrantDestroyProperty)) {
321+
vagrantDestroy = true;
322+
} else if ("false".equals(vagrantDestroyProperty)) {
323+
vagrantDestroy = false
324+
} else {
325+
throw new GradleException("[vagrant.destroy] must be [true] or [false] but was [" + vagrantDestroyProperty + "]")
326+
}
327+
/*
328+
* Some versions of Vagrant will fail destroy if the box does not exist. Therefore we check if the box exists before attempting
329+
* to destroy the box.
330+
*/
331+
final Task destroy = project.tasks.create("vagrant${boxTask}#destroy", LoggedExec) {
332+
commandLine "bash", "-c", "vagrant status ${box} | grep -q \"${box}\\s\\+not created\" || vagrant destroy ${box} --force"
333+
workingDir project.rootProject.rootDir
334+
}
335+
destroy.onlyIf { vagrantDestroy }
336+
update.mustRunAfter(destroy)
337+
312338
Task up = project.tasks.create("vagrant${boxTask}#up", VagrantCommandTask) {
313339
command 'up'
314340
boxName box
315341
environmentVars vagrantEnvVars
316-
/* Its important that we try to reprovision the box even if it already
317-
exists. That way updates to the vagrant configuration take automatically.
318-
That isn't to say that the updates will always be compatible. Its ok to
319-
just destroy the boxes if they get busted but that is a manual step
320-
because its slow-ish. */
321342
/* We lock the provider to virtualbox because the Vagrantfile specifies
322343
lots of boxes that only work properly in virtualbox. Virtualbox is
323344
vagrant's default but its possible to change that default and folks do.
@@ -326,7 +347,7 @@ class VagrantTestPlugin implements Plugin<Project> {
326347
args '--provision', '--provider', 'virtualbox'
327348
/* It'd be possible to check if the box is already up here and output
328349
SKIPPED but that would require running vagrant status which is slow! */
329-
dependsOn update
350+
dependsOn destroy, update
330351
}
331352

332353
Task smoke = project.tasks.create("vagrant${boxTask}#smoketest", Exec) {

buildSrc/src/main/resources/plugin-descriptor.properties

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
#
1111
# classname=foo.bar.BazPlugin
1212
# description=My cool plugin
13-
# version=2.0
14-
# elasticsearch.version=2.0
15-
# java.version=1.7
13+
# version=6.0
14+
# elasticsearch.version=6.0
15+
# java.version=1.8
1616
#
1717
### mandatory elements for all plugins:
1818
#

client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java

+44
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,17 @@
3030
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
3131
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
3232
import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse;
33+
import org.elasticsearch.action.admin.indices.flush.FlushRequest;
34+
import org.elasticsearch.action.admin.indices.flush.FlushResponse;
3335
import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
3436
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
3537
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse;
3638
import org.elasticsearch.action.admin.indices.open.OpenIndexRequest;
3739
import org.elasticsearch.action.admin.indices.open.OpenIndexResponse;
3840
import org.elasticsearch.action.admin.indices.rollover.RolloverRequest;
3941
import org.elasticsearch.action.admin.indices.rollover.RolloverResponse;
42+
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
43+
import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
4044
import org.elasticsearch.action.admin.indices.shrink.ResizeRequest;
4145
import org.elasticsearch.action.admin.indices.shrink.ResizeResponse;
4246

@@ -215,6 +219,46 @@ public void existsAliasAsync(GetAliasesRequest getAliasesRequest, ActionListener
215219
listener, emptySet(), headers);
216220
}
217221

222+
/**
223+
* Refresh one or more indices using the Refresh API
224+
* <p>
225+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-refresh.html"> Refresh API on elastic.co</a>
226+
*/
227+
public RefreshResponse refresh(RefreshRequest refreshRequest, Header... headers) throws IOException {
228+
return restHighLevelClient.performRequestAndParseEntity(refreshRequest, Request::refresh, RefreshResponse::fromXContent,
229+
emptySet(), headers);
230+
}
231+
232+
/**
233+
* Asynchronously refresh one or more indices using the Refresh API
234+
* <p>
235+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-refresh.html"> Refresh API on elastic.co</a>
236+
*/
237+
public void refreshAsync(RefreshRequest refreshRequest, ActionListener<RefreshResponse> listener, Header... headers) {
238+
restHighLevelClient.performRequestAsyncAndParseEntity(refreshRequest, Request::refresh, RefreshResponse::fromXContent,
239+
listener, emptySet(), headers);
240+
}
241+
242+
/**
243+
* Flush one or more indices using the Flush API
244+
* <p>
245+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-flush.html"> Flush API on elastic.co</a>
246+
*/
247+
public FlushResponse flush(FlushRequest flushRequest, Header... headers) throws IOException {
248+
return restHighLevelClient.performRequestAndParseEntity(flushRequest, Request::flush, FlushResponse::fromXContent,
249+
emptySet(), headers);
250+
}
251+
252+
/**
253+
* Asynchronously flush one or more indices using the Flush API
254+
* <p>
255+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-flush.html"> Flush API on elastic.co</a>
256+
*/
257+
public void flushAsync(FlushRequest flushRequest, ActionListener<FlushResponse> listener, Header... headers) {
258+
restHighLevelClient.performRequestAsyncAndParseEntity(flushRequest, Request::flush, FlushResponse::fromXContent,
259+
listener, emptySet(), headers);
260+
}
261+
218262
/**
219263
* Checks if the index (indices) exists or not.
220264
* <p>

client/rest-high-level/src/main/java/org/elasticsearch/client/Request.java

+18
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@
3535
import org.elasticsearch.action.admin.indices.close.CloseIndexRequest;
3636
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
3737
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
38+
import org.elasticsearch.action.admin.indices.flush.FlushRequest;
3839
import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
3940
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
4041
import org.elasticsearch.action.admin.indices.open.OpenIndexRequest;
42+
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
4143
import org.elasticsearch.action.admin.indices.rollover.RolloverRequest;
4244
import org.elasticsearch.action.admin.indices.shrink.ResizeRequest;
4345
import org.elasticsearch.action.admin.indices.shrink.ResizeType;
@@ -218,6 +220,22 @@ static Request putMapping(PutMappingRequest putMappingRequest) throws IOExceptio
218220
return new Request(HttpPut.METHOD_NAME, endpoint, parameters.getParams(), entity);
219221
}
220222

223+
static Request refresh(RefreshRequest refreshRequest) {
224+
String endpoint = endpoint(refreshRequest.indices(), "_refresh");
225+
Params parameters = Params.builder();
226+
parameters.withIndicesOptions(refreshRequest.indicesOptions());
227+
return new Request(HttpPost.METHOD_NAME, endpoint, parameters.getParams(), null);
228+
}
229+
230+
static Request flush(FlushRequest flushRequest) {
231+
String endpoint = endpoint(flushRequest.indices(), "_flush");
232+
Params parameters = Params.builder();
233+
parameters.withIndicesOptions(flushRequest.indicesOptions());
234+
parameters.putParam("wait_if_ongoing", Boolean.toString(flushRequest.waitIfOngoing()));
235+
parameters.putParam("force", Boolean.toString(flushRequest.force()));
236+
return new Request(HttpPost.METHOD_NAME, endpoint, parameters.getParams(), null);
237+
}
238+
221239
static Request info() {
222240
return new Request(HttpGet.METHOD_NAME, "/", Collections.emptyMap(), null);
223241
}

client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java

+58-1
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,16 @@
3434
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
3535
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
3636
import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse;
37+
import org.elasticsearch.action.admin.indices.flush.FlushRequest;
38+
import org.elasticsearch.action.admin.indices.flush.FlushResponse;
3739
import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
3840
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
3941
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse;
4042
import org.elasticsearch.action.admin.indices.open.OpenIndexRequest;
4143
import org.elasticsearch.action.admin.indices.open.OpenIndexResponse;
4244
import org.elasticsearch.action.support.ActiveShardCount;
45+
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
46+
import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
4347
import org.elasticsearch.action.admin.indices.rollover.RolloverRequest;
4448
import org.elasticsearch.action.admin.indices.rollover.RolloverResponse;
4549
import org.elasticsearch.action.admin.indices.shrink.ResizeRequest;
@@ -48,6 +52,7 @@
4852
import org.elasticsearch.action.index.IndexRequest;
4953
import org.elasticsearch.action.support.IndicesOptions;
5054
import org.elasticsearch.action.support.WriteRequest;
55+
import org.elasticsearch.action.support.broadcast.BroadcastResponse;
5156
import org.elasticsearch.common.settings.Settings;
5257
import org.elasticsearch.common.unit.ByteSizeUnit;
5358
import org.elasticsearch.common.unit.ByteSizeValue;
@@ -383,6 +388,58 @@ public void testCloseNonExistentIndex() throws IOException {
383388
assertEquals(RestStatus.NOT_FOUND, exception.status());
384389
}
385390

391+
public void testRefresh() throws IOException {
392+
{
393+
String index = "index";
394+
Settings settings = Settings.builder()
395+
.put("number_of_shards", 1)
396+
.put("number_of_replicas", 0)
397+
.build();
398+
createIndex(index, settings);
399+
RefreshRequest refreshRequest = new RefreshRequest(index);
400+
RefreshResponse refreshResponse =
401+
execute(refreshRequest, highLevelClient().indices()::refresh, highLevelClient().indices()::refreshAsync);
402+
assertThat(refreshResponse.getTotalShards(), equalTo(1));
403+
assertThat(refreshResponse.getSuccessfulShards(), equalTo(1));
404+
assertThat(refreshResponse.getFailedShards(), equalTo(0));
405+
assertThat(refreshResponse.getShardFailures(), equalTo(BroadcastResponse.EMPTY));
406+
}
407+
{
408+
String nonExistentIndex = "non_existent_index";
409+
assertFalse(indexExists(nonExistentIndex));
410+
RefreshRequest refreshRequest = new RefreshRequest(nonExistentIndex);
411+
ElasticsearchException exception = expectThrows(ElasticsearchException.class,
412+
() -> execute(refreshRequest, highLevelClient().indices()::refresh, highLevelClient().indices()::refreshAsync));
413+
assertEquals(RestStatus.NOT_FOUND, exception.status());
414+
}
415+
}
416+
417+
public void testFlush() throws IOException {
418+
{
419+
String index = "index";
420+
Settings settings = Settings.builder()
421+
.put("number_of_shards", 1)
422+
.put("number_of_replicas", 0)
423+
.build();
424+
createIndex(index, settings);
425+
FlushRequest flushRequest = new FlushRequest(index);
426+
FlushResponse flushResponse =
427+
execute(flushRequest, highLevelClient().indices()::flush, highLevelClient().indices()::flushAsync);
428+
assertThat(flushResponse.getTotalShards(), equalTo(1));
429+
assertThat(flushResponse.getSuccessfulShards(), equalTo(1));
430+
assertThat(flushResponse.getFailedShards(), equalTo(0));
431+
assertThat(flushResponse.getShardFailures(), equalTo(BroadcastResponse.EMPTY));
432+
}
433+
{
434+
String nonExistentIndex = "non_existent_index";
435+
assertFalse(indexExists(nonExistentIndex));
436+
FlushRequest refreshRequest = new FlushRequest(nonExistentIndex);
437+
ElasticsearchException exception = expectThrows(ElasticsearchException.class,
438+
() -> execute(refreshRequest, highLevelClient().indices()::flush, highLevelClient().indices()::flushAsync));
439+
assertEquals(RestStatus.NOT_FOUND, exception.status());
440+
}
441+
}
442+
386443
public void testExistsAlias() throws IOException {
387444
GetAliasesRequest getAliasesRequest = new GetAliasesRequest("alias");
388445
assertFalse(execute(getAliasesRequest, highLevelClient().indices()::existsAlias, highLevelClient().indices()::existsAliasAsync));
@@ -497,4 +554,4 @@ public void testRollover() throws IOException {
497554
assertEquals("test_new", rolloverResponse.getNewIndex());
498555
}
499556
}
500-
}
557+
}

0 commit comments

Comments
 (0)