Ejemplo n.º 1
0
        public void SnQuery_Result_Int()
        {
            var intResults = new Dictionary <string, QueryResult <int> > {
                { "asdf", new QueryResult <int>(new[] { 1, 2, 3 }, 4) }
            };
            var context = new TestQueryContext(QuerySettings.AdminSettings, 0, _indexingInfo, new TestQueryEngine(intResults, null));

            using (Tools.Swindle(typeof(SnQuery), "_permissionFilterFactory", new EverythingAllowedPermissionFilterFactory()))
            {
                var queryText = "asdf";

                var result = SnQuery.Query(queryText, context);

                var expected = string.Join(", ", intResults[queryText].Hits.Select(x => x.ToString()).ToArray());
                var actual   = string.Join(", ", result.Hits.Select(x => x.ToString()).ToArray());
                Assert.AreEqual(actual, expected);
                Assert.AreEqual(result.TotalCount, intResults[queryText].TotalCount);
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            args = new[] { TestType.Backup.ToString() };

            if (args.Length == 0)
            {
                Console.WriteLine("Missing test type. Expected 'Backup', 'Restore', 'Validity' or 'Cancellation'.");
                return;
            }
            if (!Enum.TryParse <TestType>(args[0], true, out _testType))
            {
                Console.WriteLine("Invalid test type. Expected 'Backup', 'Restore' or 'Validity'.");
                return;
            }

            _serviceIndexDirectory = Path.GetFullPath($"{Environment.CurrentDirectory}\\..\\..\\..\\..\\..\\" +
                                                      //"SenseNet.Search.Lucene29.Centralized.Service\\" +
                                                      "SenseNet.Search.Lucene29.Centralized.GrpcService\\" +
                                                      "bin\\Debug\\netcoreapp3.1\\App_Data\\LocalIndex");
            Console.WriteLine("IndexDirectory of the service: ");
            Console.WriteLine(_serviceIndexDirectory);

            _backupIndexDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data", "IndexBackup");
            Console.WriteLine("Backup directory: ");
            Console.WriteLine(_backupIndexDirectory);

            IConfiguration configuration = new ConfigurationBuilder()
                                           .AddJsonFile("appsettings.json", true, true)
                                           .AddEnvironmentVariables()
                                           .Build();

            //var serviceBinding = new NetTcpBinding { Security = { Mode = SecurityMode.None } };
            //var serviceEndpoint = new EndpointAddress(configuration["sensenet:search:service:address"]);
            //WaitForServiceStarted(serviceBinding, serviceEndpoint);

            var sender = new MessageSenderManager();

            var builder = new RepositoryBuilder()
                          .SetConsole(Console.Out)
                          .UseLogger(new SnFileSystemEventLogger())
                          .UseTracer(new SnFileSystemTracer())
                          .UseConfiguration(configuration)
                          .UseDataProvider(new MsSqlDataProvider(Options.Create(ConnectionStringOptions.GetLegacyConnectionStrings())))
                          .UseSecurityDataProvider(new EFCSecurityDataProvider(sender,
                                                                               Options.Create(new SenseNet.Security.EFCSecurityStore.Configuration.DataOptions()
            {
                ConnectionString = ConnectionStrings.ConnectionString
            }),
                                                                               NullLogger <EFCSecurityDataProvider> .Instance))
                          .UseSecurityMessageProvider(new RabbitMQMessageProvider(sender,
                                                                                  Options.Create(new MessagingOptions()),
                                                                                  Options.Create(new RabbitMqOptions())))
                          .UseLucene29CentralizedSearchEngineWithGrpc(configuration["sensenet:search:service:address"], options =>
            {
                // trust the server in a development environment
                options.HttpClient = new HttpClient(new HttpClientHandler
                {
                    ServerCertificateCustomValidationCallback = (message, certificate2, arg3, arg4) => true
                });
                options.DisposeHttpClient = true;
            })
                          .StartWorkflowEngine(false)
                          .DisableNodeObservers()
                          .UseTraceCategories(SnTrace.Categories.Select(x => x.Name).ToArray()) as RepositoryBuilder;

            using (Repository.Start(builder))
            {
                Console.WriteLine("CHECK SQL SERVER CONNECTIVITY (query top level nodes):");
                var root = Node.LoadNode(Repository.RootPath);
                foreach (var node in NodeQuery.QueryChildren(Repository.RootPath).Nodes)
                {
                    Console.WriteLine(node.Path);
                }
                Console.WriteLine();

                Console.WriteLine("CHECK SEARCH SERVER CONNECTIVITY (query top level nodes):");
                var queryContext = new SnQueryContext(QuerySettings.AdminSettings, User.Current.Id);
                var result       = SnQuery.Query("InFolder:/Root", queryContext);
                foreach (var id in result.Hits)
                {
                    Console.WriteLine(NodeHead.Get(id).Path);
                }
                Console.WriteLine();

                SnTrace.EnableAll();

                var engine = (ILuceneIndexingEngine)Providers.Instance.SearchEngine.IndexingEngine;
                switch (_testType)
                {
                case TestType.Backup:
                    new ContinuousIndexTest(engine).RunAsync(CancellationToken.None)
                    .ConfigureAwait(false).GetAwaiter().GetResult();
                    break;

                case TestType.Restore:
                    new RestoreTest(engine).RunAsync(CancellationToken.None)
                    .ConfigureAwait(false).GetAwaiter().GetResult();
                    break;

                case TestType.Validity:
                    new ValidityTest(engine).RunAsync(CancellationToken.None)
                    .ConfigureAwait(false).GetAwaiter().GetResult();
                    break;

                case TestType.Cancellation:
                    new CancellationTest(engine).RunAsync(CancellationToken.None)
                    .ConfigureAwait(false).GetAwaiter().GetResult();
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                // Shut down the service to leave the index.
                IndexManager.IndexingEngine.ShutDownAsync(CancellationToken.None)
                .ConfigureAwait(false).GetAwaiter().GetResult();
            }
        }