Skip to content

Commit c9ec3c0

Browse files
author
Brett Hazen
committed
Initial test for strong consistency
1 parent e59c88f commit c9ec3c0

File tree

3 files changed

+62
-3
lines changed

3 files changed

+62
-3
lines changed

riak/tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
SKIP_POOL = os.environ.get('SKIP_POOL')
4040
SKIP_RESOLVE = int(os.environ.get('SKIP_RESOLVE', '0'))
4141
SKIP_BTYPES = int(os.environ.get('SKIP_BTYPES', '0'))
42+
RUN_CONSISTENCY = int(os.environ.get('RUN_CONSISTENCY', '0'))
4243

4344
RUN_SECURITY = int(os.environ.get('RUN_SECURITY', '0'))
4445
SECURITY_USER = os.environ.get('RIAK_TEST_SECURITY_USER', 'testuser')

riak/tests/test_all.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,33 @@
2323
from riak.tests.test_2i import TwoITests
2424
from riak.tests.test_btypes import BucketTypeTests
2525
from riak.tests.test_security import SecurityTests
26+
from riak.tests.test_consistency import StrongConsistencyTests
2627

2728
from riak.tests import HOST, PB_HOST, PB_PORT, HTTP_HOST, HTTP_PORT, \
2829
HAVE_PROTO, DUMMY_HTTP_PORT, DUMMY_PB_PORT, \
29-
SKIP_SEARCH, RUN_YZ, SECURITY_CREDS
30+
SKIP_SEARCH, RUN_YZ, SECURITY_CREDS, RUN_CONSISTENCY
3031

3132
testrun_search_bucket = None
3233
testrun_props_bucket = None
3334
testrun_sibs_bucket = None
3435
testrun_yz_bucket = None
3536
testrun_mr_btype = None
3637
testrun_mr_bucket = None
38+
testrun_consist_bucket = None
3739

3840

3941
def setUpModule():
4042
global testrun_search_bucket, testrun_props_bucket, \
4143
testrun_sibs_bucket, testrun_yz_bucket, testrun_mr_btype, \
42-
testrun_mr_bucket
44+
testrun_mr_bucket, testrun_consist_bucket
4345

4446
c = RiakClient(protocol='pbc', host=PB_HOST, http_port=HTTP_PORT,
4547
pb_port=PB_PORT, credentials=SECURITY_CREDS)
4648

4749
testrun_props_bucket = 'propsbucket'
4850
testrun_sibs_bucket = 'sibsbucket'
4951
c.bucket(testrun_sibs_bucket).allow_mult = True
52+
testrun_consist_bucket = 'pytest-consistent'
5053

5154
if (not SKIP_SEARCH and not RUN_YZ):
5255
testrun_search_bucket = 'searchbucket'
@@ -82,7 +85,7 @@ def setUpModule():
8285

8386
def tearDownModule():
8487
global testrun_search_bucket, testrun_props_bucket, \
85-
testrun_sibs_bucket, testrun_yz_bucket
88+
testrun_sibs_bucket, testrun_yz_bucket, testrun_consist_bucket
8689

8790
c = RiakClient(protocol='http', host=HTTP_HOST, http_port=HTTP_PORT,
8891
pb_port=PB_PORT, credentials=SECURITY_CREDS)
@@ -153,6 +156,7 @@ def setUp(self):
153156
self.mr_btype = testrun_mr_btype
154157
self.mr_bucket = testrun_mr_bucket
155158
self.credentials = SECURITY_CREDS
159+
self.consistent_bucket = testrun_consist_bucket
156160

157161
self.client = self.create_client()
158162

@@ -314,6 +318,7 @@ class RiakPbcTransportTestCase(BasicKVTests,
314318
CounterTests,
315319
BucketTypeTests,
316320
SecurityTests,
321+
StrongConsistencyTests,
317322
BaseTestCase,
318323
unittest.TestCase):
319324

@@ -348,6 +353,7 @@ class RiakHttpTransportTestCase(BasicKVTests,
348353
CounterTests,
349354
BucketTypeTests,
350355
SecurityTests,
356+
StrongConsistencyTests,
351357
BaseTestCase,
352358
unittest.TestCase):
353359

riak/tests/test_consistency.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"""
2+
Copyright 2014 Basho Technologies, Inc.
3+
4+
This file is provided to you under the Apache License,
5+
Version 2.0 (the "License"); you may not use this file
6+
except in compliance with the License. You may obtain
7+
a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing,
12+
software distributed under the License is distributed on an
13+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
KIND, either express or implied. See the License for the
15+
specific language governing permissions and limitations
16+
under the License.
17+
"""
18+
19+
import platform
20+
if platform.python_version() < '2.7':
21+
unittest = __import__('unittest2')
22+
else:
23+
import unittest
24+
from riak.tests import RUN_CONSISTENCY
25+
26+
27+
class StrongConsistencyTests(object):
28+
@unittest.skipUnless(RUN_CONSISTENCY, 'RUN_CONSISTENCY is undefined')
29+
def test_consistency(self):
30+
"""
31+
Test the case where strong consistency has been enabled.
32+
"""
33+
btype = self.client.bucket_type(self.consistent_bucket)
34+
bucket = btype.bucket(self.consistent_bucket)
35+
key_name = self.randname()
36+
rand = self.randint()
37+
obj = bucket.new(key_name, rand)
38+
obj.store()
39+
read1 = bucket.get(key_name)
40+
read2 = bucket.get(key_name)
41+
rand1 = self.randint()
42+
read1.data = rand1
43+
read1.store()
44+
read1.reload()
45+
# read2 will have old VClock so write should fail
46+
rand2 = self.randint()
47+
read2.data = rand2
48+
with self.assertRaises(Exception):
49+
read2.store()
50+
51+
def test_consistency_empty_key(self):
52+
pass

0 commit comments

Comments
 (0)