use of com.swiftmq.impl.routing.single.smqpr.v400.CommitRequest in project swiftmq-ce by iitsoftware.
the class XARecoveryStage method doRecover.
private void doRecover(List localXids, List remoteXids) {
// Nothing to recover
if (localXids == null && remoteXids == null) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/doRecover, nothing to do");
return;
}
List remoteRecoveryList = new ArrayList();
// Check local vs remote
if (localXids != null) {
for (int i = 0; i < localXids.size(); i++) {
XidImpl lXid = (XidImpl) localXids.get(i);
if (containsXid(remoteXids, lXid)) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/doRecover [" + lXid + "], local prepared, remote prepared, commit 1:local, 2:remote");
// local prepared, remote prepared, commit 1:local, 2:remote
XAContext xac = ctx.xaResourceManagerSwiftlet.getXAContext(lXid);
try {
xac.commit(false);
} catch (XAContextException e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/doRecover, exception=" + e);
ctx.logSwiftlet.logError(ctx.routingSwiftlet.getName(), toString() + "/doRecover, commit, exception=" + e);
}
ctx.xaResourceManagerSwiftlet.removeXAContext(lXid);
remoteRecoveryList.add(new CommitRequest(lXid));
} else {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/doRecover [" + lXid + "], local prepared, remote unknown, rollback local");
// local prepared, remote unknown, rollback local
XAContext xac = ctx.xaResourceManagerSwiftlet.getXAContext(lXid);
try {
xac.rollback();
} catch (XAContextException e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/doRecover, exception=" + e);
ctx.logSwiftlet.logError(ctx.routingSwiftlet.getName(), toString() + "/doRecover, rollback, exception=" + e);
}
ctx.xaResourceManagerSwiftlet.removeXAContext(lXid);
}
}
}
// Check remote Xids not known locally
if (remoteXids != null) {
for (int i = 0; i < remoteXids.size(); i++) {
XidImpl rXid = (XidImpl) remoteXids.get(i);
if (!containsXid(localXids, rXid)) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/doRecover [" + rXid + "], remote prepared, locally already committed, commit remote");
// remote prepared, locally already committed, commit remote
remoteRecoveryList.add(new CommitRequest(rXid));
}
}
}
if (remoteRecoveryList.size() > 0) {
Collections.sort(remoteRecoveryList, new Comparator() {
public int compare(Object o1, Object o2) {
int i1 = ((CommitRequest) o1).getXid().getFormatId();
int i2 = ((CommitRequest) o2).getXid().getFormatId();
return i1 == i2 ? 0 : i1 < i2 ? -1 : 1;
}
});
for (int i = 0; i < remoteRecoveryList.size(); i++) {
CommitRequest r = (CommitRequest) remoteRecoveryList.get(i);
routingConnection.getOutboundQueue().enqueue(r);
}
}
}
use of com.swiftmq.impl.routing.single.smqpr.v400.CommitRequest in project pgadapter by GoogleCloudPlatform.
the class JdbcMockServerTest method testCopyInWithInvalidRow.
@Test
public void testCopyInWithInvalidRow() throws SQLException {
setupCopyInformationSchemaResults();
try (Connection connection = DriverManager.getConnection(createUrl())) {
CopyManager copyManager = new CopyManager(connection.unwrap(BaseConnection.class));
// This row does not contain all the necessary columns.
SQLException exception = assertThrows(SQLException.class, () -> copyManager.copyIn("COPY users FROM STDIN;", new StringReader("5\n")));
assertTrue(exception.getMessage().contains("Row length mismatched. Expected 3 columns, but only found 1"));
} finally {
assertTrue(new File("output.txt").delete());
}
List<CommitRequest> commitRequests = mockSpanner.getRequestsOfType(CommitRequest.class);
assertTrue(commitRequests.isEmpty());
}
Aggregations