Search in sources :

Example 1 with SavepointSqlConnection

use of cn.mycat.vertx.xa.SavepointSqlConnection in project Mycat2 by MyCATApache.

the class BaseSavepointSuite method baseSavepointSavepointCommit.

@Test
@SneakyThrows
public void baseSavepointSavepointCommit(VertxTestContext testContext) {
    mySQLManager.getConnection("ds1").flatMap(connection -> {
        return connection.update("delete FROM `db1`.`travelrecord`").map(u -> connection);
    }).flatMap(c -> c.close()).toCompletionStage().toCompletableFuture().get();
    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());
            NewMycatConnection ds1 = savepointSqlConnection.getConnection("ds1").toCompletionStage().toCompletableFuture().get();
            ds1.insert("insert into `db1`.`travelrecord` (`id`) values ('2')").toCompletionStage().toCompletableFuture().get();
            sss = savepointSqlConnection.createSavepoint("sss");
            sss.toCompletionStage().toCompletableFuture().get();
            RowSet objects = ds1.query("select * from `db1`.`travelrecord` where id = 2").toCompletionStage().toCompletableFuture().get();
            Assert.assertTrue(objects.size() > 0);
            savepointSqlConnection.commit().toCompletionStage().toCompletableFuture().get();
            ds1 = savepointSqlConnection.getConnection("ds1").toCompletionStage().toCompletableFuture().get();
            objects = ds1.query("select * from `db1`.`travelrecord` where id = 2").toCompletionStage().toCompletableFuture().get();
            Assert.assertTrue(objects.size() > 0);
            Assert.assertEquals("[]", savepointSqlConnection.getExistedSavepoints().toString());
            savepointSqlConnection.close();
            testContext.completeNow();
        }
    });
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) NewMycatConnection(io.mycat.newquery.NewMycatConnection) SneakyThrows(lombok.SneakyThrows) RowSet(io.mycat.newquery.RowSet) BiFunction(java.util.function.BiFunction) XaLog(cn.mycat.vertx.xa.XaLog) Future(io.vertx.core.Future) Test(org.junit.jupiter.api.Test) XaSqlConnection(cn.mycat.vertx.xa.XaSqlConnection) AsyncResult(io.vertx.core.AsyncResult) MySQLManager(cn.mycat.vertx.xa.MySQLManager) SavepointSqlConnection(cn.mycat.vertx.xa.SavepointSqlConnection) Handler(io.vertx.core.Handler) Assert(org.junit.Assert) NewMycatConnection(io.mycat.newquery.NewMycatConnection) SavepointSqlConnection(cn.mycat.vertx.xa.SavepointSqlConnection) RowSet(io.mycat.newquery.RowSet) SneakyThrows(lombok.SneakyThrows) Future(io.vertx.core.Future) AsyncResult(io.vertx.core.AsyncResult) XaSqlConnection(cn.mycat.vertx.xa.XaSqlConnection) Test(org.junit.jupiter.api.Test) SneakyThrows(lombok.SneakyThrows)

Example 2 with SavepointSqlConnection

use of cn.mycat.vertx.xa.SavepointSqlConnection in project Mycat2 by MyCATApache.

the class BaseSavepointSuite method baseSavepointCommitInSingleConnection.

