forked from yevhen/Streamstone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Virtual_partitions.cs
82 lines (64 loc) · 2.27 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
79
80
81
82
using System;
using System.Linq;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos.Table;
using NUnit.Framework;
namespace Streamstone.Scenarios
{
[TestFixture]
public class Virtual_partitions
{
CloudTable 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);
await Stream.ProvisionAsync(virtual2);
Assert.That(partition.RetrieveAll().Count, Is.EqualTo(2));
}
[Test]
public async Task When_opening()
{
await Stream.ProvisionAsync(virtual1);
Assert.True((await Stream.TryOpenAsync(virtual1)).Found);
Assert.False((await Stream.TryOpenAsync(virtual2)).Found);
}
[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, e1, e2);
await Stream.WriteAsync(stream2, e1, e2);
Assert.That(partition.RetrieveAll().Count,
Is.EqualTo(2 + 2*(2*2)));
var slice1 = await Stream.ReadAsync<TestRecordedEventEntity>(virtual1);
var slice2 = await Stream.ReadAsync<TestRecordedEventEntity>(virtual2);
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, EntityProperty>
{
{"Type", new EntityProperty("StreamChanged")},
{"Data", new EntityProperty("{}")}
};
return new EventData(EventId.From(id), EventProperties.From(properties));
}
}
}