Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-1001928: Fix flaky test DatabaseMetaDataLatestIT.testHandlingSpecialChars #1599

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/test/java/net/snowflake/client/TestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.sql.Statement;
import java.util.regex.Pattern;
import net.snowflake.client.core.SFException;
import net.snowflake.client.jdbc.SnowflakeUtil;
import net.snowflake.client.log.SFLogger;
import net.snowflake.client.log.SFLoggerFactory;
import org.junit.Assert;
Expand Down Expand Up @@ -69,4 +71,40 @@ public static void assertValidQueryId(String queryId) {
assertTrue(
"Expecting " + queryId + " is a valid UUID", QUERY_ID_REGEX.matcher(queryId).matches());
}

/**
* Creates schema and deletes it at the end of the passed function execution
*
* @param statement statement
* @param schemaName name of schema to create and delete after lambda execution
* @param action action to execute when schema was created
* @throws Exception when any error occurred
*/
public static void withSchema(Statement statement, String schemaName, ThrowingRunnable action)
throws Exception {
try {
statement.execute("CREATE OR REPLACE SCHEMA " + schemaName);
action.run();
} finally {
statement.execute("DROP SCHEMA " + schemaName);
}
}

/**
* Creates schema and deletes it at the end of the passed function execution
*
* @param statement statement
* @param action action to execute when schema was created
* @throws Exception when any error occurred
*/
public static void withRandomSchema(Statement statement, ThrowingConsumer<String> action)
throws Exception {
String customSchema = "TEST_SCHEMA_" + SnowflakeUtil.randomAlphaNumeric(5);
try {
statement.execute("CREATE OR REPLACE SCHEMA " + customSchema);
action.call(customSchema);
} finally {
statement.execute("DROP SCHEMA " + customSchema);
}
}
}
6 changes: 6 additions & 0 deletions src/test/java/net/snowflake/client/ThrowingConsumer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package net.snowflake.client;

@FunctionalInterface
public interface ThrowingConsumer<T> {
void call(T parameter) throws Exception;
}
6 changes: 6 additions & 0 deletions src/test/java/net/snowflake/client/ThrowingRunnable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package net.snowflake.client;

@FunctionalInterface
public interface ThrowingRunnable {
void run() throws Exception;
}
Loading