Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static com.google.cloud.spanner.SpannerMatchers.isSpannerException;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.fail;

import com.google.cloud.ByteArray;
import com.google.cloud.Date;
Expand Down Expand Up @@ -127,6 +128,38 @@ public void writeAtLeastOnce() {
assertThat(row.getString(0)).isEqualTo("v1");
}

@Test
public void writeAlreadyExists() {
client.write(
Arrays.asList(
Mutation.newInsertBuilder("T")
.set("K")
.to(lastKey = "key1")
.set("StringValue")
.to("v1")
.build()));
Struct row = readLastRow("StringValue");
assertThat(row.isNull(0)).isFalse();
assertThat(row.getString(0)).isEqualTo("v1");

try {
client.write(
Arrays.asList(
Mutation.newInsertBuilder("T")
.set("K")
.to(lastKey)
.set("StringValue")
.to("v2")
.build()));
fail("missing expected ALREADY_EXISTS exception");
} catch (SpannerException e) {
assertThat(e.getErrorCode()).isEqualTo(ErrorCode.ALREADY_EXISTS);
}
row = readLastRow("StringValue");
assertThat(row.isNull(0)).isFalse();
assertThat(row.getString(0)).isEqualTo("v1");
}

@Ignore // TODO(user): Fix this - backend currently accepts empty mutation.
@Test
public void emptyWrite() {
Expand Down