예제 #1
0
    def test_multiple_increment(self):
        """
        test that we can increment a key multiple times in a time interval
        """
        partial_key = "get_request"

        # create a base time, rounded off to the nearest minute
        current_time = datetime.utcnow()
        base_time = datetime(current_time.year, current_time.month,
                             current_time.day, current_time.hour,
                             current_time.minute)

        test_range = range(10)
        for index in test_range:
            timestamp = base_time + timedelta(seconds=index)
            queue_entry = redis_queue_entry_tuple(timestamp=timestamp,
                                                  collection_id=42,
                                                  value=index)

            self._redis_queue.put((partial_key, queue_entry), )

        # give the greenlet and redis some time to operate
        self._halt_event.wait(1)

        # verify that the key got incremented
        expected_key = compute_key(_node_name, queue_entry.timestamp,
                                   partial_key)
        expected_value = sum([x for x in test_range])
        hash_value = self._redis_connection.hget(expected_key,
                                                 queue_entry.collection_id)
        self.assertEqual(int(hash_value), expected_value)
예제 #2
0
    def test_single_increment(self):
        """
        test that we can increment a key once
        """
        partial_key = "get_request"
        queue_entry = redis_queue_entry_tuple(timestamp=datetime.utcnow(),
                                              collection_id=42,
                                              value=12345)

        # feed an entry to the queue
        self._redis_queue.put((partial_key, queue_entry), )

        # give the greenlet some time to start
        self._halt_event.wait(1)

        # verify that the key got incremented
        expected_key = compute_key(_node_name, queue_entry.timestamp,
                                   partial_key)
        hash_dict = self._redis_connection.hgetall(expected_key)
        items = hash_dict.items()
        self.assertEqual(len(items), 1)
        collection_id_bytes, count_bytes = items[0]
        collection_id = int(collection_id_bytes)
        count = int(count_bytes)

        self.assertEqual(collection_id, queue_entry.collection_id)
        self.assertEqual(count, queue_entry.value)
    def test_multiple_increment(self):
        """
        test that we can increment a key multiple times in a time interval
        """
        partial_key = "get_request"

        # create a base time, rounded off to the nearest minute
        current_time = datetime.utcnow()
        base_time = datetime(
            current_time.year, current_time.month, current_time.day, current_time.hour, current_time.minute
        )

        test_range = range(10)
        for index in test_range:
            timestamp = base_time + timedelta(seconds=index)
            queue_entry = redis_queue_entry_tuple(timestamp=timestamp, collection_id=42, value=index)

            self._redis_queue.put((partial_key, queue_entry))

        # give the greenlet and redis some time to operate
        self._halt_event.wait(1)

        # verify that the key got incremented
        expected_key = compute_key(_node_name, queue_entry.timestamp, partial_key)
        expected_value = sum([x for x in test_range])
        hash_value = self._redis_connection.hget(expected_key, queue_entry.collection_id)
        self.assertEqual(int(hash_value), expected_value)
예제 #4
0
 def store(self, partial_key, entry):
     """
     store one entry from the queue in redis
     """
     key = compute_key(self._node_name, entry.timestamp, partial_key)
     self._log.debug("hincrby({0}, {1}, {2})".format(
         key, entry.collection_id, entry.value))
     self._redis_connection.hincrby(key, entry.collection_id, entry.value)
 def store(self, partial_key, entry):
     """
     store one entry from the queue in redis
     """
     key = compute_key(self._node_name, entry.timestamp, partial_key)
     self._log.debug("hincrby({0}, {1}, {2})".format(key, 
                                                     entry.collection_id, 
                                                     entry.value))
     self._redis_connection.hincrby(key, entry.collection_id, entry.value)
    def test_single_increment(self):
        """
        test that we can increment a key once
        """
        partial_key = "get_request"
        queue_entry = redis_queue_entry_tuple(timestamp=datetime.utcnow(), collection_id=42, value=12345)

        # feed an entry to the queue
        self._redis_queue.put((partial_key, queue_entry))

        # give the greenlet some time to start
        self._halt_event.wait(1)

        # verify that the key got incremented
        expected_key = compute_key(_node_name, queue_entry.timestamp, partial_key)
        hash_dict = self._redis_connection.hgetall(expected_key)
        items = hash_dict.items()
        self.assertEqual(len(items), 1)
        collection_id_bytes, count_bytes = items[0]
        collection_id = int(collection_id_bytes)
        count = int(count_bytes)

        self.assertEqual(collection_id, queue_entry.collection_id)
        self.assertEqual(count, queue_entry.value)