Ejemplo n.º 1
0
        private static DatabaseStatistics DatabaseStatistics(DocumentStore store, JsonOperationContext context)
        {
            var getStatsCommand = new GetStatisticsCommand();

            store.GetRequestExecuter(store.DefaultDatabase).Execute(getStatsCommand, context);
            var databaseStatistics = getStatsCommand.Result;

            return(databaseStatistics);
        }
        public void Handle(ProjectionManagementMessage.Command.GetStatistics message)
        {
            var command = new GetStatisticsCommand {
                Name           = message.Name,
                IncludeDeleted = message.IncludeDeleted,
                Mode           = message.Mode
            };

            _writer.PublishCommand("$get-statistics", command);
        }
Ejemplo n.º 3
0
        public void Run()
        {
            using (var store = GetDocumentStore())
            {
                new StudentIndex().Execute(store);

                using (var session = store.OpenSession())
                {
                    session.Store(new Student {
                        Email = "*****@*****.**"
                    });
                    session.SaveChanges();
                }

                var requestExecuter = store.GetRequestExecutor(store.Database);
                using (requestExecuter.ContextPool.AllocateOperationContext(out JsonOperationContext context))
                {
                    var getStatsCommand = new GetStatisticsCommand();
                    if (getStatsCommand != null)
                    {
                        requestExecuter.Execute(getStatsCommand, context);
                    }
                    var databaseStatistics = getStatsCommand.Result;
                    while (databaseStatistics.StaleIndexes.Any())
                    {
                        Thread.Sleep(10);
                        requestExecuter.Execute(getStatsCommand, context);
                        databaseStatistics = getStatsCommand.Result;
                    }
                }

                using (var session = store.OpenSession())
                {
                    var query = session.Query <Student, StudentIndex>();

                    var stream = session.Advanced.Stream(query);

                    stream.MoveNext();

                    Assert.NotNull(stream.Current.Id);
                }
            }
        }
Ejemplo n.º 4
0
        public void CanDeleteCollection()
        {
            using (var store = GetDocumentStore())
            {
                using (var x = store.OpenSession())
                {
                    for (int i = 0; i < 100; i++)
                    {
                        x.Store(new User {
                        }, "users/");
                    }
                    x.SaveChanges();
                }

                JsonOperationContext context;
                store.GetRequestExecuter(store.DefaultDatabase).ContextPool.AllocateOperationContext(out context);
                var Command = new DeleteByCollectionCommand()
                {
                    CollectionName = "users"
                };
                store.GetRequestExecuter(store.DefaultDatabase).Execute(Command, context);

                var sp = Stopwatch.StartNew();

                var timeout = Debugger.IsAttached ? 60 * 10000 : 10000;

                while (sp.ElapsedMilliseconds < timeout)
                {
                    var getStatsCommand = new GetStatisticsCommand();
                    store.GetRequestExecuter(store.DefaultDatabase).Execute(getStatsCommand, context);
                    var databaseStatistics = getStatsCommand.Result;
                    if (databaseStatistics.CountOfDocuments == 0)
                    {
                        return;
                    }

                    Thread.Sleep(25);
                }
                Assert.False(true, "There are still documents after 1 second");
            }
        }
Ejemplo n.º 5
0
        public void Execute(GetStatisticsArgs args)
        {
            var provider = new ShapefileFeatureCollectionProvider(args.PathToShapefile);
            var cmd      = new GetStatisticsCommand(provider.Get);
            var req      = Mapper.Map <GetStatisticsRequest>(args);
            var res      = cmd.Execute(req);

            res.MatchSome(x =>
            {
                var json = JsonConvert.SerializeObject(x);
                Console.WriteLine(json);
            });

            res.MatchNone(x =>
            {
                Log.Error(
                    x,
                    "Could not get statistics for shapefile {Shapefile}",
                    args.PathToShapefile);
            });
        }
