Browse Source

Add Dataflow specific boilerplate & interfaces

Jérémie Laval 14 years ago
parent
commit
ffa53c322c

+ 10 - 0
mcs/class/System.Threading.Tasks.Dataflow/System.Threading.Tasks.Dataflow.dll.sources

@@ -3,3 +3,13 @@
 ../../build/common/MonoTODOAttribute.cs
 Assembly/AssemblyInfo.cs
 System.Threading.Tasks/ConcurrentExclusiveSchedulerPair.cs
+System.Threading.Tasks.Dataflow/DataflowBlockOptions.cs
+System.Threading.Tasks.Dataflow/DataflowMessageHeader.cs
+System.Threading.Tasks.Dataflow/DataflowMessageStatus.cs
+System.Threading.Tasks.Dataflow/ExecutionDataflowBlockOptions.cs
+System.Threading.Tasks.Dataflow/GroupingDataflowBlockOptions.cs
+System.Threading.Tasks.Dataflow/IDataflowBlock.cs
+System.Threading.Tasks.Dataflow/IPropagatorBlock.cs
+System.Threading.Tasks.Dataflow/IReceivableSourceBlock.cs
+System.Threading.Tasks.Dataflow/ISourceBlock.cs
+System.Threading.Tasks.Dataflow/ITargetBlock.cs

+ 66 - 0
mcs/class/System.Threading.Tasks.Dataflow/System.Threading.Tasks.Dataflow/DataflowBlockOptions.cs

@@ -0,0 +1,66 @@
+// DataflowBlockOptions.cs
+//
+// Copyright (c) 2011 Jérémie "garuma" Laval
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+//
+
+#if NET_4_0 || MOBILE
+
+using System;
+using System.Threading.Tasks;
+
+namespace System.Threading.Tasks.Dataflow
+{
+	public class DataflowBlockOptions
+	{
+		public readonly static int Unbounded = -1;
+
+		public DataflowBlockOptions ()
+		{
+			BoundedCapacity = -1;
+			CancellationToken = CancellationToken.None;
+			MaxMessagesPerTask = -1;
+			TaskScheduler = TaskScheduler.Default;
+		}
+
+		public int BoundedCapacity {
+			get;
+			set;
+		}
+
+		public CancellationToken CancellationToken {
+			get;
+			set;
+		}
+
+		public int MaxMessagesPerTask {
+			get;
+			set;
+		}
+
+		public TaskScheduler TaskScheduler {
+			get;
+			set;
+		}
+	}
+}
+
+#endif

+ 91 - 0
mcs/class/System.Threading.Tasks.Dataflow/System.Threading.Tasks.Dataflow/DataflowMessageHeader.cs

@@ -0,0 +1,91 @@
+// DataflowMessageHeader.cs
+//
+// Copyright (c) 2011 Jérémie "garuma" Laval
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+//
+
+#if NET_4_0 || MOBILE
+
+using System;
+using System.Threading.Tasks;
+
+namespace System.Threading.Tasks.Dataflow
+{
+	public struct DataflowMessageHeader : IEquatable<DataflowMessageHeader>
+	{
+		long id;
+
+		public DataflowMessageHeader (long id)
+		{
+			this.id = id;
+		}
+
+		public long Id {
+			get {
+				return id;
+			}
+		}
+
+		public bool IsValid {
+			get {
+				// Check that id isn't zero (as it would be with an empty struct ctor)
+				return id > 0;
+			}
+		}
+
+		internal DataflowMessageHeader Increment ()
+		{
+			return new DataflowMessageHeader (Interlocked.Increment (ref id));
+		}
+
+		internal static DataflowMessageHeader NewValid ()
+		{
+			return new DataflowMessageHeader (1);
+		}
+
+		public override bool Equals (object obj)
+		{
+			return obj is DataflowMessageHeader ? Equals ((DataflowMessageHeader)obj) : false;
+		}
+
+		public bool Equals (DataflowMessageHeader other)
+		{
+			return other.id == id;
+		}
+
+		public override int GetHashCode ()
+		{
+			return id.GetHashCode ();
+		}
+
+		public static bool operator== (DataflowMessageHeader left, DataflowMessageHeader right)
+		{
+			return left.Equals (right);
+		}
+
+		public static bool operator!= (DataflowMessageHeader left, DataflowMessageHeader right)
+		{
+			return !left.Equals (right);
+		}
+	}
+}
+
+#endif

