Skip to content

Commit 68a2867

Browse files
committed
add bulk invalid version api tests and create.json
1 parent 0073007 commit 68a2867

File tree

2 files changed

+138
-0
lines changed

2 files changed

+138
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
{
2+
"create": {
3+
"documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html",
4+
"methods": ["PUT","POST"],
5+
"url": {
6+
"path": "/{index}/{type}/{id}/_create",
7+
"paths": ["/{index}/{type}/{id}/_create"],
8+
"parts": {
9+
"id": {
10+
"type" : "string",
11+
"required" : true,
12+
"description" : "Document ID"
13+
},
14+
"index": {
15+
"type" : "string",
16+
"required" : true,
17+
"description" : "The name of the index"
18+
},
19+
"type": {
20+
"type" : "string",
21+
"required" : true,
22+
"description" : "The type of the document"
23+
}
24+
},
25+
"params": {
26+
"wait_for_active_shards": {
27+
"type" : "string",
28+
"description" : "Sets the number of shard copies that must be active before proceeding with the index operation. Defaults to 1, meaning the primary shard only. Set to `all` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1)"
29+
},
30+
"parent": {
31+
"type" : "string",
32+
"description" : "ID of the parent document"
33+
},
34+
"refresh": {
35+
"type" : "enum",
36+
"options": ["true", "false", "wait_for"],
37+
"description" : "If `true` then refresh the affected shards to make this operation visible to search, if `wait_for` then wait for a refresh to make this operation visible to search, if `false` (the default) then do nothing with refreshes."
38+
},
39+
"routing": {
40+
"type" : "string",
41+
"description" : "Specific routing value"
42+
},
43+
"timeout": {
44+
"type" : "time",
45+
"description" : "Explicit operation timeout"
46+
},
47+
"timestamp": {
48+
"type" : "time",
49+
"description" : "Explicit timestamp for the document"
50+
},
51+
"ttl": {
52+
"type" : "time",
53+
"description" : "Expiration time for the document"
54+
},
55+
"version" : {
56+
"type" : "number",
57+
"description" : "Explicit version number for concurrency control"
58+
},
59+
"version_type": {
60+
"type" : "enum",
61+
"options" : ["internal", "external", "external_gte", "force"],
62+
"description" : "Specific version type"
63+
},
64+
"pipeline" : {
65+
"type" : "string",
66+
"description" : "The pipeline id to preprocess incoming documents with"
67+
}
68+
}
69+
},
70+
"body": {
71+
"description" : "The document",
72+
"required" : true
73+
}
74+
}
75+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using Elasticsearch.Net;
5+
using FluentAssertions;
6+
using Nest;
7+
using Tests.Framework;
8+
using Tests.Framework.Integration;
9+
using Tests.Framework.MockData;
10+
using Xunit;
11+
12+
namespace Tests.Document.Multiple.Bulk
13+
{
14+
public class BulkInvalidVersionApiTests : ApiIntegrationTestBase<WritableCluster, IBulkResponse, IBulkRequest, BulkDescriptor, BulkRequest>
15+
{
16+
public BulkInvalidVersionApiTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
17+
protected override LazyResponses ClientUsage() => Calls(
18+
fluent: (client, f) => client.Bulk(f),
19+
fluentAsync: (client, f) => client.BulkAsync(f),
20+
request: (client, r) => client.Bulk(r),
21+
requestAsync: (client, r) => client.BulkAsync(r)
22+
);
23+
24+
protected override bool ExpectIsValid => false;
25+
protected override int ExpectStatusCode => 400;
26+
protected override HttpMethod HttpMethod => HttpMethod.POST;
27+
protected override string UrlPath => $"/{CallIsolatedValue}/_bulk";
28+
29+
protected override bool SupportsDeserialization => false;
30+
31+
protected override object ExpectJson { get; } = new object[]
32+
{
33+
new Dictionary<string, object>{ { "index", new { _type="project", _id = Project.Instance.Name } } },
34+
Project.InstanceAnonymous,
35+
new Dictionary<string, object>{ { "index", new { _type="project", _id = Project.Instance.Name, _version = 0 } } },
36+
Project.InstanceAnonymous,
37+
};
38+
39+
protected override void ExpectResponse(IBulkResponse response)
40+
{
41+
response.IsValid.Should().BeFalse();
42+
response.ServerError.Should().NotBeNull();
43+
response.ServerError.Status.Should().Be(400);
44+
response.ServerError.Error.Type.Should().Be("action_request_validation_exception");
45+
response.ServerError.Error.Reason.Should().EndWith("illegal version value [0] for version type [INTERNAL];");
46+
}
47+
48+
protected override Func<BulkDescriptor, IBulkRequest> Fluent => d => d
49+
.Index(CallIsolatedValue)
50+
.Index<Project>(i => i.Document(Project.Instance))
51+
.Index<Project>(i => i.Version(0).Document(Project.Instance));
52+
53+
54+
protected override BulkRequest Initializer => new BulkRequest(CallIsolatedValue)
55+
{
56+
Operations = new List<IBulkOperation>
57+
{
58+
new BulkIndexOperation<Project>(Project.Instance),
59+
new BulkIndexOperation<Project>(Project.Instance) { Version = 0 }
60+
}
61+
};
62+
}
63+
}

0 commit comments

Comments
 (0)