Exemplo n.º 1
0
 def test_many_tenants_having_more_than_batch_groups(self):
     """
     Gets all groups when there are many tenants each of them
     having groups > batch size
     """
     groups1 = [{'tenantId': 1, 'groupId': i,
                 'desired': 3, 'created_at': 'c'}
                for i in range(7)]
     groups2 = [{'tenantId': 2, 'groupId': i,
                 'desired': 4, 'created_at': 'c'}
                for i in range(9)]
     self._add_exec_args(
         self.select + ' LIMIT :limit;', {'limit': 5}, groups1[:5])
     where_tenant = ('WHERE "tenantId"=:tenantId AND '
                     '"groupId">:groupId LIMIT :limit;')
     where_token = ('WHERE token("tenantId") > token(:tenantId) '
                    'LIMIT :limit;')
     self._add_exec_args(
         self.select + where_tenant,
         {'limit': 5, 'tenantId': 1, 'groupId': 4}, groups1[5:])
     self._add_exec_args(
         self.select + where_token,
         {'limit': 5, 'tenantId': 1}, groups2[:5])
     self._add_exec_args(
         self.select + where_tenant,
         {'limit': 5, 'tenantId': 2, 'groupId': 4}, groups2[5:])
     self._add_exec_args(
         self.select + where_token,
         {'limit': 5, 'tenantId': 2}, [])
     d = get_scaling_group_rows(self.client, batch_size=5)
     self.assertEqual(list(self.successResultOf(d)), groups1 + groups2)
Exemplo n.º 2
0
 def test_all_groups_less_than_batch(self):
     """
     Works when number of all groups of all tenants < batch size
     """
     groups = [{'tenantId': i, 'groupId': j,
                'desired': 3, 'created_at': 'c'}
               for i in range(2) for j in range(2)]
     self._add_exec_args(
         self.select + ' LIMIT :limit;', {'limit': 5}, groups)
     d = get_scaling_group_rows(self.client, batch_size=5)
     self.assertEqual(list(self.successResultOf(d)), groups)
Exemplo n.º 3
0
def insert_deleting_false(reactor, conn):
    """
    Insert false to all group's deleting column
    """
    groups = yield get_scaling_group_rows(conn)
    query = (
        'INSERT INTO scaling_group ("tenantId", "groupId", deleting) '
        'VALUES (:tenantId{i}, :groupId{i}, false);')
    queries, params = [], {}
    for i, group in enumerate(groups):
        queries.append(query.format(i=i))
        params['tenantId{}'.format(i)] = group['tenantId']
        params['groupId{}'.format(i)] = group['groupId']
    yield conn.execute(batch(queries), params, ConsistencyLevel.ONE)
    returnValue(None)
Exemplo n.º 4
0
 def test_gets_props(self):
     """
     If props arg is given then returns groups with that property in it
     """
     groups = [{'tenantId': 1, 'groupId': 2, 'desired': 3,
                'created_at': 'c', 'launch': 'l'},
               {'tenantId': 1, 'groupId': 3, 'desired': 2,
                'created_at': 'c', 'launch': 'b'}]
     self._add_exec_args(
         ('SELECT "groupId","tenantId",active,'
          'desired,launch,pending '
          'FROM scaling_group  LIMIT :limit;'),
         {'limit': 5}, groups)
     d = get_scaling_group_rows(self.client, props=['launch'],
                                batch_size=5)
     self.assertEqual(list(self.successResultOf(d)), groups)
Exemplo n.º 5
0
 def test_last_tenant_has_less_groups(self):
     """
     Fetches initial batch, then gets all groups of last tenant
     in that batch and stops when there are no more tenants
     """
     groups = [{'tenantId': 1, 'groupId': i,
                'desired': 3, 'created_at': 'c'}
               for i in range(7)]
     self._add_exec_args(
         self.select + ' LIMIT :limit;', {'limit': 5}, groups[:5])
     self._add_exec_args(
         self.select + ('WHERE "tenantId"=:tenantId AND '
                        '"groupId">:groupId LIMIT :limit;'),
         {'limit': 5, 'tenantId': 1, 'groupId': 4}, groups[5:])
     self._add_exec_args(
         self.select + ('WHERE token("tenantId") > token(:tenantId)'
                        ' LIMIT :limit;'),
         {'limit': 5, 'tenantId': 1}, [])
     d = get_scaling_group_rows(self.client, batch_size=5)
     self.assertEqual(list(self.successResultOf(d)), groups)