+ 43 - 0
mcs/class/System.Threading.Tasks.Dataflow/System.Threading.Tasks.Dataflow/DataflowMessageStatus.cs

@@ -0,0 +1,43 @@
+// DataflowMessageStatus.cs
+//
+// Copyright (c) 2011 Jérémie "garuma" Laval
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+//
+
+#if NET_4_0 || MOBILE
+
+using System;
+using System.Threading.Tasks;
+using System.Collections.Generic;
+
+namespace System.Threading.Tasks.Dataflow
+{
+	public enum DataflowMessageStatus
+	{
+		Accepted,
+		Declined,
+		Postponed,
+		NotAvailable,
+		DecliningPermanently
+	}
+}
+
+#endif

+ 46 - 0
mcs/class/System.Threading.Tasks.Dataflow/System.Threading.Tasks.Dataflow/ExecutionDataflowBlockOptions.cs

@@ -0,0 +1,46 @@
+// ExecutionDataflowBlockOptions.cs
+//
+// Copyright (c) 2011 Jérémie "garuma" Laval
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+//
+
+#if NET_4_0 || MOBILE
+
+using System;
+using System.Threading.Tasks;
+
+namespace System.Threading.Tasks.Dataflow
+{
+	public class ExecutionDataflowBlockOptions : DataflowBlockOptions
+	{
+		public ExecutionDataflowBlockOptions ()
+		{
+			MaxDegreeOfParallelism = 1;
+		}
+
+		public int MaxDegreeOfParallelism {
+			get;
+			set;
+		}
+	}
+}
+
+#endif

+ 51 - 0
mcs/class/System.Threading.Tasks.Dataflow/System.Threading.Tasks.Dataflow/GroupingDataflowBlockOptions.cs

@@ -0,0 +1,51 @@
+// GroupingDataflowBlockOptions.cs
+//
+// Copyright (c) 2011 Jérémie "garuma" Laval
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+//
+
+#if NET_4_0 || MOBILE
+
+using System;
+using System.Threading.Tasks;
+
+namespace System.Threading.Tasks.Dataflow
+{
+	public class GroupingDataflowBlockOptions : DataflowBlockOptions
+	{
+		public GroupingDataflowBlockOptions ()
+		{
+			MaxNumberOfGroups = -1;
+		}
+
+		public bool Greedy {
+			get;
+			set;
+		}
+
+		public long MaxNumberOfGroups {
+			get;
+			set;
+		}
+	}
+}
+
+#endif

+ 43 - 0
mcs/class/System.Threading.Tasks.Dataflow/System.Threading.Tasks.Dataflow/IDataflowBlock.cs

@@ -0,0 +1,43 @@
+// IDataflowBlock.cs
+//
+// Copyright (c) 2011 Jérémie "garuma" Laval
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+//
+
+#if NET_4_0 || MOBILE
+
+using System;
+using System.Threading.Tasks;
+
+namespace System.Threading.Tasks.Dataflow
+{
+	public interface IDataflowBlock
+	{
+		Task Completion {
+			get;
+		}
+
+		void Complete ();
+		void Fault (Exception exception);
+	}
+}
+
+#endif

+ 39 - 0
mcs/class/System.Threading.Tasks.Dataflow/System.Threading.Tasks.Dataflow/IPropagatorBlock.cs

@@ -0,0 +1,39 @@
+// IPropagatorBlock.cs
+//
+// Copyright (c) 2011 Jérémie "garuma" Laval
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+//
+
+#if NET_4_0 || MOBILE
+
+using System;
+using System.Threading.Tasks;
+using System.Collections.Generic;
+
+namespace System.Threading.Tasks.Dataflow
+{
+	public interface IPropagatorBlock<TInput, TOutput> : ITargetBlock<TInput>, IDataflowBlock, ISourceBlock<TOutput>
+	{
+
+	}
+}
+
+#endif

+ 40 - 0
mcs/class/System.Threading.Tasks.Dataflow/System.Threading.Tasks.Dataflow/IReceivableSourceBlock.cs

