use of cn.mycat.vertx.xa.XaSqlConnection in project Mycat2 by MyCATApache.
the class BaseSavepointSuite method baseSavepointCommit.
@Test
public void baseSavepointCommit(VertxTestContext testContext) {
XaSqlConnection baseXaSqlConnection = factory.apply(mySQLManager, xaLog);
Assert.assertTrue(baseXaSqlConnection instanceof SavepointSqlConnection);
SavepointSqlConnection savepointSqlConnection = (SavepointSqlConnection) baseXaSqlConnection;
baseXaSqlConnection.begin().onComplete(new Handler<AsyncResult<Void>>() {
@Override
@SneakyThrows
public void handle(AsyncResult<Void> event) {
Future<Void> sss = savepointSqlConnection.createSavepoint("sss");
sss.toCompletionStage().toCompletableFuture().get();
Assert.assertEquals("[sss]", savepointSqlConnection.getExistedSavepoints().toString());
savepointSqlConnection.commit().toCompletionStage().toCompletableFuture().get();
;
Assert.assertEquals("[]", savepointSqlConnection.getExistedSavepoints().toString());
testContext.completeNow();
}
});
}
use of cn.mycat.vertx.xa.XaSqlConnection in project Mycat2 by MyCATApache.
the class XaTestSuite method beginDoubleTargetInsertButPrepareFail.
@Test
public void beginDoubleTargetInsertButPrepareFail(VertxTestContext testContext) throws Exception {
clearData();
XaSqlConnection baseXaSqlConnection = factory.apply(mySQLManager, xaLog);
baseXaSqlConnection.begin().onComplete(event -> {
Assertions.assertTrue(event.succeeded());
Future<NewMycatConnection> ds1 = baseXaSqlConnection.getConnection("ds1");
Future<NewMycatConnection> ds2 = baseXaSqlConnection.getConnection("ds2");
CompositeFuture all = CompositeFuture.join(ds1.compose(connection -> {
Future<SqlResult> future = connection.insert("INSERT INTO db1.travelrecord (id)\n" + " VALUES\n" + " (1);");
return future.compose(rowSet -> {
Assertions.assertEquals(1, rowSet.getAffectRows());
return Future.succeededFuture(connection);
});
}), ds2.compose(connection -> {
Future<SqlResult> future = connection.insert("INSERT INTO db1.travelrecord (id)\n" + " VALUES\n" + " (2);");
return future.compose(rowSet -> {
Assertions.assertEquals(1, rowSet.getAffectRows());
return Future.succeededFuture(connection);
});
}));
all.onComplete(event13 -> {
Assertions.assertTrue(event13.succeeded());
Future<Void> future = baseXaSqlConnection.commitXa((c) -> Future.failedFuture("prepare fail"));
future.onComplete(new Handler<AsyncResult<Void>>() {
@Override
public void handle(AsyncResult<Void> event) {
Assertions.assertTrue(event.failed());
baseXaSqlConnection.rollback().onComplete(new Handler<AsyncResult<Void>>() {
@Override
public void handle(AsyncResult<Void> event) {
Assertions.assertTrue(event.succeeded());
Assertions.assertFalse(baseXaSqlConnection.isInTransaction());
Future<NewMycatConnection> connectionFuture = baseXaSqlConnection.getConnection("ds1");
connectionFuture.compose(sqlConnection -> sqlConnection.query("select id from db1.travelrecord")).onComplete(event1 -> {
Assertions.assertTrue(event1.succeeded());
Assertions.assertEquals(0, event1.result().size());
testContext.completeNow();
});
}
});
}
});
});
});
}
use of cn.mycat.vertx.xa.XaSqlConnection in project Mycat2 by MyCATApache.
the class XaTestSuite method beginBegin.
@Test
@Disabled
public void beginBegin(VertxTestContext testContext) {
XaSqlConnection baseXaSqlConnection = factory.apply(mySQLManager, xaLog);
baseXaSqlConnection.begin().onComplete(new Handler<AsyncResult<Void>>() {
@Override
public void handle(AsyncResult<Void> event) {
baseXaSqlConnection.begin().onComplete(event1 -> {
Assertions.assertTrue(event1.failed());
testContext.completeNow();
});
}
});
}
use of cn.mycat.vertx.xa.XaSqlConnection in project Mycat2 by MyCATApache.
the class XaTestSuite method rollback.
@Test
public void rollback(VertxTestContext testContext) {
XaSqlConnection baseXaSqlConnection = factory.apply(mySQLManager, xaLog);
baseXaSqlConnection.rollback().onComplete(new Handler<AsyncResult<Void>>() {
@Override
public void handle(AsyncResult<Void> event) {
Assertions.assertTrue(event.succeeded());
Assertions.assertFalse(baseXaSqlConnection.isInTransaction());
testContext.completeNow();
}
});
}
use of cn.mycat.vertx.xa.XaSqlConnection in project Mycat2 by MyCATApache.
the class XaTestSuite method closeInTranscation.
@Test
public void closeInTranscation(VertxTestContext testContext) {
XaSqlConnection baseXaSqlConnection = factory.apply(mySQLManager, xaLog);
baseXaSqlConnection.begin().onComplete(new Handler<AsyncResult<Void>>() {
@Override
public void handle(AsyncResult<Void> event) {
baseXaSqlConnection.close().onComplete(new Handler<AsyncResult<Void>>() {
@Override
public void handle(AsyncResult<Void> event) {
Assertions.assertTrue(event.succeeded());
Assertions.assertFalse(baseXaSqlConnection.isInTransaction());
testContext.completeNow();
}
});
}
});
}
Aggregations