Пример #1
0
class Supervisor(object):
    def __init__(self, suite_path, args):
        self.args = args
        self.tests = []
        self.suite_path = suite_path
        self.ini = {
                'core': 'bee',
                'script': os.path.join(suite_path, 'parallel.lua'),
        }

        # read suite config
        config = ConfigParser.ConfigParser()
        config.read(os.path.join(suite_path, "suite.ini"))
        self.ini.update(dict(config.items("default")))
        self.ini.update(self.args.__dict__)
        self.jobs = int(self.ini.get('jobs', 1))
        self.count = int(self.ini.get('count', 0))

        for i in ["script"]:
            self.ini[i] = os.path.join(suite_path, self.ini[i]) if i in self.ini else None
        self.server = BeeServer(self.ini)
        self.pool = None
        self.iterator = None

    def find_tests(self):
        self.tests += [Parallel_PythonTest(k) \
                for k in sorted(glob.glob(os.path.join(self.suite_path, "*.test.py" )))]

    def take_rand(self):
        if self.count != 0:
            for test in self.tests:
                sql = self.server.sql.clone()
                admin = self.server.admin.clone()
                yield [test, [sql, admin]]
        else:
            while True:
                sql = self.server.sql.clone()
                admin = self.server.admin.clone()
                yield [random.choice(self.tests), [sql, admin]]

    def run_all(self):
        self.find_tests()
        if self.count != 0:
            self.tests *= self.count
            random.shuffle(self.tests)
        self.pool = GopherPool(processes = self.jobs)
        self.iterator = self.pool.run()
        self.filler = self.pool.fill(self.take_rand())
        try:
            self.server.cleanup()
            logger.info("Bee.Instance > Server cleaned up")
            logger.info("Bee.Instance > Server's path: %s", self.server.binary)
            self.server.deploy()
            logger.info("Bee.Instance > Server deployed")
            try:
                while True:
                    self.filler.next()
                    logger.debug("BigBrother.run > Jobs filled %d %d" %
                            (self.pool.queuein.qsize(), self.pool.queueout.qsize()))
                    while True:
                        try:
                            logger.debug("BigBrother.run > waiting for task")
                            task = self.iterator.next(1)
                            logger.debug("BigBrother.run > took task")
                            if task is None:
                                logger.info('>>>> Test return NONE')
                                continue
                            stat = task.get_status()
                            if stat.status != 3:
                                logger.info('>>>> Test %s finished' % repr(task.name))
                            else:
                                logger.error('>>>> Test %s failed with %s (%s)' %
                                        (repr(task.name), stat.message, stat.reject))
                        except (QueueEmpty, StopIteration):
                            break
            except StopIteration:
                pass
        finally:
            self.server.stop()
            logger.info("Bee.Instance > Server stopped")
Пример #2
0
# replica is read-only
replica.admin('db.space._schema:replace{"test", 48}')

replica_id2 = 10
master.admin('db.space._cluster:insert{%d, "%s"}' %
    (replica_id2, replica_uuid))
replica.wait_lsn(master_id, master.get_lsn(master_id))
replica.admin('db.info.server.id')
replica.admin('db.info.server.ro')
replica.admin('db.info.server.lsn') # 0
replica.admin('db.info.vclock[%d]' % replica_id)
replica.admin('db.info.vclock[%d]' % replica_id2)

replica_id3 = 11
server.admin("db.space._cluster:update(%d, {{'=', 1, %d}})" %
    (replica_id2, replica_id3))
replica.wait_lsn(master_id, master.get_lsn(master_id))
replica.admin('db.info.server.id')
replica.admin('db.info.server.ro')
replica.admin('db.info.server.lsn') # 0
replica.admin('db.info.vclock[%d]' % replica_id)
replica.admin('db.info.vclock[%d]' % replica_id2)
replica.admin('db.info.vclock[%d]' % replica_id3)
replica.stop()
replica.cleanup(True)

# Cleanup
sys.stdout.pop_filter()

master.admin("db.schema.user.revoke('guest', 'replication')")