@Override public TransactionRunner readWriteTransaction() { final TransactionRunner runner = delegate.readWriteTransaction(); return new TransactionRunner() { @Override @Nullable public <T> T run(TransactionCallable<T> callable) { try { markUsed(); T result = runner.run(callable); return result; } catch (SpannerException e) { throw lastException = e; } finally { close(); } } @Override public Timestamp getCommitTimestamp() { return runner.getCommitTimestamp(); } @Override public TransactionRunner allowNestedTransaction() { runner.allowNestedTransaction(); return runner; } }; }
@Override public TransactionRunner readWriteTransaction() { Span span = tracer.spanBuilder(READ_WRITE_TRANSACTION).startSpan(); try (Scope s = tracer.withSpan(span)) { return pool.getReadWriteSession().readWriteTransaction(); } catch (RuntimeException e) { TraceUtil.endSpanWithFailure(span, e); throw e; } }
@Test public void transactionClosesOldSingleUseContext() { ReadContext ctx = session.singleUse(TimestampBound.strong()); // Note that we don't even run the transaction - just preparing the runner is sufficient. session.readWriteTransaction(); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("invalidated"); ctx.read("Dummy", KeySet.all(), Arrays.asList("C")); }
@Test public void singleUseContextClosesTransaction() { TransactionRunner runner = session.readWriteTransaction(); session.singleUse(TimestampBound.strong()); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("invalidated"); runner.run( new TransactionRunner.TransactionCallable<Void>() { @Nullable @Override public Void run(TransactionContext transaction) throws SpannerException { fail("Unexpected call to transaction body"); return null; } }); }
@Override public TransactionRunner readWriteTransaction() { final TransactionRunner runner = delegate.readWriteTransaction(); return new TransactionRunner() { @Override @Nullable public <T> T run(TransactionCallable<T> callable) { try { markUsed(); T result = runner.run(callable); return result; } catch (SpannerException e) { throw lastException = e; } finally { close(); } } @Override public Timestamp getCommitTimestamp() { return runner.getCommitTimestamp(); } @Override public TransactionRunner allowNestedTransaction() { runner.allowNestedTransaction(); return runner; } }; }
@Override public TransactionRunner readWriteTransaction() { Span span = tracer.spanBuilder(READ_WRITE_TRANSACTION).startSpan(); try (Scope s = tracer.withSpan(span)) { return pool.getReadWriteSession().readWriteTransaction(); } catch (RuntimeException e) { TraceUtil.endSpanWithFailure(span, e); throw e; } }