Skip to content

Commit

Permalink
fix xa test and add some prometheus exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
junwen12221 committed Feb 15, 2022
1 parent ed31db0 commit 6995421
Show file tree
Hide file tree
Showing 9 changed files with 416 additions and 164 deletions.
26 changes: 13 additions & 13 deletions example/src/test/java/io/mycat/xa/BaseSavepointSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void baseSavepointCommit(VertxTestContext testContext) {

SavepointSqlConnection savepointSqlConnection = (SavepointSqlConnection) baseXaSqlConnection;

baseXaSqlConnection.begin(new Handler<AsyncResult<Void>>() {
baseXaSqlConnection.begin().onComplete(new Handler<AsyncResult<Void>>() {
@Override
@SneakyThrows
public void handle(AsyncResult<Void> event) {
Expand All @@ -55,7 +55,7 @@ public void baseSavepointSavepointCommit(VertxTestContext testContext) {

SavepointSqlConnection savepointSqlConnection = (SavepointSqlConnection) baseXaSqlConnection;

baseXaSqlConnection.begin(new Handler<AsyncResult<Void>>() {
baseXaSqlConnection.begin().onComplete(new Handler<AsyncResult<Void>>() {
@Override
@SneakyThrows
public void handle(AsyncResult<Void> event) {
Expand Down Expand Up @@ -99,7 +99,7 @@ public void baseSavepointRollback(VertxTestContext testContext) {

SavepointSqlConnection savepointSqlConnection = (SavepointSqlConnection) baseXaSqlConnection;

baseXaSqlConnection.begin(new Handler<AsyncResult<Void>>() {
baseXaSqlConnection.begin().onComplete(new Handler<AsyncResult<Void>>() {
@Override
@SneakyThrows
public void handle(AsyncResult<Void> event) {
Expand All @@ -120,7 +120,7 @@ public void baseSavepointRelease(VertxTestContext testContext) {

SavepointSqlConnection savepointSqlConnection = (SavepointSqlConnection) baseXaSqlConnection;

baseXaSqlConnection.begin(new Handler<AsyncResult<Void>>() {
baseXaSqlConnection.begin().onComplete(new Handler<AsyncResult<Void>>() {
@Override
@SneakyThrows
public void handle(AsyncResult<Void> event) {
Expand All @@ -142,7 +142,7 @@ public void baseSavepointRollbackSavepoint(VertxTestContext testContext) {

SavepointSqlConnection savepointSqlConnection = (SavepointSqlConnection) baseXaSqlConnection;

baseXaSqlConnection.begin(new Handler<AsyncResult<Void>>() {
baseXaSqlConnection.begin().onComplete(new Handler<AsyncResult<Void>>() {
@Override
@SneakyThrows
public void handle(AsyncResult<Void> event) {
Expand All @@ -168,7 +168,7 @@ public void baseSavepointCommitInSingleConnection(VertxTestContext testContext)

SavepointSqlConnection savepointSqlConnection = (SavepointSqlConnection) baseXaSqlConnection;

baseXaSqlConnection.begin(new Handler<AsyncResult<Void>>() {
baseXaSqlConnection.begin().onComplete(new Handler<AsyncResult<Void>>() {
@Override
@SneakyThrows
public void handle(AsyncResult<Void> event) {
Expand Down Expand Up @@ -215,7 +215,7 @@ public void baseSavepointRollbackInSingleConnection(VertxTestContext testContext

SavepointSqlConnection savepointSqlConnection = (SavepointSqlConnection) baseXaSqlConnection;

baseXaSqlConnection.begin(new Handler<AsyncResult<Void>>() {
baseXaSqlConnection.begin().onComplete(new Handler<AsyncResult<Void>>() {
@Override
@SneakyThrows
public void handle(AsyncResult<Void> event) {
Expand Down Expand Up @@ -262,7 +262,7 @@ public void baseSavepointRollbackSavepointInSingleConnection(VertxTestContext te

SavepointSqlConnection savepointSqlConnection = (SavepointSqlConnection) baseXaSqlConnection;

baseXaSqlConnection.begin(new Handler<AsyncResult<Void>>() {
baseXaSqlConnection.begin().onComplete(new Handler<AsyncResult<Void>>() {
@Override
@SneakyThrows
public void handle(AsyncResult<Void> event) {
Expand Down Expand Up @@ -320,7 +320,7 @@ public void baseSavepointReleaseSavepointInSingleConnection(VertxTestContext tes

SavepointSqlConnection savepointSqlConnection = (SavepointSqlConnection) baseXaSqlConnection;

baseXaSqlConnection.begin(new Handler<AsyncResult<Void>>() {
baseXaSqlConnection.begin().onComplete(new Handler<AsyncResult<Void>>() {
@Override
@SneakyThrows
public void handle(AsyncResult<Void> event) {
Expand Down Expand Up @@ -385,7 +385,7 @@ public void baseSavepointReleaseSavepointInTwoConnection(VertxTestContext testCo

SavepointSqlConnection savepointSqlConnection = (SavepointSqlConnection) baseXaSqlConnection;

baseXaSqlConnection.begin(new Handler<AsyncResult<Void>>() {
baseXaSqlConnection.begin().onComplete(new Handler<AsyncResult<Void>>() {
@Override
@SneakyThrows
public void handle(AsyncResult<Void> event) {
Expand Down Expand Up @@ -479,7 +479,7 @@ public void baseSavepointRollbackSavepointInTwoConnection(VertxTestContext testC

SavepointSqlConnection savepointSqlConnection = (SavepointSqlConnection) baseXaSqlConnection;

baseXaSqlConnection.begin(new Handler<AsyncResult<Void>>() {
baseXaSqlConnection.begin().onComplete(new Handler<AsyncResult<Void>>() {
@Override
@SneakyThrows
public void handle(AsyncResult<Void> event) {
Expand Down Expand Up @@ -570,7 +570,7 @@ public void baseSavepointCommitSavepointInTwoConnection(VertxTestContext testCon

SavepointSqlConnection savepointSqlConnection = (SavepointSqlConnection) baseXaSqlConnection;

baseXaSqlConnection.begin(new Handler<AsyncResult<Void>>() {
baseXaSqlConnection.begin().onComplete(new Handler<AsyncResult<Void>>() {
@Override
@SneakyThrows
public void handle(AsyncResult<Void> event) {
Expand Down Expand Up @@ -645,7 +645,7 @@ public void baseSavepointRollbackInTwoConnection(VertxTestContext testContext) {

SavepointSqlConnection savepointSqlConnection = (SavepointSqlConnection) baseXaSqlConnection;

baseXaSqlConnection.begin(new Handler<AsyncResult<Void>>() {
baseXaSqlConnection.begin().onComplete(new Handler<AsyncResult<Void>>() {
@Override
@SneakyThrows
public void handle(AsyncResult<Void> event) {
Expand Down
40 changes: 20 additions & 20 deletions example/src/test/java/io/mycat/xa/XaTestSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private void extracteInitSql(Connection mySQLConnection) throws SQLException {
@Test
public void begin(VertxTestContext testContext) {
XaSqlConnection baseXaSqlConnection = factory.apply(mySQLManager,xaLog);
baseXaSqlConnection.begin(new Handler<AsyncResult<Void>>() {
baseXaSqlConnection.begin().onComplete(new Handler<AsyncResult<Void>>() {
@Override
public void handle(AsyncResult<Void> event) {
Assertions.assertEquals(baseXaSqlConnection.isInTransaction(), true);
Expand All @@ -104,7 +104,7 @@ public void handle(AsyncResult<Void> event) {
@Test
public void beginCommit(VertxTestContext testContext) {
XaSqlConnection baseXaSqlConnection = factory.apply(mySQLManager,xaLog);
baseXaSqlConnection.begin(event -> baseXaSqlConnection.commit(new Handler<AsyncResult<Void>>() {
baseXaSqlConnection.begin().onComplete(event -> baseXaSqlConnection.commit().onComplete(new Handler<AsyncResult<Void>>() {
@Override
public void handle(AsyncResult<Void> event) {
Assertions.assertEquals(baseXaSqlConnection.isInTransaction(), false);
Expand All @@ -117,7 +117,7 @@ public void handle(AsyncResult<Void> event) {
@Test
public void beginRollback(VertxTestContext testContext) {
XaSqlConnection baseXaSqlConnection = factory.apply(mySQLManager,xaLog);
baseXaSqlConnection.begin(event -> baseXaSqlConnection.rollback(new Handler<AsyncResult<Void>>() {
baseXaSqlConnection.begin().onComplete(event -> baseXaSqlConnection.rollback().onComplete(new Handler<AsyncResult<Void>>() {
@Override
public void handle(AsyncResult<Void> event) {
Assertions.assertEquals(baseXaSqlConnection.isInTransaction(), false);
Expand All @@ -131,10 +131,10 @@ public void handle(AsyncResult<Void> event) {
@Disabled
public void beginBegin(VertxTestContext testContext) {
XaSqlConnection baseXaSqlConnection = factory.apply(mySQLManager,xaLog);
baseXaSqlConnection.begin(new Handler<AsyncResult<Void>>() {
baseXaSqlConnection.begin().onComplete(new Handler<AsyncResult<Void>>() {
@Override
public void handle(AsyncResult<Void> event) {
baseXaSqlConnection.begin(event1 -> {
baseXaSqlConnection.begin().onComplete(event1 -> {
Assertions.assertTrue(event1.failed());
testContext.completeNow();
});
Expand All @@ -146,7 +146,7 @@ public void handle(AsyncResult<Void> event) {
@Test
public void rollback(VertxTestContext testContext) {
XaSqlConnection baseXaSqlConnection = factory.apply(mySQLManager,xaLog);
baseXaSqlConnection.rollback(new Handler<AsyncResult<Void>>() {
baseXaSqlConnection.rollback().onComplete(new Handler<AsyncResult<Void>>() {
@Override
public void handle(AsyncResult<Void> event) {
Assertions.assertTrue(event.succeeded());
Expand All @@ -159,7 +159,7 @@ public void handle(AsyncResult<Void> event) {
@Test
public void commit(VertxTestContext testContext) {
XaSqlConnection baseXaSqlConnection = factory.apply(mySQLManager,xaLog);
baseXaSqlConnection.commit(new Handler<AsyncResult<Void>>() {
baseXaSqlConnection.commit().onComplete(new Handler<AsyncResult<Void>>() {
@Override
public void handle(AsyncResult<Void> event) {
Assertions.assertTrue(event.succeeded());
Expand All @@ -172,7 +172,7 @@ public void handle(AsyncResult<Void> event) {
@Test
public void close(VertxTestContext testContext) {
XaSqlConnection baseXaSqlConnection = factory.apply(mySQLManager,xaLog);
baseXaSqlConnection.close(new Handler<AsyncResult<Void>>() {
baseXaSqlConnection.close().onComplete(new Handler<AsyncResult<Void>>() {
@Override
public void handle(AsyncResult<Void> event) {
Assertions.assertTrue(event.succeeded());
Expand All @@ -185,10 +185,10 @@ public void handle(AsyncResult<Void> event) {
@Test
public void closeInTranscation(VertxTestContext testContext) {
XaSqlConnection baseXaSqlConnection = factory.apply(mySQLManager,xaLog);
baseXaSqlConnection.begin(new Handler<AsyncResult<Void>>() {
baseXaSqlConnection.begin().onComplete(new Handler<AsyncResult<Void>>() {
@Override
public void handle(AsyncResult<Void> event) {
baseXaSqlConnection.close(new Handler<AsyncResult<Void>>() {
baseXaSqlConnection.close().onComplete(new Handler<AsyncResult<Void>>() {
@Override
public void handle(AsyncResult<Void> event) {
Assertions.assertTrue(event.succeeded());
Expand All @@ -204,7 +204,7 @@ public void handle(AsyncResult<Void> event) {
public void beginSingleTargetInsertCommit(VertxTestContext testContext) throws Exception {
clearData();
XaSqlConnection baseXaSqlConnection = factory.apply(mySQLManager,xaLog);
baseXaSqlConnection.begin(event -> {
baseXaSqlConnection.begin().onComplete(event -> {
Assertions.assertTrue(event.succeeded());
Future<NewMycatConnection> ds1 = baseXaSqlConnection.getConnection("ds1");
ds1.compose(connection -> {
Expand All @@ -224,7 +224,7 @@ public void beginSingleTargetInsertCommit(VertxTestContext testContext) throws E
});
}).onComplete(event13 -> {
Assertions.assertTrue(event13.succeeded());
baseXaSqlConnection.commit(event12 -> {
baseXaSqlConnection.commit().onComplete(event12 -> {
Assertions.assertTrue(event12.succeeded());
Assertions.assertFalse(baseXaSqlConnection.isInTransaction());
Future<NewMycatConnection> connectionFuture =
Expand All @@ -247,7 +247,7 @@ public void beginSingleTargetInsertCommit(VertxTestContext testContext) throws E
public void beginDoubleTargetInsertCommit(VertxTestContext testContext) throws Exception {
clearData();
XaSqlConnection baseXaSqlConnection = factory.apply(mySQLManager,xaLog);
baseXaSqlConnection.begin(event -> {
baseXaSqlConnection.begin().onComplete(event -> {
Assertions.assertTrue(event.succeeded());
Future<NewMycatConnection> ds1 = baseXaSqlConnection.getConnection("ds1");
Future<NewMycatConnection> ds2 = baseXaSqlConnection.getConnection("ds2");
Expand All @@ -273,7 +273,7 @@ public void beginDoubleTargetInsertCommit(VertxTestContext testContext) throws E
}));
all.onComplete(event13 -> {
Assertions.assertTrue(event13.succeeded());
baseXaSqlConnection.commit(event12 -> {
baseXaSqlConnection.commit().onComplete(event12 -> {
Assertions.assertTrue(event12.succeeded());
Assertions.assertFalse(baseXaSqlConnection.isInTransaction());
Future<NewMycatConnection> connectionFuture =
Expand All @@ -295,7 +295,7 @@ public void beginDoubleTargetInsertCommit(VertxTestContext testContext) throws E
public void beginDoubleTargetInsertButStatementFail(VertxTestContext testContext) throws Exception {
clearData();
XaSqlConnection baseXaSqlConnection = factory.apply(mySQLManager,xaLog);
baseXaSqlConnection.begin(event -> {
baseXaSqlConnection.begin().onComplete(event -> {
Assertions.assertTrue(event.succeeded());
Future<NewMycatConnection> ds1 = baseXaSqlConnection.getConnection("ds1");
Future<NewMycatConnection> ds2 = baseXaSqlConnection.getConnection("ds2");
Expand All @@ -321,7 +321,7 @@ public void beginDoubleTargetInsertButStatementFail(VertxTestContext testContext
}));
all.onComplete(event13 -> {
Assertions.assertTrue(event13.failed());
baseXaSqlConnection.rollback(new Handler<AsyncResult<Void>>() {
baseXaSqlConnection.rollback().onComplete(new Handler<AsyncResult<Void>>() {
@Override
public void handle(AsyncResult<Void> event) {
Assertions.assertTrue(event.succeeded());
Expand All @@ -346,7 +346,7 @@ public void handle(AsyncResult<Void> event) {
public void beginDoubleTargetInsertButPrepareFail(VertxTestContext testContext) throws Exception {
clearData();
XaSqlConnection baseXaSqlConnection = factory.apply(mySQLManager,xaLog);
baseXaSqlConnection.begin(event -> {
baseXaSqlConnection.begin().onComplete(event -> {
Assertions.assertTrue(event.succeeded());
Future<NewMycatConnection> ds1 = baseXaSqlConnection.getConnection("ds1");
Future<NewMycatConnection> ds2 = baseXaSqlConnection.getConnection("ds2");
Expand Down Expand Up @@ -377,7 +377,7 @@ public void beginDoubleTargetInsertButPrepareFail(VertxTestContext testContext)
@Override
public void handle(AsyncResult<Void> event) {
Assertions.assertTrue(event.failed());
baseXaSqlConnection.rollback(new Handler<AsyncResult<Void>>() {
baseXaSqlConnection.rollback().onComplete(new Handler<AsyncResult<Void>>() {
@Override
public void handle(AsyncResult<Void> event) {
Assertions.assertTrue(event.succeeded());
Expand Down Expand Up @@ -405,7 +405,7 @@ public void handle(AsyncResult<Void> event) {
public void beginDoubleTargetInsertButCommitFail(VertxTestContext testContext) throws Exception {
clearData();
XaSqlConnection baseXaSqlConnection = factory.apply(mySQLManager,xaLog);
baseXaSqlConnection.begin(event -> {
baseXaSqlConnection.begin().onComplete(event -> {
Assertions.assertTrue(event.succeeded());
Future<NewMycatConnection> ds1 = baseXaSqlConnection.getConnection("ds1");
Future<NewMycatConnection> ds2 = baseXaSqlConnection.getConnection("ds2");
Expand Down Expand Up @@ -436,7 +436,7 @@ public void beginDoubleTargetInsertButCommitFail(VertxTestContext testContext) t
@Override
public void handle(AsyncResult<Void> event) {
Assertions.assertTrue(event.failed());
baseXaSqlConnection.commit(new Handler<AsyncResult<Void>>() {
baseXaSqlConnection.commit().onComplete(new Handler<AsyncResult<Void>>() {
@Override
public void handle(AsyncResult<Void> event) {
Assertions.assertTrue(event.succeeded());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public Future<Map<String, Integer>> computeConnectionUsageSnapshot() {
HashMap<String, Integer> resMap = new HashMap<>();
for (Map.Entry<String, MycatDatasourcePool> entry : map.entrySet()) {
MycatDatasourcePool pool = entry.getValue();
Integer n = pool.getAvailableNumber();
Integer n = pool.getUsedNumber();
resMap.put(entry.getKey(), n);
}
return Future.succeededFuture(resMap);
Expand Down
Loading

0 comments on commit 6995421

Please sign in to comment.