コード例 #1
0
        public void Start_should_check_that_beacon_has_started()
        {
            var zkClient = Substitute.For <IZooKeeperClient>();

            zkClient.CreateAsync(Arg.Any <CreateRequest>()).Returns(Task.FromResult(CreateResult.Unsuccessful(ZooKeeperStatus.AuthFailed, "", null)));

            application = new PortRequiresApplication();
            host        = new VostokHost(
                new TestHostSettings(
                    application,
                    s =>
            {
                SetupEnvironment(s);
                s.SetupZooKeeperClient(zkSetup => zkSetup.UseInstance(zkClient));
                s.SetupServiceBeacon(
                    beaconSetup => beaconSetup.SetupReplicaInfo(
                        replicaInfoSetup => { replicaInfoSetup.SetApplication("auth-test"); }));
            })
            {
                BeaconRegistrationWaitEnabled = true,
                BeaconRegistrationTimeout     = 2.Seconds()
            });

            Action checkStart = () => host.Start();

            checkStart.Should().Throw <Exception>().Where(e => e.Message.Contains("beacon hasn't registered"));

            host.ApplicationState.Should().Be(VostokApplicationState.CrashedDuringInitialization);
        }
コード例 #2
0
        public void Start_should_wait_until_given_state_occurs(VostokApplicationState stateToAwait)
        {
            application = new Application();
            host        = new VostokHost(new TestHostSettings(application, SetupEnvironment));

            host.Start(stateToAwait);
            host.ApplicationState.Should().Match <VostokApplicationState>(state => state >= stateToAwait);

            host.Stop();
            host.ApplicationState.IsTerminal().Should().BeTrue();
        }
コード例 #3
0
        public void Start_should_not_throw_on_run_fail()
        {
            application = new BadApplication(false);
            host        = new VostokHost(new TestHostSettings(application, SetupEnvironment));

            Action checkStart = () => host.Start(VostokApplicationState.Initialized);

            checkStart.Should().NotThrow();

            Action checkStop = () => host.Stop();

            checkStop.Should().Throw <Exception>().WithMessage("run");
        }
コード例 #4
0
        public void Should_not_block_on_dispose_longer_than_shutdown_timeout_allows()
        {
            var app = new DisposableApplication
            {
                DisposeDelay = 10.Seconds()
            };

            var host = new VostokHost(new TestHostSettings(app, SetupEnvironment));

            host.Start();

            var watch = Stopwatch.StartNew();

            host.Stop().State.Should().Be(VostokApplicationState.Exited);

            watch.Elapsed.Should().BeLessThan(2.Seconds());
        }