Beispiel #1
0
        static void Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.WriteLine($"Usage: .. <broker,broker..> <num_producers> <abort_probability (0..1)>");
                return;
            }
            var bootstrapServers = args[0];
            var numProducers     = int.Parse(args[1]);
            var abortProbability = float.Parse(args[2]);

            var conf = new SimulationConfig(
                topic: Guid.NewGuid().ToString(),
                messageCount: 10000,
                randomSeedBase: 1,
                maxRunLength: 10, // maximum number of messages in any aborted or committed transaction.
                maxPause: 0.05,   // maximum time to pause (seconds) between producing each message (per producer).
                probability_abort: abortProbability);

            var tasks = new List <Task>();

            for (int i = 0; i < numProducers; ++i)
            {
                var p = new TestProducer(bootstrapServers, i, conf);
                tasks.Add(Task.Run(() => p.Run()));
            }

            var c = new TestConsumer(bootstrapServers, conf);

            tasks.Add(Task.Run(() => c.Run()));

            Task.WaitAll(tasks.ToArray());
        }
Beispiel #2
0
        public TestProducer(string bootstrapServers, int id, SimulationConfig simulationConfig)
        {
            this.id = id;
            this.bootstrapServers = bootstrapServers;

            // ensure different string of pseudo-random behavior for each test producer.
            random = new Random(simulationConfig.RandomSeedBase + id);

            conf = simulationConfig;
        }
 public TestConsumer(string bootstrapServers, SimulationConfig conf)
 {
     this.conf             = conf;
     this.bootstrapServers = bootstrapServers;
 }