@Test public void standardDMLWithExecuteSQL() { executeQuery(DML_COUNT, INSERT_DML); // checks for multi-stmts within a txn, therefore also verifying seqNo. executeQuery(DML_COUNT * 2, UPDATE_DML, DELETE_DML); } }
@Test public void standardDMLReadYourWrites() { executeUpdate(DML_COUNT, INSERT_DML); final TransactionCallable<Void> callable = new TransactionCallable<Void>() { @Override public Void run(TransactionContext transaction) { long rowCount = transaction.executeUpdate(Statement.of("UPDATE T SET v = v * 2 WHERE k = 'boo2';")); assertThat(rowCount).isEqualTo(1); assertThat(transaction.readRow("T", Key.of("boo2"), Arrays.asList("v")).getLong(0)) .isEqualTo(2 * 2); return null; } }; TransactionRunner runner = client.readWriteTransaction(); runner.run(callable); executeUpdate(DML_COUNT, DELETE_DML); }
@Test public void abortOnceShouldSucceedAfterRetry() { try { throwAbortOnce = true; executeUpdate(DML_COUNT, INSERT_DML); assertThat(throwAbortOnce).isFalse(); } catch (AbortedException e) { fail("Abort Exception not caught and retried"); } }
@Test public void standardDMLWithDuplicates() { executeUpdate(DML_COUNT, INSERT_DML); executeUpdate( 4, "UPDATE T SET v = 200 WHERE k = 'boo1';", "UPDATE T SET v = 300 WHERE k = 'boo1';", "UPDATE T SET v = 400 WHERE k = 'boo1';", "UPDATE T SET v = 500 WHERE k = 'boo1';"); assertThat( client .singleUse(TimestampBound.strong()) .readRow("T", Key.of("boo1"), Arrays.asList("V")) .getLong(0)) .isEqualTo(500); executeUpdate(DML_COUNT, DELETE_DML, DELETE_DML); }
@Test public void standardDMLWithError() { try { executeUpdate(0, "SELECT * FROM T;"); fail("Expected illegal argument exception"); } catch (SpannerException e) { assertThat(e.getErrorCode()).isEqualTo(ErrorCode.UNKNOWN); assertThat(e.getMessage()) .contains("DML response missing stats possibly due to non-DML statement as input"); assertThat(e.getCause()).isInstanceOf(IllegalArgumentException.class); } }
@Test public void standardDML() { executeUpdate(DML_COUNT, INSERT_DML); assertThat( client .singleUse(TimestampBound.strong()) .readRow("T", Key.of("boo1"), Arrays.asList("V")) .getLong(0)) .isEqualTo(1); executeUpdate(DML_COUNT, UPDATE_DML); assertThat( client .singleUse(TimestampBound.strong()) .readRow("T", Key.of("boo1"), Arrays.asList("V")) .getLong(0)) .isEqualTo(100); executeUpdate(DML_COUNT, DELETE_DML); assertThat( client .singleUse(TimestampBound.strong()) .readRow("T", Key.of("boo1"), Arrays.asList("V"))) .isNull(); }
@Test public void partitionedDML() { executeUpdate(DML_COUNT, INSERT_DML); assertThat( client .singleUse(TimestampBound.strong()) .readRow("T", Key.of("boo1"), Arrays.asList("V")) .getLong(0)) .isEqualTo(1); long rowCount = client.executePartitionedUpdate(Statement.of(UPDATE_DML)); // Note: With PDML there is a possibility of network replay or partial update to occur, causing // this assert to fail. We should remove this assert if it is a recurring failure in IT tests. assertThat(rowCount).isEqualTo(DML_COUNT); assertThat( client .singleUse(TimestampBound.strong()) .readRow("T", Key.of("boo1"), Arrays.asList("V")) .getLong(0)) .isEqualTo(100); rowCount = client.executePartitionedUpdate(Statement.of(DELETE_DML)); assertThat(rowCount).isEqualTo(DML_COUNT); assertThat( client .singleUse(TimestampBound.strong()) .readRow("T", Key.of("boo1"), Arrays.asList("V"))) .isNull(); }