forked from aws/aws-advanced-jdbc-wrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: statement cancel not working with mysql driver
- Loading branch information
1 parent
ecfea81
commit 521ef55
Showing
5 changed files
with
140 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
wrapper/src/main/java/software/amazon/jdbc/util/AsynchronousMethodsHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package software.amazon.jdbc.util; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class AsynchronousMethodsHelper { | ||
public static final List<String> ASYNCHRONOUS_METHODS = Collections.singletonList( | ||
"Statement.cancel" | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
wrapper/src/test/java/integration/container/tests/MysqlTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package integration.container.tests; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import integration.DatabaseEngine; | ||
import integration.container.ConnectionStringHelper; | ||
import integration.container.TestDriver; | ||
import integration.container.TestDriverProvider; | ||
import integration.container.TestEnvironment; | ||
import integration.container.condition.EnableOnDatabaseEngine; | ||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
import java.util.logging.Logger; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
@EnableOnDatabaseEngine({DatabaseEngine.MYSQL}) | ||
@ExtendWith(TestDriverProvider.class) | ||
public class MysqlTests { | ||
|
||
private static final Logger LOGGER = Logger.getLogger(MysqlTests.class.getName()); | ||
|
||
@Test | ||
void testCancelStatement(TestDriver testDriver) { | ||
String url = | ||
ConnectionStringHelper.getWrapperUrl( | ||
testDriver, | ||
TestEnvironment.getCurrent() | ||
.getInfo() | ||
.getDatabaseInfo() | ||
.getInstances() | ||
.get(0) | ||
.getHost(), | ||
TestEnvironment.getCurrent() | ||
.getInfo() | ||
.getDatabaseInfo() | ||
.getInstances() | ||
.get(0) | ||
.getPort(), | ||
TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); | ||
LOGGER.finest("Connecting to " + url); | ||
try (final Connection conn = DriverManager.getConnection(url)) { | ||
Statement stmt = conn.createStatement(); | ||
Thread thread = new Thread(() -> { | ||
try { | ||
Thread.sleep(1000); | ||
stmt.cancel(); | ||
} catch (SQLException | InterruptedException e) { | ||
fail(e); | ||
} | ||
}); | ||
|
||
final long startTime = System.currentTimeMillis(); | ||
thread.start(); | ||
stmt.execute("select sleep(1000)"); | ||
|
||
try { | ||
thread.join(); | ||
assertTrue(System.currentTimeMillis() - startTime < 10000); | ||
} catch (InterruptedException e) { | ||
fail(e); | ||
} | ||
} catch (Exception e) { | ||
fail(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters