Best EvoMaster code snippet using org.evomaster.client.java.controller.db.DbCleaner.cleanDataInTables
Source: DbCleaner.java
...36 For H2, we have to delete tables one at a time... but, to avoid issues37 with FKs, we must temporarily disable the integrity checks38 */39 disableReferentialIntegrity(statement, type);40 cleanDataInTables(tablesToSkip, statement, type, schemaName, isSingleCleanCommand(type), doDropTable);41 resetSequences(statement, type, schemaName);42 enableReferentialIntegrity(statement, type);43 statement.close();44 } catch (Exception e) {45 /*46 this could happen if there is a current transaction with a lock on any table.47 We could check the content of INFORMATION_SCHEMA.LOCKS, or simply look at error message48 */49 String msg = e.getMessage();50 if(msg != null && msg.toLowerCase().contains("timeout")){51 if(retries > 0) {52 SimpleLogger.warn("Timeout issue with cleaning DB. Trying again.");53 //let's just wait a bit, and retry54 try {55 Thread.sleep(2000);56 } catch (InterruptedException interruptedException) {57 }58 retries--;59 clearDatabase(retries, connection, schemaName, tablesToSkip, type, doDropTable);60 } else {61 SimpleLogger.error("Giving up cleaning the DB. There are still timeouts.");62 }63 }64 throw new RuntimeException(e);65 }66 }67 public static void clearDatabase(Connection connection, List<String> tablesToSkip, DatabaseType type){68 clearDatabase(connection, getDefaultSchema(type), tablesToSkip, type);69 }70 public static void clearDatabase(Connection connection, String schemaName, List<String> tablesToSkip, DatabaseType type){71 clearDatabase(getDefaultReties(type), connection, schemaName, tablesToSkip, type, false);72 }73 public static void dropDatabaseTables(Connection connection, String schemaName, List<String> tablesToSkip, DatabaseType type){74 if (type != DatabaseType.MYSQL && type != DatabaseType.MARIADB)75 throw new IllegalArgumentException("Dropping tables are not supported by "+type);76 clearDatabase(getDefaultReties(type), connection, schemaName, tablesToSkip, type, true);77 }78 public static void clearDatabase_Postgres(Connection connection, String schemaName, List<String> tablesToSkip ) {79 clearDatabase(getDefaultReties(DatabaseType.POSTGRES), connection, schemaName, tablesToSkip, DatabaseType.POSTGRES, false);80 }81 /**82 *83 * @param tablesToSkip are tables to be skipped84 * @param statement is to execute the SQL command85 * @param schema specify the schema of data to clean. if [schema] is empty, all data will be cleaned.86 * @param singleCommand specify whether to execute the SQL commands (e.g., truncate table/tables) by single command87 * @param doDropTable specify whether to drop tables which is only for MySQL and MariaDB now.88 * @throws SQLException are exceptions during sql execution89 */90 private static void cleanDataInTables(List<String> tablesToSkip, Statement statement, DatabaseType type, String schema, boolean singleCommand, boolean doDropTable) throws SQLException {91 // Find all tables and truncate them92 Set<String> tables = new HashSet<>();93 ResultSet rs = statement.executeQuery(getAllTableCommand(type, schema));94 while (rs.next()) {95 tables.add(rs.getString(1));96 }97 rs.close();98 if (tables.isEmpty()) {99 throw new IllegalStateException("Could not find any table");100 }101 if (tablesToSkip != null) {102 for (String skip : tablesToSkip) {103 if (!tables.stream().anyMatch(t -> t.equalsIgnoreCase(skip))) {104 String msg = "Asked to skip table '" + skip + "', but it does not exist.";...
Check out the latest blogs from LambdaTest on this topic:
Hey everyone! We hope you had a great Hacktober. At LambdaTest, we thrive to bring you the best with each update. Our engineering and tech teams work at lightning speed to deliver you a seamless testing experience.
I was once asked at a testing summit, “How do you manage a QA team using scrum?” After some consideration, I realized it would make a good article, so here I am. Understand that the idea behind developing software in a scrum environment is for development teams to self-organize.
When most firms employed a waterfall development model, it was widely joked about in the industry that Google kept its products in beta forever. Google has been a pioneer in making the case for in-production testing. Traditionally, before a build could go live, a tester was responsible for testing all scenarios, both defined and extempore, in a testing environment. However, this concept is evolving on multiple fronts today. For example, the tester is no longer testing alone. Developers, designers, build engineers, other stakeholders, and end users, both inside and outside the product team, are testing the product and providing feedback.
Having a good web design can empower business and make your brand stand out. According to a survey by Top Design Firms, 50% of users believe that website design is crucial to an organization’s overall brand. Therefore, businesses should prioritize website design to meet customer expectations and build their brand identity. Your website is the face of your business, so it’s important that it’s updated regularly as per the current web design trends.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!