@Test
@SneakyThrows
public void baseSavepointCommitInSingleConnection(VertxTestContext testContext) {
    mySQLManager.getConnection("ds1").flatMap(connection -> {
        return connection.update("delete FROM `db1`.`travelrecord`").map(u -> connection);
    }).flatMap(c -> c.close()).toCompletionStage().toCompletableFuture().get();
    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) {
            savepointSqlConnection.createSavepoint("sss").toCompletionStage().toCompletableFuture().get();
            NewMycatConnection ds1 = savepointSqlConnection.getConnection("ds1").toCompletionStage().toCompletableFuture().get();
            ds1.insert("insert into `db1`.`travelrecord` (`id`) values ('2')").toCompletionStage().toCompletableFuture().get();
            RowSet objects = ds1.query("select * from `db1`.`travelrecord` where id = 2").toCompletionStage().toCompletableFuture().get();
            Assert.assertTrue(objects.size() > 0);
            Assert.assertEquals("[sss]", savepointSqlConnection.getExistedSavepoints().toString());
            savepointSqlConnection.commit().toCompletionStage().toCompletableFuture();
            Assert.assertEquals("[]", savepointSqlConnection.getExistedSavepoints().toString());
            ds1 = savepointSqlConnection.getConnection("ds1").toCompletionStage().toCompletableFuture().get();
            objects = ds1.query("select * from `db1`.`travelrecord` where id = 2").toCompletionStage().toCompletableFuture().get();
            Assert.assertTrue(objects.size() > 0);
            savepointSqlConnection.close();
            testContext.completeNow();
        }
    });
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) NewMycatConnection(io.mycat.newquery.NewMycatConnection) SneakyThrows(lombok.SneakyThrows) RowSet(io.mycat.newquery.RowSet) BiFunction(java.util.function.BiFunction) XaLog(cn.mycat.vertx.xa.XaLog) Future(io.vertx.core.Future) Test(org.junit.jupiter.api.Test) XaSqlConnection(cn.mycat.vertx.xa.XaSqlConnection) AsyncResult(io.vertx.core.AsyncResult) MySQLManager(cn.mycat.vertx.xa.MySQLManager) SavepointSqlConnection(cn.mycat.vertx.xa.SavepointSqlConnection) Handler(io.vertx.core.Handler) Assert(org.junit.Assert) NewMycatConnection(io.mycat.newquery.NewMycatConnection) SavepointSqlConnection(cn.mycat.vertx.xa.SavepointSqlConnection) RowSet(io.mycat.newquery.RowSet) SneakyThrows(lombok.SneakyThrows) AsyncResult(io.vertx.core.AsyncResult) XaSqlConnection(cn.mycat.vertx.xa.XaSqlConnection) Test(org.junit.jupiter.api.Test) SneakyThrows(lombok.SneakyThrows)

Example 3 with SavepointSqlConnection

use of cn.mycat.vertx.xa.SavepointSqlConnection in project Mycat2 by MyCATApache.

the class BaseSavepointSuite method baseSavepointRollbackSavepointInSingleConnection.

