public void When_Replica_Index_Postive_LocatePrimary_Returns_It() { var mockBucketConfig = new Mock <IBucketConfig>(); var server = new Server( new FakeIOService(IPEndPointExtensions.GetEndPoint("127.0.0.1:8091"), new FakeConnectionPool(), false), new NodeAdapter(new Node { Hostname = "127.0.0.1" }, new NodeExt(), mockBucketConfig.Object), new FakeTranscoder(), ContextFactory.GetCouchbaseContext()); var vbucket = new VBucket(new Dictionary <IPEndPoint, IServer> { { IPEndPointExtensions.GetEndPoint("127.0.0.1:10210"), server }, { IPEndPointExtensions.GetEndPoint("127.0.0.2:10210"), server } }, 100, -1, new[] { 0 }, 0, new VBucketServerMap { ServerList = new[] { "127.0.0.1:10210", "127.0.0.2:10210" } }, "default"); var found = vbucket.LocatePrimary(); Assert.IsNotNull(found); }
public void When_Replica_Index_Postive_LocatePrimary_Returns_It() { var server = new Server( new FakeIOService(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 Setup() { using (var stream = File.Open(@"Data\\Configs\\cluster-map.json", FileMode.Open)) { using (var reader = new StreamReader(stream)) { _clusterMap = JsonConvert.DeserializeObject<ClusterMap>(reader.ReadToEnd()); } } var vBucketServerMap = _clusterMap.VBucketServerMap; var servers = vBucketServerMap. ServerList.Select(server => new Node(server)). Cast<INode>(). ToList(); var vBuckets = new Dictionary<int, IVBucket>(); for (var i = 0; i < vBucketServerMap.VBucketMap.Length; i++) { var primary = vBucketServerMap.VBucketMap[i][0]; var replica = vBucketServerMap.VBucketMap[i][1]; var vBucket = new VBucket(servers, i, primary, replica); vBuckets[i] = vBucket; } _defaultConfig = new DefaultConfig(new Crc32(), servers, vBuckets); }
public void When_Replica_Index_1_LocatePrimary_Returns_Random_Server() { var vbucket = new VBucket(new List <IServer> { }, 100, -1, new[] { 0 }); var found = vbucket.LocatePrimary(); Assert.IsNull(found);//should be null }
public void When_Replica_Index_Positive_LocatePrimary_Returns_It() { var(vBucketServerMap, ipEndPoints) = GetServerMapAndIpEndPoints("127.0.0.1:10210", "127.0.0.2:10210"); var vBucket = new VBucket(ipEndPoints, 100, -1, new short[] { 0 }, 0, vBucketServerMap, "default", new Mock <ILogger <VBucket> >().Object); var found = vBucket.LocatePrimary(); Assert.NotNull(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_Replica_Index_Negative_LocatePrimary_Returns_Random_Server() { var vBucketServerMap = GetServerMap("127.0.0.1:10210"); var vBucket = new VBucket(vBucketServerMap.EndPoints, 100, -1, new short[] { -1 }, 0, vBucketServerMap, "default", new Mock <ILogger <VBucket> >().Object); var found = vBucket.LocatePrimary(); Assert.NotNull(found); }
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_Replica_Index_1_LocatePrimary_Returns_Random_Server() { var(vBucketServerMap, ipEndPoints) = GetServerMapAndIpEndPoints(); var vBucket = new VBucket(ipEndPoints, 100, -1, new short[] { 0 }, 0, vBucketServerMap, "default", new Mock <ILogger <VBucket> >().Object); var found = vBucket.LocatePrimary(); Assert.Null(found);//should be null }
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_1_LocatePrimary_Returns_Random_Server() { var vbucket = new VBucket(new List <IPEndPoint> { }, 100, -1, new short[] { 0 }, 0, new VBucketServerMap { ServerList = new [] { "127.0.0.1:10210" } }, "default"); var found = vbucket.LocatePrimary(); Assert.Null(found);//should be null }
public void When_Replica_Index_Negative_LocatePrimary_Returns_Random_Server() { var server = new Server(null, new Node { Hostname = "127.0.0.1" }, new ClientConfiguration()); var vbucket = new VBucket(new List <IServer> { server, server }, 100, -1, new[] { -1 }); var found = vbucket.LocatePrimary(); Assert.IsNotNull(found); }
public void When_Replica_Index_OOR_LocatePrimary_Returns_Random_Server() { var server = new Server(null, new NodeAdapter(new Node { Hostname = "127.0.0.1" }, new NodeExt()), new ClientConfiguration(), new BucketConfig { Name = "default" }); var vbucket = new VBucket(new List <IServer> { server, server }, 100, -1, new [] { 2 }); var found = vbucket.LocatePrimary(); Assert.IsNotNull(found); }
public void When_Replica_Index_Postive_LocatePrimary_Returns_It() { var vbucket = new VBucket(new List <IPEndPoint> { IpEndPointExtensions.GetEndPoint("127.0.0.1:10210"), IpEndPointExtensions.GetEndPoint("127.0.0.2:10210") }, 100, -1, new short[] { 0 }, 0, new VBucketServerMap { ServerList = new[] { "127.0.0.1:10210", "127.0.0.2:10210" } }, "default"); var found = vbucket.LocatePrimary(); Assert.NotNull(found); }
public void When_Replica_Index_Negative_LocatePrimary_Returns_Random_Server() { var vbucket = new VBucket(new List <IPEndPoint> { IpEndPointExtensions.GetEndPoint("127.0.0.1:10210"), IpEndPointExtensions.GetEndPoint("127.0.0.2:10210") }, 100, -1, new short[] { -1 }, 0, new VBucketServerMap { ServerList = new[] { "127.0.0.1:10210" } }, "default", new Mock <ILogger <VBucket> >().Object); var found = vbucket.LocatePrimary(); Assert.NotNull(found); }
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); }
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()); }
void CreateConfig() { var vBucketServerMap = _clusterMap.VBucketServerMap; var servers = vBucketServerMap. ServerList.Select(CreateServer). ToList(); var vBuckets = new Dictionary<int, IVBucket>(); for (var i = 0; i < vBucketServerMap.VBucketMap.Length; i++) { var primary = vBucketServerMap.VBucketMap[i][0]; var replica = vBucketServerMap.VBucketMap[i][1]; var vBucket = new VBucket(servers, i, primary, replica); vBuckets[i] = vBucket; //Console.WriteLine("Index=>{0} : [{1}, {2}]", i, primary, replica); } //TODO make injectable via Func<>? _configInfo = new DefaultConfig(new Crc32(), servers, vBuckets); }