TSK-2003: removed reset of schema name in SqlConRunner#runWithConnection
This commit is contained in:
parent
b96c68ac6f
commit
3af17ece6a
|
@ -26,14 +26,8 @@ public class SqlConnectionRunner {
|
|||
public void runWithConnection(CheckedConsumer<Connection, SQLException> consumer) {
|
||||
|
||||
try (Connection connection = getConnection()) {
|
||||
String originalSchema = connection.getSchema();
|
||||
try {
|
||||
connection.setSchema(taskanaEngine.getConfiguration().getSchemaName());
|
||||
consumer.accept(connection);
|
||||
} finally {
|
||||
connection.setSchema(originalSchema);
|
||||
}
|
||||
|
||||
connection.setSchema(taskanaEngine.getConfiguration().getSchemaName());
|
||||
consumer.accept(connection);
|
||||
} catch (SQLException e) {
|
||||
throw new SystemException("SQL error while running low level SQL", e);
|
||||
}
|
||||
|
|
|
@ -7,92 +7,54 @@ import acceptance.AbstractAccTest;
|
|||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import pro.taskana.TaskanaConfiguration;
|
||||
import pro.taskana.common.api.TaskanaEngine;
|
||||
import pro.taskana.common.api.exceptions.SystemException;
|
||||
import pro.taskana.common.api.exceptions.TaskanaRuntimeException;
|
||||
import pro.taskana.common.test.security.JaasExtension;
|
||||
import pro.taskana.common.test.security.WithAccessId;
|
||||
import pro.taskana.task.internal.jobs.helper.SqlConnectionRunner;
|
||||
|
||||
/** Acceptance test for all "jobs tasks runner" scenarios. */
|
||||
@ExtendWith(JaasExtension.class)
|
||||
class SqlConnectionRunnerAccTest extends AbstractAccTest {
|
||||
|
||||
@BeforeEach
|
||||
void before() throws Exception {
|
||||
// required if single tests modify database
|
||||
// TODO split test class into readOnly & modifying tests to improve performance
|
||||
resetDb(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_executeSimpleQuery() {
|
||||
void should_executeSimpleQuery() throws Exception {
|
||||
// given
|
||||
SqlConnectionRunner runner = new SqlConnectionRunner(taskanaEngine);
|
||||
String taskId = "TKI:000000000000000000000000000000000050";
|
||||
|
||||
// when
|
||||
AtomicReference<ResultSet> resultSet = new AtomicReference<>();
|
||||
runner.runWithConnection(
|
||||
connection -> {
|
||||
PreparedStatement preparedStatement =
|
||||
connection.prepareStatement("select * from TASK where ID = ?");
|
||||
preparedStatement.setString(1, taskId);
|
||||
final ResultSet resultSet = preparedStatement.executeQuery();
|
||||
|
||||
// then
|
||||
assertThat(resultSet.next()).isTrue();
|
||||
resultSet.set(preparedStatement.executeQuery());
|
||||
});
|
||||
|
||||
// then
|
||||
assertThat(resultSet.get().next()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_catchSqlExceptionAndThrowSystemException() {
|
||||
// given
|
||||
SqlConnectionRunner runner = new SqlConnectionRunner(taskanaEngine);
|
||||
SQLException expectedException = new SQLException("test");
|
||||
|
||||
// when
|
||||
assertThatThrownBy(
|
||||
() ->
|
||||
runner.runWithConnection(
|
||||
connection -> {
|
||||
throw new SQLException("test");
|
||||
}))
|
||||
.isInstanceOf(SystemException.class);
|
||||
}
|
||||
ThrowingCallable code =
|
||||
() ->
|
||||
runner.runWithConnection(
|
||||
connection -> {
|
||||
throw expectedException;
|
||||
});
|
||||
|
||||
@Test
|
||||
@WithAccessId(user = "admin")
|
||||
@Disabled("This Test does not make sense anymore")
|
||||
void should_SetOriginalSchema_When_ExceptionThrown() throws Exception {
|
||||
|
||||
TaskanaEngine taskanaEngine =
|
||||
TaskanaEngine.buildTaskanaEngine(
|
||||
new TaskanaConfiguration.Builder(AbstractAccTest.taskanaEngine.getConfiguration())
|
||||
.schemaName("NotExisting")
|
||||
.build());
|
||||
SqlConnectionRunner runner = new SqlConnectionRunner(taskanaEngine);
|
||||
|
||||
// TSK-1749
|
||||
assertThat(runner.getConnection().getSchema()).matches("TASKANA\\s|TASKANA|taskana");
|
||||
String taskId = "TKI:000000000000000000000000000000000000";
|
||||
|
||||
assertThatThrownBy(
|
||||
() ->
|
||||
runner.runWithConnection(
|
||||
connection -> {
|
||||
PreparedStatement preparedStatement =
|
||||
connection.prepareStatement("select * from TASK where ID = ?");
|
||||
preparedStatement.setString(1, taskId);
|
||||
preparedStatement.executeQuery();
|
||||
}))
|
||||
.isInstanceOf(TaskanaRuntimeException.class);
|
||||
|
||||
// TSK-1749
|
||||
assertThat(runner.getConnection().getSchema()).matches("TASKANA\\s|TASKANA|taskana");
|
||||
// then
|
||||
assertThatThrownBy(code).isInstanceOf(SystemException.class).hasCause(expectedException);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue