def _check_data(self): logger.debug('django-clickhouse: syncing left test data') # Sync all data that is not synced # Data is expected to be in test_db, not default. So we need to call subprocess # in order everything works correctly import_key = ClickHouseCollapseTestModel.get_import_key() storage = ClickHouseCollapseTestModel.get_storage() sync_left = storage.operations_count(import_key) while sync_left: logger.debug('django-clickhouse: final sync (%d left)' % sync_left) self.sync_iteration(False) sync_left = storage.operations_count(import_key) ch_data = list(connections['default'].select( 'SELECT * FROM $table FINAL ORDER BY id', model_class=ClickHouseCollapseTestModel)) pg_data = list(TestModel.objects.all().order_by('id')) if len(pg_data) != len(ch_data): absent_ids = set(item.id for item in pg_data) - set(item.id for item in ch_data) logger.debug( 'django_clickhouse: absent ranges: %s (min: %d, max: %d)' % (','.join(('(%d, %d)' % r) for r in int_ranges(absent_ids)), min(item.id for item in pg_data), max(item.id for item in pg_data))) self.assertEqual(len(pg_data), len(ch_data)) serializer = ClickHouseCollapseTestModel.get_django_model_serializer() self.assertListEqual(ch_data, [serializer.serialize(item) for item in pg_data])
def test_empty(self): self.assertListEqual([], list(int_ranges([])))
def test_simple(self): self.assertListEqual([(1, 3), (5, 6), (8, 10)], list(int_ranges([1, 2, 3, 5, 6, 8, 9, 10])))
def test_bounds(self): self.assertListEqual([(1, 1), (5, 6), (10, 10)], list(int_ranges([1, 5, 6, 10])))