-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12148 from Sanne/MySQLXA
Fix the capability to connect to MySQL in XA mode
- Loading branch information
Showing
5 changed files
with
84 additions
and
1 deletion.
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
48 changes: 48 additions & 0 deletions
48
integration-tests/jpa-mysql/src/main/java/io/quarkus/it/jpa/mysql/XaConnectionsEndpoint.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,48 @@ | ||
package io.quarkus.it.jpa.mysql; | ||
|
||
import java.io.IOException; | ||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
|
||
import javax.inject.Inject; | ||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import io.agroal.api.AgroalDataSource; | ||
import io.agroal.api.configuration.AgroalConnectionFactoryConfiguration; | ||
import io.quarkus.agroal.DataSource; | ||
|
||
@WebServlet(name = "XaConnectionEndpoint", urlPatterns = "/jpa-mysql/testxaconnection") | ||
public class XaConnectionsEndpoint extends HttpServlet { | ||
|
||
@Inject | ||
@DataSource("samebutxa") | ||
AgroalDataSource xaDatasource; | ||
|
||
@Override | ||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { | ||
|
||
// Test 1# | ||
// Verify that the connection can be obtained | ||
try (Connection connection = xaDatasource.getConnection()) { | ||
//The main goal is to check that the connection could be opened | ||
} catch (SQLException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
// Test 2# | ||
// Check it's of the expected configuration | ||
AgroalConnectionFactoryConfiguration cfg = xaDatasource.getConfiguration().connectionPoolConfiguration() | ||
.connectionFactoryConfiguration(); | ||
Class<?> connectionProviderClass = cfg.connectionProviderClass(); | ||
if (connectionProviderClass.equals(com.mysql.cj.jdbc.MysqlXADataSource.class)) { | ||
resp.getWriter().write("OK"); | ||
} else { | ||
resp.getWriter().write("Unexpected Driver class: " + connectionProviderClass.getName()); | ||
} | ||
|
||
} | ||
|
||
} |
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
8 changes: 8 additions & 0 deletions
8
...tion-tests/jpa-mysql/src/test/java/io/quarkus/it/jpa/mysql/XaConnectionInGraalITCase.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,8 @@ | ||
package io.quarkus.it.jpa.mysql; | ||
|
||
import io.quarkus.test.junit.NativeImageTest; | ||
|
||
@NativeImageTest | ||
public class XaConnectionInGraalITCase extends XaConnectionTest { | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
integration-tests/jpa-mysql/src/test/java/io/quarkus/it/jpa/mysql/XaConnectionTest.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,18 @@ | ||
package io.quarkus.it.jpa.mysql; | ||
|
||
import static org.hamcrest.Matchers.is; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.restassured.RestAssured; | ||
|
||
@QuarkusTest | ||
public class XaConnectionTest { | ||
|
||
@Test | ||
public void testJPAFunctionalityFromServlet() throws Exception { | ||
RestAssured.when().get("/jpa-mysql/testxaconnection").then().body(is("OK")); | ||
} | ||
|
||
} |