Esempio n. 1
0
    def test_queue_chunks_full(self):
        self.mox.StubOutWithMock(queuer.orm, 'Chunk')
        self.mox.StubOutWithMock(queuer.exporter, 'queue_export_chunk')

        orm.Chunk.get_by_index(
            self.redis,
            chunk_num=0, destination_shard='dst', namespace='ns', source_shard='src',
            table_name='anomaly', partition_val=43
        ).AndReturn([])
        ttc = self.mox.CreateMockAnything()
        ttc._cols().AndReturn([])
        orm.Chunk(self.redis).AndReturn(ttc)
        ttc.insert()
        queuer.exporter.queue_export_chunk(
            queuer.ChunkConfig(
                'mid', data.TableConfig('anomaly', 'tc', 'cc', None, '', '', ignore_columns=['information']),
                [], 43, 'ns', 'src', 'dst', 0, 0, 34, 'ns', 'ns', 'full', None))

        orm.Chunk.get_by_index(
            self.redis,
            chunk_num=1, destination_shard='dst', namespace='ns', source_shard='src',
            table_name='anomaly', partition_val=43
        ).AndReturn([])
        ttc = self.mox.CreateMockAnything()
        ttc._cols().AndReturn([])
        orm.Chunk(self.redis).AndReturn(ttc)
        ttc.insert()
        queuer.exporter.queue_export_chunk(
            queuer.ChunkConfig(
                'mid', data.TableConfig('anomaly', 'tc', 'cc', None, '', '', ignore_columns=['information']),
                [], 43, 'ns', 'src', 'dst', 1, 34, 34, 'ns', 'ns', 'full', None))

        orm.Chunk.get_by_index(
            self.redis,
            chunk_num=2, destination_shard='dst', namespace='ns', source_shard='src',
            table_name='anomaly', partition_val=43
        ).AndReturn([])
        ttc = self.mox.CreateMockAnything()
        ttc._cols().AndReturn([])
        orm.Chunk(self.redis).AndReturn(ttc)
        ttc.insert()
        queuer.exporter.queue_export_chunk(
            queuer.ChunkConfig(
                'mid', data.TableConfig('anomaly', 'tc', 'cc', None, '', '', ignore_columns=['information']),
                [], 43, 'ns', 'src', 'dst', 2, 68, 34, 'ns', 'ns', 'full', None))

        self.mox.ReplayAll()
        config.CHUNK_SIZE = 30
        self.config.migration_type = orm.MigrationType.FULL
        worker = queuer.QueueChunksWorker(self.config, self.redis)
        worker.min_id = 0
        worker.max_id = 100
        worker.num_rows = 80
        worker.queue_chunks()
        self.assertEqual(worker.c.chunk_size, 34)
        self.assertEqual(worker.num_chunks, 3)
Esempio n. 2
0
    def test_queue_chunks_bad_type(self):
        self.mox.StubOutWithMock(queuer.orm, 'Chunk')

        ttc = self.mox.CreateMockAnything()
        ttc._cols().AndReturn([])
        orm.Chunk(self.redis).AndReturn(ttc)
        ttc.insert()

        self.mox.ReplayAll()
        config.CHUNK_SIZE = 30
        self.config.migration_type = '__UNKNOWN__'
        worker = queuer.QueueChunksWorker(self.config, self.redis)
        worker.min_id = 0
        worker.max_id = 100
        worker.num_rows = 80
        with self.assertRaises(queuer.UnrecoverableError):
            worker.queue_chunks()
Esempio n. 3
0
    def test_queue_chunks_delta(self):
        self.mox.StubOutWithMock(queuer.orm, 'Chunk')
        self.mox.StubOutWithMock(queuer.pipe, 'queue_pipe_chunk')

        ttc = self.mox.CreateMockAnything()
        ttc._cols().AndReturn([])
        orm.Chunk(self.redis).AndReturn(ttc)
        ttc.insert()
        queuer.pipe.queue_pipe_chunk(
            queuer.ChunkConfig(
                'mid', data.TableConfig('anomaly', 'tc', 'cc', None, '', '', ignore_columns=['information']),
                [], 43, 'ns', 'src', 'dst', 0, 0, 34, 'ns', 'ns', 'delta', None))

        ttc = self.mox.CreateMockAnything()
        ttc._cols().AndReturn([])
        orm.Chunk(self.redis).AndReturn(ttc)
        ttc.insert()
        queuer.pipe.queue_pipe_chunk(
            queuer.ChunkConfig(
                'mid', data.TableConfig('anomaly', 'tc', 'cc', None, '', '', ignore_columns=['information']),
                [], 43, 'ns', 'src', 'dst', 1, 34, 34, 'ns', 'ns', 'delta', None))

        ttc = self.mox.CreateMockAnything()
        ttc._cols().AndReturn([])
        orm.Chunk(self.redis).AndReturn(ttc)
        ttc.insert()
        queuer.pipe.queue_pipe_chunk(
            queuer.ChunkConfig(
                'mid', data.TableConfig('anomaly', 'tc', 'cc', None, '', '', ignore_columns=['information']),
                [], 43, 'ns', 'src', 'dst', 2, 68, 34, 'ns', 'ns', 'delta', None))

        self.mox.ReplayAll()
        config.CHUNK_SIZE = 30
        self.config.migration_type = orm.MigrationType.DELTA
        worker = queuer.QueueChunksWorker(self.config, self.redis)
        worker.min_id = 0
        worker.max_id = 100
        worker.num_rows = 80
        worker.queue_chunks()
        self.assertEqual(worker.c.chunk_size, 34)
        self.assertEqual(worker.num_chunks, 3)