IGNITE-5606 .NET: Test various data types as messaging topic and message
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/641dd670 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/641dd670 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/641dd670 Branch: refs/heads/ignite-3478 Commit: 641dd6707f1a20601ac9c00d824bfff2aa54b994 Parents: b4b3fea Author: Pavel Tupitsyn <[email protected]> Authored: Tue Sep 26 20:00:52 2017 +0300 Committer: Pavel Tupitsyn <[email protected]> Committed: Tue Sep 26 20:00:52 2017 +0300 ---------------------------------------------------------------------- .../Apache.Ignite.Core.Tests/MessagingTest.cs | 95 +++++++++++++++----- 1 file changed, 75 insertions(+), 20 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/641dd670/modules/platforms/dotnet/Apache.Ignite.Core.Tests/MessagingTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/MessagingTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/MessagingTest.cs index f41474d..f4660b1 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/MessagingTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/MessagingTest.cs @@ -24,10 +24,12 @@ namespace Apache.Ignite.Core.Tests using System.Linq; using System.Threading; using System.Threading.Tasks; + using Apache.Ignite.Core.Cache.Configuration; using Apache.Ignite.Core.Cluster; using Apache.Ignite.Core.Common; using Apache.Ignite.Core.Messaging; using Apache.Ignite.Core.Resource; + using Apache.Ignite.Core.Tests.Cache; using NUnit.Framework; /// <summary> @@ -47,6 +49,25 @@ namespace Apache.Ignite.Core.Tests /** */ private static int _messageId; + /** Objects to test against. */ + private static readonly object[] Objects = { + // Primitives. + null, + "string topic", + Guid.NewGuid(), + DateTime.Now, + byte.MinValue, + short.MaxValue, + + // Enums. + CacheMode.Local, + GCCollectionMode.Forced, + + // Objects. + new CacheTestKey(25), + new IgniteGuid(Guid.NewGuid(), 123), + }; + /// <summary> /// Executes before each test. /// </summary> @@ -80,14 +101,49 @@ namespace Apache.Ignite.Core.Tests } /// <summary> + /// Tests that any data type can be used as a message. + /// </summary> + [Test] + public void TestMessageDataTypes() + { + var topic = "dataTypes"; + object lastMsg = null; + var evt = new AutoResetEvent(false); + + var messaging1 = _grid1.GetMessaging(); + var messaging2 = _grid2.GetMessaging(); + + var listener = new MessageListener<object>((nodeId, msg) => + { + lastMsg = msg; + evt.Set(); + return true; + }); + + messaging1.LocalListen(listener, topic); + + foreach (var msg in Objects.Where(x => x != null)) + { + messaging2.Send(msg, topic); + evt.WaitOne(500); + Assert.AreEqual(msg, lastMsg); + } + + messaging1.StopLocalListen(listener, topic); + } + + /// <summary> /// Tests LocalListen. /// </summary> [Test] public void TestLocalListen() { - TestLocalListen(null); - TestLocalListen("string topic"); TestLocalListen(NextId()); + + foreach (var topic in Objects) + { + TestLocalListen(topic); + } } /// <summary> @@ -145,9 +201,13 @@ namespace Apache.Ignite.Core.Tests [Test] public void TestLocalListenProjection() { - TestLocalListenProjection(null); - TestLocalListenProjection("prj"); TestLocalListenProjection(NextId()); + TestLocalListenProjection("prj"); + + foreach (var topic in Objects) + { + TestLocalListenProjection(topic); + } } /// <summary> @@ -266,22 +326,14 @@ namespace Apache.Ignite.Core.Tests /// Tests RemoteListen. /// </summary> [Test] - public void TestRemoteListen() + public void TestRemoteListen([Values(true, false)] bool async) { - TestRemoteListen(null); - TestRemoteListen("string topic"); - TestRemoteListen(NextId()); - } + TestRemoteListen(NextId(), async); - /// <summary> - /// Tests RemoteListen with async mode enabled. - /// </summary> - [Test] - public void TestRemoteListenAsync() - { - TestRemoteListen(null, true); - TestRemoteListen("string topic", true); - TestRemoteListen(NextId(), true); + foreach (var topic in Objects) + { + TestRemoteListen(topic, async); + } } /// <summary> @@ -335,9 +387,12 @@ namespace Apache.Ignite.Core.Tests [Test] public void TestRemoteListenProjection() { - TestRemoteListenProjection(null); - TestRemoteListenProjection("string topic"); TestRemoteListenProjection(NextId()); + + foreach (var topic in Objects) + { + TestRemoteListenProjection(topic); + } } /// <summary>
