public void Should_Resolve_Conflict_With_Highest_Number() { using (var store1 = GetDocumentStore(dbSuffixIdentifier: "foo1")) using (var store2 = GetDocumentStore(dbSuffixIdentifier: "foo2")) { using (var s1 = store1.OpenSession()) { var hiloDoc = new HiloDoc { Max = 128 }; s1.Store(hiloDoc, "Raven/Hilo/users"); s1.Store(new User(), "marker/doc"); s1.SaveChanges(); } using (var s2 = store2.OpenSession()) { var hiloDoc2 = new HiloDoc { Max = 64 }; s2.Store(hiloDoc2, "Raven/Hilo/users"); s2.SaveChanges(); } SetupReplication(store1, store2); WaitForMarkerDocumentAndAllPrecedingDocumentsToReplicate(store2); var nextId = new AsyncHiLoKeyGenerator("users", store2, store2.DefaultDatabase, store2.Conventions.IdentityPartsSeparator).NextIdAsync().GetAwaiter().GetResult(); Assert.Equal(nextId, 129); } }
public void Hilo_Cannot_Go_Down() { using (var store = GetDocumentStore()) { using (var session = store.OpenSession()) { var hiloDoc = new HiloDoc { Max = 32 }; session.Store(hiloDoc, "Raven/Hilo/users"); session.SaveChanges(); var hiLoKeyGenerator = new AsyncHiLoIdGenerator("users", store, store.Database, store.Conventions.IdentityPartsSeparator); var ids = new HashSet <long> { hiLoKeyGenerator.NextIdAsync().GetAwaiter().GetResult() }; hiloDoc.Max = 12; session.Store(hiloDoc, null, "Raven/Hilo/users"); session.SaveChanges(); for (int i = 0; i < 128; i++) { var nextId = hiLoKeyGenerator.NextIdAsync().GetAwaiter().GetResult(); Assert.True(ids.Add(nextId), "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); } } }