Skip to content

Commit

Permalink
Merge pull request #12148 from Sanne/MySQLXA
Browse files Browse the repository at this point in the history
Fix the capability to connect to MySQL in XA mode
  • Loading branch information
machi1990 authored Sep 16, 2020
2 parents 90c66c9 + 6969897 commit bff1662
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ void registerDriverForReflection(BuildProducer<ReflectiveClassBuildItem> reflect
com.mysql.cj.jdbc.ha.LoadBalancedAutoCommitInterceptor.class.getName()));
reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, StandardLogger.class.getName()));
reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, Wrapper.class.getName()));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, false, com.mysql.cj.jdbc.MysqlDataSource.class.getName()));
}

@BuildStep
Expand Down
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());
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,12 @@ quarkus.datasource.db-kind=mysql
quarkus.datasource.username=hibernate_orm_test
quarkus.datasource.password=hibernate_orm_test
quarkus.datasource.jdbc.url=${mysql.url}
quarkus.datasource.max-size=1
quarkus.datasource.jdbc.max-size=1
quarkus.datasource.jdbc.transactions=enabled

quarkus.datasource.samebutxa.db-kind=mysql
quarkus.datasource.samebutxa.username=hibernate_orm_test
quarkus.datasource.samebutxa.password=hibernate_orm_test
quarkus.datasource.samebutxa.jdbc.url=${mysql.url}
quarkus.datasource.samebutxa.jdbc.max-size=1
quarkus.datasource.samebutxa.jdbc.transactions=xa
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 {

}
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"));
}

}

0 comments on commit bff1662

Please sign in to comment.