public void When_Observing_Key_During_Remove_Durability_Constraint_Is_Reached() { var configuration = new ClientConfiguration { Servers = new List<Uri> { new Uri(ConfigurationManager.AppSettings["bootstrapUrl"]) } }; configuration.Initialize(); var provider = new CarrierPublicationProvider( configuration, (pool) => new DefaultIOStrategy(pool), (config, endpoint) => new ConnectionPool<EapConnection>(config, endpoint), SaslFactory.GetFactory3(), new AutoByteConverter(), new TypeSerializer(new AutoByteConverter())); var configInfo = provider.GetConfig("default"); var observer = new KeyObserver(configInfo, 10, 500); var constraintReached = observer.ObserveRemove("Test_Timeout_Remove", 0, ReplicateTo.Zero, PersistTo.One); Assert.IsTrue(constraintReached); }
public void When_Observing_Key_During_Add_Durability_Constraint_Is_Reached() { var configuration = new ClientConfiguration { Servers = new List<Uri> { new Uri(ConfigurationManager.AppSettings["bootstrapUrl"]) } }; configuration.Initialize(); var provider = new CarrierPublicationProvider( configuration, (pool) => new DefaultIOStrategy(pool), (config, endpoint) => new ConnectionPool<EapConnection>(config, endpoint), SaslFactory.GetFactory3(), new AutoByteConverter(), new TypeSerializer(new AutoByteConverter())); var configInfo = provider.GetConfig("default"); ulong cas = 0; using (var cluster = new CouchbaseCluster(configuration)) { using (var bucket = cluster.OpenBucket()) { bucket.Remove("Test_Timeout_Add"); bucket.Insert("Test_Timeout_Add", ""); cas = bucket.Upsert("Test_Timeout_Add", "").Cas; } } var observer = new KeyObserver(configInfo, 10, 500); var constraintReached = observer.ObserveAdd("Test_Timeout_Add", cas, ReplicateTo.One, PersistTo.One); Assert.IsTrue(constraintReached); }
public async Task When_Observing_Key_During_RemoveAsync_Durability_Constraint_Is_Reached() { var configuration = new ClientConfiguration { Servers = new List<Uri> { new Uri(ConfigurationManager.AppSettings["bootstrapUrl"]) } }; configuration.Initialize(); var provider = new CarrierPublicationProvider( configuration, (pool) => new PooledIOService(pool), (config, endpoint) => new ConnectionPool<Connection>(config, endpoint), SaslFactory.GetFactory(), new DefaultConverter(), new DefaultTranscoder(new DefaultConverter())); var configInfo = provider.GetConfig("default"); var clusterController = new Mock<IClusterController>(); clusterController.Setup(x => x.Transcoder).Returns(new DefaultTranscoder()); var pending = new ConcurrentDictionary<uint, IOperation>(); var observer = new KeyObserver(pending, configInfo, clusterController.Object, 10, 500); using (var cts = new CancellationTokenSource(configuration.ObserveTimeout)) { var constraintReached = await observer.ObserveRemoveAsync("Test_Timeout_Remove_Async", 0, ReplicateTo.Zero, PersistTo.One, cts); Assert.IsTrue(constraintReached); } }
public void Test_KeySeqnoObserver() { var configuration = new ClientConfiguration { Servers = new List<Uri> { new Uri(ConfigurationManager.AppSettings["bootstrapUrl"]) } }; var key = "Test_KeySeqnoObserver"; using (var cluster = new Cluster(configuration)) { using (var bucket = cluster.OpenBucket()) { bucket.Remove(key); } } configuration.Initialize(); var provider = new CarrierPublicationProvider( configuration, (pool) => new PooledIOService(pool), (config, endpoint) => new ConnectionPool<Connection>(config, endpoint), SaslFactory.GetFactory(), new DefaultConverter(), new DefaultTranscoder(new DefaultConverter(), new DefaultSerializer())); var configInfo = provider.GetConfig("default"); var features = new List<short>(); features.Add((short)ServerFeatures.MutationSeqno); var keyMapper = configInfo.GetKeyMapper(); var mappedNode = keyMapper.MapKey(key); var node = mappedNode.LocatePrimary(); foreach (var server in configInfo.Servers.Where(x=>x.IsDataNode)) { var hello = new Hello("couchbase-net-sdk/2.1.4", features.ToArray(), provider.Transcoder, 0, 0); var result3 = server.Send(hello); Assert.IsTrue(result3.Success); } var result = node.Send(new Add<string>(key, "", (VBucket)mappedNode, new DefaultTranscoder(new DefaultConverter(), new DefaultSerializer()), 1000)); var clusterController = new Mock<IClusterController>(); clusterController.Setup(x => x.Transcoder).Returns(new DefaultTranscoder()); var pending = new ConcurrentDictionary<uint, IOperation>(); var keyObserver = new KeySeqnoObserver("thekey", pending, configInfo, clusterController.Object, 0, 1000); var durabilityReached = keyObserver.Observe(result.Token, ReplicateTo.Zero, PersistTo.One); Assert.IsTrue(durabilityReached); }
public async void Test_Timeout_Add_PersistTo_Master_Async() { var configuration = new ClientConfiguration { Servers = new List<Uri> { new Uri(ConfigurationManager.AppSettings["bootstrapUrl"]) } }; configuration.Initialize(); var provider = new CarrierPublicationProvider( configuration, (pool) => new DefaultIOStrategy(pool), (config, endpoint) => new ConnectionPool<Connection>(config, endpoint), SaslFactory.GetFactory3(), new DefaultConverter(), new DefaultTranscoder(new DefaultConverter())); var configInfo = provider.GetConfig("default"); var key = "Test_Timeout_Add_PersistTo_Master_Async"; IOperationResult result; using (var cluster = new Cluster(configuration)) { using (var bucket = cluster.OpenBucket()) { bucket.Remove(key); result = bucket.Insert(key, ""); } } var observer = new KeyObserver(configInfo, 10, 500); var constraintReached = await observer.ObserveAddAsync(key, result.Cas, ReplicateTo.Zero, PersistTo.Zero); Assert.IsTrue(constraintReached); }
public async void When_Mutation_Happens_Observe_Fails_Async() { var configuration = new ClientConfiguration { Servers = new List<Uri> { new Uri(ConfigurationManager.AppSettings["bootstrapUrl"]) } }; configuration.Initialize(); var provider = new CarrierPublicationProvider( configuration, (pool) => new DefaultIOStrategy(pool), (config, endpoint) => new ConnectionPool<Connection>(config, endpoint), SaslFactory.GetFactory3(), new DefaultConverter(), new DefaultTranscoder(new DefaultConverter())); var configInfo = provider.GetConfig("default"); var key = "When_Mutation_Happens_Observe_Fails_async"; ulong cas = 0; using (var cluster = new Cluster(configuration)) { using (var bucket = cluster.OpenBucket()) { bucket.Remove(key); cas = bucket.Insert(key, "").Cas; bucket.Upsert(key, ""); } } var observer = new KeyObserver(configInfo, 10, 500); var constraintReached = await observer.ObserveAddAsync(key, cas, ReplicateTo.One, PersistTo.One); Assert.IsFalse(constraintReached); }
public void When_Observing_Key_During_Add_Durability_Constraint_Is_Reached() { var configuration = new ClientConfiguration { Servers = new List<Uri> { new Uri(ConfigurationManager.AppSettings["bootstrapUrl"]) } }; configuration.Initialize(); var provider = new CarrierPublicationProvider( configuration, (pool) => new PooledIOService(pool), (config, endpoint) => new ConnectionPool<Connection>(config, endpoint), SaslFactory.GetFactory(), new DefaultConverter(), new DefaultTranscoder(new DefaultConverter())); var configInfo = provider.GetConfig("default"); ulong cas = 0; using (var cluster = new Cluster(configuration)) { using (var bucket = cluster.OpenBucket()) { bucket.Remove("Test_Timeout_Add"); bucket.Insert("Test_Timeout_Add", ""); cas = bucket.Upsert("Test_Timeout_Add", "").Cas; } } var clusterController = new Mock<IClusterController>(); clusterController.Setup(x => x.Transcoder).Returns(new DefaultTranscoder()); var pending = new ConcurrentDictionary<uint, IOperation>(); var observer = new KeyObserver(pending, configInfo, clusterController.Object, 10, 500); var constraintReached = observer.ObserveAdd("Test_Timeout_Add", cas, ReplicateTo.Zero, PersistTo.Zero); Assert.IsTrue(constraintReached); }
public async Task Test_Timeout_Add_PersistTo_Master_Async() { var configuration = new ClientConfiguration { Servers = new List<Uri> { new Uri(ConfigurationManager.AppSettings["bootstrapUrl"]) } }; configuration.Initialize(); var provider = new CarrierPublicationProvider( configuration, (pool) => new PooledIOService(pool), (config, endpoint) => new ConnectionPool<Connection>(config, endpoint), SaslFactory.GetFactory(), new DefaultConverter(), new DefaultTranscoder(new DefaultConverter())); var configInfo = provider.GetConfig("default"); var key = "Test_Timeout_Add_PersistTo_Master_Async"; IOperationResult result; using (var cluster = new Cluster(configuration)) { using (var bucket = cluster.OpenBucket()) { bucket.Remove(key); result = bucket.Insert(key, ""); } } var clusterController = new Mock<IClusterController>(); clusterController.Setup(x => x.Transcoder).Returns(new DefaultTranscoder()); var pending = new ConcurrentDictionary<uint, IOperation>(); var observer = new KeyObserver(pending, configInfo, clusterController.Object, 10, 500); using (var cts = new CancellationTokenSource(configuration.ObserveTimeout)) { var constraintReached = await observer.ObserveAddAsync(key, result.Cas, ReplicateTo.Zero, PersistTo.Zero, cts); Assert.IsTrue(constraintReached); } }
public async void When_Observing_Key_During_AddAsync_Durability_Constraint_Is_Reached() { var configuration = new ClientConfiguration { Servers = new List<Uri> { new Uri(ConfigurationManager.AppSettings["bootstrapUrl"]) } }; configuration.Initialize(); var provider = new CarrierPublicationProvider( configuration, (pool) => new PooledIOService(pool), (config, endpoint) => new ConnectionPool<Connection>(config, endpoint), SaslFactory.GetFactory(), new DefaultConverter(), new DefaultTranscoder(new DefaultConverter())); var configInfo = provider.GetConfig("default"); var key = "Test_Timeout_Add_Async"; ulong cas = 0; using (var cluster = new Cluster(configuration)) { using (var bucket = cluster.OpenBucket()) { bucket.Remove(key); bucket.Insert(key, ""); cas = bucket.Upsert(key, "").Cas; } } var observer = new KeyObserver(configInfo, 10, 500); var constraintReached = await observer.ObserveAddAsync(key, cas, ReplicateTo.Zero, PersistTo.Zero); Assert.IsTrue(constraintReached); }