Ejemplo n.º 6
0
        public void CanPatchCollection()
        {
            using (var store = GetDocumentStore())
            {
                using (var x = store.OpenSession())
                {
                    for (int i = 0; i < 100; i++)
                    {
                        x.Store(new User {
                        }, "users/");
                    }
                    x.SaveChanges();
                }

                JsonOperationContext context;
                store.GetRequestExecuter(store.DefaultDatabase).ContextPool.AllocateOperationContext(out context);

                var patchByCollectionOperation = new PatchByCollectionOperation(context);
                var patchCommand = patchByCollectionOperation.CreateRequest("users",
                                                                            new PatchRequest {
                    Script = " this.Name = __document_id;"
                }, store);
                if (patchCommand != null)
                {
                    store.GetRequestExecuter(store.DefaultDatabase).Execute(patchCommand, context);
                }

                var sp = Stopwatch.StartNew();

                var timeout = Debugger.IsAttached ? 60 * 10000 : 10000;

                GetStatisticsCommand getStatsCommand;
                DatabaseStatistics   databaseStatistics;
                while (sp.ElapsedMilliseconds < timeout)
                {
                    getStatsCommand = new GetStatisticsCommand();
                    store.GetRequestExecuter(store.DefaultDatabase).Execute(getStatsCommand, context);
                    databaseStatistics = getStatsCommand.Result;
                    if (databaseStatistics.LastDocEtag >= 200)
                    {
                        break;
                    }
                    Thread.Sleep(25);
                }

                getStatsCommand = new GetStatisticsCommand();
                store.GetRequestExecuter(store.DefaultDatabase).Execute(getStatsCommand, context);
                databaseStatistics = getStatsCommand.Result;

                Assert.Equal(100, databaseStatistics.CountOfDocuments);
                using (var x = store.OpenSession())
                {
                    var users = x.Load <User>(Enumerable.Range(1, 100).Select(i => "users/" + i));
                    Assert.Equal(100, users.Length);

                    foreach (var user in users)
                    {
                        Assert.NotNull(user.Name);
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public static void WaitForIndexing(IDocumentStore store, string dbName = null, TimeSpan?timeout = null)
        {
            JsonOperationContext jsonOperationContext;
            var requestExecuter = store.GetRequestExecuter(dbName ?? store.DefaultDatabase);

            requestExecuter.ContextPool.AllocateOperationContext(out jsonOperationContext);

            timeout = timeout ?? (Debugger.IsAttached
                          ? TimeSpan.FromMinutes(15)
                          : TimeSpan.FromMinutes(1));


            var sp = Stopwatch.StartNew();

            while (sp.Elapsed < timeout.Value)
            {
                var getStatsCommand = new GetStatisticsCommand();
                requestExecuter.Execute(getStatsCommand, jsonOperationContext);

                var databaseStatistics = getStatsCommand.Result;


                if (databaseStatistics.Indexes.All(x => x.IsStale == false))
                {
                    return;
                }

                if (databaseStatistics.Indexes.Any(x => x.State == IndexState.Error))
                {
                    break;
                }
                Thread.Sleep(32);
            }

            // TODO iftah

            /*var request = databaseCommands.CreateRequest("/indexes/performance", HttpMethod.Get);
             * var perf = request.ReadResponseJson();
             * request = databaseCommands.CreateRequest("/indexes/errors", HttpMethod.Get);
             * var errors = request.ReadResponseJson();
             *
             * var total = new JObject
             * {
             *  ["Errors"] = JObject.Parse(errors.ToString()),
             *  ["Performance"] = JObject.Parse(perf.ToString())
             * };
             *
             * //var total = new RavenJObject
             * //{
             * //    ["Errors"] = errors,
             * //    ["Performance"] = perf
             * //};
             *
             * var file = Path.GetTempFileName() + ".json";
             * using (var writer = File.CreateText(file))
             * {
             *  var jsonTextWriter = new JsonTextWriter(writer);
             *  total.WriteTo(jsonTextWriter);
             *  jsonTextWriter.Flush();
             * }
             *
             * var stats = databaseCommands.GetStatistics();
             *
             * var corrupted = stats.Indexes.Where(x => x.State == IndexState.Error).ToList();
             * if (corrupted.Count > 0)
             * {
             *  throw new InvalidOperationException(
             *      $"The following indexes are with error state: {string.Join(",", corrupted.Select(x => x.Name))} - details at " + file);
             * }
             *
             * throw new TimeoutException("The indexes stayed stale for more than " + timeout.Value + ", stats at " + file);*/
        }