forked from yevhen/Streamstone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Virtual_partitions.cs
78 lines (62 loc) · 2.26 KB
/
Virtual_partitions.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure.Data.Tables;
using NUnit.Framework;
namespace Streamstone.Scenarios
{
[TestFixture]
public class Virtual_partitions
{
TableClient table;
Partition partition;
Partition virtual1;
Partition virtual2;
[SetUp]
public void SetUp()
{
table = Storage.SetUp();
partition = new Partition(table, "test");
virtual1 = new Partition(table, "test|123");
virtual2 = new Partition(table, "test", "456");
}
[Test]
public async Task When_provisioning()
{
await Stream.ProvisionAsync(virtual1, default);
await Stream.ProvisionAsync(virtual2, default);
Assert.That(partition.RetrieveAll().Count, Is.EqualTo(2));
}
[Test]
public async Task When_opening()
{
await Stream.ProvisionAsync(virtual1, default);
Assert.That((await Stream.TryOpenAsync(virtual1, default)).Found, Is.True);
Assert.That((await Stream.TryOpenAsync(virtual2, default)).Found, Is.False);
}
[Test]
public async Task When_writing_and_reading()
{
var stream1 = new Stream(virtual1);
var stream2 = new Stream(virtual2);
var e1 = CreateEvent("e1");
var e2 = CreateEvent("e2");
await Stream.WriteAsync(stream1, default, e1, e2);
await Stream.WriteAsync(stream2, default, e1, e2);
Assert.That(partition.RetrieveAll().Count,
Is.EqualTo(2 + 2 * (2 * 2)));
var slice1 = await Stream.ReadAsync<TestRecordedEventEntity>(virtual1, default);
var slice2 = await Stream.ReadAsync<TestRecordedEventEntity>(virtual2, default);
Assert.That(slice1.Events.Length, Is.EqualTo(2));
Assert.That(slice2.Events.Length, Is.EqualTo(2));
}
static EventData CreateEvent(string id)
{
var properties = new Dictionary<string, object>
{
{"Type", "StreamChanged"},
{"Data", "{}"}
};
return new EventData(EventId.From(id), EventProperties.From(properties));
}
}
}