Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1182,4 +1182,4 @@
}
},
"NestedTypes": {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Microsoft.Azure.Cosmos
{
using System;
using System.Collections.Generic;
using System.Net;
using Microsoft.Azure.Cosmos.Resource.FullFidelity;
using Microsoft.Azure.Documents;
using Newtonsoft.Json;
Expand All @@ -28,12 +29,34 @@ class ChangeFeedMetadata
/// </summary>
[System.Text.Json.Serialization.JsonIgnore]
[Newtonsoft.Json.JsonIgnore]
public DateTime? ConflictResolutionTimestamp => this.ConflictResolutionTimestampInSeconds.HasValue ? UnixEpoch.AddSeconds(this.ConflictResolutionTimestampInSeconds.Value) : null;
public DateTime ConflictResolutionTimestamp => UnixEpoch.AddSeconds(this.ConflictResolutionTimestampInSeconds);

private double conflictResolutionTimestampInSeconds;

[System.Text.Json.Serialization.JsonInclude]
[System.Text.Json.Serialization.JsonPropertyName(ChangeFeedMetadataFields.ConflictResolutionTimestamp)]
[JsonProperty(PropertyName = ChangeFeedMetadataFields.ConflictResolutionTimestamp)]
internal double? ConflictResolutionTimestampInSeconds { get; set; }
[JsonProperty(PropertyName = ChangeFeedMetadataFields.ConflictResolutionTimestamp, Required = Required.Always)]
internal double ConflictResolutionTimestampInSeconds
{
get
{
if (this.conflictResolutionTimestampInSeconds == 0)
{
throw new System.Text.Json.JsonException(
$"{ChangeFeedMetadataFields.ConflictResolutionTimestamp} not set.");
}
return this.conflictResolutionTimestampInSeconds;
}
set
{
if (value == 0)
{
throw new System.Text.Json.JsonException(
$"{ChangeFeedMetadataFields.ConflictResolutionTimestamp} cannot be zero.");
}
this.conflictResolutionTimestampInSeconds = value;
}
}

/// <summary>
/// The current change's logical sequence number.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,48 @@ public void ValidateChangeFeedMetadataSerializationCreateWriteTest(bool property
actual: json);
}

[TestMethod]
[Owner("trivediyash")]
[Description("Validates that ConflictResolutionTimestampInSeconds getter throws JsonException when value is zero.")]
public void ValidateConflictResolutionTimestampInSecondsGetterThrowsOnZeroTest()
{
ChangeFeedMetadata metadata = new()
{
Lsn = 374,
OperationType = ChangeFeedOperationType.Create
};

// Accessing the getter should throw JsonException when the value is zero (default)
System.Text.Json.JsonException exception = Assert.ThrowsException<System.Text.Json.JsonException>(() =>
{
double value = metadata.ConflictResolutionTimestampInSeconds;
});

Assert.IsTrue(exception.Message.Contains("crts"));
Assert.IsTrue(exception.Message.Contains("not set"));
}

[TestMethod]
[Owner("trivediyash")]
[Description("Validates that ConflictResolutionTimestampInSeconds setter throws JsonException when attempting to set zero.")]
public void ValidateConflictResolutionTimestampInSecondsSetterThrowsOnZeroTest()
{
ChangeFeedMetadata metadata = new()
{
Lsn = 374,
OperationType = ChangeFeedOperationType.Create
};

// Setting the value to zero should throw JsonException
System.Text.Json.JsonException exception = Assert.ThrowsException<System.Text.Json.JsonException>(() =>
{
metadata.ConflictResolutionTimestampInSeconds = 0;
});

Assert.IsTrue(exception.Message.Contains("crts"));
Assert.IsTrue(exception.Message.Contains("cannot be zero"));
}

[TestMethod]
[Timeout(300000)]
[TestCategory("LongRunning")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,18 @@
],
"MethodInfo": "System.Collections.Generic.Dictionary`2[System.String,System.Object] PartitionKey;CanRead:True;CanWrite:True;System.Collections.Generic.Dictionary`2[System.String,System.Object] get_PartitionKey();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"System.Nullable`1[System.DateTime] ConflictResolutionTimestamp[System.Text.Json.Serialization.JsonIgnoreAttribute()]-[Newtonsoft.Json.JsonIgnoreAttribute()]": {
"System.DateTime ConflictResolutionTimestamp[System.Text.Json.Serialization.JsonIgnoreAttribute()]-[Newtonsoft.Json.JsonIgnoreAttribute()]": {
"Type": "Property",
"Attributes": [
"JsonIgnoreAttribute",
"JsonIgnoreAttribute"
],
"MethodInfo": "System.Nullable`1[System.DateTime] ConflictResolutionTimestamp;CanRead:True;CanWrite:False;System.Nullable`1[System.DateTime] get_ConflictResolutionTimestamp();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
"MethodInfo": "System.DateTime ConflictResolutionTimestamp;CanRead:True;CanWrite:False;System.DateTime get_ConflictResolutionTimestamp();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"System.Nullable`1[System.DateTime] get_ConflictResolutionTimestamp()": {
"System.DateTime get_ConflictResolutionTimestamp()": {
"Type": "Method",
"Attributes": [],
"MethodInfo": "System.Nullable`1[System.DateTime] get_ConflictResolutionTimestamp();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
"MethodInfo": "System.DateTime get_ConflictResolutionTimestamp();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"System.String get_Id()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": {
"Type": "Method",
Expand Down