Merged
Show file tree
Hide file tree
Changes from 1 commit
Show all changes
25 commits
Select commit Hold shift + click to select a range
3872199
feat!: add support for CommitStats
olavloiteOct 24, 2020
def8768
fix: add clirr ignored differences
olavloiteOct 24, 2020
5372dae
Merge branch 'master' into commit-stats2
olavloiteOct 31, 2020
34fbda6
fix: error message should start with getCommitResponse
olavloiteOct 31, 2020
8f61c2a
Merge branch 'master' into commit-stats2
olavloiteNov 6, 2020
041b34d
Merge branch 'master' into commit-stats2
olavloiteDec 5, 2020
8299054
fix: remove overload delay
olavloiteDec 10, 2020
9b710a7
Merge branch 'master' into commit-stats2
olavloiteDec 10, 2020
8c15641
Merge branch 'master' into commit-stats2
olavloiteJan 23, 2021
919cf02
chore: cleanup after merge
olavloiteJan 23, 2021
97ec917
fix: update copyright years of new files
olavloiteJan 23, 2021
afeb0fd
test: fix flaky test
olavloiteJan 23, 2021
8524526
test: skip commit stats tests on emulator
olavloiteJan 23, 2021
06b3e22
test: missed one commit stats tests against emulator
olavloiteJan 23, 2021
1c17d16
test: skip another emulator test
olavloiteJan 23, 2021
664b87d
test: add missing test cases
olavloiteJan 23, 2021
6573a0f
fix: address review comments
olavloiteJan 30, 2021
0b448c3
Merge branch 'master' into commit-stats2
olavloiteFeb 1, 2021
83039fb
Merge branch 'master' into commit-stats2
olavloiteFeb 3, 2021
57ea714
chore: use junit assertion instead of truth
olavloiteFeb 3, 2021
66c5f88
chore: replace truth asserts with junit asserts
olavloiteFeb 4, 2021
1d17973
chore: replace truth assertions with junit
olavloiteFeb 5, 2021
48ef21b
chore: cleanup test and variable names
olavloiteFeb 8, 2021
1f33c42
fix: rename test method and variables
olavloiteFeb 9, 2021
7d45ace
fix: address review comments
olavloiteFeb 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Failed to load files.
PrevPrevious commit
Next Next commit
chore: replace truth assertions with junit
  • Loading branch information
@olavloite
olavloite committedFeb 5, 2021
commit 1d17973b81e2903cbab466b7a3bb6e577f707c8b
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,7 +46,7 @@ public interface UpdateOption {}
/** Marker interface to mark options applicable to list operations in admin API. */
public interface ListOption {}

