public void When_No_Replicas_Are_Found_GetReplicas_Returns_Empty_List()
 {
     var vBucket = new VBucket(null, 0, 0, new[] { -1, -1, -1 });
     var expected = new int[] {};
     var observer = new KeyObserver(null, 10, 500);
     var actual = observer.GetReplicas(vBucket, ReplicateTo.One, PersistTo.Two);
     Assert.AreEqual(expected, actual);
     Assert.AreEqual(expected.Count(), actual.Count());
 }
 public void When_PersistTo_Is_Greater_Than_ReplicateTo_Length_Of_Replicas_Is_PersistTo()
 {
     var vBucket = new VBucket(null, 0, 0, new[] { 0, 2, 1 });
     var expected = new[] { 0, 2 };
     var observer = new KeyObserver(null, 10, 500);
     var actual = observer.GetReplicas(vBucket, ReplicateTo.One, PersistTo.Two);
     Assert.AreEqual(expected, actual);
     Assert.AreEqual(actual.Count, (int)PersistTo.Two);
 }
        public void When_Replica_Index_Postive_LocatePrimary_Returns_It()
        {
            var server = new Server(
                new FakeIOStrategy(IPEndPointExtensions.GetEndPoint("127.0.0.1:8091"),
                new FakeConnectionPool(), false),
                new NodeAdapter(new Node { Hostname = "127.0.0.1" },
                new NodeExt()),
                new ClientConfiguration(),
                new BucketConfig { Name = "default" },
                new FakeTranscoder());

            var vbucket =
                new VBucket(new Dictionary<IPAddress, IServer>
                {
                    {IPEndPointExtensions.GetEndPoint("127.0.0.1:10210").Address, server},
                    {IPEndPointExtensions.GetEndPoint("127.0.0.2:10210").Address, server}
                },
                100, -1, new[] { 0 }, 0, new VBucketServerMap { ServerList = new[] { "127.0.0.1:10210", "127.0.0.2:10210" } });
            var found = vbucket.LocatePrimary();
            Assert.IsNotNull(found);
        }
 public void When_Replica_Index_1_LocatePrimary_Returns_Random_Server()
 {
     var vbucket = new VBucket(new Dictionary<IPAddress, IServer>{}, 100, -1, new[] { 0 }, 0, new VBucketServerMap{ ServerList = new []{ "127.0.0.1:10210" }});
     var found = vbucket.LocatePrimary();
     Assert.IsNull(found);//should be null
 }
        public void When_No_Replicas_Are_Found_GetReplicas_Returns_Empty_List()
        {
            var vBucket = new VBucket(null, 0, 0, new[] { -1, -1, -1 }, 0, new VBucketServerMap { ServerList = new string[] { } }, "default");
            var expected = new int[] {};

            var clusterController = new Mock<IClusterController>();
            clusterController.Setup(x => x.Transcoder).Returns(new DefaultTranscoder());
            var pending = new ConcurrentDictionary<uint, IOperation>();
            var observer = new KeyObserver(pending, null, clusterController.Object, 10, 500);

            var actual = observer.GetReplicas(vBucket, ReplicateTo.One, PersistTo.Two);

            Assert.AreEqual(expected, actual);
            Assert.AreEqual(expected.Count(), actual.Count());
        }
        public void When_PersistTo_Is_Greater_Than_ReplicateTo_Length_Of_Replicas_Is_PersistTo()
        {
            var vBucket = new VBucket(null, 0, 0, new[] { 0, 2, 1 }, 0, new VBucketServerMap { ServerList = new string[] { } }, "default");
            var expected = new[] { 0, 2 };

            var clusterController = new Mock<IClusterController>();
            clusterController.Setup(x => x.Transcoder).Returns(new DefaultTranscoder());
            var pending = new ConcurrentDictionary<uint, IOperation>();
            var observer = new KeyObserver(pending, null, clusterController.Object, 10, 500);

            var actual = observer.GetReplicas(vBucket, ReplicateTo.One, PersistTo.Two);

            Assert.AreEqual(expected, actual);
            Assert.AreEqual(actual.Count, (int)PersistTo.Two);
        }