Skip to content

Commit

Permalink
Tests for AGENT-199
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwardill committed May 31, 2012
1 parent 2e34e08 commit 08da899
Show file tree
Hide file tree
Showing 3 changed files with 195 additions and 0 deletions.
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>
</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{B75B0BA0-3D8D-450C-8611-F223655BC91C}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AgentTests</RootNamespace>
<AssemblyName>AgentTests</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
</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="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
<Visible>False</Visible>
</CodeAnalysisDependentAssemblyPaths>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="NetworkCalculations.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\sd-agent-windows\BoxedIce.ServerDensity.Agent.PluginSupport\BoxedIce.ServerDensity.Agent.PluginSupport.csproj">
<Project>{6A68C2EB-1842-4B84-97C9-885BA534A280}</Project>
<Name>BoxedIce.ServerDensity.Agent.PluginSupport</Name>
</ProjectReference>
<ProjectReference Include="..\..\sd-agent-windows\BoxedIce.ServerDensity.Agent\BoxedIce.ServerDensity.Agent.csproj">
<Project>{BF3E0C66-7707-4357-9172-2B00F10F9913}</Project>
<Name>BoxedIce.ServerDensity.Agent</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
91 changes: 91 additions & 0 deletions BoxedIce.ServerDensity.AgentTests/NetworkCalculations.cs
@@ -0,0 +1,91 @@
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using BoxedIce.ServerDensity.Agent;
using BoxedIce.ServerDensity.Agent.Checks;

namespace AgentTests
{
[TestClass]
public class NetworkCalculations
{
[TestMethod]
public void StandardNetworkTraffic()
{
NetworkTrafficCheck check = new NetworkTrafficCheck();

var store = new Dictionary<string, long>();
store["recv_bytes"] = 10;

var result = check.CheckForOverflow("recv", store, 100);
Assert.AreEqual(result[0], 90);
Assert.AreEqual(result[1], 100);
Assert.AreEqual(result[2], 0);
}

[TestMethod]
public void HigherStandardNetworkTraffic()
{
NetworkTrafficCheck check = new NetworkTrafficCheck();

var store = new Dictionary<string, long>();
store["recv_bytes"] = 30000000;

var result = check.CheckForOverflow("recv", store, 30001000);
Assert.AreEqual(result[0], 1000);
Assert.AreEqual(result[1], 30001000);
Assert.AreEqual(result[2], 0);
}

[TestMethod]
public void StandardNetworkTrafficWithOverFlow()
{
NetworkTrafficCheck check = new NetworkTrafficCheck();

var store = new Dictionary<string, long>();
store["recv_bytes"] = UInt32.MaxValue - 100;

var result = check.CheckForOverflow("recv", store, 100);
Assert.AreEqual(200, result[0]);
Assert.AreEqual(100, result[1]);
Assert.AreEqual(UInt32.MaxValue, result[2]);
}

[TestMethod]
public void DoubleStandardNetworkTraffic()
{
NetworkTrafficCheck check = new NetworkTrafficCheck();

var store = new Dictionary<string, long>();
store["recv_bytes"] = 1216986405;

var result = check.CheckForOverflow("recv", store, 1217007129);
store["recv_bytes"] = result[1];

var second_result = check.CheckForOverflow("recv", store, 1217010727);
Assert.AreEqual(3598, second_result[0]);
Assert.AreEqual(1217010727, second_result[1]);
}

[TestMethod]
public void AfterOverFlow()
{
NetworkTrafficCheck check = new NetworkTrafficCheck();

var store = new Dictionary<string, long>();
store["recv_bytes"] = UInt32.MaxValue - 100;

long target = UInt32.MaxValue;
target += 100;

var result = check.CheckForOverflow("recv", store, 100);
store["recv_bytes"] = result[0];

var second_result = check.CheckForOverflow("recv", store, 100 + result[0]);
Assert.AreEqual(100, second_result[0]);
}
}
}
35 changes: 35 additions & 0 deletions BoxedIce.ServerDensity.AgentTests/Properties/AssemblyInfo.cs
@@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.CompilerServices;
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("AgentTests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AgentTests")]
[assembly: AssemblyCopyright("Copyright © 2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("ac57aea2-b5f2-4786-a043-67012e20af56")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

0 comments on commit 08da899

Please sign in to comment.