public void ConnectionStringProvider_from_string_provider()
        {
            var str      = "localhost:56736,localhost:56739,localhost:56742";
            var settings = new ZooKeeperClientSettings(() => str);

            settings.ConnectionStringProvider().Should().Be(str);
        }
        public void GetConnectedClient_should_reconnect_to_new_ensemble_after_timeout()
        {
            using (var ensemble1 = ZooKeeperEnsemble.DeployNew(10, 1, Log))
            {
                var connectionString = ensemble1.ConnectionString;
                // ReSharper disable once AccessToModifiedClosure
                var settings = new ZooKeeperClientSettings(() => connectionString)
                {
                    Timeout = DefaultTimeout
                };

                var holder = new ClientHolder(settings, Log);
                WaitForNewConnectedClient(holder);

                ensemble1.Dispose();
                WaitForDisconnectedState(holder);

                using (var ensemble2 = ZooKeeperEnsemble.DeployNew(11, 1, Log))
                {
                    ensemble2.ConnectionString.Should().NotBe(connectionString);
                    connectionString = ensemble2.ConnectionString;

                    Thread.Sleep(DefaultTimeout);

                    WaitForNewConnectedClient(holder);
                }
            }
        }
        public void ConnectionStringProvider_from_replicas_provider()
        {
            var str      = "http://localhost:56736/,http://localhost:56739/,http://localhost:56742/";
            var replicas = str.Split(',').Select(x => new Uri(x)).ToArray();
            var settings = new ZooKeeperClientSettings(() => replicas);

            settings.ConnectionStringProvider().Should().Be("localhost:56736,localhost:56739,localhost:56742");
        }
 public void Setup()
 {
     settings = new ZooKeeperClientSettings("127.0.0.1:4222")
     {
         CanBeReadOnly = false,
         Timeout       = 13.Seconds()
     };
 }
Beispiel #5
0
        protected ZooKeeperClient GetClient(TimeSpan?timeout = null)
        {
            var settings = new ZooKeeperClientSettings(Ensemble.ConnectionString)
            {
                Timeout = timeout ?? DefaultTimeout, LoggingLevel = LogLevel.Debug
            };

            return(new ZooKeeperClient(settings, Log));
        }
Beispiel #6
0
        protected ClientHolder GetClientHolder(string connectionString, TimeSpan?timeout = null)
        {
            var settings = new ZooKeeperClientSettings(connectionString)
            {
                Timeout = timeout ?? DefaultTimeout, LoggingLevel = LogLevel.Debug
            };

            return(new ClientHolder(settings, Log));
        }
Beispiel #7
0
        public ClientHolder(ZooKeeperClientSettings settings, ILog log)
        {
            this.log      = log;
            this.settings = settings;

            state = new ClientHolderState(null, null, ConnectionState.Disconnected, null);

            ZooKeeperLogInjector.Register(this, this.log);
        }
Beispiel #8
0
        protected ZooKeeperClient GetZooKeeperClient()
        {
            var settings = new ZooKeeperClientSettings(Ensemble.ConnectionString)
            {
                Timeout = DefaultTimeout
            };

            return(new ZooKeeperClient(settings, Log));
        }
Beispiel #9
0
        public ClientHolder(ZooKeeperClientSettings settings, ILog log)
        {
            this.log      = log;
            this.settings = settings;

            state            = ClientHolderState.CreateActive(null, null, ConnectionState.Disconnected, null, settings);
            suspendedManager = new SuspendedManager(settings.Timeout, settings.Timeout.Multiply(settings.MaximumConnectPeriodMultiplier), -3);

            ZooKeeperLogInjector.Register(this, this.log);
        }
        public void Should_work_with_uri_provider()
        {
            var settings = new ZooKeeperClientSettings(() => Ensemble.Topology)
            {
                Timeout = DefaultTimeout
            };

            var holder = new ClientHolder(settings, Log);

            WaitForNewConnectedClient(holder);

            holder.ConnectionState.Should().Be(ConnectionState.Connected);
            holder.SessionId.Should().NotBe(0);
        }
 public static ClientHolderState CreateActive(
     Lazy <ZooKeeperNetExClient> client,
     IConnectionWatcher connectionWatcher,
     ConnectionState connectionState,
     string connectionString,
     ZooKeeperClientSettings settings) =>
 new ClientHolderState(
     false,
     connectionState.IsConnected(settings.CanBeReadOnly),
     client,
     connectionWatcher,
     connectionState,
     connectionString,
     TimeBudget.StartNew(settings.Timeout));
Beispiel #12
0
        public static ClientHolderState CreateActiveClientHolderState(ZooKeeperClientSettings settings)
        {
            var connectionString  = settings.ConnectionStringProvider();
            var connectionWatcher = new ConnectionWatcher(_ => {});

            var client = new Lazy <ZooKeeperNetExClient>(
                () =>
            {
                using (ExecutionContext.SuppressFlow())
                {
                    return(new ZooKeeperNetExClient(
                               connectionString,
                               settings.ToInnerConnectionTimeout(),
                               connectionWatcher,
                               settings.CanBeReadOnly));
                }
            },
                LazyThreadSafetyMode.ExecutionAndPublication);

            return(ClientHolderState.CreateActive(client, connectionWatcher, ConnectionState.Connected, connectionString, settings));
        }
 public static int ToInnerConnectionTimeout(this ZooKeeperClientSettings settings) => (int)settings.Timeout.TotalMilliseconds;
 public bool NeedToResetClient(ZooKeeperClientSettings settings)
 {
     return(Client == null ||
            !ConnectionState.IsConnected(settings.CanBeReadOnly) && DateTime.UtcNow - stateChanged > settings.Timeout ||
            ConnectionString != settings.ConnectionStringProvider());
 }
 public ClientHolderState WithConnectionState(ConnectionState newConnectionState, ZooKeeperClientSettings settings) =>
 new ClientHolderState(
     IsSuspended,
     newConnectionState.IsConnected(settings.CanBeReadOnly),
     lazyClient,
     ConnectionWatcher,
     newConnectionState,
     ConnectionString,
     TimeBudget.StartNew(settings.Timeout));