Beispiel #1
0
		public void TestSendReceive()
		{
			var transport = GetTransport();
			var ids = new List<Guid>();

			transport.Open();

			for (var i = 0; i < 100; i++)
			{
				var message = new FakeMessage();
				transport.Send(message);

				ids.Add(message.Identifier);
			}

			for (var i = 0; i < 10; i++)
			{
				var j = 0;
				foreach (var message in transport.ReceiveMany(10, TimeSpan.MaxValue))
				{
					Assert.True(ids.Contains(message.Identifier));
					j++;
				}

				Assert.AreEqual(10, j);
			}

			transport.Close();
		}
		public void MultipleMessagesAreRecognizedByProcessor()
		{
			var processor = new FakeMultipleMessageProcessor();

			var fakeMessage = new FakeMessage();
			var differentMessage = new DifferentFakeMessage();

			Assert.IsTrue(processor.CanProcessMessage(fakeMessage));
			Assert.IsTrue(processor.CanProcessMessage(differentMessage));
		}
Beispiel #3
0
		public static void Clear(IMessageChannel channel)
		{
			channel.Open();

			for (var i = 0; i < 5; i++)
			{
				var m = new FakeMessage();
				channel.Send(m);
			}

			channel.Clear();

			var messages = channel.ReceiveMany(5, TimeSpan.MaxValue);

			Assert.AreEqual(0, messages.Count());

			channel.Close();
		}
Beispiel #4
0
		public static void ReceiveTimeout(IMessageChannel channel)
		{
			var ts = new TimeSpan(0, 0, 0, 0, 500);

			channel.Open();
			channel.Clear();

			var m = new FakeMessage();
			var m2 = new FakeMessage();

			channel.Send(m);
			channel.Send(m2);

			var count = 0;
			foreach (var msg in channel.ReceiveMany(2, ts))
			{
				count++;
				Thread.Sleep(500);
			}

			Assert.AreEqual(1, count);
		}
		public void Process(FakeMessage message)
		{
			ProcessedMessages++;
		}
		private IPublicationRecord GetRecord()
		{
			var msg = new FakeMessage
				{
					Created = DateTime.Now,
					Field1 = 1,
					CreatedBy = new Guid("1ABA1517-6A7B-410B-8E90-0F8C73886B01"),
					Field2 = new List<string> { "foo", "bar", "baz" }
				};

			return _registry.PublishMessage(msg);
		}
		public void DispatchesMessagesToSameProcessor()
		{
			var settings = new MessageDispatcherSettings();

			settings.InputChannel.WithDefault(new InMemoryMessageChannel());
			settings.InvalidChannel.WithDefault(new InMemoryMessageChannel());
			settings.MessageProcessorTypes.WithDefault(new List<Type> { typeof(FakeMultipleMessageProcessor) });
			settings.DurationOfDispatchingSlice.WithDefault(new TimeSpan(0, 0, 0, 0, 200));
			settings.NumberOfMessagesToDispatchPerSlice.WithDefault(30);

			_dispatcher.Configure(settings);

			_dispatcher.Enable();

			_transport.Open();

			var fakeMessage = new FakeMessage();
			var differentFakeMessage = new DifferentFakeMessage();

			_transport.Send(_registry.PublishMessage(fakeMessage));
			_transport.Send(_registry.PublishMessage(differentFakeMessage));

			Assert.AreEqual(MessageDispatcherState.Enabled, _dispatcher.State);

			Thread.Sleep(5000); // wait for message to be processed

			Assert.AreEqual(2, FakeMultipleMessageProcessor.ProcessedMessages);

			_dispatcher.Disable();

			Assert.AreEqual(MessageDispatcherState.Disabled, _dispatcher.State);

			Assert.NotNull(_dispatcher);
		}