|
| 1 | +# -*- coding: utf-8 -*- |
1 | 2 | import mock |
2 | 3 | import time |
3 | 4 | import threading |
@@ -46,14 +47,23 @@ def test_chunk_sent_from_different_threads(self, _process_bulk_chunk): |
46 | 47 | class TestChunkActions(TestCase): |
47 | 48 | def setUp(self): |
48 | 49 | super(TestChunkActions, self).setUp() |
49 | | - self.actions = [({'index': {}}, {'some': 'data', 'i': i}) for i in range(100)] |
| 50 | + self.actions = [({'index': {}}, {'some': u'datá', 'i': i}) for i in range(100)] |
50 | 51 |
|
51 | 52 | def test_chunks_are_chopped_by_byte_size(self): |
52 | 53 | self.assertEquals(100, len(list(helpers._chunk_actions(self.actions, 100000, 1, JSONSerializer())))) |
53 | 54 |
|
54 | 55 | def test_chunks_are_chopped_by_chunk_size(self): |
55 | 56 | self.assertEquals(10, len(list(helpers._chunk_actions(self.actions, 10, 99999999, JSONSerializer())))) |
56 | 57 |
|
| 58 | + def test_chunks_are_chopped_by_byte_size_properly(self): |
| 59 | + max_byte_size = 170 |
| 60 | + chunks = list(helpers._chunk_actions(self.actions, 100000, max_byte_size, JSONSerializer())) |
| 61 | + self.assertEquals(25, len(chunks)) |
| 62 | + for chunk_data, chunk_actions in chunks: |
| 63 | + chunk = u''.join(chunk_actions) |
| 64 | + chunk = chunk if isinstance(chunk, str) else chunk.encode('utf-8') |
| 65 | + self.assertLessEqual(len(chunk), max_byte_size) |
| 66 | + |
57 | 67 | class TestExpandActions(TestCase): |
58 | 68 | def test_string_actions_are_marked_as_simple_inserts(self): |
59 | 69 | self.assertEquals(('{"index":{}}', "whatever"), helpers.expand_action('whatever')) |
0 commit comments