Skip to content

Commit

Permalink
Add doc’s sequence number + primary term to get responses (#3767)
Browse files Browse the repository at this point in the history
Add doc’s sequence number + primary term to get responses
  • Loading branch information
codebrain authored May 28, 2019
1 parent 1cc18f1 commit 202d9e8
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Nest/Document/Multiple/MultiGet/Response/MultiGetHit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public interface IMultiGetHit<out TDocument> where TDocument : class
string Type { get; }

long Version { get; }

long PrimaryTerm { get; }

long SequenceNumber { get; }
}

[JsonObject]
Expand Down Expand Up @@ -58,5 +62,11 @@ public class MultiGetHit<TDocument> : IMultiGetHit<TDocument>

[JsonProperty("_version")]
public long Version { get; internal set; }

[JsonProperty("_primary_term")]
public long PrimaryTerm { get; internal set; }

[JsonProperty("_seq_no")]
public long SequenceNumber { get; internal set; }
}
}
8 changes: 8 additions & 0 deletions src/Nest/Document/Single/Get/GetResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ public interface IGetResponse<out TDocument> : IResponse where TDocument : class

[JsonProperty("_version")]
long Version { get; }

[JsonProperty("_primary_term")]
long? PrimaryTerm { get; }

[JsonProperty("_seq_no")]
long? SequenceNumber { get; }
}

[JsonObject(MemberSerialization.OptIn)]
Expand All @@ -47,5 +53,7 @@ public class GetResponse<TDocument> : ResponseBase, IGetResponse<TDocument> wher
public TDocument Source { get; internal set; }
public string Type { get; internal set; }
public long Version { get; internal set; }
public long? PrimaryTerm { get; internal set; }
public long? SequenceNumber { get; internal set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ protected override void ExpectResponse(IMultiGetResponse response)
hit.Id.Should().NotBeNullOrWhiteSpace();
hit.Found.Should().BeTrue();
hit.Version.Should().Be(1);
if (base.Cluster.ClusterConfiguration.Version >= "6.8.0")
{
hit.PrimaryTerm.Should().BeGreaterOrEqualTo(1);
hit.SequenceNumber.Should().BeGreaterOrEqualTo(0);
}
hit.Source.ShouldAdhereToSourceSerializerWhenSet();
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/Tests/Tests/Document/Single/DocumentCrudTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ [I] protected async Task DocumentIsUpdated() => await AssertOnGetAfterUpdate(r =
{
r.Source.Should().NotBeNull();
r.Version.Should().BeGreaterThan(1);
if (base.Cluster.ClusterConfiguration.Version >= "6.8.0")
{
r.SequenceNumber.Should().BeGreaterOrEqualTo(1);
r.PrimaryTerm.Should().BeGreaterThan(0);
}
r.Source.Description.Should().EndWith("updated");
});

Expand Down
6 changes: 6 additions & 0 deletions src/Tests/Tests/Document/Single/Get/GetApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ protected override void ExpectResponse(IGetResponse<Project> response)
response.Source.Should().NotBeNull();
response.Source.Name.Should().Be(ProjectId);
response.Source.ShouldAdhereToSourceSerializerWhenSet();

if (base.Cluster.ClusterConfiguration.Version >= "6.8.0")
{
response.SequenceNumber.Should().BeGreaterOrEqualTo(0);
response.PrimaryTerm.Should().BeGreaterOrEqualTo(1);
}
}
}

Expand Down

0 comments on commit 202d9e8

Please sign in to comment.