Skip to content

Commit

Permalink
Added support for Amazon S3 for external storage
Browse files Browse the repository at this point in the history
You can also use S3Connection to another S3 bucket to retrieve S3Blob objects. These can be used as any other Blob object but can also be saved to your NHibernate mapped S3 store more efficiently than reading it and then writing it.
  • Loading branch information
sebmarkbage committed Dec 28, 2011
1 parent e03c814 commit 68cc4ac
Show file tree
Hide file tree
Showing 8 changed files with 677 additions and 91 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?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>{05E1FCF0-2311-42C2-ADE7-2466D21FCD81}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>NHibernate.Lob.External.S3.Tests</RootNamespace>
<AssemblyName>NHibernate.Lob.External.S3.Tests</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="S3ConnectionTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Calyptus.Lob\Calyptus.Lob.csproj">
<Project>{548E083F-F742-41B7-8971-6004E85907AA}</Project>
<Name>Calyptus.Lob</Name>
</ProjectReference>
<ProjectReference Include="..\NHibernate.Lob.External.S3\NHibernate.Lob.External.S3.csproj">
<Project>{A3C37404-FF97-4896-92E7-634D5CCE6790}</Project>
<Name>NHibernate.Lob.External.S3</Name>
</ProjectReference>
<ProjectReference Include="..\NHibernate.Lob\NHibernate.Lob.csproj">
<Project>{6C14E813-80A3-406F-A582-6C10881B9E39}</Project>
<Name>NHibernate.Lob</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>
35 changes: 35 additions & 0 deletions Src/NHibernate.Lob.External.S3.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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("NHibernate.Lob.External.S3.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("NHibernate.Lob.External.S3.Tests")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
[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("b2a0cb29-5699-4b72-893c-a9600cc02fa4")]

// 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")]
53 changes: 53 additions & 0 deletions Src/NHibernate.Lob.External.S3.Tests/S3ConnectionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;
using Calyptus.Lob;

namespace NHibernate.Lob.External.S3.Tests
{
/// <summary>
/// Summary description for UnitTest1
/// </summary>
[TestClass]
public class S3ConnectionTests
{
[TestMethod]
public void SavingDataAndReadingItBackShouldYieldTheSameDataAndItShouldBeDeletedAfter()
{
var connectionProvider = new S3ConnectionProvider();
connectionProvider.ConnectionString = "AccessKey=YOURACCESSKEY;SecretKey=YOURSECRETKEY;BucketName=testbucket;Hash=sha1";

var arr = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

var content = Blob.Create(arr);
using (var conn = connectionProvider.GetConnection())
{
byte[] id;
using (var w = conn.OpenWriter())
{
content.WriteTo(w);
id = w.Commit();
}

var extBlob = new ExternalBlob(conn, id);
using (var s = new MemoryStream())
{
extBlob.WriteTo(s);
AssertEqualArrays(arr, s.ToArray());
}

conn.Delete(id);
}
}

private void AssertEqualArrays(byte[] a, byte[] b)
{
Assert.AreEqual(a.Length, b.Length);
for (var i = 0; i < a.Length; i++)
Assert.AreEqual(a[i], b[i]);
}
}
}
Loading

0 comments on commit 68cc4ac

Please sign in to comment.