예제 #1
0
파일: test.py 프로젝트: turekj/cassom
def main():
    items = 100000
    cluster = Cluster(['127.0.0.1'])
    session = cluster.connect()
    session.execute('DROP KEYSPACE queue_test;')
    session.execute("CREATE KEYSPACE queue_test WITH REPLICATION = { 'class': 'SimpleStrategy', 'replication_factor': 1 };")
    session.execute("USE queue_test;")
    session.execute("CREATE TABLE queue (id text, event_at timeuuid, payload text, PRIMARY KEY(id, event_at));")

    timeuuid = TimeUUID.with_utcnow()

    for i in range(0, items - 1):
        timeuuid = TimeUUID.with_utcnow()
        query = "INSERT INTO queue (id, event_at, payload) VALUES ('queue_1', " + str(timeuuid) + ", 'payload" + str(i) + "');"
        session.execute(query)
        session.execute("DELETE FROM queue WHERE id = 'queue_1' AND event_at = " + str(timeuuid) + ";")

    query = "INSERT INTO queue (id, event_at, payload) VALUES ('queue_1', " + str(TimeUUID.with_utcnow()) + ", 'payload100000');"
    session.execute(query)

    before = time.time()
    result = session.execute("SELECT * FROM queue WHERE id = 'queue_1' LIMIT 1;")
    print 'Not enqueued executed in %s ms' % str(time.time() - before)
    print 'Result: %s' % str(result[0])

    before = time.time()
    result = session.execute("SELECT * FROM queue WHERE id = 'queue_1' AND event_at > " + str(timeuuid) + " LIMIT 1;")
    print 'Enqueued executed in %s ms' % str(time.time() - before)
    print 'Result: %s' % str(result[0])

    session.execute("TRUNCATE queue;")
    session.execute('DROP KEYSPACE queue_test;')
예제 #2
0
	def generate_uri(host, structure, dataset_type, uuid=None):
		"""
		Builds a URI from the structure and host defined in config file.

		:param str host: Host value for the URI
		:param str structure: Structure used to form the final URL
		:param Model dataset_type: For which element the URI will be generated
		:param str or None uuid: ID in case that already exists. Default: None
		:return: Tuple with well formatted URI and UUID
		:rtype: (str, str)
		"""
		Validators.is_informed(const.URI_HOST, host)

		if not uuid:
			uuid = str(TimeUUID.with_utcnow())

		if dataset_type is Model.CATALOGUE:
			return 'http://{host}/'.format(host=host), uuid

		Validators.is_expected_value(const.URI_STRUCTURE, '{host}', structure)
		if structure[-1] is not '/':
			structure += '/'
		structure += '{type}/'

		return structure.format(host=host, type=dataset_type.value) + uuid, uuid
예제 #3
0
 def __init__(self, pool, column_family, key, **kwargs):
     self.pool = pool
     if isinstance(column_family, ColumnFamily):
         self.column_family = column_family
     else:
         cf_kwargs = {k: kwargs.get(k) for k in _cf_args if k in kwargs}
         self.column_family = ColumnFamily(self.pool, column_family, **cf_kwargs)
     self.key = key
     self.consistency_level = kwargs.get('consistency_level', ConsistencyLevel.LOCAL_QUORUM)
     self.prefix = kwargs.get('prefix', '_lock_')
     self.lock_id = kwargs.get('lock_id', str(TimeUUID.with_utcnow()))
     self.fail_on_stale_lock = kwargs.get('fail_on_stale_lock', False)
     self.timeout = kwargs.get('timeout', 60.0)  # seconds
     self.ttl = kwargs.get('ttl', None)
     self.backoff_policy = kwargs.get('backoff_policy', getUtility(IRetryPolicy, 'run_once'))
     self.allow_retry = kwargs.get('allow_retry', True)
     self.locks_to_delete = set()
     self.lock_column = None
예제 #4
0
    def get_tuuid(self,
                  hex: Optional[str] = None,
                  timestamp: Optional[float] = None) -> TimeUUID:
        """
        Get a TimeUUID.

        Args:
            hex: The optional TimeUUID as hex.
            timestamp: The optional timestamp to use in the TimeUUID
        Returns:
            The TimeUUID.
        """
        if hex:
            tuuid = TimeUUID(hex=hex)
        elif timestamp:
            tuuid = TimeUUID.with_timestamp(timestamp)
        else:
            tuuid = TimeUUID.with_utcnow()

        return tuuid
예제 #5
0
 def __init__(self, pool, column_family, key, **kwargs):
     self.pool = pool
     if isinstance(column_family, ColumnFamily):
         self.column_family = column_family
     else:
         cf_kwargs = {k: kwargs.get(k) for k in _cf_args if k in kwargs}
         self.column_family = ColumnFamily(self.pool, column_family,
                                           **cf_kwargs)
     self.key = key
     self.consistency_level = kwargs.get('consistency_level',
                                         ConsistencyLevel.LOCAL_QUORUM)
     self.prefix = kwargs.get('prefix', '_lock_')
     self.lock_id = kwargs.get('lock_id', str(TimeUUID.with_utcnow()))
     self.fail_on_stale_lock = kwargs.get('fail_on_stale_lock', False)
     self.timeout = kwargs.get('timeout', 60.0)  # seconds
     self.ttl = kwargs.get('ttl', None)
     self.backoff_policy = kwargs.get('backoff_policy',
                                      getUtility(IRetryPolicy, 'run_once'))
     self.allow_retry = kwargs.get('allow_retry', True)
     self.locks_to_delete = set()
     self.lock_column = None
예제 #6
0
파일: test.py 프로젝트: EvaSDK/time_uuid
    def test_with_utcnow(self):
        res = TimeUUID.with_utcnow()

        self.assertIsInstance(res, uuid.UUID)
        self.assertIsInstance(res, TimeUUID)