Permalink
Browse files

Initial checkin of transactional dictionary

  • Loading branch information...
xoltar committed Oct 22, 2012
1 parent 3e0e78d commit 34f20e415c92de1b57ca7b6b55bc43a9cb19b5f4
View
@@ -0,0 +1,22 @@
+# Auto detect text files and perform LF normalization
+* text=auto
+
+# Custom for Visual Studio
+*.cs diff=csharp
+*.sln merge=union
+*.csproj merge=union
+*.vbproj merge=union
+*.fsproj merge=union
+*.dbproj merge=union
+
+# Standard to msysgit
+*.doc diff=astextplain
+*.DOC diff=astextplain
+*.docx diff=astextplain
+*.DOCX diff=astextplain
+*.dot diff=astextplain
+*.DOT diff=astextplain
+*.pdf diff=astextplain
+*.PDF diff=astextplain
+*.rtf diff=astextplain
+*.RTF diff=astextplain
View
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="xunit.runners" version="1.9.1" />
+</packages>
View
@@ -0,0 +1,33 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Express 2012 for Web
+Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Xoltar.Core", "Xoltar.Core\Xoltar.Core.fsproj", "{5E7440B3-0716-46B6-93B1-48AA3D0B1A7B}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{63D7A2CE-0BE8-4E3D-AF7F-91962625D125}"
+ ProjectSection(SolutionItems) = preProject
+ .nuget\NuGet.Config = .nuget\NuGet.Config
+ .nuget\NuGet.exe = .nuget\NuGet.exe
+ .nuget\NuGet.targets = .nuget\NuGet.targets
+ EndProjectSection
+EndProject
+Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Xoltar.Core.Test", "Xoltar.Core.Test\Xoltar.Core.Test.fsproj", "{FAACD970-DE96-4405-A1BE-15AE84EB2C34}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {5E7440B3-0716-46B6-93B1-48AA3D0B1A7B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {5E7440B3-0716-46B6-93B1-48AA3D0B1A7B}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {5E7440B3-0716-46B6-93B1-48AA3D0B1A7B}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {5E7440B3-0716-46B6-93B1-48AA3D0B1A7B}.Release|Any CPU.Build.0 = Release|Any CPU
+ {FAACD970-DE96-4405-A1BE-15AE84EB2C34}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {FAACD970-DE96-4405-A1BE-15AE84EB2C34}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {FAACD970-DE96-4405-A1BE-15AE84EB2C34}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {FAACD970-DE96-4405-A1BE-15AE84EB2C34}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
@@ -0,0 +1,8 @@
+// Learn more about F# at http://fsharp.net. See the 'F# Tutorial' project
+// for more guidance on F# programming.
+
+#load "Library1.fs"
+open Xoltar.Core.Test
+
+// Define your library scripting code here
+
@@ -0,0 +1,123 @@
+namespace Xoltar.Core.Transaction.Test
+open Xunit
+open Xoltar.Core.Transaction
+open System.Collections.Generic
+
+module Dictionary =
+ let dict () = Dictionary()
+ let trans<'k,'v when 'k:equality and 'v:equality>() =
+ let d = dict()
+ TransactionalDictionary<'k,'v>(d) :> IDictionary<'k,'v>, d
+ let slim set = new System.Threading.ManualResetEventSlim(set)
+ [<Fact>]
+ let ``a new dictionary has count = 0``() =
+ let d,back = trans()
+ Assert.Equal(0, d.Count)
+
+ [<Fact>]
+ let ``after adding an item, the item can be retrieved``()=
+ let d,back = trans()
+ d.[1] <- 2
+ Assert.Equal(2, d.[1])
+
+ [<Fact>]
+ let ``after adding an item, then clearing, the count = 0``() =
+ let d,back = trans()
+ d.[1] <- 2
+ d.Clear()
+ Assert.Equal(0, d.Count)
+
+ [<Fact>]
+ let ``after adding an item, then removing, the count = 0``() =
+ let d,back = trans()
+ d.[1] <- 2
+ d.Remove(1) |> ignore
+ Assert.Equal(0, d.Count)
+
+ [<Fact>]
+ let ``values in a transaction are isolated``() =
+ use valueSet = slim false
+ use valueChecked = slim false
+ (
+ let d,back = trans()
+ d.[1] <- 2
+ let t = System.Threading.Tasks.Task.Factory.StartNew (fun () ->
+ valueSet.Wait()
+ try
+ Assert.Equal(2, d.[1])
+ finally
+ valueChecked.Set())
+ use txn = new System.Transactions.TransactionScope()
+ (
+ d.[1] <- 5
+ valueSet.Set()
+ valueChecked.Wait()
+ )
+ t.Wait()
+ )
+
+ [<Fact>]
+ let ``values in a transaction are visible to the transaction``() =
+ let d,back = trans()
+ d.[1] <- 2
+ use txn = new System.Transactions.TransactionScope()
+ (
+ d.[1] <- 5
+ Assert.Equal(5, d.[1])
+ )
+
+ [<Fact>]
+ let ``after rollback, transaction values are not committed``()=
+ let d,back = trans()
+ d.[1] <- 2
+ use txn = new System.Transactions.TransactionScope()
+ (
+ d.[1] <- 5
+ )
+ Assert.Equal(2, back.[1])
+
+ [<Fact>]
+ let ``after rollback, transaction values are gone in trans dict``()=
+ let d,back = trans()
+ d.[1] <- 2
+ use txn = new System.Transactions.TransactionScope()
+ (
+ d.[1] <- 5
+ )
+ Assert.Equal(2, d.[1])
+
+ [<Fact>]
+ let ``after commit, transaction values persist``()=
+ let d,back = trans()
+ d.[1] <- 2
+ use txn = new System.Transactions.TransactionScope()
+ (
+ d.[1] <- 5
+ txn.Complete()
+ )
+ Assert.Equal(5, back.[1])
+
+ [<Fact>]
+ let ``last commit wins``() =
+ use valueSet = slim false
+ use valueSet2 = slim false
+ use valueChecked = slim false
+ (
+ let d,back = trans()
+ d.[1] <- 2
+ let t = System.Threading.Tasks.Task.Factory.StartNew (fun () ->
+ valueSet.Wait()
+ try
+ Assert.Equal(2, d.[1])
+ finally
+ valueChecked.Set())
+ use txn = new System.Transactions.TransactionScope()
+ (
+ d.[1] <- 5
+ valueSet.Set()
+ valueChecked.Wait()
+ txn.Complete()
+ )
+ t.Wait()
+ Assert.Equal(5, back.[1])
+ )
@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" 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>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>faacd970-de96-4405-a1be-15ae84eb2c34</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <RootNamespace>Xoltar.Core.Test</RootNamespace>
+ <AssemblyName>Xoltar.Core.Test</AssemblyName>
+ <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+ <Name>Xoltar.Core.Test</Name>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <Tailcalls>false</Tailcalls>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <WarningLevel>3</WarningLevel>
+ <DocumentationFile>bin\Debug\Xoltar.Core.Test.XML</DocumentationFile>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <Tailcalls>true</Tailcalls>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <WarningLevel>3</WarningLevel>
+ <DocumentationFile>bin\Release\Xoltar.Core.Test.XML</DocumentationFile>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="FsCheck">
+ <HintPath>..\packages\FsCheck.0.8.3.0\lib\net40-Client\FsCheck.dll</HintPath>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="FsCheck.Xunit">
+ <HintPath>..\packages\FsCheck.Xunit.0.3.0.0\lib\net40-Client\FsCheck.Xunit.dll</HintPath>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="mscorlib" />
+ <Reference Include="FSharp.Core, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Numerics" />
+ <Reference Include="System.Transactions" />
+ <Reference Include="xunit, Version=1.9.1.1600, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c">
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="xunit.extensions">
+ <HintPath>..\packages\xunit.extensions.1.9.1\lib\net20\xunit.extensions.dll</HintPath>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="xunit.runner.msbuild, Version=1.9.1.1600, Culture=neutral, PublicKeyToken=null">
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="xunit.runner.tdnet, Version=1.9.1.1600, Culture=neutral, PublicKeyToken=null">
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="xunit.runner.utility, Version=1.9.1.1600, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c">
+ <Private>True</Private>
+ </Reference>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="TransactionalDictionary.fs" />
+ <None Include="Script.fsx" />
+ <None Include="packages.config" />
+ <None Include="app.config" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\Xoltar.Core\Xoltar.Core.fsproj">
+ <Name>Xoltar.Core</Name>
+ <Project>{5e7440b3-0716-46b6-93b1-48aa3d0b1a7b}</Project>
+ <Private>True</Private>
+ </ProjectReference>
+ </ItemGroup>
+ <PropertyGroup>
+ <MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
+ </PropertyGroup>
+ <Import Project="$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets" Condition=" Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.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>
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration />
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="FsCheck" version="0.8.3.0" targetFramework="net45" />
+</packages>
View
@@ -0,0 +1,8 @@
+// Learn more about F# at http://fsharp.net. See the 'F# Tutorial' project
+// for more guidance on F# programming.
+
+#load "Library1.fs"
+open Xoltar.Core
+
+// Define your library scripting code here
+
Oops, something went wrong.

0 comments on commit 34f20e4

Please sign in to comment.