def setUp(self): self.connection = aws_simpledb.SimpleDB() # If the testing domain, already exists, delete it if self.connection.has_domain(settings.test_domains[0]): helpers.msg(self, 'Test domain already exists - delete it') self.connection.delete_domain(settings.test_domains[0]) helpers.eventualConsistencySleep()
def test_03_get(self): # initiate the test items # domain a consistent_sdb.connection.delete_attributes(settings.test_domains[0], self.test_items[0]) consistent_sdb.connection.delete_attributes(settings.test_domains[0], self.test_items[1]) consistent_sdb.connection.delete_attributes(settings.test_domains[0], self.test_items[2]) # domain b consistent_sdb.connection.delete_attributes(settings.test_domains[1], self.test_items[0]) # put records to more than one domain at once. put_records = { settings.test_domains[0]: { self.test_items[0]: { 'attribute_a': { 'values': set(['a', 'b']), 'replace': False } }, self.test_items[1]: { 'attribute_b': { 'values': set(['c', 'd']), 'replace': False } } }, settings.test_domains[1]: { self.test_items[0]: { 'attribute_a': { 'values': set(['a', 'b']), 'replace': False } } } } consistent_sdb.put(put_records) helpers.eventualConsistencySleep() get_records = { settings.test_domains[0]: { self.test_items[0]: ['attribute_a'], self.test_items[1]: [] }, settings.test_domains[1]: { self.test_items[0]: [] }, } print consistent_sdb.get(get_records)
def test_00_put_attributes(self): # new attributes, some with more with one value self.connection.put_attributes( settings.test_domains[0], self.test_items[0], { 'a': { 'values': ['1', '2'], 'replace': False }, 'b': { 'values': ['3'], 'replace': False }, 'c': { 'values': ['4'], 'replace': False } }) # append attributes self.connection.put_attributes( settings.test_domains[0], self.test_items[0], {'b': { 'values': ['2'], 'replace': False }}) # override attributes self.connection.put_attributes( settings.test_domains[0], self.test_items[0], {'c': { 'values': ['3'], 'replace': True }}) helpers.eventualConsistencySleep() self.assertEqual( { 'a': OrderedSet(['1', '2']), 'b': OrderedSet(['2', '3']), 'c': OrderedSet(['3']) }, self.connection.get_attributes(settings.test_domains[0], self.test_items[0]))
def test_01_batch_put_attributes(self): # new attributes, some with more with one value self.connection.batch_put_attributes( settings.test_domains[0], { self.test_items[0]: { 'a': { 'values': ['1', '2'], 'replace': False }, 'b': { 'values': ['3'], 'replace': False } }, self.test_items[1]: { 'a': { 'values': ['3', '5'], 'replace': False }, 'b': { 'values': ['7'], 'replace': False }, } }) helpers.eventualConsistencySleep() self.assertEqual( self.connection.get_attributes(settings.test_domains[0], self.test_items[0]), { 'a': OrderedSet(['1', '2']), 'b': OrderedSet(['3']) }) self.assertEqual( self.connection.get_attributes(settings.test_domains[0], self.test_items[1]), { 'a': OrderedSet(['3', '5']), 'b': OrderedSet(['7']) })
def test_04_select(self): self.connection.delete_attributes(settings.test_domains[0], self.test_items[0]) self.connection.delete_attributes(settings.test_domains[0], self.test_items[1]) # new attributes, some with more with one value self.connection.batch_put_attributes( settings.test_domains[0], { self.test_items[0]: { 'a': { 'values': ['1', '2'], 'replace': False }, 'b': { 'values': ['3'], 'replace': False } }, self.test_items[1]: { 'a': { 'values': ['3', '5'], 'replace': False }, 'b': { 'values': ['7'], 'replace': False }, } }) helpers.eventualConsistencySleep() print self.connection.get_attributes(settings.test_domains[0], self.test_items[0]), print self.connection.get_attributes(settings.test_domains[0], self.test_items[1]), print self.connection.select('a', settings.test_domains[0], 'a > "1"')
def setUp(self): self.connection = aws_simpledb.SimpleDB() if not self.connection.has_domain(settings.test_domains[0]): helpers.msg(self, 'Create test domain') self.connection.create_domain(settings.test_domains[0]) helpers.eventualConsistencySleep()
def runTest(self): self.connection.create_domain(settings.test_domains[0]) helpers.msg(self, 'Test Domain created') helpers.eventualConsistencySleep() self.assertTrue(self.connection.has_domain(settings.test_domains[0]))
def test_01_delete(self): domain_a_new_items = \ { self.test_items[0]: { 'a': {'values': ['0', '1', '2'], 'replace': False }, }, self.test_items[1]: { 'b': {'values': ['3', '4', '5'], 'replace': False }, 'c': {'values': ['6', '7', '8'], 'replace': False }, }, self.test_items[2]: { 'd': {'values': ['6', '7', '8'], 'replace': False }, 'e': {'values': ['9', '10', '11'], 'replace': False }, } } domain_b_new_items = \ { self.test_items[0]: { 'f': {'values': ['10', '11', '12'], 'replace': False }, }, } consistent_sdb.connection.batch_put_attributes(settings.test_domains[0], domain_a_new_items) consistent_sdb.connection.batch_put_attributes(settings.test_domains[1], domain_b_new_items) delete_records = { settings.test_domains[0]: { # delete only some values from item1's attribute # one of the values doesn't exists on purpose self.test_items[0]: { 'a': ['0', '3'], }, # delete item2's attribute totally self.test_items[1]: { 'b': [], }, # delete item3 self.test_items[2]: {} }, settings.test_domains[1]: { # delete some values from domain_b's item1 attribute # important to see if deleting from more than one # domain works self.test_items[0]: { 'f': ['10', '11'], } } } consistent_sdb.delete(delete_records) helpers.eventualConsistencySleep() consistent_sdb.connection.http = httplib2.Http(timeout=10) d1_item1 = \ consistent_sdb.connection.get_attributes( settings.test_domains[0], self.test_items[0] ) d1_item1_no_change_timestamp = copy.deepcopy(d1_item1) d1_item2 = d1_item2_no_change_timestamp = \ consistent_sdb.connection.get_attributes( settings.test_domains[0], self.test_items[1] ) d1_item2_no_change_timestamp = copy.deepcopy(d1_item2) d1_item3 = d1_item3_no_change_timestamp = \ consistent_sdb.connection.get_attributes( settings.test_domains[0], self.test_items[2] ) d1_item3_no_change_timestamp = copy.deepcopy(d1_item3) d2_item1 = d2_item1_no_change_timestamp = \ consistent_sdb.connection.get_attributes( settings.test_domains[1], self.test_items[0] ) d2_item1_no_change_timestamp = copy.deepcopy(d2_item1) # delete the last change timestamp attribute del d1_item1_no_change_timestamp[consistent_sdb.last_changed_attribute_key()] del d1_item2_no_change_timestamp[consistent_sdb.last_changed_attribute_key()] del d1_item3_no_change_timestamp[consistent_sdb.last_changed_attribute_key()] del d2_item1_no_change_timestamp[consistent_sdb.last_changed_attribute_key()] # Check changes applied correctly # domain a self.assertEqual( d1_item1_no_change_timestamp, {'a': ['1', '2']} ) self.assertEqual( d1_item2_no_change_timestamp, {'c': ['6', '7', '8']} ) self.assertEqual( d1_item3_no_change_timestamp, {} ) self.assertEqual( d2_item1_no_change_timestamp, {'f': ['12']} ) # Check action timestamp entered to the item's journal of each changed # item self.assertEqual( consistent_sdb.journals_db.lrange( consistent_sdb.actions_journal_key( settings.test_domains[0], self.test_items[0] ), -1, -1 ), d1_item1[consistent_sdb.last_changed_attribute_key()] ) self.assertEqual( consistent_sdb.journals_db.lrange( consistent_sdb.actions_journal_key( settings.test_domains[0], self.test_items[1] ), -1, -1 ), d1_item2[consistent_sdb.last_changed_attribute_key()] ) self.assertEqual( consistent_sdb.journals_db.lrange( consistent_sdb.actions_journal_key( settings.test_domains[0], self.test_items[2] ), -1, -1 ), d1_item3[consistent_sdb.last_changed_attribute_key()] ) self.assertEqual( consistent_sdb.journals_db.lrange( consistent_sdb.actions_journal_key( settings.test_domains[1], self.test_items[0] ), -1, -1 ), d2_item1[consistent_sdb.last_changed_attribute_key()] ) # Check action item created in redis for each item action performed self.assertEqual( pickle.loads(str(consistent_sdb.logs_db.get( consistent_sdb.action_log_key( settings.test_domains[0], self.test_items[0], d1_item1[consistent_sdb.last_changed_attribute_key()][0] ) ))), {'action': 'delete', 'attributes': delete_records[settings.test_domains[0]][self.test_items[0]]} ) self.assertEqual( pickle.loads(str(consistent_sdb.logs_db.get( consistent_sdb.action_log_key( settings.test_domains[0], self.test_items[1], d1_item2[consistent_sdb.last_changed_attribute_key()][0] ) ))), {'action': 'delete', 'attributes': delete_records[settings.test_domains[0]][self.test_items[1]]} ) self.assertEqual( pickle.loads(str(consistent_sdb.logs_db.get( consistent_sdb.action_log_key( settings.test_domains[0], self.test_items[2], d1_item3[consistent_sdb.last_changed_attribute_key()][0] ) ))), {'action': 'delete', 'attributes': delete_records[settings.test_domains[0]][self.test_items[2]]} ) self.assertEqual( pickle.loads(str(consistent_sdb.logs_db.get( consistent_sdb.action_log_key( settings.test_domains[1], self.test_items[0], d2_item1[consistent_sdb.last_changed_attribute_key()][0] ) ))), {'action': 'delete', 'attributes': delete_records[settings.test_domains[1]][self.test_items[0]]} ) # Check ttl was set for the cached action items self.assertTrue( consistent_sdb.logs_db.ttl( consistent_sdb.action_log_key( settings.test_domains[0], self.test_items[0], d1_item1[consistent_sdb.last_changed_attribute_key()][0] ) ) > 0 ) self.assertTrue( consistent_sdb.logs_db.ttl( consistent_sdb.action_log_key( settings.test_domains[0], self.test_items[1], d1_item2[consistent_sdb.last_changed_attribute_key()][0] ) ) > 0 ) self.assertTrue( consistent_sdb.logs_db.ttl( consistent_sdb.action_log_key( settings.test_domains[0], self.test_items[2], d1_item3[consistent_sdb.last_changed_attribute_key()][0] ) ) > 0 ) self.assertTrue( consistent_sdb.logs_db.ttl( consistent_sdb.action_log_key( settings.test_domains[1], self.test_items[0], d2_item1[consistent_sdb.last_changed_attribute_key()][0] ) ) > 0 )
def test_02_put(self): # initiate the test items # domain a consistent_sdb.connection.delete_attributes(settings.test_domains[0], self.test_items[0]) consistent_sdb.connection.delete_attributes(settings.test_domains[0], self.test_items[1]) consistent_sdb.connection.delete_attributes(settings.test_domains[0], self.test_items[2]) # domain b consistent_sdb.connection.delete_attributes(settings.test_domains[1], self.test_items[0]) # put records to more than one domain at once. put_records = { settings.test_domains[0]: { self.test_items[0]: { 'attribute_a': { 'values': set(['a', 'b']), 'replace': False } }, self.test_items[1]: { 'attribute_b': { 'values': set(['c', 'd']), 'replace': False } } }, settings.test_domains[1]: { self.test_items[0]: { 'attribute_a': { 'values': set(['a', 'b']), 'replace': False } } } } consistent_sdb.put(put_records) records_state = {} # the keys are in the form of domain_names::item the # values are the attribute received from # get_attributes for that item helpers.eventualConsistencySleep() for domain, items in put_records.items(): for item in items: # Get the items we changed records_state[domain + '::' + item] = \ consistent_sdb.connection.get_attributes(domain, item) # check that the values that were put (except of the last # changed attribute) are the values we wanted. self.assertEqual( # The items received dict( [ (attribute_name, attribute_properties) for (attribute_name, attribute_properties) in records_state[domain + '::' + item].items() if attribute_name != consistent_sdb.last_changed_attribute_key() ] ), # The items that were put # keys are the item's attributes names the values are # their values dict( [ (attribute_name, attribute_properties['values']) for (attribute_name, attribute_properties) in put_records[domain][item].items() ] ) ) # Check that the changes done for each item, were logged # correctly and expiry time was set for them # 1. Make sure the timestamp that was logged in the item's # journal by verifing its last record has the same value as the # item's last changed attribute value in the database self.assertEqual( consistent_sdb.journals_db.lrange( consistent_sdb.actions_journal_key(domain, item), -1, -1 )[0], records_state[domain + '::' + item] [consistent_sdb.last_changed_attribute_key()] [0] ) timestamp = records_state[domain + '::' + item]\ [consistent_sdb.last_changed_attribute_key()]\ [0] # 2. Make sure the correct values were put to the action log self.assertEqual( pickle.loads( str(consistent_sdb.logs_db.get( consistent_sdb.action_log_key(domain, item, timestamp) )) ), {'action': 'put', 'attributes': put_records[domain][item]} ) # 3. Verify expiry time was set self.assertTrue( consistent_sdb.logs_db.ttl( consistent_sdb.action_log_key(domain, item, timestamp) ) > 0 )
def test_03_delete_attributes(self): self.connection.put_attributes( settings.test_domains[0], self.test_items[0], { 'a': { 'values': ['0'], 'replace': False }, 'b': { 'values': ['1', '2'], 'replace': False }, 'c': { 'values': ['1', '2', '3'], 'replace': False }, 'd': { 'values': ['1', '2'], 'replace': False }, 'e': { 'values': ['a', 'b', 'c'], 'replace': False }, 'f': { 'values': ['a', 'b', 'c'], 'replace': False }, 'g': { 'values': ['go'], 'replace': False }, 'h': { 'values': ['foo'], 'replace': False }, }) # Delete specific attribute's values self.connection.delete_attributes(settings.test_domains[0], self.test_items[0], {'c': ['2', '3']}) # Delete specific attribute's value self.connection.delete_attributes(settings.test_domains[0], self.test_items[0], {'d': '2'}) # Delete all attribute's values self.connection.delete_attributes(settings.test_domains[0], self.test_items[0], {'b': OrderedSet()}) # Delete specific values from more than one attribute self.connection.delete_attributes(settings.test_domains[0], self.test_items[0], { 'a': '0', 'e': ['a', 'b'], 'f': ['c'] }) # Delete more than one attribute self.connection.delete_attributes(settings.test_domains[0], self.test_items[0], { 'g': None, 'h': None }) helpers.eventualConsistencySleep() # Check deletion of specific attribute's values self.assertEqual( self.connection.get_attributes(settings.test_domains[0], self.test_items[0], ['c']), {'c': OrderedSet(['1'])}) # Check deletion of specific attribute's value self.assertEqual( self.connection.get_attributes(settings.test_domains[0], self.test_items[0], ['d']), {'d': OrderedSet(['1'])}) # Check deletion of all attribute's values self.assertEqual( self.connection.get_attributes(settings.test_domains[0], self.test_items[0], ['b']), {'b': OrderedSet([])}) # Check deletion of specific values from more than one attribute self.assertEqual( self.connection.get_attributes(settings.test_domains[0], self.test_items[0], ['a', 'e', 'f']), { 'a': OrderedSet([]), 'e': OrderedSet(['c']), 'f': OrderedSet(['a', 'b']) }) # Check deletion of more than one attribute self.assertEqual( self.connection.get_attributes(settings.test_domains[0], self.test_items[0], ['g', 'h']), { 'g': OrderedSet([]), 'h': OrderedSet([]) }) # Delete entire item self.connection.delete_attributes(settings.test_domains[0], self.test_items[0]) helpers.eventualConsistencySleep() # Check deletion of entire item self.assertEqual( self.connection.get_attributes(settings.test_domains[0], self.test_items[0]), {})
def test_02_get_attributes(self): self.connection.put_attributes( settings.test_domains[0], self.test_items[0], { 'a': { 'values': ['0'], 'replace': False }, 'b': { 'values': ['2'], 'replace': False }, 'c': { 'values': ['1', '2'], 'replace': False } }) helpers.eventualConsistencySleep() # Get entire item self.assertEqual( self.connection.get_attributes(settings.test_domains[0], self.test_items[0]), { 'a': OrderedSet(['0']), 'b': OrderedSet(['2']), 'c': OrderedSet(['1', '2']) }) # Get specific Attributes self.assertEqual( self.connection.get_attributes(settings.test_domains[0], self.test_items[0], ['a', 'b']), { 'a': OrderedSet(['0']), 'b': OrderedSet(['2']) }) # Get attribute which has more than one value self.assertEqual( self.connection.get_attributes(settings.test_domains[0], self.test_items[0], ['c']), {'c': OrderedSet(['1', '2'])}) # Get attribute that doesn't exists # When requesting all the Item self.assertTrue(not self.connection.get_attributes( settings.test_domains[0], self.test_items[0]).has_key('d')) # When requesting it specifically self.assertEqual( self.connection.get_attributes(settings.test_domains[0], self.test_items[0], ['d']), {'d': OrderedSet([])}) # Get attribute that doesn't exists from item that doesn't exists self.assertEqual( self.connection.get_attributes(settings.test_domains[0], 'test_item2', ['d']), {'d': OrderedSet([])}) # Get item that doesn't exists self.assertEqual( self.connection.get_attributes(settings.test_domains[0], 'test_item2'), {})