コード例 #1
0
ファイル: AwsSqsClientTests.cs プロジェクト: danice/DReAM
 public void LIVE_STRESSTEST_Produce_Consume()
 {
     var client = CreateLiveClient();
     var queue = "test-" + StringUtil.CreateAlphaNumericKey(8);
     client.CreateQueue(queue, new Result<AwsSqsResponse>()).Wait();
     try {
         var n = 100;
         var productions = new List<Result<Production>>();
         var producer = new Producer(queue, GetConfig());
         for(var i = 0; i < 4; i++) {
             productions.Add(producer.Produce(n));
         }
         productions.Join(new Result()).Wait();
         var totalMessages = productions.Count * n;
         var consumers = new List<Consumer>();
         for(var i = 0; i < 10; i++) {
             var consumer = new Consumer(queue, CreateLiveClient());
             consumer.Consume();
             consumers.Add(consumer);
         }
         Assert.IsTrue(
             Wait.For(() => consumers.Sum(x => x.Received) == totalMessages, (totalMessages * 0.2).Seconds()),
             string.Format("got {0} instead of the expected {1} messages", consumers.Sum(x => x.Received), totalMessages)
         );
     } finally {
         _log.DebugFormat("cleaning up queue '{0}'", queue);
         client.DeleteQueue(queue, new Result<AwsSqsResponse>()).Wait();
     }
 }
コード例 #2
0
ファイル: AwsSqsClientTests.cs プロジェクト: danice/DReAM
 public void LIVE_Produce_Consume()
 {
     var client = CreateLiveClient();
     var queue = "test-" + StringUtil.CreateAlphaNumericKey(8);
     client.CreateQueue(queue, new Result<AwsSqsResponse>()).Wait();
     try {
         var producer = new Producer(queue, GetConfig());
         var n = 100;
         var r = producer.Produce(n);
         var consumer = new Consumer(queue, CreateLiveClient());
         consumer.Consume();
         var production = r.Wait();
         Assert.AreEqual(n, production.Sent.Count, "wrong number of sent messages");
         Assert.IsTrue(
             Wait.For(() => consumer.Received == n, (n * 0.5).Seconds()),
             string.Format("got {0} instead of the expected {1} messages", consumer.Received, n)
         );
         var consumed = consumer.Stop();
         Assert.AreEqual(
             production.Sent.OrderBy(x => x).ToArray(),
             consumed.OrderBy(x => x).ToArray(),
             "wrong set of messages"
         );
     } finally {
         _log.DebugFormat("cleaning up queue '{0}'", queue);
         client.DeleteQueue(queue, new Result<AwsSqsResponse>()).Wait();
     }
 }