@Test
@SneakyThrows
public void baseSavepointRollbackSavepointInSingleConnection(VertxTestContext testContext) {
    mySQLManager.getConnection("ds1").flatMap(connection -> {
        return connection.update("delete FROM `db1`.`travelrecord`").map(u -> connection);
    }).flatMap(c -> c.close()).toCompletionStage().toCompletableFuture().get();
    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) {
            savepointSqlConnection.createSavepoint("sss").toCompletionStage().toCompletableFuture().get();
            NewMycatConnection ds1 = savepointSqlConnection.getConnection("ds1").toCompletionStage().toCompletableFuture().get();
            ds1.insert("insert into `db1`.`travelrecord` (`id`) values ('2')").toCompletionStage().toCompletableFuture().get();
            RowSet objects = ds1.query("select * from `db1`.`travelrecord` where id = 2").toCompletionStage().toCompletableFuture().get();
            Assert.assertTrue(objects.size() > 0);
            Assert.assertEquals("[sss]", savepointSqlConnection.getExistedSavepoints().toString());
            savepointSqlConnection.rollbackSavepoint("sss").toCompletionStage().toCompletableFuture().get();
            Assert.assertEquals("[]", savepointSqlConnection.getExistedSavepoints().toString());
            Assert.assertTrue(savepointSqlConnection.isInTransaction());
            ds1 = savepointSqlConnection.getConnection("ds1").toCompletionStage().toCompletableFuture().get();
            objects = ds1.query("select * from `db1`.`travelrecord` where id = 2").toCompletionStage().toCompletableFuture().get();
            Assert.assertTrue(objects.size() == 0);
            ds1.insert("insert into `db1`.`travelrecord` (`id`) values ('2')").toCompletionStage().toCompletableFuture().get();
            savepointSqlConnection.commit().toCompletionStage().toCompletableFuture().get();
            Assert.assertEquals("[]", savepointSqlConnection.getExistedSavepoints().toString());
            Assert.assertFalse(savepointSqlConnection.isInTransaction());
            savepointSqlConnection.close();
            testContext.completeNow();
        }
    });
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) NewMycatConnection(io.mycat.newquery.NewMycatConnection) SneakyThrows(lombok.SneakyThrows) RowSet(io.mycat.newquery.RowSet) BiFunction(java.util.function.BiFunction) XaLog(cn.mycat.vertx.xa.XaLog) Future(io.vertx.core.Future) Test(org.junit.jupiter.api.Test) XaSqlConnection(cn.mycat.vertx.xa.XaSqlConnection) AsyncResult(io.vertx.core.AsyncResult) MySQLManager(cn.mycat.vertx.xa.MySQLManager) SavepointSqlConnection(cn.mycat.vertx.xa.SavepointSqlConnection) Handler(io.vertx.core.Handler) Assert(org.junit.Assert) NewMycatConnection(io.mycat.newquery.NewMycatConnection) SavepointSqlConnection(cn.mycat.vertx.xa.SavepointSqlConnection) RowSet(io.mycat.newquery.RowSet) SneakyThrows(lombok.SneakyThrows) AsyncResult(io.vertx.core.AsyncResult) XaSqlConnection(cn.mycat.vertx.xa.XaSqlConnection) Test(org.junit.jupiter.api.Test) SneakyThrows(lombok.SneakyThrows)

Example 4 with SavepointSqlConnection

use of cn.mycat.vertx.xa.SavepointSqlConnection in project Mycat2 by MyCATApache.

the class BaseSavepointSuite method baseSavepointRollbackInTwoConnection.

