public void ShouldPublishAndRemoveShardletConnection()
        {
            //assemble
            var driver = new AzureShardSetConnectionDriver();

            var shardingKey = 1.ToString(CultureInfo.InvariantCulture);
            var shardlet    = GetShardlet(shardingKey);

            // act
            driver.PublishShardletConnection(shardlet, 1);
            driver.PublishShardletConnection(shardlet, 2);

            var spids = driver.GetConnectedSpids(shardlet).ToArray();

            Assert.AreEqual(2, spids.Count());
            Assert.AreEqual(1, spids.First());
            Assert.AreEqual(2, spids.Last());

            driver.RemoveShardletConnection(shardlet, 1);

            spids = driver.GetConnectedSpids(shardlet).ToArray();

            Assert.AreEqual(1, spids.Count());
            Assert.AreEqual(2, spids.First());
        }
        public void ShouldPublishAndTerminate100ShardletConnectionsBySpid()
        {
            //assemble
            var driver = new AzureShardSetConnectionDriver();

            var shardingKey = 1.ToString(CultureInfo.InvariantCulture);
            var shardlet    = GetShardlet(shardingKey);

            // act

            // publish connections - avoid connections under 500 for testing
            // don't want to KILL core processes in SQL Server
            const int   numberOfConnections = 210;
            const short startSpid           = 500;
            const short endSpid             = 500 + numberOfConnections - 1;

            for (var i = startSpid; i <= endSpid; i++)
            {
                driver.PublishShardletConnection(shardlet, i);
            }

            var spids = driver.GetConnectedSpids(shardlet).OrderBy(spid => spid).ToArray();

            Assert.AreEqual(numberOfConnections, spids.Count());
            Assert.AreEqual(startSpid, spids.First());
            Assert.AreEqual(endSpid, spids.Last());

            driver.TerminateConnections(shardlet);

            spids = driver.GetConnectedSpids(shardlet).ToArray();

            Assert.AreEqual(0, spids.Count());
        }
        public void ShouldPublishAndRemoveOver100ShardletConnectionsByUtcDateTime()
        {
            //assemble
            var driver = new AzureShardSetConnectionDriver();

            var shardingKey = 1.ToString(CultureInfo.InvariantCulture);
            var shardlet    = GetShardlet(shardingKey);

            // act
            const int   numberOfConnections = 210;
            const short startSpid           = 500;
            const short endSpid             = 500 + numberOfConnections - 1;

            for (var i = startSpid; i <= endSpid; i++)
            {
                driver.PublishShardletConnection(shardlet, i);
            }

            var spids = driver.GetConnectedSpids(shardlet).OrderBy(spid => spid).ToArray();

            Assert.AreEqual(numberOfConnections, spids.Count());
            Assert.AreEqual(startSpid, spids.First());
            Assert.AreEqual(endSpid, spids.Last());

            Thread.Sleep(10000);

            driver.RemoveConnections(shardlet.ShardSetName, DateTime.UtcNow);

            spids = driver.GetConnectedSpids(shardlet).ToArray();

            Assert.AreEqual(0, spids.Count());
        }