/** Specifying this will cause the transaction to request {@link CommitStats} from the backend. */
/** Specifying this instructs the transaction to request {@link CommitStats} from the backend. */
public static TransactionOption commitStats() {
return COMMIT_STATS_OPTION;
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -121,6 +121,7 @@ public Timestamp getCommitTimestamp() {
return txn.getCommitResponse().getCommitTimestamp();
}

@Override
public CommitResponse getCommitResponse() {
Preconditions.checkState(
txnState == TransactionState.COMMITTED,
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,8 +16,9 @@

package com.google.cloud.spanner;

import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;

import com.google.cloud.Timestamp;
import org.junit.Test;
Expand All@@ -43,8 +44,8 @@ public void testFromProto() {

CommitResponse response = new CommitResponse(proto);

assertThat(response.getCommitTimestamp()).isEqualTo(Timestamp.ofTimeSecondsAndNanos(123L, 456));
assertThat(response.getCommitStats().getMutationCount()).isEqualTo(mutationCount);
assertEquals(Timestamp.ofTimeSecondsAndNanos(123L, 456), response.getCommitTimestamp());
assertEquals(mutationCount, response.getCommitStats().getMutationCount());
}

@Test
Expand All@@ -66,14 +67,14 @@ public void testEqualsAndHashCode() {
CommitResponse response2 = new CommitResponse(proto2);
CommitResponse response3 = new CommitResponse(proto3);

assertThat(response1).isEqualTo(response3);
assertThat(response1).isNotEqualTo(response2);
assertThat(response2).isNotEqualTo(response3);
assertEquals(response3, response1);
assertNotEquals(response2, response1);
assertNotEquals(response3, response2);
assertFalse(response1.equals(null));
assertFalse(response1.equals(new Object()));

assertThat(response1.hashCode()).isEqualTo(response3.hashCode());
assertThat(response1.hashCode()).isNotEqualTo(response2.hashCode());
assertThat(response2.hashCode()).isNotEqualTo(response3.hashCode());
assertEquals(response3.hashCode(), response1.hashCode());
assertNotEquals(response2.hashCode(), response1.hashCode());
assertNotEquals(response3.hashCode(), response2.hashCode());
}
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,6 +19,7 @@
import static com.google.cloud.spanner.SpannerApiFutures.get;
import static com.google.cloud.spanner.testing.EmulatorSpannerHelper.isUsingEmulator;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeFalse;
Expand DownExpand Up@@ -339,7 +340,7 @@ public ApiFuture<Void> doWorkAsync(TransactionContext txn) {
executor);
assertNotNull(get(runner.getCommitResponse()).getCommitStats());
// MutationCount = 2 columns + 2 secondary indexes.
assertThat(get(runner.getCommitResponse()).getCommitStats().getMutationCount()).isEqualTo(4L);
assertEquals(4L, get(runner.getCommitResponse()).getCommitStats().getMutationCount());
}

@Test
Expand DownExpand Up@@ -369,8 +370,7 @@ public ApiFuture<Void> apply(TransactionContext txn, Void input)
executor)
.commitAsync());
assertNotNull(get(mgr.getCommitResponse()).getCommitStats());
assertThat(get(mgr.getCommitResponse()).getCommitStats().getMutationCount())
.isEqualTo(4L);
assertEquals(4L, get(mgr.getCommitResponse()).getCommitStats().getMutationCount());
break;
} catch (AbortedException e) {
Thread.sleep(e.getRetryDelayInMillis() / 1000);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,6 +18,7 @@

import static com.google.cloud.spanner.testing.EmulatorSpannerHelper.isUsingEmulator;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeFalse;
Expand DownExpand Up@@ -231,7 +232,7 @@ public void transactionManagerReturnsCommitStats() throws InterruptedException {
try {
manager.commit();
assertNotNull(manager.getCommitResponse().getCommitStats());
assertThat(manager.getCommitResponse().getCommitStats().getMutationCount()).isEqualTo(2L);
assertEquals(2L, manager.getCommitResponse().getCommitStats().getMutationCount());
break;
} catch (AbortedException e) {
Thread.sleep(e.getRetryDelayInMillis() / 1000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BUG! Thread.sleep takes milliseconds. No need to divide by 1000.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Changed and filed a bug for the documentation that also includes this.

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,6 +19,7 @@
import static com.google.cloud.spanner.SpannerExceptionFactory.newSpannerException;
import static com.google.cloud.spanner.testing.EmulatorSpannerHelper.isUsingEmulator;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeFalse;
Expand DownExpand Up@@ -649,6 +650,6 @@ public Void run(TransactionContext transaction) throws Exception {
});
assertNotNull(runner.getCommitResponse().getCommitStats());
// MutationCount = 2 (2 columns).
assertThat(runner.getCommitResponse().getCommitStats().getMutationCount()).isEqualTo(2L);
assertEquals(2L, runner.getCommitResponse().getCommitStats().getMutationCount());
}
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,6 +19,7 @@
import static com.google.cloud.spanner.SpannerMatchers.isSpannerException;
import static com.google.cloud.spanner.testing.EmulatorSpannerHelper.isUsingEmulator;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeFalse;
Expand DownExpand Up@@ -176,7 +177,7 @@ public void writeReturnsCommitStats() {
assertNotNull(response);
assertNotNull(response.getCommitTimestamp());
assertNotNull(response.getCommitStats());
assertThat(response.getCommitStats().getMutationCount()).isEqualTo(2L);
assertEquals(2L, response.getCommitStats().getMutationCount());
}

@Test
Expand All@@ -195,7 +196,7 @@ public void writeAtLeastOnceReturnsCommitStats() {
assertNotNull(response);
assertNotNull(response.getCommitTimestamp());
assertNotNull(response.getCommitStats());
assertThat(response.getCommitStats().getMutationCount()).isEqualTo(2L);
assertEquals(2L, response.getCommitStats().getMutationCount());
}

@Test
Expand Down