コード例 #1
0
    public async Task DoesNotLogTaskCancelledException()
    {
        var topic    = _brokerFactory.GetNewTopic();
        var producer = _brokerFactory.ConfigureProducer().Create();

        Using(producer);

        var logs = new ListLoggerFactory();
        var weAreInTheHandler = new ManualResetEvent(initialState: false);

        var consumer = _brokerFactory.ConfigureConsumer("default-group")
                       .Logging(l => l.Use(logs))
                       .Handle(async(messages, context, token) =>
        {
            weAreInTheHandler.Set();
            await Task.Delay(TimeSpan.FromSeconds(100), token);
        })
                       .Topics(t => t.Subscribe(topic))
                       .Positions(p => p.StoreInMemory())
                       .Start();

        Using(consumer);

        await producer.Send(topic, new ToposMessage("wazzup my mayn?!"));

        weAreInTheHandler.WaitOrDie(timeoutSeconds: 15);

        // force everything to shut down now
        CleanUpDisposables();

        logs.DumpLogs();

        // check that we didn't get that silly TaskCancelledException in the logs
        var logLineWithException = logs.FirstOrDefault(l => l.Exception != null);

        Assert.That(logLineWithException, Is.Null,
                    $"Didn't expect any exceptions, but we got this: {logLineWithException?.Exception}");
    }
コード例 #2
0
        public async Task VerifyNiceExceptionWhenSerializerHasBeenImproperlyCustomized()
        {
            BsonClassMap.RegisterClassMap <SagaData>(c =>
            {
                c.MapField(d => d.Id);
            });

            var activator         = Using(new BuiltinHandlerActivator());
            var listLoggerFactory = new ListLoggerFactory();

            activator.Register(() => new SomeSaga());

            Configure.With(activator)
            .Logging(l => l.Use(listLoggerFactory))
            .Transport(t => t.UseInMemoryTransport(new InMemNetwork(), "who-cares"))
            .Sagas(s => s.StoreInMongoDb(MongoTestHelper.GetMongoDatabase()))
            .Start();

            await activator.Bus.SendLocal("hej med dig!");

            await Task.Delay(TimeSpan.FromSeconds(2));

            var error = listLoggerFactory.FirstOrDefault(l => l.Level == LogLevel.Error)
                        ?? throw new AssertionException("Did not find any log entries with Level == Error");

            Console.WriteLine($@"----------------------------------------------------------------------------------------------
Found this:

{error.Text}
----------------------------------------------------------------------------------------------");

            var message = error.Text;

            Assert.That(message, Contains.Substring("_id"));
            Assert.That(message, Contains.Substring("Id"));
        }