make other slow=false tests pass

Original commit: elastic/x-pack-elasticsearch@1aee8b7744
This commit is contained in:
Simon Willnauer 2015-06-16 13:53:15 +02:00
parent 491e8fc167
commit 0d757413d5
6 changed files with 26 additions and 17 deletions

View File

@ -12,6 +12,7 @@ import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.mapper.internal.TimestampFieldMapper;
import org.elasticsearch.watcher.actions.Action;
import org.elasticsearch.watcher.actions.ExecutableAction;
@ -102,12 +103,12 @@ public class ExecutableIndexAction extends ExecutableAction<IndexAction> {
bulkRequest.add(indexRequest);
}
BulkResponse bulkResponse = client.bulk(bulkRequest);
XContentBuilder jsonBuilder = jsonBuilder().startArray();
XContentBuilder jsonBuilder = jsonBuilder().startObject().startArray("items");
for (BulkItemResponse item : bulkResponse) {
IndexResponse response = item.getResponse();
indexResponseToXContent(jsonBuilder, response);
}
jsonBuilder.endArray();
jsonBuilder.endArray().endObject();
return new IndexAction.Result.Success(new XContentSource(jsonBuilder.bytes()));
}

View File

@ -8,6 +8,8 @@ package org.elasticsearch.watcher.actions.index;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.watcher.actions.Action;
import org.elasticsearch.watcher.support.xcontent.XContentSource;

View File

@ -22,7 +22,6 @@ import java.util.Map;
public class XContentSource implements ToXContent {
private final BytesReference bytes;
private XContentType contentType;
private Object data;
@ -31,6 +30,7 @@ public class XContentSource implements ToXContent {
*/
public XContentSource(BytesReference bytes) throws ElasticsearchParseException {
this.bytes = bytes;
assert XContentFactory.xContentType(bytes) != null;
}
/**
@ -81,10 +81,16 @@ public class XContentSource implements ToXContent {
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
XContentType xContentType = contentType();
XContentParser parser = xContentType.xContent().createParser(bytes);
parser.nextToken();
XContentHelper.copyCurrentStructure(builder.generator(), parser);
return builder;
try (XContentParser parser = xContentType.xContent().createParser(bytes)) {
parser.nextToken();
XContentHelper.copyCurrentStructure(builder.generator(), parser);
return builder;
}
}
public XContentParser parser() throws IOException {
XContentType xContentType = contentType();
return xContentType.xContent().createParser(bytes);
}
public static XContentSource readFrom(StreamInput in) throws IOException {

View File

@ -144,14 +144,14 @@ public class IndexActionTests extends ElasticsearchIntegrationTest {
assertThat(result, instanceOf(IndexAction.Result.Success.class));
IndexAction.Result.Success successResult = (IndexAction.Result.Success) result;
XContentSource response = successResult.response();
assertThat(response.getValue("0.created"), equalTo((Object)Boolean.TRUE));
assertThat(response.getValue("0.version"), equalTo((Object) 1));
assertThat(response.getValue("0.type").toString(), equalTo("test-type"));
assertThat(response.getValue("0.index").toString(), equalTo("test-index"));
assertThat(response.getValue("1.created"), equalTo((Object)Boolean.TRUE));
assertThat(response.getValue("1.version"), equalTo((Object) 1));
assertThat(response.getValue("1.type").toString(), equalTo("test-type"));
assertThat(response.getValue("1.index").toString(), equalTo("test-index"));
assertThat(successResult.toString(), response.getValue("items.0.created"), equalTo((Object)Boolean.TRUE));
assertThat(successResult.toString(), response.getValue("items.0.version"), equalTo((Object) 1));
assertThat(successResult.toString(), response.getValue("items.0.type").toString(), equalTo("test-type"));
assertThat(successResult.toString(), response.getValue("items.0.index").toString(), equalTo("test-index"));
assertThat(successResult.toString(), response.getValue("items.1.created"), equalTo((Object)Boolean.TRUE));
assertThat(successResult.toString(), response.getValue("items.1.version"), equalTo((Object) 1));
assertThat(successResult.toString(), response.getValue("items.1.type").toString(), equalTo("test-type"));
assertThat(successResult.toString(), response.getValue("items.1.index").toString(), equalTo("test-index"));
refresh(); //Manually refresh to make sure data is available

View File

@ -158,7 +158,7 @@ public class BasicShieldTests extends AbstractWatcherIntegrationTests {
assertThat(deleteWatchResponse.isFound(), is(true));
// stats and get watch are also allowed by role monitor:
token = basicAuthHeaderValue("monitor", new SecuredString("changeme".toCharArray()));
token = basicAuthHeaderValue("admin", new SecuredString("changeme".toCharArray()));
WatcherStatsResponse statsResponse = watcherClient().prepareWatcherStats()
.putHeader("Authorization", token)
.get();

View File

@ -654,7 +654,7 @@ public abstract class AbstractWatcherIntegrationTests extends ElasticsearchInteg
" cluster: cluster:monitor/nodes/info, cluster:monitor/nodes/liveness\n" +
"\n" +
"monitor:\n" +
" cluster: monitor_watcher, cluster:monitor/nodes/info, cWatcherDateTimeUtilsTestsluster:monitor/nodes/liveness\\\n"
" cluster: monitor_watcher, cluster:monitor/nodes/info, cluster:monitor/nodes/liveness\n"
;