public void testAddRemoveThreaded()
        {
            var mockStorage = new MockStorage();

            var q = new PersistentBlockingQueue(mockStorage, new PayloadToJsonString());

            int expectedRecordCount = 1000;

            var consumer = new MockConsumer(expectedRecordCount, q);

            var producer       = new MockProducer(expectedRecordCount / 2, q);
            var secondProducer = new MockProducer(expectedRecordCount / 2, q);

            var consumerThread = new Thread(new ThreadStart(consumer.Consume));

            consumerThread.Start();

            var producerThread = new Thread(new ThreadStart(producer.Produce));

            producerThread.Start();

            var secondProducerThread = new Thread(new ThreadStart(secondProducer.Produce));

            secondProducerThread.Start();

            consumerThread.Join(1000); // time out if errors

            Assert.AreEqual(expectedRecordCount, consumer.Consumed.Count);
        }
        public void testMultipleConsumers()
        {
            var mockStorage = new MockStorage();

            var q = new PersistentBlockingQueue(mockStorage, new PayloadToJsonString());

            int expectedRecordCount = 1000;

            var producer = new MockProducer(expectedRecordCount, q);

            var producerThread = new Thread(new ThreadStart(producer.Produce));

            producerThread.Start();

            var threads   = new List <Thread>();
            var consumers = new List <MockConsumer>();

            for (int i = 0; i < expectedRecordCount; i++)
            {
                var consumer       = new MockConsumer(1, q);
                var consumerThread = new Thread(new ThreadStart(consumer.Consume));
                consumerThread.Start();
                threads.Add(consumerThread);
                consumers.Add(consumer);
            }

            threads.ForEach(t => { t.Join(100); });

            var  total = (from c in consumers select c.Consumed.Count).Sum();
            bool allConsumedOneItem = !consumers.Any(item => { return(item.Consumed.Count != 1); });

            Assert.IsTrue(allConsumedOneItem);
            Assert.AreEqual(expectedRecordCount, total);
        }
        public void Setup()
        {
            var mockProducer = new MockProducer();

            _mockIdentityDirectory = new MockIdentityDirectory();
            _identityDirectory     = _mockIdentityDirectory.GetImplementation <IIdentityDirectory>(mockProducer);
            mockProducer.Add(_identityDirectory);

            _mockIdentityStore = new MockIdentityStore();
            _identityStore     = _mockIdentityStore.GetImplementation <IIdentityStore>(mockProducer);
            mockProducer.Add(_identityStore);
        }
예제 #4
0
        public void TestAdapterLogProducer()
        {
            var mockProducer = new MockProducer(null, "PRODUCER");
            var config       = new StreamConfig();

            config.ApplicationId = "test-logger-adapter";
            var logger  = new InMemoryLogger();
            var log     = new LogImpl(logger);
            var adapter = new KafkaLoggerAdapter(config, log);

            adapter.LogProduce(mockProducer,
                               new Confluent.Kafka.LogMessage("error", Confluent.Kafka.SyslogLevel.Critical, "", "error"));

            Assert.AreEqual(1, logger.Logs.Count);
            logger.Logs.Clear();

            adapter.ErrorProduce(mockProducer,
                                 new Confluent.Kafka.Error(Confluent.Kafka.ErrorCode.BrokerNotAvailable, "error"));

            Assert.AreEqual(1, logger.Logs.Count);
            logger.Logs.Clear();
        }