Search in sources :

Example 96 with CommitRequest

use of com.google.firestore.v1beta1.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);
        }
    }
}
Also used : CommitRequest(com.swiftmq.impl.routing.single.smqpr.v400.CommitRequest) XAContext(com.swiftmq.swiftlet.xa.XAContext) XidImpl(com.swiftmq.jms.XidImpl) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) XAContextException(com.swiftmq.swiftlet.xa.XAContextException) Comparator(java.util.Comparator)

Example 97 with CommitRequest

use of com.google.firestore.v1beta1.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());
}
Also used : CommitRequest(com.google.spanner.v1.CommitRequest) SQLException(java.sql.SQLException) Connection(java.sql.Connection) BaseConnection(org.postgresql.core.BaseConnection) StringReader(java.io.StringReader) CopyManager(org.postgresql.copy.CopyManager) File(java.io.File) BaseConnection(org.postgresql.core.BaseConnection) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)85 CommitRequest (com.google.spanner.v1.CommitRequest)47 CommitRequest (com.google.firestore.v1.CommitRequest)40 CommitResponse (com.google.firestore.v1.CommitResponse)40 ArrayList (java.util.ArrayList)26 Connection (java.sql.Connection)23 ByteString (com.google.protobuf.ByteString)14 ExecuteSqlRequest (com.google.spanner.v1.ExecuteSqlRequest)12 SQLException (java.sql.SQLException)12 Statement (java.sql.Statement)12 CopyManager (org.postgresql.copy.CopyManager)11 BaseConnection (org.postgresql.core.BaseConnection)11 ExecuteBatchDmlRequest (com.google.spanner.v1.ExecuteBatchDmlRequest)10 ArrayValue (com.google.firestore.v1.ArrayValue)9 MapValue (com.google.firestore.v1.MapValue)9 Value (com.google.firestore.v1.Value)9 Write (com.google.firestore.v1.Write)9 StringReader (java.io.StringReader)9 HashMap (java.util.HashMap)9 AbstractMessage (com.google.protobuf.AbstractMessage)8