Skip to content

Commit

Permalink
Add test records
Browse files Browse the repository at this point in the history
  • Loading branch information
williamzhao87 committed Oct 30, 2023
1 parent af16434 commit 18858e8
Show file tree
Hide file tree
Showing 17 changed files with 209 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "net",
"TagPrefix": "net/communication/Azure.Communication.JobRouter",
"Tag": "net/communication/Azure.Communication.JobRouter_33a06c6ea8"
"Tag": "net/communication/Azure.Communication.JobRouter_83ab5cb025"
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public virtual async Task<Response<RouterJob>> CreateJobWithClassificationPolicy
var response = await UpsertJobAsync(
jobId: options.JobId,
content: request.ToRequestContent(),
requestConditions: options.RequestConditions,
requestConditions: options.RequestConditions ?? new RequestConditions(),
context: FromCancellationToken(cancellationToken))
.ConfigureAwait(false);

Expand Down Expand Up @@ -210,7 +210,7 @@ public virtual Response<RouterJob> CreateJobWithClassificationPolicy(
var response = UpsertJob(
jobId: options.JobId,
content: request.ToRequestContent(),
requestConditions: options.RequestConditions,
requestConditions: options.RequestConditions ?? new RequestConditions(),
context: FromCancellationToken(cancellationToken));

return Response.FromValue(RouterJob.FromResponse(response), response);
Expand Down Expand Up @@ -270,7 +270,7 @@ public virtual async Task<Response<RouterJob>> CreateJobAsync(
var response = await UpsertJobAsync(
jobId: options.JobId,
content: request.ToRequestContent(),
requestConditions: options.RequestConditions,
requestConditions: options.RequestConditions ?? new RequestConditions(),
context: FromCancellationToken(cancellationToken))
.ConfigureAwait(false);

Expand Down Expand Up @@ -327,7 +327,7 @@ public virtual Response<RouterJob> CreateJob(
var response = UpsertJob(
jobId: options.JobId,
content: request.ToRequestContent(),
requestConditions: options.RequestConditions,
requestConditions: options.RequestConditions ?? new RequestConditions(),
context: FromCancellationToken(cancellationToken));

return Response.FromValue(RouterJob.FromResponse(response), response);
Expand Down Expand Up @@ -357,7 +357,7 @@ public virtual async Task<Response<RouterJob>> UpdateJobAsync(
var response = await UpsertJobAsync(
jobId: job.Id,
content: job.ToRequestContent(),
requestConditions: requestConditions,
requestConditions: requestConditions ?? new RequestConditions(),
context: FromCancellationToken(cancellationToken))
.ConfigureAwait(false);

Expand Down Expand Up @@ -386,7 +386,7 @@ public virtual Response<RouterJob> UpdateJob(
var response = UpsertJob(
jobId: job.Id,
content: job.ToRequestContent(),
requestConditions: requestConditions,
requestConditions: requestConditions ?? new RequestConditions(),
context: FromCancellationToken(cancellationToken));

return Response.FromValue(RouterJob.FromResponse(response), response);
Expand Down Expand Up @@ -421,8 +421,8 @@ public virtual async Task<Response> UpdateJobAsync(string jobId, RequestContent
Argument.AssertNotNullOrEmpty(jobId, nameof(jobId));
Argument.AssertNotNull(content, nameof(content));

Argument.AssertNull(requestConditions.IfNoneMatch, nameof(requestConditions), "Service does not support the If-None-Match header for this operation.");
Argument.AssertNull(requestConditions.IfModifiedSince, nameof(requestConditions), "Service does not support the If-Modified-Since header for this operation.");
Argument.AssertNull(requestConditions?.IfNoneMatch, nameof(requestConditions), "Service does not support the If-None-Match header for this operation.");
Argument.AssertNull(requestConditions?.IfModifiedSince, nameof(requestConditions), "Service does not support the If-Modified-Since header for this operation.");

using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(JobRouterClient)}.{nameof(UpdateJob)}");
scope.Start();
Expand Down Expand Up @@ -461,8 +461,8 @@ public virtual Response UpdateJob(string jobId, RequestContent content, RequestC
Argument.AssertNotNullOrEmpty(jobId, nameof(jobId));
Argument.AssertNotNull(content, nameof(content));

Argument.AssertNull(requestConditions.IfNoneMatch, nameof(requestConditions), "Service does not support the If-None-Match header for this operation.");
Argument.AssertNull(requestConditions.IfModifiedSince, nameof(requestConditions), "Service does not support the If-Modified-Since header for this operation.");
Argument.AssertNull(requestConditions?.IfNoneMatch, nameof(requestConditions), "Service does not support the If-None-Match header for this operation.");
Argument.AssertNull(requestConditions?.IfModifiedSince, nameof(requestConditions), "Service does not support the If-Modified-Since header for this operation.");

using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(JobRouterClient)}.{nameof(UpdateJob)}");
scope.Start();
Expand Down Expand Up @@ -566,7 +566,7 @@ public virtual async Task<Response<RouterWorker>> CreateWorkerAsync(
var response = await UpsertWorkerAsync(
workerId: options.WorkerId,
content: request.ToRequestContent(),
requestConditions: options.RequestConditions,
requestConditions: options.RequestConditions ?? new RequestConditions(),
context: FromCancellationToken(cancellationToken))
.ConfigureAwait(false);

Expand Down Expand Up @@ -613,7 +613,7 @@ public virtual Response<RouterWorker> CreateWorker(
var response = UpsertWorker(
workerId: options.WorkerId,
content: request.ToRequestContent(),
requestConditions: options.RequestConditions,
requestConditions: options.RequestConditions ?? new RequestConditions(),
context: FromCancellationToken(cancellationToken));

return Response.FromValue(RouterWorker.FromResponse(response), response);
Expand Down Expand Up @@ -641,7 +641,7 @@ public virtual async Task<Response<RouterWorker>> UpdateWorkerAsync(
var response = await UpsertWorkerAsync(
workerId: worker.Id,
content: worker.ToRequestContent(),
requestConditions: requestConditions,
requestConditions: requestConditions ?? new RequestConditions(),
context: FromCancellationToken(cancellationToken))
.ConfigureAwait(false);

Expand Down Expand Up @@ -670,7 +670,7 @@ public virtual Response<RouterWorker> UpdateWorker(
var response = UpsertWorker(
workerId: worker.Id,
content: worker.ToRequestContent(),
requestConditions: requestConditions,
requestConditions: requestConditions ?? new RequestConditions(),
context: FromCancellationToken(cancellationToken));

return Response.FromValue(RouterWorker.FromResponse(response), response);
Expand Down Expand Up @@ -705,8 +705,8 @@ public virtual async Task<Response> UpdateWorkerAsync(string workerId, RequestCo
Argument.AssertNotNullOrEmpty(workerId, nameof(workerId));
Argument.AssertNotNull(content, nameof(content));

Argument.AssertNull(requestConditions.IfNoneMatch, nameof(requestConditions), "Service does not support the If-None-Match header for this operation.");
Argument.AssertNull(requestConditions.IfModifiedSince, nameof(requestConditions), "Service does not support the If-Modified-Since header for this operation.");
Argument.AssertNull(requestConditions?.IfNoneMatch, nameof(requestConditions), "Service does not support the If-None-Match header for this operation.");
Argument.AssertNull(requestConditions?.IfModifiedSince, nameof(requestConditions), "Service does not support the If-Modified-Since header for this operation.");

using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(JobRouterClient)}.{nameof(UpdateWorker)}");
scope.Start();
Expand Down Expand Up @@ -745,8 +745,8 @@ public virtual Response UpdateWorker(string workerId, RequestContent content, Re
Argument.AssertNotNullOrEmpty(workerId, nameof(workerId));
Argument.AssertNotNull(content, nameof(content));

Argument.AssertNull(requestConditions.IfNoneMatch, nameof(requestConditions), "Service does not support the If-None-Match header for this operation.");
Argument.AssertNull(requestConditions.IfModifiedSince, nameof(requestConditions), "Service does not support the If-Modified-Since header for this operation.");
Argument.AssertNull(requestConditions?.IfNoneMatch, nameof(requestConditions), "Service does not support the If-None-Match header for this operation.");
Argument.AssertNull(requestConditions?.IfModifiedSince, nameof(requestConditions), "Service does not support the If-Modified-Since header for this operation.");

using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(JobRouterClient)}.{nameof(UpdateWorker)}");
scope.Start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public partial class ReclassifyExceptionAction : IUtf8JsonSerializable
public ReclassifyExceptionAction()
{
Kind = "reclassify";
_labelsToUpsert = new ChangeTrackingDictionary<string, BinaryData>();
}

[CodeGenMember("LabelsToUpsert")]
Expand All @@ -43,7 +44,7 @@ internal IDictionary<string, BinaryData> _labelsToUpsert
/// <summary>
/// (optional) Dictionary containing the labels to update (or add if not existing) in key-value pairs
/// </summary>
public IDictionary<string, LabelValue> LabelsToUpsert { get; }
public IDictionary<string, LabelValue> LabelsToUpsert { get; } = new Dictionary<string, LabelValue>();

/// <summary>
/// (optional) The new classification policy that will determine queue, priority
Expand Down Expand Up @@ -76,7 +77,7 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
writer.WriteNullValue();
continue;
}
writer.WriteObjectValue(item.Value);
writer.WriteObjectValue(item.Value.ToObjectFromJson());
}
writer.WriteEndObject();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public RouterChannel(string channelId, int capacityCostPerJob)
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
{
writer.WriteStartObject();
writer.WritePropertyName("channelId"u8);
writer.WriteStringValue(ChannelId);
writer.WritePropertyName("capacityCostPerJob"u8);
writer.WriteNumberValue(CapacityCostPerJob);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ public partial class RouterJob : IUtf8JsonSerializable
public RouterJob(string jobId)
{
Argument.AssertNotNullOrWhiteSpace(jobId, nameof(jobId));

Id = jobId;

_labels = new ChangeTrackingDictionary<string, BinaryData>();
_tags = new ChangeTrackingDictionary<string, BinaryData>();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
// Licensed under the MIT License.

using System;
using System.Text.Json;
using Azure.Core;

namespace Azure.Communication.JobRouter
{
/// <summary>
/// A note attached to a job
/// </summary>
public partial class RouterJobNote
public partial class RouterJobNote : IUtf8JsonSerializable
{
/// <summary> Initializes a new instance of RouterJobNote. </summary>
/// <param name="message"> The message contained in the note. </param>
Expand All @@ -25,5 +26,18 @@ public RouterJobNote(string message)
/// The time at which the note was added in UTC. If not provided, will default to the current time.
/// </summary>
public DateTimeOffset? AddedAt { get; set; }

void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
{
writer.WriteStartObject();
writer.WritePropertyName("message"u8);
writer.WriteStringValue(Message);
if (Optional.IsDefined(AddedAt))
{
writer.WritePropertyName("addedAt"u8);
writer.WriteStringValue(AddedAt.Value, "O");
}
writer.WriteEndObject();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public RouterWorker(string workerId)
Argument.AssertNotNullOrWhiteSpace(workerId, nameof(workerId));

Id = workerId;

_labels = new ChangeTrackingDictionary<string, BinaryData>();
_tags = new ChangeTrackingDictionary<string, BinaryData>();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class RouterLiveTestBase : RecordedTestBase<RouterTestEnvironment>
private ConcurrentDictionary<string, Stack<Task>> _testCleanupTasks;
private const string URIDomainRegEx = @"https://([^/?]+)";

public RouterLiveTestBase(bool isAsync, RecordedTestMode? mode = RecordedTestMode.Playback) : base(isAsync, RecordedTestMode.Record)
public RouterLiveTestBase(bool isAsync, RecordedTestMode? mode = RecordedTestMode.Playback) : base(isAsync, mode)
{
_testCleanupTasks = new ConcurrentDictionary<string, Stack<Task>>();
JsonPathSanitizers.Add("$..token");
Expand All @@ -43,6 +43,8 @@ public async Task CleanUp()
var mode = TestEnvironment.Mode ?? Mode;
if (mode != RecordedTestMode.Playback)
{
await Task.Delay(TimeSpan.FromSeconds(3));

var testName = TestContext.CurrentContext.Test.FullName;

var popTestResources = _testCleanupTasks.TryRemove(testName, out var cleanupTasks);
Expand All @@ -52,8 +54,19 @@ public async Task CleanUp()
{
while (cleanupTasks.Count > 0)
{
await Task.Delay(TimeSpan.FromSeconds(1));

var executableTask = cleanupTasks.Pop();
await Task.Run(() => executableTask.Start());
try
{
await Task.Run(() => executableTask.Start());
}
catch (Exception)
{
// Retry after delay
await Task.Delay(TimeSpan.FromSeconds(3));
await Task.Run(() => executableTask.Start());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,18 @@ public async Task CreateClassificationPolicyTest()
Assert.IsTrue(!string.IsNullOrWhiteSpace(createClassificationPolicy.FallbackQueueId) && createClassificationPolicy.FallbackQueueId == createQueueResponse.Value.Id);
Assert.IsFalse(string.IsNullOrWhiteSpace(createClassificationPolicy.Name));

updateClassificationPolicyResponse.Value.FallbackQueueId = null;
updateClassificationPolicyResponse.Value.PrioritizationRule = null;
updateClassificationPolicyResponse.Value.QueueSelectorAttachments.Clear();
updateClassificationPolicyResponse.Value.WorkerSelectorAttachments.Clear();
updateClassificationPolicyResponse.Value.Name = $"{classificationPolicyName}-updated";

updateClassificationPolicyResponse = await routerClient.UpdateClassificationPolicyAsync(
new ClassificationPolicy(classificationPolicyId)
{
FallbackQueueId = null,
PrioritizationRule = null,
Name = $"{classificationPolicyName}-updated",
});
updateClassificationPolicyResponse.Value);

var updateClassificationPolicy = updateClassificationPolicyResponse.Value;
Assert.IsTrue(updateClassificationPolicy.QueueSelectorAttachments.Any());
Assert.IsTrue(updateClassificationPolicy.WorkerSelectorAttachments.Any());
Assert.IsFalse(updateClassificationPolicy.QueueSelectorAttachments.Any());
Assert.IsFalse(updateClassificationPolicy.WorkerSelectorAttachments.Any());
Assert.AreEqual(updateClassificationPolicy.Name, $"{classificationPolicyName}-updated");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ public async Task CreateExceptionPolicyTest_WaitTime()

var exceptionPolicy = createExceptionPolicyResponse.Value;

Assert.AreEqual(exceptionPolicyId, exceptionPolicy.Id);
Assert.AreEqual(exceptionPolicyId, exceptionPolicy.Id);
Assert.DoesNotThrow(() =>
{
Expand Down
Loading

0 comments on commit 18858e8

Please sign in to comment.