@Test
@SneakyThrows
public void baseSavepointRollbackInTwoConnection(VertxTestContext testContext) {
    mySQLManager.getConnection("ds1").flatMap(connection -> {
        return connection.update("delete FROM `db1`.`travelrecord`").map(u -> connection);
    }).flatMap(c -> c.close()).toCompletionStage().toCompletableFuture().get();
    mySQLManager.getConnection("ds2").flatMap(connection -> {
        return connection.update("delete FROM `db1`.`travelrecord`").map(u -> connection);
    }).flatMap(c -> c.close()).toCompletionStage().toCompletableFuture().get();
    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) {
            NewMycatConnection ds1 = savepointSqlConnection.getConnection("ds1").toCompletionStage().toCompletableFuture().get();
            ds1.insert("insert into `db1`.`travelrecord` (`id`) values ('2')").toCompletionStage().toCompletableFuture().get();
            NewMycatConnection ds2 = savepointSqlConnection.getConnection("ds2").toCompletionStage().toCompletableFuture().get();
            ds2.insert("insert into `db1`.`travelrecord` (`id`) values ('2')").toCompletionStage().toCompletableFuture().get();
            savepointSqlConnection.createSavepoint("sss").toCompletionStage().toCompletableFuture().get();
            RowSet objects = ds1.query("select * from `db1`.`travelrecord` where id = 2").toCompletionStage().toCompletableFuture().get();
            Assert.assertTrue(objects.size() > 0);
            RowSet objects2 = ds2.query("select * from `db1`.`travelrecord` where id = 2").toCompletionStage().toCompletableFuture().get();
            Assert.assertTrue(objects2.size() > 0);
            ds2.insert("insert into `db1`.`travelrecord` (`id`) values ('3')").toCompletionStage().toCompletableFuture().get();
            Assert.assertEquals("[sss]", savepointSqlConnection.getExistedSavepoints().toString());
            savepointSqlConnection.rollback().toCompletionStage().toCompletableFuture().get();
            Assert.assertEquals("[]", savepointSqlConnection.getExistedSavepoints().toString());
            Assert.assertFalse(savepointSqlConnection.isInTransaction());
            ds1 = savepointSqlConnection.getConnection("ds1").toCompletionStage().toCompletableFuture().get();
            objects = ds1.query("select * from `db1`.`travelrecord` where id = 2").toCompletionStage().toCompletableFuture().get();
            Assert.assertTrue(objects.size() == 0);
            ds2 = savepointSqlConnection.getConnection("ds2").toCompletionStage().toCompletableFuture().get();
            objects = ds2.query("select * from `db1`.`travelrecord` where id = 2").toCompletionStage().toCompletableFuture().get();
            Assert.assertTrue(objects.size() == 0);
            savepointSqlConnection.close();
            testContext.completeNow();
        }
    });
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) NewMycatConnection(io.mycat.newquery.NewMycatConnection) SneakyThrows(lombok.SneakyThrows) RowSet(io.mycat.newquery.RowSet) BiFunction(java.util.function.BiFunction) XaLog(cn.mycat.vertx.xa.XaLog) Future(io.vertx.core.Future) Test(org.junit.jupiter.api.Test) XaSqlConnection(cn.mycat.vertx.xa.XaSqlConnection) AsyncResult(io.vertx.core.AsyncResult) MySQLManager(cn.mycat.vertx.xa.MySQLManager) SavepointSqlConnection(cn.mycat.vertx.xa.SavepointSqlConnection) Handler(io.vertx.core.Handler) Assert(org.junit.Assert) NewMycatConnection(io.mycat.newquery.NewMycatConnection) SavepointSqlConnection(cn.mycat.vertx.xa.SavepointSqlConnection) RowSet(io.mycat.newquery.RowSet) SneakyThrows(lombok.SneakyThrows) AsyncResult(io.vertx.core.AsyncResult) XaSqlConnection(cn.mycat.vertx.xa.XaSqlConnection) Test(org.junit.jupiter.api.Test) SneakyThrows(lombok.SneakyThrows)

Example 5 with SavepointSqlConnection

use of cn.mycat.vertx.xa.SavepointSqlConnection in project Mycat2 by MyCATApache.

the class BaseSavepointSuite method baseSavepointCommitSavepointInTwoConnection.

