Search in sources :

Example 1 with AbortedException

use of com.google.api.gax.rpc.AbortedException in project java-spanner by googleapis.

the class PartitionedDmlTransactionTest method testExecuteStreamingPartitionedUpdateAbortedAndThenDeadlineExceeded.

@Test
public void testExecuteStreamingPartitionedUpdateAbortedAndThenDeadlineExceeded() {
    PartialResultSet p1 = PartialResultSet.newBuilder().setResumeToken(resumeToken).build();
    ServerStream<PartialResultSet> stream1 = mock(ServerStream.class);
    Iterator<PartialResultSet> iterator = mock(Iterator.class);
    when(iterator.hasNext()).thenReturn(true, true, false);
    when(iterator.next()).thenReturn(p1).thenThrow(new AbortedException("transaction aborted", null, GrpcStatusCode.of(Code.ABORTED), true));
    when(stream1.iterator()).thenReturn(iterator);
    when(rpc.executeStreamingPartitionedDml(Mockito.eq(executeRequestWithoutResumeToken), anyMap(), any(Duration.class))).thenReturn(stream1);
    when(ticker.read()).thenReturn(0L, 1L, TimeUnit.NANOSECONDS.convert(10L, TimeUnit.MINUTES));
    SpannerException e = assertThrows(SpannerException.class, () -> tx.executeStreamingPartitionedUpdate(Statement.of(sql), Duration.ofMinutes(10)));
    assertEquals(ErrorCode.DEADLINE_EXCEEDED, e.getErrorCode());
    verify(rpc, times(2)).beginTransaction(any(BeginTransactionRequest.class), anyMap());
    verify(rpc).executeStreamingPartitionedDml(Mockito.eq(executeRequestWithoutResumeToken), anyMap(), any(Duration.class));
}
Also used : AbortedException(com.google.api.gax.rpc.AbortedException) BeginTransactionRequest(com.google.spanner.v1.BeginTransactionRequest) Duration(org.threeten.bp.Duration) PartialResultSet(com.google.spanner.v1.PartialResultSet) Test(org.junit.Test)

Example 2 with AbortedException

use of com.google.api.gax.rpc.AbortedException in project jade-data-repo by DataBiosphere.

the class FireStoreDirectoryDao method updateDirectoryEntry.

// Non-transactional update of a directory entry
void updateDirectoryEntry(Firestore firestore, String collectionId, FireStoreDirectoryEntry entry) {
    try {
        DocumentReference newRef = getDocRef(firestore, collectionId, entry);
        ApiFuture<WriteResult> writeFuture = newRef.set(entry);
        writeFuture.get();
    } catch (InterruptedException ex) {
        Thread.currentThread().interrupt();
        throw new FileSystemExecutionException("updateDirectoryEntry - execution interrupted", ex);
    } catch (AbortedException | ExecutionException ex) {
        throw handleExecutionException("updateDirectoryEntry", ex);
    }
}
Also used : WriteResult(com.google.cloud.firestore.WriteResult) AbortedException(com.google.api.gax.rpc.AbortedException) FileSystemExecutionException(bio.terra.service.filedata.exception.FileSystemExecutionException) FileSystemExecutionException(bio.terra.service.filedata.exception.FileSystemExecutionException) ExecutionException(java.util.concurrent.ExecutionException) DocumentReference(com.google.cloud.firestore.DocumentReference)

Example 3 with AbortedException

use of com.google.api.gax.rpc.AbortedException in project jade-data-repo by DataBiosphere.

the class FireStoreDirectoryDao method lookupByFilePath.

private DocumentSnapshot lookupByFilePath(Firestore firestore, String collectionId, String lookupPath, Transaction xn) {
    try {
        DocumentReference docRef = firestore.collection(collectionId).document(encodePathAsFirestoreDocumentName(lookupPath));
        ApiFuture<DocumentSnapshot> docSnapFuture = xn.get(docRef);
        return docSnapFuture.get();
    } catch (InterruptedException ex) {
        Thread.currentThread().interrupt();
        throw new FileSystemExecutionException("lookupByEntryPath - execution interrupted", ex);
    } catch (AbortedException | ExecutionException ex) {
        throw handleExecutionException("lookupByEntryPath", ex);
    }
}
Also used : QueryDocumentSnapshot(com.google.cloud.firestore.QueryDocumentSnapshot) DocumentSnapshot(com.google.cloud.firestore.DocumentSnapshot) AbortedException(com.google.api.gax.rpc.AbortedException) FileSystemExecutionException(bio.terra.service.filedata.exception.FileSystemExecutionException) FileSystemExecutionException(bio.terra.service.filedata.exception.FileSystemExecutionException) ExecutionException(java.util.concurrent.ExecutionException) DocumentReference(com.google.cloud.firestore.DocumentReference)

Example 4 with AbortedException

use of com.google.api.gax.rpc.AbortedException in project jade-data-repo by DataBiosphere.

the class FireStoreDirectoryDao method storeDirectoryEntry.

// Non-transactional store of a directory entry
private void storeDirectoryEntry(Firestore firestore, String collectionId, FireStoreDirectoryEntry entry) {
    try {
        DocumentReference newRef = getDocRef(firestore, collectionId, entry);
        ApiFuture<DocumentSnapshot> newSnapFuture = newRef.get();
        DocumentSnapshot newSnap = newSnapFuture.get();
        if (!newSnap.exists()) {
            ApiFuture<WriteResult> writeFuture = newRef.set(entry);
            writeFuture.get();
        }
    } catch (InterruptedException ex) {
        Thread.currentThread().interrupt();
        throw new FileSystemExecutionException("storeDirectoryEntry - execution interrupted", ex);
    } catch (AbortedException | ExecutionException ex) {
        throw handleExecutionException("storeDirectoryEntry", ex);
    }
}
Also used : QueryDocumentSnapshot(com.google.cloud.firestore.QueryDocumentSnapshot) DocumentSnapshot(com.google.cloud.firestore.DocumentSnapshot) WriteResult(com.google.cloud.firestore.WriteResult) AbortedException(com.google.api.gax.rpc.AbortedException) FileSystemExecutionException(bio.terra.service.filedata.exception.FileSystemExecutionException) FileSystemExecutionException(bio.terra.service.filedata.exception.FileSystemExecutionException) ExecutionException(java.util.concurrent.ExecutionException) DocumentReference(com.google.cloud.firestore.DocumentReference)

Example 5 with AbortedException

use of com.google.api.gax.rpc.AbortedException in project jade-data-repo by DataBiosphere.

the class FireStoreDirectoryDao method lookupByPathNoXn.

// Non-transactional lookup of an entry
private DocumentSnapshot lookupByPathNoXn(Firestore firestore, String collectionId, String lookupPath) {
    try {
        DocumentReference docRef = firestore.collection(collectionId).document(encodePathAsFirestoreDocumentName(lookupPath));
        ApiFuture<DocumentSnapshot> docSnapFuture = docRef.get();
        return docSnapFuture.get();
    } catch (InterruptedException ex) {
        Thread.currentThread().interrupt();
        throw new FileSystemExecutionException("lookupByPathNoXn - execution interrupted", ex);
    } catch (AbortedException | ExecutionException ex) {
        throw handleExecutionException("lookupByPathNoXn", ex);
    }
}
Also used : QueryDocumentSnapshot(com.google.cloud.firestore.QueryDocumentSnapshot) DocumentSnapshot(com.google.cloud.firestore.DocumentSnapshot) AbortedException(com.google.api.gax.rpc.AbortedException) FileSystemExecutionException(bio.terra.service.filedata.exception.FileSystemExecutionException) FileSystemExecutionException(bio.terra.service.filedata.exception.FileSystemExecutionException) ExecutionException(java.util.concurrent.ExecutionException) DocumentReference(com.google.cloud.firestore.DocumentReference)

Aggregations

AbortedException (com.google.api.gax.rpc.AbortedException)10 FileSystemExecutionException (bio.terra.service.filedata.exception.FileSystemExecutionException)6 ExecutionException (java.util.concurrent.ExecutionException)6 DocumentReference (com.google.cloud.firestore.DocumentReference)4 QueryDocumentSnapshot (com.google.cloud.firestore.QueryDocumentSnapshot)4 PartialResultSet (com.google.spanner.v1.PartialResultSet)4 Duration (org.threeten.bp.Duration)4 DocumentSnapshot (com.google.cloud.firestore.DocumentSnapshot)3 BeginTransactionRequest (com.google.spanner.v1.BeginTransactionRequest)3 Test (org.junit.Test)3 FileSystemAbortTransactionException (bio.terra.service.filedata.exception.FileSystemAbortTransactionException)2 WriteResult (com.google.cloud.firestore.WriteResult)2 ExecuteSqlRequest (com.google.spanner.v1.ExecuteSqlRequest)2 DeadlineExceededException (com.google.api.gax.rpc.DeadlineExceededException)1 InternalException (com.google.api.gax.rpc.InternalException)1 UnavailableException (com.google.api.gax.rpc.UnavailableException)1 CollectionReference (com.google.cloud.firestore.CollectionReference)1 FirestoreException (com.google.cloud.firestore.FirestoreException)1 Query (com.google.cloud.firestore.Query)1 QuerySnapshot (com.google.cloud.firestore.QuerySnapshot)1