Esempio n. 1
0
class TestAdd(BulkQueueTest):

    def setup(self):
        super(TestAdd, self).setup()
        self.queue = BulkQueue(self.es_client, threshold=20)

    def test_basic_add(self):
        assert self.queue.size() == 0
        self.queue.add(index='events', doc_type='event', body={'keyname', 'valuename'})
        assert self.queue.size() == 1
        assert self.queue.started() is False

    def test_add_exact_threshold(self):
        for num in range(0, 20):
            self.queue.add(index='events', doc_type='event', body={'keyname': 'value' + str(num)})
        assert self.queue.size() == 0
        assert self.num_objects_saved() == 20
        assert self.queue.started() is False

    def test_add_over_threshold(self):
        for num in range(0, 21):
            self.queue.add(index='events', doc_type='event', body={'keyname': 'value' + str(num)})
        assert self.num_objects_saved() == 20
        assert self.queue.size() == 1
        assert self.queue.started() is False

    def test_add_multiple_thresholds(self):
        for num in range(0, 201):
            self.queue.add(index='events', doc_type='event', body={'keyname': 'value' + str(num)})
        assert self.num_objects_saved() == 200
        assert self.queue.size() == 1
        assert self.queue.started() is False
Esempio n. 2
0
 def test_over_threshold(self):
     queue = BulkQueue(self.es_client, flush_time=3, threshold=10)
     queue.start_timer()
     for num in range(0, 201):
         queue.add(index='events', doc_type='event', body={'keyname': 'value' + str(num)})
     assert self.num_objects_saved() == 200
     assert queue.size() == 1
     time.sleep(4)
     assert self.num_objects_saved() == 201
     assert queue.size() == 0
     queue.stop_timer()
Esempio n. 3
0
 def test_basic_timer(self):
     queue = BulkQueue(self.es_client, flush_time=2)
     assert queue.started() is False
     queue.start_timer()
     assert queue.started() is True
     queue.add(index='events', doc_type='event', body={'keyname': 'valuename'})
     assert queue.size() == 1
     time.sleep(3)
     assert queue.size() == 0
     queue.stop_timer()
     assert queue.started() is False
Esempio n. 4
0
 def test_ten_iterations(self):
     queue = BulkQueue(self.es_client, flush_time=3, threshold=10)
     queue.start_timer()
     total_events = 0
     for num_rounds in range(0, 10):
         for num in range(0, 20):
             total_events += 1
             queue.add(index='events', doc_type='event', body={'keyname': 'value' + str(num)})
         assert self.num_objects_saved() == total_events
     assert queue.size() == 0
     queue.stop_timer()
     assert self.num_objects_saved() == 200
Esempio n. 5
0
class TestBasicInit(BulkQueueTest):

    def setup(self):
        super(TestBasicInit, self).setup()
        self.queue = BulkQueue(self.es_client)

    def test_threshold(self):
        assert self.queue.threshold == 10

    def test_size(self):
        assert self.queue.size() == 0

    def test_flush_time(self):
        assert self.queue.flush_time == 30