public async void IfFirstBrokerIsDownThenNextOneWillConnect() { var badSeed = "192.168.56.111," + _seed2Addresses; var cluster = new Cluster(badSeed); await cluster.ConnectAsync(); await cluster.GetAllTopicsAsync(); //var producer = new Producer(cluster, new ProducerConfiguration("notopic")); //await producer.ConnectAsync(); await cluster.CloseAsync(TimeSpan.FromSeconds(1)); }
public async void SchedulerThreadIsIsolatedFromUserCode() { kafka4net.Tracing.EtwTrace.Marker("SchedulerThreadIsIsolatedFromUserCode"); const string threadName = "kafka-scheduler"; _log.Info("Test Runner is using thread {0}", Thread.CurrentThread.Name); var topic = "topic." + _rnd.Next(); VagrantBrokerUtil.CreateTopic(topic,6,3); var cluster = new Cluster(_seed2Addresses); await cluster.ConnectAsync(); Assert.AreNotEqual(threadName, Thread.CurrentThread.Name); await cluster.FetchPartitionOffsetsAsync(topic, ConsumerLocation.TopicStart); Assert.AreNotEqual(threadName, Thread.CurrentThread.Name); var topics = await cluster.GetAllTopicsAsync(); Assert.AreNotEqual(threadName, Thread.CurrentThread.Name); // now create a producer var producer = new Producer(cluster, new ProducerConfiguration(topic)); await producer.ConnectAsync(); Assert.AreNotEqual(threadName, Thread.CurrentThread.Name); // create a producer that also creates a cluster var producerWithCluster = new Producer(_seed2Addresses, new ProducerConfiguration(topic)); await producerWithCluster.ConnectAsync(); Assert.AreNotEqual(threadName, Thread.CurrentThread.Name); // TODO: Subscribe and check thread on notification observables! // run them both for a little while (~5 seconds) var msgs = await Observable.Interval(TimeSpan.FromMilliseconds(100)) .Do(l => { producer.Send(new Message { Value = BitConverter.GetBytes(l) }); producerWithCluster.Send(new Message { Value = BitConverter.GetBytes(l) }); _log.Debug("After Producer Send using thread {0}", Thread.CurrentThread.Name); }).Take(50).ToArray(); Assert.AreNotEqual(threadName, Thread.CurrentThread.Name); // now consumer(s) var consumer = new Consumer(new ConsumerConfiguration(_seed2Addresses, topic, new StartPositionTopicStart())); Assert.AreNotEqual(threadName, Thread.CurrentThread.Name); var msgsRcv = new List<long>(); var messageSubscription = consumer.OnMessageArrived .Do(msg => Assert.AreEqual(threadName, Thread.CurrentThread.Name), exception => Assert.AreEqual(threadName, Thread.CurrentThread.Name), () => Assert.AreEqual(threadName, Thread.CurrentThread.Name)) .Take(50) .TakeUntil(DateTime.Now.AddSeconds(500)) .ObserveOn(System.Reactive.Concurrency.DefaultScheduler.Instance) .Do(msg => Assert.AreNotEqual(threadName, Thread.CurrentThread.Name), exception => Assert.AreNotEqual(threadName, Thread.CurrentThread.Name), () => Assert.AreNotEqual(threadName, Thread.CurrentThread.Name)) .Subscribe( msg=> { msgsRcv.Add(BitConverter.ToInt64(msg.Value,0)); Assert.AreNotEqual(threadName, Thread.CurrentThread.Name); _log.Debug("In Consumer Subscribe OnNext using thread {0}", Thread.CurrentThread.Name); }, exception => { _log.Debug("In Consumer Subscribe OnError using thread {0} Error: {1}", Thread.CurrentThread.Name, exception.Message); throw exception; }, () => { Assert.AreNotEqual(threadName, Thread.CurrentThread.Name); _log.Debug("In Consumer Subscribe OnComplete using thread {0}", Thread.CurrentThread.Name); }); await consumer.IsConnected; _log.Info("Waitng for consumer to read"); await Task.Delay(TimeSpan.FromSeconds(6)); _log.Debug("After Consumer Subscribe using thread {0}", Thread.CurrentThread.Name); consumer.Dispose(); Assert.AreNotEqual(threadName, Thread.CurrentThread.Name); Assert.AreEqual(msgs.Length, msgsRcv.Count); messageSubscription.Dispose(); Assert.AreNotEqual(threadName, Thread.CurrentThread.Name); // now close down await producer.CloseAsync(TimeSpan.FromSeconds(5)); _log.Debug("After Consumer Close using thread {0}", Thread.CurrentThread.Name); Assert.AreNotEqual(threadName, Thread.CurrentThread.Name); await producerWithCluster.CloseAsync(TimeSpan.FromSeconds(5)); _log.Debug("After Producer Subscribe using thread {0}", Thread.CurrentThread.Name); Assert.AreNotEqual(threadName, Thread.CurrentThread.Name); Assert.AreNotEqual(threadName, Thread.CurrentThread.Name); await cluster.CloseAsync(TimeSpan.FromSeconds(5)); _log.Debug("After Cluster Close using thread {0}", Thread.CurrentThread.Name); Assert.AreNotEqual(threadName, Thread.CurrentThread.Name); kafka4net.Tracing.EtwTrace.Marker("/SchedulerThreadIsIsolatedFromUserCode"); }