forked from litedb-org/LiteDB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParallelQuery_Tests.cs
47 lines (38 loc) · 1.26 KB
/
ParallelQuery_Tests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System.Collections.Concurrent;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using FluentAssertions;
using Xunit;
namespace LiteDB.Tests.Engine
{
public class ParallelQuery_Tests
{
[Fact(Skip = "Must fix parallel query fetch")]
public void Query_Parallel()
{
using(var db = new LiteDatabase(new MemoryStream()))
{
var col = db.GetCollection<Person>("person");
var all = DataGen.Person().ToArray();
col.Insert(all);
var bag = new ConcurrentBag<Person>();
var people = col.FindAll();
Parallel.ForEach(people, person =>
//foreach(var person in people)
{
var col2 = db.GetCollection<Person>("person");
var exists = col2.Exists(x => x.Id == person.Id);
if (exists)
{
var col3 = db.GetCollection<Person>("person");
var item = col3.FindOne(x => x.Id == person.Id);
bag.Add(item);
}
});
all.Length.Should().Be(bag.Count);
}
}
}
}