Skip to content
This repository has been archived by the owner on Aug 3, 2024. It is now read-only.
/ ServerCommon Public archive

Commit

Permalink
Adding the ability to schedule validation message processing in the f…
Browse files Browse the repository at this point in the history
…uture (#69)

* Added ScheduledEnqueueTimeUtc to the IBrokeredMessage and implementation.
Added tests for the property

* Added the postponed version of the StartValidationAsync to the IPackageValidationEnqueuer
  • Loading branch information
agr authored Oct 10, 2017
1 parent 5c98bf2 commit 2b04171
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 1 deletion.
9 changes: 8 additions & 1 deletion NuGet.Server.Common.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.0
VisualStudioVersion = 15.0.27005.2
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{8415FED7-1BED-4227-8B4F-BB7C24E041CD}"
EndProject
Expand Down Expand Up @@ -50,6 +50,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NuGet.Services.Validation.T
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NuGet.Services.Contracts.Tests", "tests\NuGet.Services.Contracts.Tests\NuGet.Services.Contracts.Tests.csproj", "{79F72C83-E94D-4D04-B904-5A4DA161168E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NuGet.Services.ServiceBus.Tests", "tests\NuGet.Services.ServiceBus.Tests\NuGet.Services.ServiceBus.Tests.csproj", "{FF5CA51A-CD6A-463F-AE9A-5737FF0FCFA7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -132,6 +134,10 @@ Global
{79F72C83-E94D-4D04-B904-5A4DA161168E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{79F72C83-E94D-4D04-B904-5A4DA161168E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{79F72C83-E94D-4D04-B904-5A4DA161168E}.Release|Any CPU.Build.0 = Release|Any CPU
{FF5CA51A-CD6A-463F-AE9A-5737FF0FCFA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FF5CA51A-CD6A-463F-AE9A-5737FF0FCFA7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FF5CA51A-CD6A-463F-AE9A-5737FF0FCFA7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FF5CA51A-CD6A-463F-AE9A-5737FF0FCFA7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -156,6 +162,7 @@ Global
{C1E36A2C-1C1B-4521-B256-AD42505D9EFB} = {8415FED7-1BED-4227-8B4F-BB7C24E041CD}
{E29F54DF-DFB8-4E27-940D-21ECCB9B6FC1} = {7783A106-0F4C-4055-9AB4-413FB2C7B8F0}
{79F72C83-E94D-4D04-B904-5A4DA161168E} = {7783A106-0F4C-4055-9AB4-413FB2C7B8F0}
{FF5CA51A-CD6A-463F-AE9A-5737FF0FCFA7} = {7783A106-0F4C-4055-9AB4-413FB2C7B8F0}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {AA413DB0-5475-4B5D-A3AF-6323DA8D538B}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace NuGet.Services.ServiceBus
public interface IBrokeredMessage : IDisposable
{
IDictionary<string, object> Properties { get; }
DateTimeOffset ScheduledEnqueueTimeUtc { get; set; }
Task CompleteAsync();
string GetBody();
IBrokeredMessage Clone();
Expand Down
6 changes: 6 additions & 0 deletions src/NuGet.Services.ServiceBus/BrokeredMessageWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ public BrokeredMessageWrapper(BrokeredMessage brokeredMessage)

public IDictionary<string, object> Properties => BrokeredMessage.Properties;

public DateTimeOffset ScheduledEnqueueTimeUtc
{
get => new DateTimeOffset(BrokeredMessage.ScheduledEnqueueTimeUtc);
set => BrokeredMessage.ScheduledEnqueueTimeUtc = new DateTime(value.UtcTicks, DateTimeKind.Utc);
}

public string GetBody()
{
return BrokeredMessage.GetBody<string>();
Expand Down
12 changes: 12 additions & 0 deletions src/NuGet.Services.Validation/IPackageValidationEnqueuer.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Threading.Tasks;

namespace NuGet.Services.Validation
{
public interface IPackageValidationEnqueuer
{
/// <summary>
/// Enqueues validation of the specified package to start ASAP.
/// </summary>
/// <param name="message">Package information</param>
Task StartValidationAsync(PackageValidationMessageData message);

/// <summary>
/// Enqueues validation of the specified package to start no sooner than specified time
/// </summary>
/// <param name="message">Package information</param>
/// <param name="postponeProcessingTill">The time till which validation processing should be postponed.</param>
Task StartValidationAsync(PackageValidationMessageData message, DateTimeOffset postponeProcessingTill);
}
}
7 changes: 7 additions & 0 deletions src/NuGet.Services.Validation/PackageValidationEnqueuer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Threading.Tasks;
using NuGet.Services.ServiceBus;

Expand All @@ -18,8 +19,14 @@ public PackageValidationEnqueuer(ITopicClient topicClient, IServiceBusMessageSer
}

public async Task StartValidationAsync(PackageValidationMessageData message)
{
await StartValidationAsync(message, DateTimeOffset.MinValue);
}

public async Task StartValidationAsync(PackageValidationMessageData message, DateTimeOffset postponeProcessingTill)
{
var brokeredMessage = _serializer.SerializePackageValidationMessageData(message);
brokeredMessage.ScheduledEnqueueTimeUtc = postponeProcessingTill;
await _topicClient.SendAsync(brokeredMessage);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using Xunit;

namespace NuGet.Services.ServiceBus.Tests
{
public class BrokeredMessageWrapperFacts
{
[Fact]
public void DoesNotMessUpScheduledEnqueueTimeUtc()
{
var now = DateTimeOffset.Now;

var message = new BrokeredMessageWrapper("data");
message.ScheduledEnqueueTimeUtc = now;
Assert.Equal(now, message.ScheduledEnqueueTimeUtc);
}

[Fact]
public void ForcesUtcOnScheduledEnqueueTimeUtc()
{
var now = DateTimeOffset.Now;
var nowUtc = now.UtcDateTime;

var message = new BrokeredMessageWrapper("data");
message.ScheduledEnqueueTimeUtc = now;

Assert.Equal(DateTimeKind.Utc, message.BrokeredMessage.ScheduledEnqueueTimeUtc.Kind);
Assert.Equal(nowUtc, message.BrokeredMessage.ScheduledEnqueueTimeUtc);
Assert.Equal(TimeSpan.Zero, message.ScheduledEnqueueTimeUtc.Offset);
}

[Fact]
public void DefaultScheduledEnqueueTimeUtcIsNotInTheFuture()
{
var message = new BrokeredMessageWrapper("data");
Assert.True(message.ScheduledEnqueueTimeUtc <= DateTimeOffset.Now);
}

[Fact]
public void MinScheduledEnqueueTimeUtcWorks()
{
var message = new BrokeredMessageWrapper("data");
message.ScheduledEnqueueTimeUtc = DateTimeOffset.MinValue;

Assert.True(message.ScheduledEnqueueTimeUtc < DateTimeOffset.Now);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{FF5CA51A-CD6A-463F-AE9A-5737FF0FCFA7}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>NuGet.Services.ServiceBus.Tests</RootNamespace>
<AssemblyName>NuGet.Services.ServiceBus.Tests</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="BrokeredMessageWrapperFacts.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="project.json" />
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\NuGet.Services.ServiceBus\NuGet.Services.ServiceBus.csproj">
<Project>{9337000b-ea3b-40be-9a33-38bc28dfd0cb}</Project>
<Name>NuGet.Services.ServiceBus</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
14 changes: 14 additions & 0 deletions tests/NuGet.Services.ServiceBus.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Reflection;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("NuGet.Services.ServiceBus.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("NuGet.Services.ServiceBus.Tests")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: ComVisible(false)]
[assembly: Guid("ff5ca51a-cd6a-463f-ae9a-5737ff0fcfa7")]
14 changes: 14 additions & 0 deletions tests/NuGet.Services.ServiceBus.Tests/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"dependencies": {
"WindowsAzure.ServiceBus": "4.1.3",
"Moq": "4.5.23",
"xunit": "2.1.0",
"xunit.runner.visualstudio": "2.1.0"
},
"frameworks": {
"net452": {}
},
"runtimes": {
"win": {}
}
}

0 comments on commit 2b04171

Please sign in to comment.