|
20 | 20 | import static org.junit.Assert.assertEquals; |
21 | 21 |
|
22 | 22 | import com.google.api.gax.longrunning.OperationFuture; |
23 | | -import com.google.cloud.spanner.BatchClient; |
24 | 23 | import com.google.cloud.spanner.Database; |
25 | 24 | import com.google.cloud.spanner.DatabaseAdminClient; |
26 | 25 | import com.google.cloud.spanner.DatabaseClient; |
|
45 | 44 | import org.apache.beam.sdk.testing.TestPipeline; |
46 | 45 | import org.apache.beam.sdk.testing.TestPipelineOptions; |
47 | 46 | import org.apache.beam.sdk.transforms.Count; |
48 | | -import org.apache.beam.sdk.transforms.Create; |
49 | 47 | import org.apache.beam.sdk.transforms.MapElements; |
50 | | -import org.apache.beam.sdk.transforms.ParDo; |
51 | 48 | import org.apache.beam.sdk.transforms.SerializableFunction; |
52 | | -import org.apache.beam.sdk.transforms.SimpleFunction; |
53 | | -import org.apache.beam.sdk.transforms.View; |
54 | 49 | import org.apache.beam.sdk.values.PCollection; |
55 | 50 | import org.apache.beam.sdk.values.PCollectionView; |
56 | 51 | import org.apache.beam.sdk.values.TypeDescriptor; |
|
70 | 65 | public class SpannerReadIT { |
71 | 66 |
|
72 | 67 | private static final int MAX_DB_NAME_LENGTH = 30; |
73 | | - private static final int CLEANUP_PROPAGATION_DELAY_MS = 5000; |
74 | 68 |
|
75 | 69 | @Rule public final transient TestPipeline p = TestPipeline.create(); |
76 | 70 | @Rule public transient ExpectedException thrown = ExpectedException.none(); |
@@ -275,55 +269,6 @@ public void testReadFailsBadTable() throws Exception { |
275 | 269 | p.run().waitUntilFinish(); |
276 | 270 | } |
277 | 271 |
|
278 | | - private static class CloseTransactionFn extends SimpleFunction<Transaction, Transaction> { |
279 | | - private final SpannerConfig spannerConfig; |
280 | | - |
281 | | - private CloseTransactionFn(SpannerConfig spannerConfig) { |
282 | | - this.spannerConfig = spannerConfig; |
283 | | - } |
284 | | - |
285 | | - @Override |
286 | | - public Transaction apply(Transaction tx) { |
287 | | - BatchClient batchClient = SpannerAccessor.getOrCreate(spannerConfig).getBatchClient(); |
288 | | - batchClient.batchReadOnlyTransaction(tx.transactionId()).cleanup(); |
289 | | - try { |
290 | | - // Wait for cleanup to propagate. |
291 | | - Thread.sleep(CLEANUP_PROPAGATION_DELAY_MS); |
292 | | - } catch (InterruptedException e) { |
293 | | - Thread.currentThread().interrupt(); |
294 | | - } |
295 | | - return tx; |
296 | | - } |
297 | | - } |
298 | | - |
299 | | - @Test |
300 | | - public void testReadFailsBadSession() throws Exception { |
301 | | - |
302 | | - thrown.expect(new SpannerWriteIT.StackTraceContainsString("SpannerException")); |
303 | | - thrown.expect(new SpannerWriteIT.StackTraceContainsString("NOT_FOUND: Session not found")); |
304 | | - |
305 | | - SpannerConfig spannerConfig = createSpannerConfig(); |
306 | | - |
307 | | - // This creates a transaction then closes the session. |
308 | | - // The (closed) transaction is then passed to SpannerIO.read() and should |
309 | | - // raise SessionNotFound errors. |
310 | | - PCollectionView<Transaction> tx = |
311 | | - p.apply("Transaction seed", Create.of(1)) |
312 | | - .apply( |
313 | | - "Create transaction", |
314 | | - ParDo.of(new CreateTransactionFn(spannerConfig, TimestampBound.strong()))) |
315 | | - .apply("Close Transaction", MapElements.via(new CloseTransactionFn(spannerConfig))) |
316 | | - .apply("As PCollectionView", View.asSingleton()); |
317 | | - p.apply( |
318 | | - "read db", |
319 | | - SpannerIO.read() |
320 | | - .withSpannerConfig(spannerConfig) |
321 | | - .withTable(options.getTable()) |
322 | | - .withColumns("Key", "Value") |
323 | | - .withTransaction(tx)); |
324 | | - p.run().waitUntilFinish(); |
325 | | - } |
326 | | - |
327 | 272 | @Test |
328 | 273 | public void testQuery() throws Exception { |
329 | 274 | SpannerConfig spannerConfig = createSpannerConfig(); |
|
0 commit comments