@@ -0,0 +1,40 @@
+// DataflowBlockOptions.cs
+//
+// Copyright (c) 2011 Jérémie "garuma" Laval
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+//
+
+#if NET_4_0 || MOBILE
+
+using System;
+using System.Threading.Tasks;
+using System.Collections.Generic;
+
+namespace System.Threading.Tasks.Dataflow
+{
+	public interface IReceivableSourceBlock<TOutput> : ISourceBlock<TOutput>, IDataflowBlock
+	{
+		bool TryReceive (Predicate<TOutput> filter, out TOutput item);
+		bool TryReceiveAll (out IList<TOutput> items);
+	}
+}
+
+#endif

+ 41 - 0
mcs/class/System.Threading.Tasks.Dataflow/System.Threading.Tasks.Dataflow/ISourceBlock.cs

@@ -0,0 +1,41 @@
+// ISourceBlock.cs
+//
+// Copyright (c) 2011 Jérémie "garuma" Laval
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+//
+
+#if NET_4_0 || MOBILE
+
+using System;
+using System.Threading.Tasks;
+
+namespace System.Threading.Tasks.Dataflow
+{
+	public interface ISourceBlock<TOutput> : IDataflowBlock
+	{
+		TOutput ConsumeMessage (DataflowMessageHeader messageHeader, ITargetBlock<TOutput> target, out bool messageConsumed);
+		IDisposable LinkTo (ITargetBlock<TOutput> target, bool unlinkAfterOne);
+		void ReleaseReservation (DataflowMessageHeader messageHeader, ITargetBlock<TOutput> target);
+		bool ReserveMessage (DataflowMessageHeader messageHeader, ITargetBlock<TOutput> target);
+	}
+}
+
+#endif

+ 41 - 0
mcs/class/System.Threading.Tasks.Dataflow/System.Threading.Tasks.Dataflow/ITargetBlock.cs

@@ -0,0 +1,41 @@
+// ITargetBlock.cs
+//
+// Copyright (c) 2011 Jérémie "garuma" Laval
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+//
+
+#if NET_4_0 || MOBILE
+
+using System;
+using System.Threading.Tasks;
+
+namespace System.Threading.Tasks.Dataflow
+{
+	public interface ITargetBlock<TInput> : IDataflowBlock
+	{
+		DataflowMessageStatus OfferMessage (DataflowMessageHeader messageHeader,
+		                                    TInput messageValue,
+		                                    ISourceBlock<TInput> source,
+		                                    bool consumeToAccept);
+	}
+}
+
+#endif

+ 1 - 0
mcs/class/System.Threading.Tasks.Dataflow/System.Threading.Tasks.Dataflow_test.dll.sources

@@ -1 +1,2 @@
 System.Threading.Tasks/ConcurrentExclusiveSchedulerPairTest.cs
+System.Threading.Tasks.Dataflow/DataflowMessageHeaderTest.cs

+ 67 - 0
mcs/class/System.Threading.Tasks.Dataflow/Test/System.Threading.Tasks.Dataflow/DataflowMessageHeaderTest.cs

@@ -0,0 +1,67 @@
+#if NET_4_0
+// 
+// DataflowMessageHeaderTest.cs
+//  
+// Author:
+//       Jérémie "garuma" Laval <[email protected]>
+// 
+// Copyright (c) 2011 Jérémie "garuma" Laval
+// 
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+// 
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using System;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
+using System.Threading.Tasks.Dataflow;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Threading.Tasks.Dataflow
+{
+	[TestFixture]
+	public class DataflowMessageHeaderTest
+	{
+		[Test]
+		public void EqualityTest ()
+		{
+			var header1 = new DataflowMessageHeader (2);
+			var header2 = new DataflowMessageHeader (5);
+			var header3 = new DataflowMessageHeader (2);
+
+			Assert.AreEqual (header1, header1);
+			Assert.AreEqual (header1.GetHashCode (), header1.GetHashCode ());
+			Assert.AreEqual (header1, header3);
+			Assert.AreEqual (header1.GetHashCode (), header3.GetHashCode ());
+			Assert.AreNotEqual (header1, header2);
+			Assert.AreNotEqual (header1.GetHashCode (), header2.GetHashCode ());
+		}
+
+		[Test]
+		public void ValidityTest ()
+		{
+			var header1 = new DataflowMessageHeader ();
+			var header2 = new DataflowMessageHeader (2);
+
+			Assert.IsFalse (header1.IsValid);
+			Assert.IsTrue (header2.IsValid);
+		}
+	}
+}
+#endif