コード例 #1
0
    def test_table_queries(self):
        self.engine.execute(tables.Queues.insert(),
                            id=1,
                            project='test',
                            name='zaqar',
                            metadata=utils.json_encode('aaaa'))
        self.engine.execute(tables.Messages.insert(),
                            id=1,
                            qid=1,
                            ttl=10,
                            body=utils.json_encode('bbbb'),
                            client='a',
                            created=datetime.datetime.now())
        self.engine.execute(tables.Claims.insert(),
                            id=1,
                            qid=1,
                            ttl=10,
                            created=datetime.datetime.now())

        rs = self.engine.execute(tables.Claims.select())
        row = rs.fetchone()

        self.assertEqual(row.id, 1)
        self.assertEqual(row.qid, 1)
        self.assertEqual(row.ttl, 10)

        self.engine.execute(tables.Claims.delete(tables.Claims.c.id == 1))
        rs = self.engine.execute(tables.Claims.select())
        row = rs.fetchone()

        self.assertIsNone(row)
コード例 #2
0
    def test_table_queries(self):
        self.engine.execute(tables.Queues.insert(), id=1, project='test',
                            name='zaqar', metadata=utils.json_encode('aaaa'))
        self.engine.execute(tables.Messages.insert(), id=1, qid=1, ttl=10,
                            body=utils.json_encode('bbbb'), client='a',
                            created=datetime.datetime.now())
        self.engine.execute(tables.Claims.insert(), id=1, qid=1, ttl=10,
                            created=datetime.datetime.now())

        rs = self.engine.execute(tables.Claims.select())
        row = rs.fetchone()

        self.assertEqual(row.id, 1)
        self.assertEqual(row.qid, 1)
        self.assertEqual(row.ttl, 10)

        self.engine.execute(tables.Claims.delete(tables.Claims.c.id == 1))
        rs = self.engine.execute(tables.Claims.select())
        row = rs.fetchone()

        self.assertIsNone(row)
コード例 #3
0
ファイル: queues.py プロジェクト: AsherBond/marconi
    def create(self, name, metadata=None, project=None):
        if project is None:
            project = ''

        try:
            smeta = utils.json_encode(metadata or {})
            ins = tables.Queues.insert().values(project=project,
                                                name=name,
                                                metadata=smeta)
            res = self.driver.run(ins)
        except sa.exc.IntegrityError:
            return False

        return res.rowcount == 1
コード例 #4
0
ファイル: queues.py プロジェクト: jeffrey4l/zaqar
    def create(self, name, metadata=None, project=None):
        if project is None:
            project = ''

        try:
            smeta = utils.json_encode(metadata or {})
            ins = tables.Queues.insert().values(project=project,
                                                name=name,
                                                metadata=smeta)
            res = self.driver.run(ins)
        except sa.exc.IntegrityError:
            return False

        return res.rowcount == 1
コード例 #5
0
ファイル: pools.py プロジェクト: AsherBond/marconi
    def create(self, name, weight, uri, options=None):
        opts = None if options is None else utils.json_encode(options)

        try:
            stmt = sa.sql.expression.insert(tables.Pools).values(
                name=name, weight=weight, uri=uri, options=opts
            )
            self._conn.execute(stmt)

        except sa.exc.IntegrityError:
            # TODO(cpp-cabrera): merge update/create into a single
            # method with introduction of upsert
            self.update(name, weight=weight, uri=uri,
                        options=options)
コード例 #6
0
ファイル: pools.py プロジェクト: echevemaster/zaqar
    def create(self, name, weight, uri, options=None):
        opts = None if options is None else utils.json_encode(options)

        try:
            stmt = sa.sql.expression.insert(tables.Pools).values(name=name,
                                                                 weight=weight,
                                                                 uri=uri,
                                                                 options=opts)
            self._conn.execute(stmt)

        except sa.exc.IntegrityError:
            # TODO(cpp-cabrera): merge update/create into a single
            # method with introduction of upsert
            self.update(name, weight=weight, uri=uri, options=options)
コード例 #7
0
ファイル: queues.py プロジェクト: echevemaster/zaqar
    def set_metadata(self, name, metadata, project):
        if project is None:
            project = ''

        update = (tables.Queues.update().where(
            sa.and_(tables.Queues.c.project == project,
                    tables.Queues.c.name == name)).values(
                        metadata=utils.json_encode(metadata)))

        res = self.driver.run(update)

        try:
            if res.rowcount != 1:
                raise errors.QueueDoesNotExist(name, project)
        finally:
            res.close()
コード例 #8
0
ファイル: queues.py プロジェクト: AsherBond/marconi
    def set_metadata(self, name, metadata, project):
        if project is None:
            project = ''

        update = (tables.Queues.update().
                  where(sa.and_(
                      tables.Queues.c.project == project,
                      tables.Queues.c.name == name)).
                  values(metadata=utils.json_encode(metadata)))

        res = self.driver.run(update)

        try:
            if res.rowcount != 1:
                raise errors.QueueDoesNotExist(name, project)
        finally:
            res.close()
コード例 #9
0
ファイル: pools.py プロジェクト: AsherBond/marconi
    def update(self, name, **kwargs):
        # NOTE(cpp-cabrera): by pruning None-valued kwargs, we avoid
        # overwriting the existing options field with None, since that
        # one can be null.
        names = ('uri', 'weight', 'options')
        fields = common_utils.fields(kwargs, names,
                                     pred=lambda x: x is not None)

        assert fields, '`weight`, `uri`, or `options` not found in kwargs'

        if 'options' in fields:
            fields['options'] = utils.json_encode(fields['options'])

        stmt = sa.sql.update(tables.Pools).where(
            tables.Pools.c.name == name).values(**fields)

        res = self._conn.execute(stmt)
        if res.rowcount == 0:
            raise errors.PoolDoesNotExist(name)
コード例 #10
0
ファイル: pools.py プロジェクト: echevemaster/zaqar
    def update(self, name, **kwargs):
        # NOTE(cpp-cabrera): by pruning None-valued kwargs, we avoid
        # overwriting the existing options field with None, since that
        # one can be null.
        names = ('uri', 'weight', 'options')
        fields = common_utils.fields(kwargs,
                                     names,
                                     pred=lambda x: x is not None)

        assert fields, '`weight`, `uri`, or `options` not found in kwargs'

        if 'options' in fields:
            fields['options'] = utils.json_encode(fields['options'])

        stmt = sa.sql.update(
            tables.Pools).where(tables.Pools.c.name == name).values(**fields)

        res = self._conn.execute(stmt)
        if res.rowcount == 0:
            raise errors.PoolDoesNotExist(name)
コード例 #11
0
ファイル: messages.py プロジェクト: gashe5363/zaqar
 def it():
     for m in messages:
         yield dict(qid=qid,
                    ttl=m['ttl'],
                    body=utils.json_encode(m['body']),
                    client=str(client_uuid))
コード例 #12
0
ファイル: messages.py プロジェクト: jeffrey4l/zaqar
 def it():
     for m in messages:
         yield dict(qid=qid,
                    ttl=m['ttl'],
                    body=utils.json_encode(m['body']),
                    client=str(client_uuid))