def _mock_db_instances(self):
     self.shard_id = uuid.uuid4()
     self.cluster.members = [
         inst_models.DBInstance(inst_tasks.InstanceTasks.NONE,
                                id='id1',
                                cluster_id=self.cluster_id,
                                shard_id=self.shard_id,
                                type='member'),
         inst_models.DBInstance(inst_tasks.InstanceTasks.NONE,
                                id='id2',
                                cluster_id=self.cluster_id,
                                shard_id=self.shard_id,
                                type='member'),
         inst_models.DBInstance(inst_tasks.InstanceTasks.NONE,
                                id='id3',
                                cluster_id=self.cluster_id,
                                shard_id=self.shard_id,
                                type='member'),
     ]
     self.cluster.query_routers = [
         inst_models.DBInstance(inst_tasks.InstanceTasks.NONE,
                                id='id4',
                                cluster_id=self.cluster_id,
                                type='query_router')
     ]
     self.cluster.config_svrs = [
         inst_models.DBInstance(inst_tasks.InstanceTasks.NONE,
                                id='id5',
                                cluster_id=self.cluster_id,
                                type='config_server')
     ]
    def test_shrink(self, mock_load_any_instance, mock_update_db,
                    mock_check_shard_status, mock_prep_resize):
        self._mock_db_instances()
        self.cluster.query_routers.append(
            inst_models.DBInstance(inst_tasks.InstanceTasks.NONE,
                                   id='id6',
                                   cluster_id=self.cluster_id,
                                   type='query_router'))

        self.cluster.shrink(['id1', 'id2', 'id3', 'id4'])

        self.assertTrue(mock_prep_resize.called)
        mock_check_shard_status.assert_called_with('id1')
        mock_update_db.assert_called_with(
            task_status=tasks.ClusterTasks.SHRINKING_CLUSTER)
        self.assertEqual(4, mock_load_any_instance().delete.call_count)
        self.manager.shrink_cluster.assert_called_with(
            self.cluster_id, ['id1', 'id2', 'id3', 'id4'])