forked from voldemort/voldemort
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVectorClock_test.cpp
More file actions
101 lines (82 loc) · 3.45 KB
/
Copy pathVectorClock_test.cpp
File metadata and controls
101 lines (82 loc) · 3.45 KB
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
/* -*- C++ -*-; c-basic-offset: 4; indent-tabs-mode: nil */
/*
* Test suite for VectorClock class.
*
* Copyright (c) 2009 Webroot Software, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
#include "VectorClock.h"
using namespace Voldemort;
using namespace std;
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE(VectorClock_test)
BOOST_AUTO_TEST_CASE( empty_test ) {
std::list<std::pair<short, uint64_t> > versions;
VectorClock emptyClock(&versions, 0L);
BOOST_CHECK_MESSAGE(emptyClock.compare(&emptyClock) != Version::CONCURRENTLY,
"Empty clocks should not be concurrent");
}
BOOST_AUTO_TEST_CASE( identical_test ) {
std::list<std::pair<short, uint64_t> > versions;
versions.push_back(make_pair((short)1, 2));
versions.push_back(make_pair((short)2, 1));
VectorClock clock(&versions, 0L);
BOOST_CHECK_MESSAGE(clock.compare(&clock) == Version::EQUAL,
"Identical clocks should be equal");
}
BOOST_AUTO_TEST_CASE( single_addition_test ) {
std::list<std::pair<short, uint64_t> > versions;
versions.push_back(make_pair((short)1, 2));
versions.push_back(make_pair((short)2, 1));
VectorClock clock1(&versions, 0L);
versions.push_back(make_pair((short)3, 1));
VectorClock clock2(&versions, 0L);
BOOST_CHECK_MESSAGE(clock1.compare(&clock2) == Version::BEFORE,
"A clock should happen before an identical clock "
"with a single additional event");
}
BOOST_AUTO_TEST_CASE( larger_test ) {
std::list<std::pair<short, uint64_t> > versions;
versions.push_back(make_pair((short)1, 2));
versions.push_back(make_pair((short)2, 1));
VectorClock clock1(&versions, 0L);
versions.clear();
versions.push_back(make_pair((short)1, 1));
versions.push_back(make_pair((short)2, 1));
versions.push_back(make_pair((short)3, 1));
VectorClock clock2(&versions, 0L);
BOOST_CHECK_MESSAGE(clock1.compare(&clock2) == Version::CONCURRENTLY,
"Result should be CONCURRENTLY");
}
BOOST_AUTO_TEST_CASE( different_events_test ) {
std::list<std::pair<short, uint64_t> > versions;
versions.push_back(make_pair((short)1, 1));
VectorClock clock3(&versions, 0L);
versions.clear();
versions.push_back(make_pair((short)2, 1));
VectorClock clock4(&versions, 0L);
BOOST_CHECK_MESSAGE(clock3.compare(&clock4) == Version::CONCURRENTLY,
"Clocks with different events should be concurrent.");
versions.clear();
versions.push_back(make_pair((short)1, 2));
versions.push_back(make_pair((short)2, 1));
VectorClock clock5(&versions, 0L);
versions.clear();
versions.push_back(make_pair((short)1, 2));
versions.push_back(make_pair((short)3, 1));
VectorClock clock6(&versions, 0L);
BOOST_CHECK_MESSAGE(clock5.compare(&clock6) == Version::CONCURRENTLY,
"Clocks with different events should be concurrent.");
}
BOOST_AUTO_TEST_SUITE_END()