public void When_BucketConfig_Has_Replicas_VBucketKeyMapper_LocateReplica_Returns_Correct_Server() { var json = File.ReadAllText(@"Data\\Configuration\\config-with-replicas-complete.json"); var bucketConfig = JsonConvert.DeserializeObject <BucketConfig>(json); var servers = new Dictionary <IPAddress, IServer>(); foreach (var node in bucketConfig.GetNodes()) { servers.Add(node.GetIPAddress(), new Server(new FakeIOService(node.GetIPEndPoint(), new FakeConnectionPool(), false), node, new ClientConfiguration(), bucketConfig, new FakeTranscoder())); } var mapper = new VBucketKeyMapper(servers, bucketConfig.VBucketServerMap, bucketConfig.Rev); var vBucket = (IVBucket)mapper.MapKey("somekey"); foreach (var index in vBucket.Replicas) { var server = vBucket.LocateReplica(index); Assert.IsNotNull(server); var expected = bucketConfig.VBucketServerMap.ServerList[index]; Assert.AreEqual(server.EndPoint.Address.ToString(), expected.Split(':').First()); } }
public void When_Primary_Is_Negative_Random_Server_Returned() { var json = File.ReadAllText(@"Data\\Configuration\\config-with-negative-one-primary.json"); var bucketConfig = JsonConvert.DeserializeObject <BucketConfig>(json); var servers = new Dictionary <IPAddress, IServer>(); foreach (var node in bucketConfig.GetNodes()) { servers.Add(node.GetIPAddress(), new Server(new FakeIOStrategy(node.GetIPEndPoint(), new FakeConnectionPool(), false), node, new ClientConfiguration(), bucketConfig, new FakeTranscoder())); } var mapper = new VBucketKeyMapper(servers, bucketConfig.VBucketServerMap, bucketConfig.Rev); //maps to -1 primary const string key = "somekey0"; var vBucket = (IVBucket)mapper.MapKey(key); Assert.AreEqual(-1, vBucket.Primary); var primary = vBucket.LocatePrimary(); Assert.IsNotNull(primary); }
public void When_BucketConfig_Has_Replicas_VBucketKeyMapper_Replicas_Are_Equal() { var json = File.ReadAllText(@"Data\\Configuration\\config-with-replicas-complete.json"); var bucketConfig = JsonConvert.DeserializeObject <BucketConfig>(json); var servers = new Dictionary <IPAddress, IServer>(); foreach (var node in bucketConfig.GetNodes()) { servers.Add(node.GetIPAddress(), new Server(new FakeIOService(node.GetIPEndPoint(), new FakeConnectionPool(), false), node, new ClientConfiguration(), bucketConfig, new FakeTranscoder())); } var mapper = new VBucketKeyMapper(servers, bucketConfig.VBucketServerMap, bucketConfig.Rev); var vBucket = (IVBucket)mapper.MapKey("somekey"); var index = mapper.GetIndex("somekey"); var expected = bucketConfig.VBucketServerMap.VBucketMap[index]; for (var i = 0; i < vBucket.Replicas.Length; i++) { Assert.AreEqual(vBucket.Replicas[i], expected[i + 1]); } }
public void TestMapKey() { IKeyMapper mapper = new VBucketKeyMapper(_servers, _vBucketServerMap, _bucketConfig.Rev, _bucketConfig.Name); var vBucket = mapper.MapKey(Key); Assert.IsNotNull(vBucket); }
public void When_Primary_Index_Is_Greater_Than_Cluster_Count_Random_Server_Returned() { var json = File.ReadAllText(@"Data\\Configuration\\config-with-negative-one-primary.json"); var bucketConfig = JsonConvert.DeserializeObject <BucketConfig>(json); var servers = new Dictionary <IPAddress, IServer>(); foreach (var node in bucketConfig.GetNodes()) { servers.Add(node.GetIPAddress(), new Server(new FakeIOService(node.GetIPEndPoint(), new FakeConnectionPool(), false), node, new ClientConfiguration(), bucketConfig, new FakeTranscoder())); } //remove one server servers.Remove(_vBucketServerMap.IPEndPoints.Skip(1).First().Address); var mapper = new VBucketKeyMapper(servers, bucketConfig.VBucketServerMap, bucketConfig.Rev); //maps to -1 primary const string key = "somekey23"; var vBucket = (IVBucket)mapper.MapKey(key); var primary = vBucket.LocatePrimary(); Assert.IsNotNull(primary); }
public void VBucket_HasCorrectBucketname() { var expected = "travel-sample"; IKeyMapper mapper = new VBucketKeyMapper(_servers, _vBucketServerMap, _bucketConfig.Rev, expected); var vBucket = (IVBucket)mapper.MapKey(Key); Assert.AreEqual(expected, vBucket.BucketName); }
public void Test_That_Key_XXXXX_Maps_To_VBucket_389() { const int actual = 389; IKeyMapper mapper = new VBucketKeyMapper(_servers, _vBucketServerMap, _bucketConfig.Rev, _bucketConfig.Name); var vBucket = (IVBucket)mapper.MapKey(Key); Assert.AreEqual(vBucket.Index, actual); }
public void TestMapKey(int index, string key) { var config = ResourceHelper.ReadResource <BucketConfig>(@"Documents\config.json"); IKeyMapper mapper = new VBucketKeyMapper(config, new VBucketFactory(new Mock <ILogger <VBucket> >().Object)); var vBucket = (VBucket)mapper.MapKey(key); Assert.Equal(index, vBucket.Index); }
public void Test_That_Key_XXXXX_Maps_To_VBucket_389() { const int actual = 389; var config = ResourceHelper.ReadResource <BucketConfig>(@"Documents\config.json"); IKeyMapper mapper = new VBucketKeyMapper(config, new VBucketFactory(new Mock <ILogger <VBucket> >().Object)); var vBucket = (IVBucket)mapper.MapKey(Key); Assert.Equal(vBucket.Index, actual); }
public void TestMapKey(int index, string key) { var config = ResourceHelper.ReadResource <BucketConfig>(@"Documents\config.json"); IKeyMapper mapper = new VBucketKeyMapper(config); var vBucket = (VBucket)mapper.MapKey(key); Assert.Equal(index, vBucket.Index); }
public void VBucket_HasCorrectBucketname() { var expected = "default"; var config = ResourceHelper.ReadResource <BucketConfig>(@"Documents\config.json"); IKeyMapper mapper = new VBucketKeyMapper(config, new VBucketFactory(new Mock <ILogger <VBucket> >().Object)); var vBucket = (IVBucket)mapper.MapKey(Key); Assert.Equal(expected, vBucket.BucketName); }
public void VBucket_Supports_LocalHost() { var expected = "default"; var config = ResourceHelper.ReadResource <BucketConfig>(@"Documents\configs\config-localhost.json"); config.ReplacePlaceholderWithBootstrapHost(new Uri("http://127.0.0.1")); IKeyMapper mapper = new VBucketKeyMapper(config, new VBucketFactory(new Mock <ILogger <VBucket> >().Object)); var vBucket = (IVBucket)mapper.MapKey(Key); Assert.Equal(expected, vBucket.BucketName); }
public void When_BucketConfig_Has_Replicas_VBucketKeyMapper_Replica_Count_Is_Equal() { var json = ResourceHelper.ReadResource(@"Data\Configuration\config-with-replicas-complete.json"); var bucketConfig = JsonConvert.DeserializeObject <BucketConfig>(json); var mapper = new VBucketKeyMapper(bucketConfig, new VBucketFactory(new Mock <ILogger <VBucket> >().Object)); var vBucket = (IVBucket)mapper.MapKey("somekey"); const int expected = 3; Assert.Equal(expected, vBucket.Replicas.Count()); }
public void TestMapKey(int index, string key) { var config = ResourceHelper.ReadResource(@"Documents\config.json", InternalSerializationContext.Default.BucketConfig); var vBucketServerMap = new VBucketServerMap(config.VBucketServerMap); IKeyMapper mapper = new VBucketKeyMapper(config, vBucketServerMap, new VBucketFactory(new Mock <ILogger <VBucket> >().Object)); var vBucket = (VBucket)mapper.MapKey(key); Assert.Equal(index, vBucket.Index); }
public void Config_With_FFMaps_Uses_Them_When_NMVB(string nodeIp, ResponseStatus responseStatus) { var config = ResourceHelper.ReadResource <BucketConfig>(@"Documents\configs\config-with-ffmaps.json"); var(vBucketServerMap, _) = GetServerMapAndIpEndPoints(config.VBucketServerMap); IKeyMapper mapper = new VBucketKeyMapper(config, vBucketServerMap, new VBucketFactory(new Mock <ILogger <VBucket> >().Object)); var vBucket = (IVBucket)mapper.MapKey(Key); var op = new Get <dynamic>() { Header = new OperationHeader { Status = responseStatus } }; var mappedKey = mapper.MapKey("mykey", op.WasNmvb()); Assert.Equal(nodeIp, mappedKey.LocatePrimary().ToString()); }
public void Test_That_Key_XXXXX_Maps_To_VBucket_389() { const int actual = 389; var config = ResourceHelper.ReadResource(@"Documents\config.json", InternalSerializationContext.Default.BucketConfig); var vBucketServerMap = new VBucketServerMap(config.VBucketServerMap); IKeyMapper mapper = new VBucketKeyMapper(config, vBucketServerMap, new VBucketFactory(new Mock <ILogger <VBucket> >().Object)); var vBucket = (IVBucket)mapper.MapKey(Key); Assert.Equal(vBucket.Index, actual); }
public void When_BucketConfig_Has_Replicas_VBucketKeyMapper_Replica_Count_Is_Equal() { var bucketConfig = ResourceHelper.ReadResource(@"Data\Configuration\config-with-replicas-complete.json", InternalSerializationContext.Default.BucketConfig); var vBucketServerMap = GetServerMap(bucketConfig.VBucketServerMap); var mapper = new VBucketKeyMapper(bucketConfig, vBucketServerMap, new VBucketFactory(new Mock <ILogger <VBucket> >().Object)); var vBucket = (IVBucket)mapper.MapKey("somekey"); const int expected = 3; Assert.Equal(expected, vBucket.Replicas.Count()); }
public void VBucket_HasCorrectBucketname() { var expected = "default"; var config = ResourceHelper.ReadResource(@"Documents\config.json", InternalSerializationContext.Default.BucketConfig); var vBucketServerMap = new VBucketServerMap(config.VBucketServerMap); IKeyMapper mapper = new VBucketKeyMapper(config, vBucketServerMap, new VBucketFactory(new Mock <ILogger <VBucket> >().Object)); var vBucket = (IVBucket)mapper.MapKey(Key); Assert.Equal(expected, vBucket.BucketName); }
public void When_BucketConfig_Has_Replicas_VBucketKeyMapper_Replicas_Are_Equal() { var json = ResourceHelper.ReadResource(@"Data\Configuration\config-with-replicas-complete.json"); var bucketConfig = JsonConvert.DeserializeObject <BucketConfig>(json); var mapper = new VBucketKeyMapper(bucketConfig, new VBucketFactory(new Mock <ILogger <VBucket> >().Object)); var vBucket = (IVBucket)mapper.MapKey("somekey"); var index = mapper.GetIndex("somekey"); var expected = bucketConfig.VBucketServerMap.VBucketMap[index]; for (var i = 0; i < vBucket.Replicas.Length; i++) { Assert.Equal(vBucket.Replicas[i], expected[i + 1]); } }
public void VBucket_Supports_LocalHost() { var expected = "default"; var config = ResourceHelper.ReadResource(@"Documents\configs\config-localhost.json", InternalSerializationContext.Default.BucketConfig); config.ReplacePlaceholderWithBootstrapHost("127.0.0.1"); var vBucketServerMap = new VBucketServerMap(config.VBucketServerMap); IKeyMapper mapper = new VBucketKeyMapper(config, vBucketServerMap, new VBucketFactory(new Mock <ILogger <VBucket> >().Object)); var vBucket = (IVBucket)mapper.MapKey(Key); Assert.Equal(expected, vBucket.BucketName); }
public void When_BucketConfig_Has_Replicas_VBucketKeyMapper_Replica_Count_Is_Equal() { var json = File.ReadAllText(@"Data\\Configuration\\config-with-replicas-complete.json"); var bucketConfig = JsonConvert.DeserializeObject <BucketConfig>(json); var servers = bucketConfig.VBucketServerMap. ServerList. Select(server => new Server(ObjectFactory.CreateIOStrategy(server), new Node(), new ClientConfiguration())). Cast <IServer>(). ToList(); var mapper = new VBucketKeyMapper(servers, bucketConfig.VBucketServerMap); var vBucket = (IVBucket)mapper.MapKey("somekey"); const int expected = 3; Assert.AreEqual(expected, vBucket.Replicas.Count()); }
public void When_BucketConfig_Has_Replicas_VBucketKeyMapper_LocateReplica_Returns_Correct_Server() { var json = ResourceHelper.ReadResource(@"Data\Configuration\config-with-replicas-complete.json"); var bucketConfig = JsonConvert.DeserializeObject <BucketConfig>(json); var mapper = new VBucketKeyMapper(bucketConfig, new VBucketFactory(new Mock <ILogger <VBucket> >().Object)); var vBucket = (IVBucket)mapper.MapKey("somekey"); foreach (var index in vBucket.Replicas) { var server = vBucket.LocateReplica(index); Assert.NotNull(server); var expected = bucketConfig.VBucketServerMap.ServerList[index]; Assert.Equal(server.Address.ToString(), expected.Split(':').First()); } }
public void When_Primary_Is_Negative_Random_Server_Returned() { var json = ResourceHelper.ReadResource(@"Data\Configuration\config-with-negative-one-primary.json"); var bucketConfig = JsonConvert.DeserializeObject <BucketConfig>(json); var mapper = new VBucketKeyMapper(bucketConfig, new VBucketFactory(new Mock <ILogger <VBucket> >().Object)); //maps to -1 primary const string key = "somekey0"; var vBucket = (IVBucket)mapper.MapKey(key); Assert.Equal(-1, vBucket.Primary); var primary = vBucket.LocatePrimary(); Assert.NotNull(primary); }
public void When_Primary_Index_Is_Greater_Than_Cluster_Count_Random_Server_Returned() { var json = ResourceHelper.ReadResource(@"Data\Configuration\config-with-negative-one-primary.json"); var bucketConfig = JsonConvert.DeserializeObject <BucketConfig>(json); //remove one server bucketConfig.NodesExt.Remove(bucketConfig.NodesExt.First()); bucketConfig.Nodes.Remove(bucketConfig.Nodes.First()); var mapper = new VBucketKeyMapper(bucketConfig, new VBucketFactory(new Mock <ILogger <VBucket> >().Object)); //maps to -1 primary const string key = "somekey23"; var vBucket = (IVBucket)mapper.MapKey(key); var primary = vBucket.LocatePrimary(); Assert.NotNull(primary); }
public void When_BucketConfig_Has_Replicas_VBucketKeyMapper_LocateReplica_Returns_Correct_Server() { var bucketConfig = ResourceHelper.ReadResource(@"Data\Configuration\config-with-replicas-complete.json", InternalSerializationContext.Default.BucketConfig); var vBucketServerMap = GetServerMap(bucketConfig.VBucketServerMap); var mapper = new VBucketKeyMapper(bucketConfig, vBucketServerMap, new VBucketFactory(new Mock <ILogger <VBucket> >().Object)); var vBucket = (IVBucket)mapper.MapKey("somekey"); foreach (var index in vBucket.Replicas) { var server = vBucket.LocateReplica(index); Assert.NotNull(server); var expected = bucketConfig.VBucketServerMap.ServerList[index]; Assert.Equal(server.Value.Host, expected.Split(':').First()); } }
public void When_BucketConfig_Has_Replicas_VBucketKeyMapper_Replicas_Are_Equal() { var json = File.ReadAllText(@"Data\\Configuration\\config-with-replicas-complete.json"); var bucketConfig = JsonConvert.DeserializeObject <BucketConfig>(json); var servers = bucketConfig.VBucketServerMap. ServerList. Select(server => new Server(ObjectFactory.CreateIOStrategy(server), new Node(), new ClientConfiguration())). Cast <IServer>(). ToList(); var mapper = new VBucketKeyMapper(servers, bucketConfig.VBucketServerMap); var vBucket = (IVBucket)mapper.MapKey("somekey"); var index = mapper.GetIndex("somekey"); var expected = bucketConfig.VBucketServerMap.VBucketMap[index]; for (var i = 0; i < vBucket.Replicas.Length; i++) { Assert.AreEqual(vBucket.Replicas[i], expected[i + 1]); } }
public void When_BucketConfig_Has_Replicas_VBucketKeyMapper_LocateReplica_Returns_Correct_Server() { var json = File.ReadAllText(@"Data\\Configuration\\config-with-replicas-complete.json"); var bucketConfig = JsonConvert.DeserializeObject <BucketConfig>(json); var servers = bucketConfig.VBucketServerMap. ServerList. Select(server => new Server(ObjectFactory.CreateIOStrategy(server), new Node(), new ClientConfiguration())). Cast <IServer>(). ToList(); var mapper = new VBucketKeyMapper(servers, bucketConfig.VBucketServerMap); var vBucket = (IVBucket)mapper.MapKey("somekey"); foreach (var index in vBucket.Replicas) { var server = vBucket.LocateReplica(index); Assert.IsNotNull(server); var expected = bucketConfig.VBucketServerMap.ServerList[index]; Assert.AreEqual(server.EndPoint.Address.ToString(), expected.Split(':').First()); } }
public void When_Primary_Is_Negative_Random_Server_Returned() { var json = File.ReadAllText(@"Data\\Configuration\\config-with-negative-one-primary.json"); var bucketConfig = JsonConvert.DeserializeObject <BucketConfig>(json); var servers = bucketConfig.VBucketServerMap. ServerList. Select(s => new Server(ObjectFactory.CreateIOStrategy(s), new Node(), new ClientConfiguration())). Cast <IServer>(). ToList(); var mapper = new VBucketKeyMapper(servers, bucketConfig.VBucketServerMap); //maps to -1 primary const string key = "somekey0"; var vBucket = (IVBucket)mapper.MapKey(key); Assert.AreEqual(-1, vBucket.Primary); var server = vBucket.LocatePrimary(); Assert.IsNotNull(server); }
public void When_Primary_Index_Is_Greater_Than_Cluster_Count_Random_Server_Returned() { var json = File.ReadAllText(@"Data\\Configuration\\config-with-negative-one-primary.json"); var bucketConfig = JsonConvert.DeserializeObject <BucketConfig>(json); var servers = bucketConfig.VBucketServerMap. ServerList. Select(s => new Server(ObjectFactory.CreateIOStrategy(s), new NodeAdapter(new Node(), new NodeExt()), new ClientConfiguration(), bucketConfig)). Cast <IServer>(). ToList(); //remove one server servers.RemoveAt(1); var mapper = new VBucketKeyMapper(servers, bucketConfig.VBucketServerMap, bucketConfig.Rev); //maps to -1 primary const string key = "somekey23"; var vBucket = (IVBucket)mapper.MapKey(key); var server = vBucket.LocatePrimary(); Assert.IsNotNull(server); }
public void When_BucketConfig_Has_Replicas_VBucketKeyMapper_Replica_Count_Is_Equal() { var json = File.ReadAllText(@"Data\\Configuration\\config-with-replicas-complete.json"); var bucketConfig = JsonConvert.DeserializeObject <BucketConfig>(json); var servers = new Dictionary <IPAddress, IServer>(); foreach (var node in bucketConfig.GetNodes()) { servers.Add(node.GetIPAddress(), new Server(new FakeIOService(node.GetIPEndPoint(), new FakeConnectionPool(), false), node, new ClientConfiguration(), bucketConfig, new FakeTranscoder())); } var mapper = new VBucketKeyMapper(servers, bucketConfig.VBucketServerMap, bucketConfig.Rev); var vBucket = (IVBucket)mapper.MapKey("somekey"); const int expected = 3; Assert.AreEqual(expected, vBucket.Replicas.Count()); }