forked from LGouellec/streamiz
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
101 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
test/Streamiz.Kafka.Net.Tests/Private/ConcurrentSetTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using NUnit.Framework; | ||
using Streamiz.Kafka.Net.State.InMemory.Internal; | ||
|
||
namespace Streamiz.Kafka.Net.Tests.Private; | ||
|
||
public class ConcurrentSetTests | ||
{ | ||
private ConcurrentSet<string> concurrentSet; | ||
|
||
[SetUp] | ||
public void Init() | ||
{ | ||
concurrentSet = new(); | ||
} | ||
|
||
[TearDown] | ||
public void Dispose() | ||
{ | ||
concurrentSet.Clear(); | ||
} | ||
|
||
[TestCase(1000)] | ||
public void ConcurrencyAdded(int numberTasks) | ||
{ | ||
var taskList = new List<Task>(); | ||
for (int i = 0; i < numberTasks; i++) | ||
{ | ||
taskList.Add(Task.Factory.StartNew((Object obj) => | ||
{ | ||
concurrentSet.Add(Guid.NewGuid().ToString()); | ||
}, null)); | ||
} | ||
Task.WaitAll(taskList.ToArray()); | ||
Assert.AreEqual(numberTasks, concurrentSet.Count); | ||
} | ||
|
||
[TestCase(1000)] | ||
public void ConcurrencyRemoved(int numberTasks) | ||
{ | ||
for (int i = 0; i < numberTasks; i++) | ||
concurrentSet.Add(i.ToString()); | ||
|
||
var taskList = new List<Task>(); | ||
for (int i = 0; i < numberTasks; i++) | ||
{ | ||
taskList.Add(Task.Factory.StartNew((Object obj) => | ||
{ | ||
concurrentSet.Remove(obj.ToString()); | ||
}, i)); | ||
} | ||
|
||
Task.WaitAll(taskList.ToArray()); | ||
Assert.AreEqual(0, concurrentSet.Count); | ||
} | ||
|
||
[TestCase(10000)] | ||
public void ConcurrencyAddedAndForeach(int numberTasks) | ||
{ | ||
var taskList = new List<Task>(); | ||
for (int i = 0; i < numberTasks; i++) | ||
{ | ||
taskList.Add(Task.Factory.StartNew((Object obj) => | ||
{ | ||
concurrentSet.Add(Guid.NewGuid().ToString()); | ||
foreach (var c in concurrentSet) | ||
; | ||
}, null)); | ||
} | ||
Task.WaitAll(taskList.ToArray()); | ||
Assert.AreEqual(numberTasks, concurrentSet.Count); | ||
} | ||
|
||
[TestCase(10000)] | ||
public void ConcurrencyAddedAndContains(int numberTasks) | ||
{ | ||
var taskList = new List<Task>(); | ||
for (int i = 0; i < numberTasks; i++) | ||
{ | ||
taskList.Add(Task.Factory.StartNew((Object obj) => | ||
{ | ||
var guid = Guid.NewGuid().ToString(); | ||
concurrentSet.Add(guid); | ||
Assert.IsTrue(concurrentSet.Contains(guid)); | ||
}, null)); | ||
} | ||
Task.WaitAll(taskList.ToArray()); | ||
Assert.AreEqual(numberTasks, concurrentSet.Count); | ||
} | ||
|
||
} |