-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyRavenDb.cs
50 lines (42 loc) · 1.43 KB
/
MyRavenDb.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
48
49
50
using Raven.Embedded;
namespace DbBench;
public class MyRavenDb : BenchDb
{
public static bool IsServerStarted = false;
public override async Task BenchWrite()
{
if (!IsServerStarted)
{
EmbeddedServer.Instance.StartServer(new ServerOptions() {DataDirectory = GetDatabaseStoragePath(), FrameworkVersion = "6.0.0"});
IsServerStarted = true;
}
using var store = await EmbeddedServer.Instance.GetDocumentStoreAsync("Embedded").ConfigureAwait(false);
using var session = store.OpenSession();
foreach (var commonRecord in session.Query<CommonRecord>())
{
session.Delete(commonRecord);
}
session.SaveChanges();
foreach (var numb in Enumerable.Range(0, NumberOfDocs))
{
session.Store(new CommonRecord()
{
Name = "John",
Age = numb,
Timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds()
});
}
session.SaveChanges();
}
public override async Task<int> BenchRead()
{
using var store = await EmbeddedServer.Instance.GetDocumentStoreAsync("Embedded").ConfigureAwait(false);
using var session = store.OpenSession();
var total = 0;
foreach (var commonRecord in session.Query<CommonRecord>())
{
total += commonRecord.Age;
}
return total;
}
}