@Override public ReadOnlyTransaction singleUseReadOnlyTransaction() { try { return new AutoClosingReadTransaction(delegate.singleUseReadOnlyTransaction(), this, true); } catch (Exception e) { close(); throw e; } }
@Override public ReadOnlyTransaction singleUseReadOnlyTransaction(TimestampBound bound) { try { return new AutoClosingReadTransaction( delegate.singleUseReadOnlyTransaction(bound), this, true); } catch (Exception e) { close(); throw e; } }
@Override public ReadOnlyTransaction singleUseReadOnlyTransaction(TimestampBound bound) { Span span = tracer.spanBuilder(READ_ONLY_TRANSACTION).startSpan(); try (Scope s = tracer.withSpan(span)) { return pool.getReadSession().singleUseReadOnlyTransaction(bound); } catch (RuntimeException e) { TraceUtil.endSpanWithFailure(span, e); throw e; } }
@Override public ReadOnlyTransaction singleUseReadOnlyTransaction() { Span span = tracer.spanBuilder(READ_ONLY_TRANSACTION).startSpan(); try (Scope s = tracer.withSpan(span)) { return pool.getReadSession().singleUseReadOnlyTransaction(); } catch (RuntimeException e) { TraceUtil.endSpanWithFailure(span, e); throw e; } }
@Test public void newSingleUseContextClosesOldSingleUseReadOnlyTransactionContext() { ReadContext ctx = session.singleUseReadOnlyTransaction(TimestampBound.strong()); session.singleUse(TimestampBound.strong()); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("invalidated"); ctx.read("Dummy", KeySet.all(), Arrays.asList("C")); }
@Test public void newSingleUseContextClosesOldMultiUseReadOnlyTransactionContext() { ReadContext ctx = session.singleUseReadOnlyTransaction(TimestampBound.strong()); session.singleUse(TimestampBound.strong()); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("invalidated"); ctx.read("Dummy", KeySet.all(), Arrays.asList("C")); }
@Test public void newSingleUseReadOnlyTransactionContextClosesOldSingleUseContext() { ReadContext ctx = session.singleUse(TimestampBound.strong()); session.singleUseReadOnlyTransaction(TimestampBound.strong()); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("invalidated"); ctx.read("Dummy", KeySet.all(), Arrays.asList("C")); }
@Test public void singleUseReadOnlyTransactionDoesntReturnTransactionMetadata() { PartialResultSet resultSet = PartialResultSet.newBuilder() .setMetadata(newMetadata(Type.struct(Type.StructField.of("C", Type.string())))) .build(); mockRead(resultSet); ReadOnlyTransaction txn = session.singleUseReadOnlyTransaction(TimestampBound.strong()); assertThat(txn.readRow("Dummy", Key.of(), Arrays.asList("C"))).isNull(); // For now, getReadTimestamp() will raise an ISE because it hasn't seen a timestamp. It would // be better for the read to fail with an INTERNAL error, but we can't do that until txn // metadata is returned for failed reads (e.g., table-not-found) as well as successful ones. // TODO(user): Fix this. expectedException.expect(IllegalStateException.class); txn.getReadTimestamp(); }
@Test public void singleUseReadOnlyTransactionReturnsEmptyTransactionMetadata() { PartialResultSet resultSet = PartialResultSet.newBuilder() .setMetadata( newMetadata(Type.struct(Type.StructField.of("C", Type.string()))) .toBuilder() .setTransaction(Transaction.getDefaultInstance())) .build(); mockRead(resultSet); ReadOnlyTransaction txn = session.singleUseReadOnlyTransaction(TimestampBound.strong()); expectedException.expect(SpannerMatchers.isSpannerException(ErrorCode.INTERNAL)); txn.readRow("Dummy", Key.of(), Arrays.asList("C")); }
@Override public ReadOnlyTransaction singleUseReadOnlyTransaction() { try { return new AutoClosingReadTransaction(delegate.singleUseReadOnlyTransaction(), this, true); } catch (Exception e) { close(); throw e; } }
@Override public ReadOnlyTransaction singleUseReadOnlyTransaction(TimestampBound bound) { try { return new AutoClosingReadTransaction( delegate.singleUseReadOnlyTransaction(bound), this, true); } catch (Exception e) { close(); throw e; } }
@Override public ReadOnlyTransaction singleUseReadOnlyTransaction() { Span span = tracer.spanBuilder(READ_ONLY_TRANSACTION).startSpan(); try (Scope s = tracer.withSpan(span)) { return pool.getReadSession().singleUseReadOnlyTransaction(); } catch (RuntimeException e) { TraceUtil.endSpanWithFailure(span, e); throw e; } }
@Override public ReadOnlyTransaction singleUseReadOnlyTransaction(TimestampBound bound) { Span span = tracer.spanBuilder(READ_ONLY_TRANSACTION).startSpan(); try (Scope s = tracer.withSpan(span)) { return pool.getReadSession().singleUseReadOnlyTransaction(bound); } catch (RuntimeException e) { TraceUtil.endSpanWithFailure(span, e); throw e; } }