@Test
@SneakyThrows
public void baseSavepointCommitSavepointInTwoConnection(VertxTestContext testContext) {
    mySQLManager.getConnection("ds1").flatMap(connection -> {
        return connection.update("delete FROM `db1`.`travelrecord`").map(u -> connection);
    }).flatMap(c -> c.close()).toCompletionStage().toCompletableFuture().get();
    mySQLManager.getConnection("ds2").flatMap(connection -> {
        return connection.update("delete FROM `db1`.`travelrecord`").map(u -> connection);
    }).flatMap(c -> c.close()).toCompletionStage().toCompletableFuture().get();
    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) {
            NewMycatConnection ds1 = savepointSqlConnection.getConnection("ds1").toCompletionStage().toCompletableFuture().get();
            ds1.insert("insert into `db1`.`travelrecord` (`id`) values ('2')").toCompletionStage().toCompletableFuture().get();
            NewMycatConnection ds2 = savepointSqlConnection.getConnection("ds2").toCompletionStage().toCompletableFuture().get();
            ds2.insert("insert into `db1`.`travelrecord` (`id`) values ('2')").toCompletionStage().toCompletableFuture().get();
            savepointSqlConnection.createSavepoint("sss").toCompletionStage().toCompletableFuture().get();
            RowSet objects = ds1.query("select * from `db1`.`travelrecord` where id = 2").toCompletionStage().toCompletableFuture().get();
            Assert.assertTrue(objects.size() > 0);
            RowSet objects2 = ds2.query("select * from `db1`.`travelrecord` where id = 2").toCompletionStage().toCompletableFuture().get();
            Assert.assertTrue(objects2.size() > 0);
            ds1.update("delete FROM `db1`.`travelrecord`").toCompletionStage().toCompletableFuture().get();
            ds2.update("delete FROM `db1`.`travelrecord`").toCompletionStage().toCompletableFuture().get();
            Assert.assertEquals("[sss]", savepointSqlConnection.getExistedSavepoints().toString());
            savepointSqlConnection.commit().toCompletionStage().toCompletableFuture().get();
            Assert.assertEquals("[]", savepointSqlConnection.getExistedSavepoints().toString());
            Assert.assertFalse(savepointSqlConnection.isInTransaction());
            ds1 = savepointSqlConnection.getConnection("ds1").toCompletionStage().toCompletableFuture().get();
            objects = ds1.query("select * from `db1`.`travelrecord` where id = 2").toCompletionStage().toCompletableFuture().get();
            Assert.assertTrue(objects.size() == 0);
            ds2 = savepointSqlConnection.getConnection("ds2").toCompletionStage().toCompletableFuture().get();
            objects = ds2.query("select * from `db1`.`travelrecord` where id = 2").toCompletionStage().toCompletableFuture().get();
            Assert.assertTrue(objects.size() == 0);
            savepointSqlConnection.close();
            testContext.completeNow();
        }
    });
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) NewMycatConnection(io.mycat.newquery.NewMycatConnection) SneakyThrows(lombok.SneakyThrows) RowSet(io.mycat.newquery.RowSet) BiFunction(java.util.function.BiFunction) XaLog(cn.mycat.vertx.xa.XaLog) Future(io.vertx.core.Future) Test(org.junit.jupiter.api.Test) XaSqlConnection(cn.mycat.vertx.xa.XaSqlConnection) AsyncResult(io.vertx.core.AsyncResult) MySQLManager(cn.mycat.vertx.xa.MySQLManager) SavepointSqlConnection(cn.mycat.vertx.xa.SavepointSqlConnection) Handler(io.vertx.core.Handler) Assert(org.junit.Assert) NewMycatConnection(io.mycat.newquery.NewMycatConnection) SavepointSqlConnection(cn.mycat.vertx.xa.SavepointSqlConnection) RowSet(io.mycat.newquery.RowSet) SneakyThrows(lombok.SneakyThrows) AsyncResult(io.vertx.core.AsyncResult) XaSqlConnection(cn.mycat.vertx.xa.XaSqlConnection) Test(org.junit.jupiter.api.Test) SneakyThrows(lombok.SneakyThrows)

Aggregations

SavepointSqlConnection (cn.mycat.vertx.xa.SavepointSqlConnection)14 XaSqlConnection (cn.mycat.vertx.xa.XaSqlConnection)14 AsyncResult (io.vertx.core.AsyncResult)13 Future (io.vertx.core.Future)13 SneakyThrows (lombok.SneakyThrows)13 Test (org.junit.jupiter.api.Test)13 MySQLManager (cn.mycat.vertx.xa.MySQLManager)9 XaLog (cn.mycat.vertx.xa.XaLog)9 NewMycatConnection (io.mycat.newquery.NewMycatConnection)9 RowSet (io.mycat.newquery.RowSet)9 Handler (io.vertx.core.Handler)9 VertxTestContext (io.vertx.junit5.VertxTestContext)9 BiFunction (java.util.function.BiFunction)9 Assert (org.junit.Assert)9 LocalSqlConnection (cn.mycat.vertx.xa.impl.LocalSqlConnection)1 LocalXaSqlConnection (cn.mycat.vertx.xa.impl.LocalXaSqlConnection)1