コード例 #1
0
        public override void SetUp()
        {
            base.SetUp();
            clientWorkDir    = CreateTempDir("httpReplicatorTest");
            handlerIndexDir  = NewDirectory();
            serverIndexDir   = NewDirectory();
            mockErrorConfig  = new MockErrorConfig(); // LUCENENET specific
            serverReplicator = new LocalReplicator();
            StartServer();

            IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, null);

            conf.IndexDeletionPolicy = new SnapshotDeletionPolicy(conf.IndexDeletionPolicy);
            writer = new IndexWriter(serverIndexDir, conf);
            reader = DirectoryReader.Open(writer, false);
        }
コード例 #2
0
        /// <summary>
        /// Call this overload to use <see cref="ReplicationServiceMiddleware"/> to host <see cref="ReplicationService"/>.
        /// </summary>
        /// <param name="service">The <see cref="ReplicationService"/> that will be registered as singleton.</param>
        /// <param name="mockErrorConfig">The <see cref="MockErrorConfig"/> that will be registered as singleton.</param>
        /// <returns>A configured <see cref="TestServer"/> instance.</returns>
        public static TestServer NewHttpServer(IReplicationService service, MockErrorConfig mockErrorConfig)
        {
            var builder = new WebHostBuilder()
                          .ConfigureServices(container =>
            {
                container.AddRouting();
                container.AddSingleton(service);
                container.AddSingleton(mockErrorConfig);
                container.AddSingleton <ReplicationServiceMiddleware>();
                container.AddSingleton <MockErrorMiddleware>();
            })
                          .Configure(app =>
            {
                app.UseRouting();

                // Middleware so we can mock a server exception and toggle the exception on and off.
                app.UseMiddleware <MockErrorMiddleware>();

                app.UseEndpoints(endpoints =>
                {
                    // This is to define the endpoint for Replicator.
                    // All URLs with the pattern /replicate/{shard?}/{action?} terminate here and any middleware that
                    // is expected to run for Replicator must be registered before this call.
                    endpoints.MapReplicator(ReplicationService.REPLICATION_CONTEXT + "/{shard?}/{action?}");

                    endpoints.MapGet("/{controller?}/{action?}/{id?}", async context =>
                    {
                        // This is just to demonstrate allowing requests to other services/controllers in the same
                        // application. This isn't required, but is allowed.
                        await context.Response.WriteAsync("Hello World!");
                    });
                });
            });
            var server = new TestServer(builder);

            return(server);
        }
コード例 #3
0
        /// <summary>
        /// Call this overload to use <typeparamref name="TStartUp"/> as the Startup Class.
        /// </summary>
        /// <typeparam name="TStartUp">The type of startup class.</typeparam>
        /// <param name="service">The <see cref="ReplicationService"/> that will be registered as singleton.</param>
        /// <param name="mockErrorConfig">The <see cref="MockErrorConfig"/> that will be registered as singleton.</param>
        /// <returns>A configured <see cref="TestServer"/> instance.</returns>
        public static TestServer NewHttpServer <TStartUp>(IReplicationService service, MockErrorConfig mockErrorConfig) where TStartUp : class
        {
            var builder = new WebHostBuilder()
                          .ConfigureServices(container =>
            {
                container.AddSingleton(service);
                container.AddSingleton(mockErrorConfig);
            })
                          .UseStartup <TStartUp>();

            var server = new TestServer(builder);

            server.BaseAddress = new Uri("http://localhost" + ReplicationService.REPLICATION_CONTEXT);
            return(server);
        }
コード例 #4
0
 public MockErrorMiddleware(RequestDelegate next, MockErrorConfig mockErrorConfig)
 {
     this.next            = next ?? throw new ArgumentNullException(nameof(next));
     this.mockErrorConfig = mockErrorConfig ?? throw new ArgumentNullException(nameof(mockErrorConfig));
 }