|
19 | 19 | import static com.google.cloud.spanner.SpannerApiFutures.get;
|
20 | 20 | import static com.google.common.truth.Truth.assertThat;
|
21 | 21 | import static org.junit.Assert.assertEquals;
|
| 22 | +import static org.junit.Assert.assertFalse; |
22 | 23 | import static org.junit.Assert.assertNull;
|
23 | 24 | import static org.junit.Assert.assertThrows;
|
24 | 25 | import static org.junit.Assert.fail;
|
@@ -535,8 +536,16 @@ private void testExecuteQuery(Function<Connection, Void> connectionConfigurator)
|
535 | 536 | }
|
536 | 537 | assertThat(timeout).isFalse();
|
537 | 538 | } catch (SpannerException e) {
|
538 |
| - assertThat(timeout).isTrue(); |
539 |
| - assertThat(e.getErrorCode()).isEqualTo(ErrorCode.DEADLINE_EXCEEDED); |
| 539 | + if (e.getErrorCode() == ErrorCode.FAILED_PRECONDITION |
| 540 | + && e.getMessage() |
| 541 | + .contains( |
| 542 | + "This transaction has been invalidated by a later transaction in the same session")) { |
| 543 | + // Ignore for regular sessions. |
| 544 | + assertFalse(isMultiplexedSessionsEnabledForRW(connection.getSpanner())); |
| 545 | + } else { |
| 546 | + assertThat(e.getErrorCode()).isEqualTo(ErrorCode.DEADLINE_EXCEEDED); |
| 547 | + assertThat(timeout).isTrue(); |
| 548 | + } |
540 | 549 | // Start a new transaction if a timeout occurred on a read/write transaction, as that will
|
541 | 550 | // invalidate that transaction.
|
542 | 551 | if (!connection.isReadOnly() && connection.isInTransaction()) {
|
@@ -577,8 +586,16 @@ private void testExecuteUpdateAsync(
|
577 | 586 | assertThat(connection.getCommitTimestamp()).isNotNull();
|
578 | 587 | assertThat(timeout).isFalse();
|
579 | 588 | } catch (SpannerException e) {
|
580 |
| - assertThat(timeout).isTrue(); |
581 |
| - assertThat(e.getErrorCode()).isEqualTo(ErrorCode.DEADLINE_EXCEEDED); |
| 589 | + if (e.getErrorCode() == ErrorCode.FAILED_PRECONDITION |
| 590 | + && e.getMessage() |
| 591 | + .contains( |
| 592 | + "This transaction has been invalidated by a later transaction in the same session")) { |
| 593 | + // Ignore for regular sessions. |
| 594 | + assertFalse(isMultiplexedSessionsEnabledForRW(connection.getSpanner())); |
| 595 | + } else { |
| 596 | + assertThat(e.getErrorCode()).isEqualTo(ErrorCode.DEADLINE_EXCEEDED); |
| 597 | + assertThat(timeout).isTrue(); |
| 598 | + } |
582 | 599 | // Start a new transaction if a timeout occurred on a read/write transaction, as that will
|
583 | 600 | // invalidate that transaction.
|
584 | 601 | if (!connection.isReadOnly() && connection.isInTransaction()) {
|
@@ -611,8 +628,16 @@ private void testExecuteUpdate(Function<Connection, Void> connectionConfigurator
|
611 | 628 | assertThat(connection.getCommitTimestamp()).isNotNull();
|
612 | 629 | assertThat(timeout).isFalse();
|
613 | 630 | } catch (SpannerException e) {
|
614 |
| - assertThat(timeout).isTrue(); |
615 |
| - assertThat(e.getErrorCode()).isEqualTo(ErrorCode.DEADLINE_EXCEEDED); |
| 631 | + if (e.getErrorCode() == ErrorCode.FAILED_PRECONDITION |
| 632 | + && e.getMessage() |
| 633 | + .contains( |
| 634 | + "This transaction has been invalidated by a later transaction in the same session")) { |
| 635 | + // Ignore for regular sessions. |
| 636 | + assertFalse(isMultiplexedSessionsEnabledForRW(connection.getSpanner())); |
| 637 | + } else { |
| 638 | + assertThat(e.getErrorCode()).isEqualTo(ErrorCode.DEADLINE_EXCEEDED); |
| 639 | + assertThat(timeout).isTrue(); |
| 640 | + } |
616 | 641 | // Start a new transaction if a timeout occurred on a read/write transaction, as that will
|
617 | 642 | // invalidate that transaction.
|
618 | 643 | if (!connection.isReadOnly() && connection.isInTransaction()) {
|
@@ -647,8 +672,16 @@ private void testExecuteBatchUpdateAsync(Function<Connection, Void> connectionCo
|
647 | 672 | assertThat(connection.getCommitTimestamp()).isNotNull();
|
648 | 673 | assertThat(timeout).isFalse();
|
649 | 674 | } catch (SpannerException e) {
|
650 |
| - assertThat(timeout).isTrue(); |
651 |
| - assertThat(e.getErrorCode()).isEqualTo(ErrorCode.DEADLINE_EXCEEDED); |
| 675 | + if (e.getErrorCode() == ErrorCode.FAILED_PRECONDITION |
| 676 | + && e.getMessage() |
| 677 | + .contains( |
| 678 | + "This transaction has been invalidated by a later transaction in the same session")) { |
| 679 | + // Ignore for regular sessions. |
| 680 | + assertFalse(isMultiplexedSessionsEnabledForRW(connection.getSpanner())); |
| 681 | + } else { |
| 682 | + assertThat(e.getErrorCode()).isEqualTo(ErrorCode.DEADLINE_EXCEEDED); |
| 683 | + assertThat(timeout).isTrue(); |
| 684 | + } |
652 | 685 | // Start a new transaction if a timeout occurred on a read/write transaction, as that will
|
653 | 686 | // invalidate that transaction.
|
654 | 687 | if (!connection.isReadOnly() && connection.isInTransaction()) {
|
@@ -682,8 +715,16 @@ private void testExecuteBatchUpdate(Function<Connection, Void> connectionConfigu
|
682 | 715 | assertThat(connection.getCommitTimestamp()).isNotNull();
|
683 | 716 | assertThat(timeout).isFalse();
|
684 | 717 | } catch (SpannerException e) {
|
685 |
| - assertThat(e.getErrorCode()).isEqualTo(ErrorCode.DEADLINE_EXCEEDED); |
686 |
| - assertThat(timeout).isTrue(); |
| 718 | + if (e.getErrorCode() == ErrorCode.FAILED_PRECONDITION |
| 719 | + && e.getMessage() |
| 720 | + .contains( |
| 721 | + "This transaction has been invalidated by a later transaction in the same session")) { |
| 722 | + // Ignore for regular sessions. |
| 723 | + assertFalse(isMultiplexedSessionsEnabledForRW(connection.getSpanner())); |
| 724 | + } else { |
| 725 | + assertThat(e.getErrorCode()).isEqualTo(ErrorCode.DEADLINE_EXCEEDED); |
| 726 | + assertThat(timeout).isTrue(); |
| 727 | + } |
687 | 728 | // Start a new transaction if a timeout occurred on a read/write transaction, as that will
|
688 | 729 | // invalidate that transaction.
|
689 | 730 | if (!connection.isReadOnly() && connection.isInTransaction()) {
|
|
0 commit comments