Skip to content

Commit e8b704a

Browse files
andrxrusscam
authored andcommitted
Fix fluent serialization of if_primary_term (#4078) (#4087)
Fixes fluent serialization of if_primary_term for BulkIndexDescriptor and BulkUpdateDescriptor (cherry picked from commit 0c5cbbd)
1 parent 739ff8f commit e8b704a

File tree

4 files changed

+44
-8
lines changed

4 files changed

+44
-8
lines changed

src/Nest/Document/Multiple/Bulk/BulkOperation/BulkIndex.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,6 @@ public class BulkIndexDescriptor<T> : BulkOperationDescriptorBase<BulkIndexDescr
7979

8080
public BulkIndexDescriptor<T> IfSequenceNumber(long? seqNo) => Assign(seqNo, (a, v) => a.IfSequenceNumber = v);
8181

82-
public BulkIndexDescriptor<T> IfPrimaryTerm(long? primaryTerm) => Assign(primaryTerm, (a, v) => a.IfSequenceNumber = v);
82+
public BulkIndexDescriptor<T> IfPrimaryTerm(long? primaryTerm) => Assign(primaryTerm, (a, v) => a.IfPrimaryTerm = v);
8383
}
8484
}

src/Nest/Document/Multiple/Bulk/BulkOperation/BulkUpdate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,6 @@ public BulkUpdateDescriptor<TDocument, TPartialDocument> IfSequenceNumber(long?
233233
/// Operations can be made conditional and only be performed if the last modification to the document was assigned the primary term.
234234
/// </summary>
235235
public BulkUpdateDescriptor<TDocument, TPartialDocument> IfPrimaryTerm(long? primaryTerm) =>
236-
Assign(primaryTerm, (a, v) => a.IfSequenceNumber = v);
236+
Assign(primaryTerm, (a, v) => a.IfPrimaryTerm = v);
237237
}
238238
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using Elastic.Xunit.XunitPlumbing;
5+
using FluentAssertions;
6+
using Nest;
7+
using Tests.Core.Client;
8+
using Tests.Core.Extensions;
9+
using Tests.Core.Serialization;
10+
using Tests.Domain;
11+
12+
namespace Tests.Reproduce
13+
{
14+
public class GithubIssue4078
15+
{
16+
[U]
17+
public void BulkIndexOperationIssue() {
18+
19+
var indexResponse = TestClient.InMemoryWithJsonNetSerializer.Bulk(d =>
20+
d.Index<Project>(i => i.IfSequenceNumber(12345).IfPrimaryTerm(67890).Document(Project.Instance))
21+
);
22+
Encoding.UTF8.GetString(indexResponse.ApiCall.RequestBodyInBytes).Should().Contain("\"if_seq_no\"").And.Contain("12345")
23+
.And.Contain("\"if_primary_term\"").And.Contain("67890");
24+
}
25+
26+
[U]
27+
public void BulkUpdateOperationIssue()
28+
{
29+
30+
var indexResponse = TestClient.InMemoryWithJsonNetSerializer.Bulk(d =>
31+
d.Update<Project, object>(i => i.IfSequenceNumber(12345).IfPrimaryTerm(67890).Doc(Project.Instance))
32+
);
33+
Encoding.UTF8.GetString(indexResponse.ApiCall.RequestBodyInBytes).Should().Contain("\"if_seq_no\"").And.Contain("12345")
34+
.And.Contain("\"if_primary_term\"").And.Contain("67890");
35+
}
36+
}
37+
}

src/Tests/Tests/Document/Multiple/Bulk/BulkInvalidVersionApiTests.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ public BulkInvalidVersionApiTests(WritableCluster cluster, EndpointUsage usage)
2121
{
2222
new Dictionary<string, object> { { "index", new { _type = "doc", _id = Project.Instance.Name, routing = Project.Instance.Name } } },
2323
Project.InstanceAnonymous,
24-
new Dictionary<string, object>
25-
{ { "index", new { _type = "doc", _id = Project.Instance.Name, routing = Project.Instance.Name, version = 0 } } },
24+
new Dictionary<string, object> { { "index", new { _type = "doc", _id = Project.Instance.Name, routing = Project.Instance.Name, if_seq_no = -1, if_primary_term = 0 } } },
2625
Project.InstanceAnonymous,
2726
};
2827

@@ -31,7 +30,7 @@ public BulkInvalidVersionApiTests(WritableCluster cluster, EndpointUsage usage)
3130
protected override Func<BulkDescriptor, IBulkRequest> Fluent => d => d
3231
.Index(CallIsolatedValue)
3332
.Index<Project>(i => i.Document(Project.Instance))
34-
.Index<Project>(i => i.Version(0).Document(Project.Instance));
33+
.Index<Project>(i => i.IfSequenceNumber(-1).IfPrimaryTerm(0).Document(Project.Instance));
3534

3635
protected override HttpMethod HttpMethod => HttpMethod.POST;
3736

@@ -41,7 +40,7 @@ public BulkInvalidVersionApiTests(WritableCluster cluster, EndpointUsage usage)
4140
Operations = new List<IBulkOperation>
4241
{
4342
new BulkIndexOperation<Project>(Project.Instance),
44-
new BulkIndexOperation<Project>(Project.Instance) { Version = 0 }
43+
new BulkIndexOperation<Project>(Project.Instance) { IfSequenceNumber = -1, IfPrimaryTerm = 0 }
4544
}
4645
};
4746

@@ -60,8 +59,8 @@ protected override void ExpectResponse(IBulkResponse response)
6059
response.ShouldNotBeValid();
6160
response.ServerError.Should().NotBeNull();
6261
response.ServerError.Status.Should().Be(400);
63-
response.ServerError.Error.Type.Should().Be("action_request_validation_exception");
64-
response.ServerError.Error.Reason.Should().EndWith("illegal version value [0] for version type [INTERNAL];");
62+
response.ServerError.Error.Type.Should().Be("illegal_argument_exception");
63+
response.ServerError.Error.Reason.Should().Contain("sequence numbers must be non negative.");
6564
}
6665
}
6766
}

0 commit comments

Comments
 (0)