def __schemaCreate(self, schemaDefObj): """Test case - create table schema using schema definition""" ret = 0 try: tableIdList = schemaDefObj.getTableIdList() sqlGen = SqlGenAdmin(self.__verbose, serverType="CockroachDb") dbName = schemaDefObj.getVersionedDatabaseName() sqlL = sqlGen.createDatabaseSQL(dbName) for tableId in tableIdList: tableDefObj = schemaDefObj.getTable(tableId) sqlL.extend(sqlGen.createTableSQL(databaseName=schemaDefObj.getVersionedDatabaseName(), tableDefObj=tableDefObj)) logger.debug("\nSchema creation SQL string\n %s\n\n", "\n".join(sqlL)) logger.info("Creating schema using database %s", schemaDefObj.getVersionedDatabaseName()) # with Connection(cfgOb=self.__cfgOb, resourceName=self.__resourceName) as client: crQ = CockroachDbQuery(dbcon=client, verbose=self.__verbose) ret = crQ.sqlCommandList(sqlCommandList=sqlL) # ret = crQ.sqlCommand(' '.join(sqlL)) logger.info("Schema create command returns %r\n", ret) return ret # except Exception as e: logger.exception("Failing with %s", str(e)) self.fail()
def testConnection(self): try: with Connection(cfgOb=self.__cfgOb, resourceName=self.__resourceName) as client: self.assertNotEqual(client, None) except Exception as e: logger.exception("Failing with %s", str(e)) self.fail()
def loadInsertMany(self, dataList, procName, optionsD, workingDir): try: _ = workingDir ret = None sd = optionsD["sd"] skipD = optionsD["skip"] ioObj = IoAdapter(verbose=self.__verbose) logger.debug("%s pathlist %r", procName, dataList) with Connection(cfgOb=self.__cfgOb, resourceName=self.__resourceName) as client: sdl = CockroachDbLoader(schemaDefObj=sd, ioObj=ioObj, dbCon=client, workPath=self.__workPath, cleanUp=False, warnings="default", verbose=self.__verbose) ret = sdl.load(inputPathList=dataList, loadType="cockroach-insert-many", deleteOpt="selected", tableIdSkipD=skipD) # all or nothing here if ret: return dataList, dataList, [] else: return [], [], [] except Exception as e: logger.info("Failing with dataList %r", dataList) logger.exception("Failing with %s", str(e)) return [], [], []
def testLoadInsertBirdReference(self): try: sd, _, _, _ = self.__schP.getSchemaInfo("bird") if self.__createFlag: self.__schemaCreate(schemaDefObj=sd) inputPathList = self.__rpP.getLocatorObjList("bird") inputPathList.extend(self.__rpP.getLocatorObjList("bird_family")) with Connection(cfgOb=self.__cfgOb, resourceName=self.__resourceName) as client: sdl = CockroachDbLoader(schemaDefObj=sd, ioObj=self.__ioObj, dbCon=client, workPath=self.__workPath, cleanUp=False, warnings="default", verbose=self.__verbose) ret = sdl.load(inputPathList=inputPathList, loadType="cockroach-insert", deleteOpt="selected") self.assertEqual(ret, True) except Exception as e: logger.exception("Failing with %s", str(e)) self.fail()
def testCreateMultipleConnections(self): """Test case - multiple connection creation""" try: for _ in range(25): with Connection(cfgOb=self.__cfgOb, resourceName=self.__resourceName) as client: self.assertNotEqual(client, None) except Exception as e: logger.exception("Failing with %s", str(e)) self.fail()
def testLoadInsertManyPdbxExampleFiles(self): try: sd, _, _, _ = self.__schP.getSchemaInfo("pdbx") if self.__createFlag: self.__schemaCreate(schemaDefObj=sd) inputPathList = self.__rpP.getLocatorObjList("pdbx") with Connection(cfgOb=self.__cfgOb, resourceName=self.__resourceName) as client: sdl = CockroachDbLoader(schemaDefObj=sd, ioObj=self.__ioObj, dbCon=client, workPath=self.__workPath, cleanUp=False, warnings="default", verbose=self.__verbose) ret = sdl.load(inputPathList=inputPathList, loadType="cockroach-insert-many", deleteOpt="selected", tableIdSkipD=self.__tableIdSkipD) self.assertEqual(ret, True) except Exception as e: logger.exception("Failing with %s", str(e)) self.fail()
def __schemaRemove(self, schemaDefObj): """Test case - remove table schema using schema definition""" ret = 0 try: dbName = schemaDefObj.getVersionedDatabaseName() sqlGen = SqlGenAdmin(self.__verbose, serverType="CockroachDb") sqlL = sqlGen.removeDatabaseSQL(dbName) logger.debug("Schema Remove SQL string\n %s", "\n".join(sqlL)) with Connection(cfgOb=self.__cfgOb, resourceName=self.__resourceName) as client: crQ = CockroachDbQuery(dbcon=client, verbose=self.__verbose) ret = crQ.sqlCommandList(sqlCommandList=sqlL) # ret = crQ.sqlCommand(' '.join(sqlL)) logger.debug("Schema remove command returns %r\n", ret) return ret # except Exception as e: logger.exception("Failing with %s", str(e)) self.fail()