def test_record(self): cache = Cache("test_cache") record = Record("rocket", "saturn-v", tombstone='0', store_position=25, key_link=5, value_type='l', value_link=54378) marshalled_record = record.marshal() cache.put(0, marshalled_record) print(cache.get(0)) byte_partial_value = str(10075).encode().rjust(Record.RECORD_LINK_LEN) cache.partial_update_from_zero_index(0, byte_partial_value) print(cache.get(0)) unmarshalled_record = Record.unmarshal(cache.get(0)) print(unmarshalled_record) self.assertTrue(record.is_equal_val(unmarshalled_record)) self.assertEqual(record.key, unmarshalled_record.key) self.assertEqual(record.value, unmarshalled_record.value) self.assertEqual(record.tombstone, unmarshalled_record.tombstone) self.assertEqual(10075, unmarshalled_record.key_link) self.assertEqual(record.value_type, unmarshalled_record.value_type) self.assertEqual(record.value_link, unmarshalled_record.value_link)
def test_indexer(self): dictConfig(config.logging_config) logger = logging.getLogger() expected_data = Record("new super data", "super new old stuff") table = Table("testdb", "test_table", "test_xcvzdfsadx", config, logger) store = table.store indexer = table.indexer position = store.save(expected_data) print("stored") indexer.put(expected_data.key, position, store) print("indexed by indexer") returned_data = indexer.get(expected_data.key, store) print("indexer retrieved data: " + str(returned_data)) self.assertTrue(expected_data.is_equal_val(returned_data)) indexer.delete(expected_data.key, store) returned_data = indexer.get(expected_data.key, store) print("indexer retrieved data after delete: " + str(returned_data)) self.assertTrue(returned_data.is_empty()) indexer.close() store.close()
def test_put_get(self): dictConfig(config.logging_config) logger = logging.getLogger() tablemeta = TableMeta("testdb", "test_table", "test_xcvzdfsadx", None) store = Store(tablemeta, config, logger) index = Index(tablemeta, config, logger, 0) test_size = 30 for i in range(test_size): key= ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10)) value= ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(100)) expected_data = Record(key, value) position=store.save(expected_data) index.put(expected_data.key,position,store) returned_data=index.get(expected_data.key, store) self.assertTrue(expected_data.is_equal_val(returned_data)) c = 0 scanner = index.scanner(store) for r in scanner: print(r) c += 1 self.assertEqual(test_size, c) index.close() store.close()
def test_db(self): data = Record('user100','{"firstname":"Hari","lastname":"seldon"}') cogdb = Cog() cogdb.create_namespace("test") cogdb.create_table("db_test", "test") cogdb.put(data) scanner = cogdb.scanner() res = None for r in scanner: res = r print(res) self.assertTrue(data.is_equal_val(res)) cogdb.close()
def test_record_list(self): record = Record("rockets", ["saturn-v", "delta", "atlas", "mercury"], tombstone='0', store_position=25, key_link=5, value_type='l', value_link=54378) unmarshalled_record = Record.unmarshal(record.marshal()) print(unmarshalled_record) self.assertTrue(record.is_equal_val(unmarshalled_record)) self.assertEqual(record.key, unmarshalled_record.key) self.assertEqual(record.value, unmarshalled_record.value) self.assertEqual(record.tombstone, unmarshalled_record.tombstone) self.assertEqual(record.key_link, unmarshalled_record.key_link) self.assertEqual(record.value_type, unmarshalled_record.value_type) self.assertEqual(record.value_link, unmarshalled_record.value_link)
def test_record(self): record = Record("rocket", "saturn-v", tombstone='0', store_position=25, key_link=5, value_type='s', value_link=54378) print(record.marshal()) unmarshalled_record = Record.unmarshal(record.marshal()) print(unmarshalled_record) self.assertTrue(record.is_equal_val(unmarshalled_record)) self.assertEqual(record.key, unmarshalled_record.key) self.assertEqual(record.value, unmarshalled_record.value) self.assertEqual(record.tombstone, unmarshalled_record.tombstone) self.assertEqual(record.key_link, unmarshalled_record.key_link) self.assertEqual(record.value_type, unmarshalled_record.value_type) self.assertEqual(None, unmarshalled_record.value_link)
def test_indexer_put_get(self): if not os.path.exists("/tmp/" + DIR_NAME + "/test_table/"): os.makedirs("/tmp/" + DIR_NAME + "/test_table/") config.COG_HOME = DIR_NAME print("*** " + config.COG_HOME + "\n") dictConfig(config.logging_config) logger = logging.getLogger() table = Table("testdb", "test_table", "test_xcvzdfsadx", config, logger) store = table.store indexer = table.indexer.index_list[0] max_range = 100 for i in range(max_range): key = ''.join( random.choice(string.ascii_uppercase + string.digits) for _ in range(10)) value = ''.join( random.choice(string.ascii_uppercase + string.digits) for _ in range(100)) expected_data = Record(key, value) position = store.save(expected_data) indexer.put(expected_data.key, position, store) returned_data = indexer.get(expected_data.key, store) print("indexer retrieved data: " + str(returned_data)) self.assertTrue(expected_data.is_equal_val(returned_data)) print("Test progress: " + str(i * 100.0 / max_range)) c = 0 scanner = indexer.scanner(store) for r in scanner: c += 1 self.assertEqual(max_range, c) indexer.close() store.close() table.close()
def test_put_get_string(self): dictConfig(config.logging_config) logger = logging.getLogger() expected_data = Record("new super data", "super new old stuff") table = Table("testdb", "test_table", "test_xcvzdfsadx", config, logger) print(config.COG_HOME) store = table.store index = table.indexer.index_list[0] position = store.save(expected_data) print("stored") index.put(expected_data.key, position, store) print("indexed") returned_data = index.get(expected_data.key, store) print("retrieved data: " + str(returned_data)) self.assertTrue(expected_data.is_equal_val(returned_data)) index.close() store.close()