def setUpClass(cls):
     pool = BurstyPool()
     cls._db = Config.INSTANCE.database(cls.DATABASE_NAME,
                                        ddl_statements=DDL_STATEMENTS,
                                        pool=pool)
     operation = cls._db.create()
     operation.result(30)  # raises on failure / timeout.
    def test_read_w_index(self):
        ROW_COUNT = 2000
        # Indexed reads cannot return non-indexed columns
        MY_COLUMNS = self.COLUMNS[0], self.COLUMNS[2]
        EXTRA_DDL = [
            'CREATE INDEX contacts_by_last_name ON contacts(last_name)',
        ]
        pool = BurstyPool()
        temp_db = Config.INSTANCE.database('test_read_w_index',
                                           ddl_statements=DDL_STATEMENTS +
                                           EXTRA_DDL,
                                           pool=pool)
        operation = temp_db.create()
        self.to_delete.append(_DatabaseDropper(temp_db))

        # We want to make sure the operation completes.
        operation.result(30)  # raises on failure / timeout.

        session, committed = self._set_up_table(ROW_COUNT, db=temp_db)

        snapshot = session.snapshot(read_timestamp=committed)
        rows = list(
            snapshot.read(self.TABLE,
                          MY_COLUMNS,
                          self.ALL,
                          index='contacts_by_last_name'))

        expected = list(
            reversed([(row[0], row[2]) for row in self._row_data(ROW_COUNT)]))
        self._check_row_data(rows, expected)
Exemple #3
0
 def setUpClass(cls):
     """Create a test database."""
     cls._db = Config.INSTANCE.database(
         cls.DATABASE_NAME,
         ddl_statements=DDL_STATEMENTS,
         pool=BurstyPool(labels={"testcase": "database_api"}),
     )
     cls._db.create().result(30)  # raises on failure / timeout.
Exemple #4
0
    def test_create_database(self):
        pool = BurstyPool()
        temp_db_id = 'temp_db' + unique_resource_id('_')
        temp_db = Config.INSTANCE.database(temp_db_id, pool=pool)
        operation = temp_db.create()
        self.to_delete.append(temp_db)

        # We want to make sure the operation completes.
        operation.result(30)  # raises on failure / timeout.

        database_ids = [
            database.database_id
            for database in Config.INSTANCE.list_databases()]
        self.assertIn(temp_db_id, database_ids)
Exemple #5
0
    def test_create_database(self):
        pool = BurstyPool()
        temp_db_id = 'temp-db'  # test w/ hyphen
        temp_db = Config.INSTANCE.database(temp_db_id, pool=pool)
        operation = temp_db.create()
        self.to_delete.append(temp_db)

        # We want to make sure the operation completes.
        operation.result(30)  # raises on failure / timeout.

        name_attr = operator.attrgetter('name')
        expected = sorted([temp_db, self._db], key=name_attr)

        databases = list(Config.INSTANCE.list_databases())
        found = sorted(databases, key=name_attr)
        self.assertEqual(found, expected)
    def test_update_database_ddl(self):
        pool = BurstyPool()
        temp_db_id = 'temp_db'
        temp_db = Config.INSTANCE.database(temp_db_id, pool=pool)
        create_op = temp_db.create()
        self.to_delete.append(temp_db)

        # We want to make sure the operation completes.
        create_op.result(90)  # raises on failure / timeout.

        operation = temp_db.update_ddl(DDL_STATEMENTS)

        # We want to make sure the operation completes.
        operation.result(90)  # raises on failure / timeout.

        temp_db.reload()

        self.assertEqual(len(temp_db.ddl_statements), len(DDL_STATEMENTS))
Exemple #7
0
 def setUpClass(cls):
     pool = BurstyPool()
     cls._db = Config.INSTANCE.database(DATABASE_ID,
                                        ddl_statements=DDL_STATEMENTS,
                                        pool=pool)
     cls._db.create()