This repository was archived by the owner on Sep 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathTokenTest.cs
130 lines (102 loc) · 3.73 KB
/
TokenTest.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
using System;
using System.IO.Packaging;
using CqlSharp.Network.Partition;
using CqlSharp.Serialization;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace CqlSharp.Test
{
[TestClass]
public class TokenTest
{
[TestMethod]
public void CompositeTokenValue1()
{
/*
id1 | id2 | token_id1__id2
-----+-----+----------------------
10 | 20 | -9026262514124674157
*/
var key = new PartitionKey();
key.Set(new[] {CqlType.Int, CqlType.Text}, new object[] {10, "20"});
var calculatedToken = new MurmurToken();
calculatedToken.Parse(key.GetValue());
var tokenFromCassandra = new MurmurToken();
tokenFromCassandra.Parse("-9026262514124674157");
Assert.AreEqual(tokenFromCassandra, calculatedToken);
}
[TestMethod]
public void CompositeTokenValueFromClass()
{
/*
id1 | id2 | token_id1__id2
-----+-----+----------------------
10 | 20 | -9026262514124674157
*/
var key = new PartitionKey();
key.Set(new CompositeKeyType { Id1 = 10, Id2 = "20", Val="test"});
var calculatedToken = new MurmurToken();
calculatedToken.Parse(key.GetValue());
var tokenFromCassandra = new MurmurToken();
tokenFromCassandra.Parse("-9026262514124674157");
Assert.AreEqual(tokenFromCassandra, calculatedToken);
}
[TestMethod]
public void CompositeTokenValue2()
{
/*
id1 | id2 | token_id1__id2
-----+-----+----------------------
1 | 2 | 4093852821103061060
*/
var key = new PartitionKey();
key.Set(new[] { CqlType.Int, CqlType.Text }, new object[] { 1, "2" });
var calculatedToken = new MurmurToken();
calculatedToken.Parse(key.GetValue());
var tokenFromCassandra = new MurmurToken();
tokenFromCassandra.Parse("4093852821103061060");
Assert.AreEqual(tokenFromCassandra, calculatedToken);
}
[TestMethod]
public void SingleTokenValue()
{
/*
id1 | token_id1
-----+----------------------
1 | -4069959284402364209
*/
var key = new PartitionKey();
key.Set(CqlType.Int, 1);
var calculatedToken = new MurmurToken();
calculatedToken.Parse(key.GetValue());
var tokenFromCassandra = new MurmurToken();
tokenFromCassandra.Parse("-4069959284402364209");
Assert.AreEqual(tokenFromCassandra, calculatedToken);
}
[TestMethod]
public void SingleTokenValueFromArray()
{
/*
id1 | token_id1
-----+----------------------
1 | -4069959284402364209
*/
var key = new PartitionKey();
key.Set(new[] { CqlType.Int }, new object[] { 1 });
var calculatedToken = new MurmurToken();
calculatedToken.Parse(key.GetValue());
var tokenFromCassandra = new MurmurToken();
tokenFromCassandra.Parse("-4069959284402364209");
Assert.AreEqual(tokenFromCassandra, calculatedToken);
}
class CompositeKeyType
{
[CqlColumn(Order = 0)]
[CqlKey(IsPartitionKey = true)]
public int Id1 { get; set; }
[CqlColumn(Order = 1)]
[CqlKey(IsPartitionKey = true)]
public string Id2 { get; set; }
public string Val { get; set; }
}
}
}