Example #1
0
        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);
                }
        }
Example #2
0
 public void SequentialGeneration_NoClashesOrGaps()
 {
     using (var store = GetDocumentStore())
     {
         var gen = new AsyncHiLoKeyGenerator("When_generating_lots_of_keys_concurrently_there_are_no_clashes", store,
                                             store.DefaultDatabase, store.Conventions.IdentityPartsSeparator);
         ConcurrencyTester(() => gen.NextIdAsync().GetAwaiter().GetResult(), 1, GeneratedIdCount);
     }
 }
 public void AsyncSequentialGeneration_NoClashesOrGaps()
 {
     using (GetNewServer())
         using (var store = new DocumentStore
         {
             Url = "http://localhost:8079"
         }.Initialize())
         {
             var gen = new AsyncHiLoKeyGenerator("When_async_generating_lots_of_keys_concurrently_there_are_no_clashes", 2);
             Test(() => gen.NextIdAsync(store.AsyncDatabaseCommands).Result, 1, GeneratedIdCount);
         }
 }
Example #4
0
 public async Task HiLoKeyGenerator_async_hangs_when_aggressive_caching_enabled()
 {
     using (var store = NewDocumentStore())
     {
         using (store.AggressivelyCache())
         {
             var hilo = new AsyncHiLoKeyGenerator("test", 1);
             Assert.Equal(1L, await hilo.NextIdAsync(store.AsyncDatabaseCommands));
             Assert.Equal(2L, await hilo.NextIdAsync(store.AsyncDatabaseCommands));
         }
     }
 }
Example #5
0
 public async Task HiLoKeyGenerator_async_hangs_when_aggressive_caching_enabled_on_other_documentstore()
 {
     using (var store = NewDocumentStore())
         using (var otherStore = NewDocumentStore())
         {
             using (otherStore.AggressivelyCache()) // Note that we don't even use the other store, we just call AggressivelyCache on it
             {
                 var hilo = new AsyncHiLoKeyGenerator("test", 1);
                 Assert.Equal(1L, await hilo.NextIdAsync(store.AsyncDatabaseCommands));
                 Assert.Equal(2L, await hilo.NextIdAsync(store.AsyncDatabaseCommands));
             }
         }
 }
Example #6
0
        public void Can_Use_Server_Prefix()
        {
            using (var store = GetDocumentStore())
            {
                using (var session = store.OpenSession())
                {
                    session.Store(new PrefixHiloDoc()
                    {
                        ServerPrefix = "4,"
                    }, "Raven/ServerPrefixForHilo");

                    session.SaveChanges();

                    var hiLoKeyGenerator = new AsyncHiLoKeyGenerator("users", store, store.DefaultDatabase,
                                                                     store.Conventions.IdentityPartsSeparator);

                    var generateDocumentKey = hiLoKeyGenerator.GenerateDocumentKeyAsync(new User()).GetAwaiter().GetResult();
                    Assert.Equal("users/4,1", generateDocumentKey);
                }
            }
        }
Example #7
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 AsyncHiLoKeyGenerator("users", store, store.DefaultDatabase,
                                                                     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);
                }
            }
        }
Example #8
0
        public void Capacity_Should_Double()
        {
            using (var store = GetDocumentStore())
            {
                var hiLoKeyGenerator = new AsyncHiLoKeyGenerator("users", store, store.DefaultDatabase,
                                                                 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.GenerateDocumentKeyAsync(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.GenerateDocumentKeyAsync(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);
                }
            }
        }