public void HiLoKeyGenerator_works_without_aggressive_caching() { using (var store = NewDocumentStore()) { var hilo = new HiLoKeyGenerator("test", 1); Assert.Equal(1L, hilo.NextId(store.DatabaseCommands)); Assert.Equal(2L, hilo.NextId(store.DatabaseCommands)); } }
public void HiLoKeyGenerator_hangs_when_aggressive_caching_enabled() { using (var store = NewDocumentStore()) { using (store.AggressivelyCache()) { var hilo = new HiLoKeyGenerator("test", 1); Assert.Equal(1L, hilo.NextId(store.DatabaseCommands)); Assert.Equal(2L, hilo.NextId(store.DatabaseCommands)); } } }
public void HiLoKeyGenerator_hangs_when_aggressive_caching_enabled_on_other_documentstore() { using (var server = GetNewServer(port: 8079)) using (var otherServer = GetNewServer(port: 8078)) using (var store = NewRemoteDocumentStore(ravenDbServer: server)) using (var otherStore = NewRemoteDocumentStore(ravenDbServer: otherServer)) { using (otherStore.AggressivelyCache()) // Note that we don't even use the other store, we just call AggressivelyCache on it { var hilo = new HiLoKeyGenerator("test", 1); Assert.Equal(1L, hilo.NextId(store.DatabaseCommands)); Assert.Equal(2L, hilo.NextId(store.DatabaseCommands)); } } }
public void HiLo_Modified_InReplicated_Scenario() { const string key = "Raven/Hilo/managers"; var store1 = CreateStore(configureStore: store => store.Conventions.FailoverBehavior = FailoverBehavior.ReadFromAllServers); var store2 = CreateStore(); ((DocumentStore)store1).GetReplicationInformerForDatabase() .UpdateReplicationInformationIfNeeded((AsyncServerClient)store1.AsyncDatabaseCommands) .Wait(); ((DocumentStore)store2).GetReplicationInformerForDatabase() .UpdateReplicationInformationIfNeeded((AsyncServerClient)store2.AsyncDatabaseCommands) .Wait(); TellFirstInstanceToReplicateToSecondInstance(); TellSecondInstanceToReplicateToFirstInstance(); var hiLoKeyGenerator = new HiLoKeyGenerator("managers", 2) { DisableCapacityChanges = true }; for (long i = 0; i < 4; i++) { Assert.Equal(i + 1, hiLoKeyGenerator.NextId(store1.DatabaseCommands)); } WaitForReplication(store2, session => { var load = session.Load <dynamic>(key); return(load != null && load.Max == 4); }); var jsonDocument = store2.DatabaseCommands.Get(key); store2.DatabaseCommands.Put(key, null, new RavenJObject { { "Max", 49 } }, jsonDocument.Metadata); WaitForReplication(store1, session => session.Load <dynamic>(key).Max == 49); for (long i = 0; i < 4; i++) { var nextId = hiLoKeyGenerator.NextId(store1.DatabaseCommands); Assert.Equal(i + 50, nextId); } }
public void ShouldResolveConflictWithHighestNumber() { using (var server = GetNewServer()) using (var store = new DocumentStore { Url = "http://*****:*****@Http-Status-Code" , 409 }, { "@Http-Status-Description" , "Conflicted doc" } }); }); var hiLoKeyGenerator = new HiLoKeyGenerator("Users", 32); var nextId = hiLoKeyGenerator.NextId(store.DatabaseCommands); Assert.Equal(65, nextId); } }
public void FromScratch() { using (var store = NewDocumentStore()) { var generator = new HiLoKeyGenerator(store.DatabaseCommands, "users", 3); for (long i = 0; i < 50; i++) { Assert.Equal(i + 1, generator.NextId()); } } }
//TODO: Write couple tests to be sure public bool BeforeStore(string key, object entityInstance, RavenJObject metadata, RavenJObject original) { var commit = entityInstance as RavenCommit; if (commit != null && commit.CheckpointNumber == 0) { commit.CheckpointNumber = _generator.NextId(_store.DatabaseCommands); return(true); } return(false); }
public void HiloCannotGoDown() { using (var store = NewDocumentStore()) { store.DatabaseCommands.Put( "Raven/Hilo/Users", null, new RavenJObject { { "Max", 32 } }, new RavenJObject()); var hiLoKeyGenerator = new HiLoKeyGenerator("Users", 32); var ids = new HashSet <long> { hiLoKeyGenerator.NextId(store.DatabaseCommands) }; store.DatabaseCommands.Put( "Raven/Hilo/Users", null, new RavenJObject { { "Max", 12 } }, new RavenJObject()); for (int i = 0; i < 128; i++) { Assert.True(ids.Add(hiLoKeyGenerator.NextId(store.DatabaseCommands)), "Failed at " + i); } var list = ids.GroupBy(x => x).Select(g => new { g.Key, Count = g.Count() }).Where(x => x.Count > 1).ToList(); Assert.Empty(list); } }
public void SequentialGeneration_NoClashesOrGaps() { using (GetNewServer()) using (var store = new DocumentStore { Url = "http://localhost:8079" }.Initialize()) { var gen = new HiLoKeyGenerator("When_generating_lots_of_keys_concurrently_there_are_no_clashes", 2); Test(() => gen.NextId(store.DatabaseCommands), 1, GeneratedIdCount); } }
public void ConcurrentWillNoGenerateConflicts() { using (var store = NewDocumentStore()) { var generator1 = new HiLoKeyGenerator(store.DatabaseCommands, "users", 3); var generator2 = new HiLoKeyGenerator(store.DatabaseCommands, "users", 3); var dic = new Dictionary <long, int>(); for (long i = 0; i < 50; i++) { dic.Add(generator1.NextId(), 1); dic.Add(generator2.NextId(), 1); } } }
public void CanUpgradeFromOldHiLo() { using (var store = NewDocumentStore()) { store.DatabaseCommands.Put("Raven/Hilo/users", null, RavenJObject.FromObject(new{ ServerHi = 2 }), new RavenJObject()); var generator = new HiLoKeyGenerator(store.DatabaseCommands, "users", 1024); for (long i = 0; i < 50; i++) { Assert.Equal((i + 1) + 1024, generator.NextId()); } } }