~ntt-pf-lab/nova/monkey_patch_notification

« back to all changes in this revision

Viewing changes to nova/tests/keeper_unittest.py

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
import random
 
3
 
 
4
from nova import datastore
 
5
from nova import test
 
6
 
 
7
class KeeperTestCase(test.TrialTestCase):
 
8
    """
 
9
    Basic persistence tests for Keeper datastore.
 
10
    Generalize, then use these to support
 
11
    migration to redis / cassandra / multiple stores.
 
12
    """
 
13
 
 
14
    def setUp(self):
 
15
        super(KeeperTestCase, self).setUp()
 
16
        self.keeper = datastore.Keeper('test')
 
17
 
 
18
    def tearDown(self):
 
19
        super(KeeperTestCase, self).tearDown()
 
20
        self.keeper.clear()
 
21
 
 
22
    def test_store_strings(self):
 
23
        """
 
24
        Confirm that simple strings go in and come out safely.
 
25
        Should also test unicode strings.
 
26
        """
 
27
        randomstring = ''.join(
 
28
                [random.choice('ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-')
 
29
                 for _x in xrange(20)]
 
30
                )
 
31
        self.keeper['test_string'] = randomstring
 
32
        self.assertEqual(randomstring, self.keeper['test_string'])
 
33
 
 
34
    def test_store_dicts(self):
 
35
        """
 
36
        Arbitrary dictionaries should be storable.
 
37
        """
 
38
        test_dict = {'key_one': 'value_one'}
 
39
        self.keeper['test_dict'] = test_dict
 
40
        self.assertEqual(test_dict['key_one'],
 
41
            self.keeper['test_dict']['key_one'])
 
42
 
 
43
    def test_sets(self):
 
44
        """
 
45
        A keeper dict should be self-serializing.
 
46
        """
 
47
        self.keeper.set_add('test_set', 'foo')
 
48
        test_dict = {'arbitrary': 'dict of stuff'}
 
49
        self.keeper.set_add('test_set', test_dict)
 
50
        self.assertTrue(self.keeper.set_is_member('test_set', 'foo'))
 
51
        self.assertFalse(self.keeper.set_is_member('test_set', 'bar'))
 
52
        self.keeper.set_remove('test_set', 'foo')
 
53
        self.assertFalse(self.keeper.set_is_member('test_set', 'foo'))
 
54
        rv = self.keeper.set_fetch('test_set')
 
55
        self.assertEqual(test_dict, rv.next())
 
56
        self.keeper.set_remove('test_set', test_dict)
 
57