use of cn.mycat.vertx.xa.XaSqlConnection in project Mycat2 by MyCATApache.
the class XaTestSuite method beginDoubleTargetInsertButStatementFail.
@Test
public void beginDoubleTargetInsertButStatementFail(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 (id)\n" + " VALUES\n" + " (2/0);");
return future.compose(rowSet -> {
Assertions.assertEquals(1, rowSet.getAffectRows());
return Future.succeededFuture(connection);
});
}));
all.onComplete(event13 -> {
Assertions.assertTrue(event13.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 beginCommit.
@Test
public void beginCommit(VertxTestContext testContext) {
XaSqlConnection baseXaSqlConnection = factory.apply(mySQLManager, xaLog);
baseXaSqlConnection.begin().onComplete(event -> baseXaSqlConnection.commit().onComplete(new Handler<AsyncResult<Void>>() {
@Override
public void handle(AsyncResult<Void> event) {
Assertions.assertEquals(baseXaSqlConnection.isInTransaction(), false);
baseXaSqlConnection.close();
testContext.completeNow();
}
}));
}
use of cn.mycat.vertx.xa.XaSqlConnection in project Mycat2 by MyCATApache.
the class XaTestSuite method beginRollback.
@Test
public void beginRollback(VertxTestContext testContext) {
XaSqlConnection baseXaSqlConnection = factory.apply(mySQLManager, xaLog);
baseXaSqlConnection.begin().onComplete(event -> baseXaSqlConnection.rollback().onComplete(new Handler<AsyncResult<Void>>() {
@Override
public void handle(AsyncResult<Void> event) {
Assertions.assertEquals(baseXaSqlConnection.isInTransaction(), false);
baseXaSqlConnection.close();
testContext.completeNow();
}
}));
}
use of cn.mycat.vertx.xa.XaSqlConnection in project Mycat2 by MyCATApache.
the class XaTestSuite method close.
@Test
public void close(VertxTestContext testContext) {
XaSqlConnection baseXaSqlConnection = factory.apply(mySQLManager, xaLog);
baseXaSqlConnection.close().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 commit.
@Test
public void commit(VertxTestContext testContext) {
XaSqlConnection baseXaSqlConnection = factory.apply(mySQLManager, xaLog);
baseXaSqlConnection.commit().onComplete(new Handler<AsyncResult<Void>>() {
@Override
public void handle(AsyncResult<Void> event) {
Assertions.assertTrue(event.succeeded());
Assertions.assertFalse(baseXaSqlConnection.isInTransaction());
testContext.completeNow();
}
});
}
Aggregations