use of io.mycat.newquery.SqlResult 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 io.mycat.newquery.SqlResult in project Mycat2 by MyCATApache.
the class XaTestSuite method beginSingleTargetInsertCommit.
@Test
public void beginSingleTargetInsertCommit(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");
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);
});
}).compose(connection -> {
return connection.query("select id from db1.travelrecord").compose(rows -> {
Assertions.assertEquals(1, rows.size());
return Future.succeededFuture(connection);
});
}).onComplete(event13 -> {
Assertions.assertTrue(event13.succeeded());
baseXaSqlConnection.commit().onComplete(event12 -> {
Assertions.assertTrue(event12.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(1, event1.result().size());
testContext.completeNow();
});
});
});
});
}
use of io.mycat.newquery.SqlResult in project Mycat2 by MyCATApache.
the class XaTestSuite method beginDoubleTargetInsertButCommitFail.
@Test
public void beginDoubleTargetInsertButCommitFail(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.update("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((log) -> Future.failedFuture("commit fail"));
future.onComplete(new Handler<AsyncResult<Void>>() {
@Override
public void handle(AsyncResult<Void> event) {
Assertions.assertTrue(event.failed());
baseXaSqlConnection.commit().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(1, event1.result().size());
testContext.completeNow();
});
}
});
}
});
});
});
}
use of io.mycat.newquery.SqlResult in project Mycat2 by MyCATApache.
the class VertxConnection method update.
public Future<SqlResult> update(String sql) {
synchronized (VertxConnection.this) {
Future<SqlResult> sqlResultFuture = future.transform(unused -> Future.future(promise -> {
checkException();
OkCommand queryCommand = new OkCommand(sql, netSocket, promise);
netSocket.handler(queryCommand);
queryCommand.write();
promise.future().onSuccess(event -> VertxConnection.this.serverstatus = queryCommand.serverstatus);
}));
future = sqlResultFuture.mapEmpty();
return sqlResultFuture;
}
}
use of io.mycat.newquery.SqlResult 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();
});
}
});
}
});
});
});
}
Aggregations