public ReplicaSetPoolManager(int count, PoolSettings poolSettings) { replicaInfos = Enumerable.Range(0, count).ToDictionary(x => x, x => new ReplicaInfo { Key = new ReplicaKey("replica" + x), IsDead = false }); replicaSetPool = ReplicaSetPool.Create <Item, ItemKey, ReplicaKey>( replicaInfos.Values.Select(x => x.Key).ToArray(), (x, z) => new Pool <Item>(y => CreateReplicaConnection(z, x), new SilentLog()), poolSettings, new SilentLog()); }
private ReplicaSetPool <IThriftConnection, string, IPEndPoint> CreateFierceConnectionPool(ICassandraClusterSettings settings) { var result = ReplicaSetPool.Create <IThriftConnection, string, IPEndPoint>( new[] { settings.EndpointForFierceCommands }, (key, replicaKey) => CreateFiercePool(settings, replicaKey, key), c => ((ThriftConnectionInPoolWrapper)c).ReplicaKey, c => ((ThriftConnectionInPoolWrapper)c).KeyspaceName, settings.ConnectionIdleTimeout, PoolSettings.CreateDefault(), logger); return(result); }
private ReplicaSetPool <IThriftConnection, string, IPEndPoint> CreateDataConnectionPool(ICassandraClusterSettings settings) { var replicaSetPool = ReplicaSetPool.Create <IThriftConnection, string, IPEndPoint>( settings.Endpoints, (key, replicaKey) => GetDataConnectionPool(settings, replicaKey, key), c => ((ThriftConnectionInPoolWrapper)c).ReplicaKey, c => ((ThriftConnectionInPoolWrapper)c).KeyspaceName, settings.ConnectionIdleTimeout, PoolSettings.CreateDefault(), logger); return(replicaSetPool); }
public void TestRemoveUnusedConnection() { using (var pool = ReplicaSetPool.Create <Item, ItemKey, ReplicaKey>(new[] { new ReplicaKey("replica1") }, (x, z) => new Pool <Item>(y => new Item(x, z), new SilentLog()), PoolSettings.CreateDefault(), TimeSpan.FromMilliseconds(100), new SilentLog())) { var item1 = pool.Acquire(null); var item2 = pool.Acquire(null); pool.Release(item1); Thread.Sleep(500); pool.Release(item2); var item3 = pool.Acquire(null); var item4 = pool.Acquire(null); Assert.That(item3, Is.EqualTo(item2)); Assert.That(item4, Is.Not.EqualTo(item1) & Is.Not.EqualTo(item2)); } }