Skip to content

Instantly share code, notes, and snippets.

@jesuslpm
Created October 2, 2012 12:38
Show Gist options
  • Save jesuslpm/3818723 to your computer and use it in GitHub Desktop.
Save jesuslpm/3818723 to your computer and use it in GitHub Desktop.
Default sharding strategy doesn't save all entities in all shards
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Raven.Client.Document;
using Raven.Client.Shard;
using Raven.Client.Embedded;
using Raven.Client;
using Xunit;
namespace Raven.Tests.UpdateCascade
{
public class CreditCardType
{
public string Id { get; set; }
public string Name { get; set; }
}
public class ShardingTest : IDisposable
{
DocumentStore shard1;
DocumentStore shard2;
ShardedDocumentStore store;
ShardStrategy strategy;
#region IDisposable Members
public ShardingTest()
{
shard1 = new EmbeddableDocumentStore
{
RunInMemory = true
};
shard1.Initialize();
shard2 = new EmbeddableDocumentStore
{
RunInMemory = true
};
shard1.Initialize();
strategy = new ShardStrategy(new Dictionary<string, IDocumentStore>
{
{ "shard1", shard1 },
{ "shard2", shard2 }
});
store = new ShardedDocumentStore(strategy);
store.Initialize();
}
public bool IsDisposed { get; private set; }
public void Dispose()
{
if (store != null) store.Dispose();
if (shard1 != null) shard1.Dispose();
if (shard2 != null) shard2.Dispose();
}
#endregion
[Fact]
public void DefaultStrategyShouldStoreToAllShards()
{
using (var session = store.OpenSession())
{
var visa = new CreditCardType { Id = "CreditCardsTypes/Visa", Name = "Visa" };
session.Store(visa);
session.SaveChanges();
}
using (var session = shard1.OpenSession())
{
var cc = session.Load<CreditCardType>("CreditCardsTypes/Visa");
Assert.NotNull(cc);
Assert.Equal(cc.Name, "Visa");
}
using (var session = shard2.OpenSession())
{
var cc = session.Load<CreditCardType>("CreditCardsTypes/Visa");
Assert.NotNull(cc);
Assert.Equal(cc.Name, "Visa");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment