示例#1
0
 public void SequentialGeneration_NoClashesOrGaps()
 {
     using (var store = GetDocumentStore())
     {
         var gen = new AsyncHiLoIdGenerator("When_generating_lots_of_keys_concurrently_there_are_no_clashes", store,
                                            store.Database, store.Conventions.IdentityPartsSeparator);
         ConcurrencyTester(() => gen.NextIdAsync().GetAwaiter().GetResult(), 1, GeneratedIdCount);
     }
 }
示例#2
0
        public void HiLoKeyGenerator_works_without_aggressive_caching()
        {
            using (var store = GetDocumentStore())
            {
                var hiLoKeyGenerator = new AsyncHiLoIdGenerator("users", store, store.Database,
                                                                store.Conventions.IdentityPartsSeparator);

                Assert.Equal(1L, hiLoKeyGenerator.NextIdAsync().GetAwaiter().GetResult());
                Assert.Equal(2L, hiLoKeyGenerator.NextIdAsync().GetAwaiter().GetResult());
            }
        }
示例#3
0
        public async Task HiLoKeyGenerator_async_hangs_when_aggressive_caching_enabled()
        {
            using (var store = GetDocumentStore())
            {
                using (store.AggressivelyCache())
                {
                    var hiLoKeyGenerator = new AsyncHiLoIdGenerator("users", store, store.Database,
                                                                    store.Conventions.IdentityPartsSeparator);

                    Assert.Equal(1L, await hiLoKeyGenerator.NextIdAsync());
                    Assert.Equal(2L, await hiLoKeyGenerator.NextIdAsync());
                }
            }
        }
示例#4
0
 public async Task HiLoKeyGenerator_async_hangs_when_aggressive_caching_enabled_on_other_documentstore()
 {
     using (var server = GetNewServer())
         using (var otherServer = GetNewServer())
             using (var store = GetDocumentStore(new Options {
                 Server = server
             }))
                 using (var otherStore = GetDocumentStore(new Options {
                     Server = otherServer
                 }))
                 {
                     using (otherStore.AggressivelyCache()) // Note that we don't even use the other store, we just call AggressivelyCache on it
                     {
                         var hilo = new AsyncHiLoIdGenerator("users", store, store.Database,
                                                             store.Conventions.IdentityPartsSeparator);
                         Assert.Equal(1L, await hilo.NextIdAsync());
                         Assert.Equal(2L, await hilo.NextIdAsync());
                     }
                 }
 }
示例#5
0
        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);
                }
            }
        }
示例#6
0
        public void Capacity_Should_Double()
        {
            using (var store = GetDocumentStore())
            {
                var hiLoKeyGenerator = new AsyncHiLoIdGenerator("users", store, store.Database,
                                                                store.Conventions.IdentityPartsSeparator);

                using (var session = store.OpenSession())
                {
                    session.Store(new HiloDoc
                    {
                        Max = 64
                    }, "Raven/Hilo/users");

                    session.SaveChanges();

                    for (var i = 0; i < 32; i++)
                    {
                        hiLoKeyGenerator.GenerateDocumentIdAsync(new User()).GetAwaiter().GetResult();
                    }
                }

                using (var session = store.OpenSession())
                {
                    var hiloDoc = session.Load <HiloDoc>("Raven/Hilo/Users");
                    var max     = hiloDoc.Max;
                    Assert.Equal(max, 96);

                    //we should be receiving a range of 64 now
                    hiLoKeyGenerator.GenerateDocumentIdAsync(new User()).GetAwaiter().GetResult();
                }

                using (var session = store.OpenSession())
                {
                    var hiloDoc = session.Load <HiloDoc>("Raven/Hilo/users");
                    var max     = hiloDoc.Max;
                    Assert.Equal(max, 160);
                }
            }
        }
示例#7
0
        public async Task Should_Resolve_Conflict_With_Highest_Number()
        {
            using (var store1 = GetDocumentStore(new Options {
                ModifyDatabaseName = s => s + "_foo1"
            }))
                using (var store2 = GetDocumentStore(new Options {
                    ModifyDatabaseName = s => s + "_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();
                    }

                    await SetupReplicationAsync(store1, store2);

                    WaitForMarkerDocumentAndAllPrecedingDocumentsToReplicate(store2);

                    var nextId = new AsyncHiLoIdGenerator("users", store2, store2.Database,
                                                          store2.Conventions.IdentityPartsSeparator).NextIdAsync().GetAwaiter().GetResult();
                    Assert.Equal(nextId, 129);
                }
        }