Пример #1
0
 def test_select_calls_with_correct_params(self, mock_select_object_content):
     s3.select_transaction("loc", "block", "txn")
     mock_select_object_content.assert_called_once_with(
         Bucket="loc",
         Key="TRANSACTION/block",
         Expression="select s.txn from s3object s where s.txn_id = 'txn' limit 1",
         ExpressionType="SQL",
         InputSerialization={"JSON": {"Type": "DOCUMENT"}},
         OutputSerialization={"JSON": {"RecordDelimiter": "\n"}},
     )
Пример #2
0
def select_transaction(block_id: str,
                       txn_id: str,
                       cache_expire: Optional[int] = None) -> dict:
    """Returns an transaction in a block from storage through the LRU cache
        block_id: The ID of the block being queried
        txn_id: The ID of the transaction in the block
        cache_expire: The amount of time (in seconds) until the key expires if cache miss
    Returns:
        transaction JSON object
    Raises:
        exceptions.NotFound exception when block id not found
        exceptions.StorageError on any unexpected error interacting with storage
    """
    try:
        obj: Any = None
        key = f"{block_id}/{txn_id}"
        obj = redis.cache_get(key)
        if obj:
            return json.loads(obj)
        obj = storage.select_transaction(STORAGE_LOCATION, block_id, txn_id)
        cache_val = json.dumps(obj, separators=(",", ":")).encode("utf-8")
        if len(cache_val) < CACHE_LIMIT:
            redis.cache_put(key, cache_val, cache_expire)
        return obj
    except exceptions.NotFound:
        raise
    except Exception:
        _log.exception(
            "Uncaught exception while performing storage select_transaction")
        raise exceptions.StorageError(
            "Uncaught exception while performing storage select_transaction")
Пример #3
0
 def test_select_gets_nested_data_properly(self,
                                           mock_select_object_content):
     self.assertEqual(s3.select_transaction("loc", "block", "txn"), "thing")