@Test public void writeClosesOldSingleUseContext() throws ParseException { ReadContext ctx = session.singleUse(TimestampBound.strong()); Mockito.when(rpc.commit(Mockito.<CommitRequest>any(), Mockito.eq(options))) .thenReturn( CommitResponse.newBuilder() .setCommitTimestamp(Timestamps.parse("2015-10-01T10:54:20.021Z")) .build()); session.writeAtLeastOnce(Arrays.<Mutation>asList()); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("invalidated"); ctx.read("Dummy", KeySet.all(), Arrays.asList("C")); }
/** * * * <pre> * The Cloud Spanner timestamp at which the transaction committed. * </pre> * * <code>.google.protobuf.Timestamp commit_timestamp = 1;</code> */ private com.google.protobuf.SingleFieldBuilderV3< com.google.protobuf.Timestamp, com.google.protobuf.Timestamp.Builder, com.google.protobuf.TimestampOrBuilder> getCommitTimestampFieldBuilder() { if (commitTimestampBuilder_ == null) { commitTimestampBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< com.google.protobuf.Timestamp, com.google.protobuf.Timestamp.Builder, com.google.protobuf.TimestampOrBuilder>( getCommitTimestamp(), getParentForChildren(), isClean()); commitTimestamp_ = null; } return commitTimestampBuilder_; }
/** * * * <pre> * The Cloud Spanner timestamp at which the transaction committed. * </pre> * * <code>.google.protobuf.Timestamp commit_timestamp = 1;</code> */ public com.google.protobuf.Timestamp.Builder getCommitTimestampBuilder() { onChanged(); return getCommitTimestampFieldBuilder().getBuilder(); } /**
@Test public void writeAtLeastOnce() throws ParseException { String timestampString = "2015-10-01T10:54:20.021Z"; ArgumentCaptor<CommitRequest> commit = ArgumentCaptor.forClass(CommitRequest.class); CommitResponse response = CommitResponse.newBuilder().setCommitTimestamp(Timestamps.parse(timestampString)).build(); Mockito.when(rpc.commit(commit.capture(), Mockito.eq(options))).thenReturn(response); Timestamp timestamp = session.writeAtLeastOnce( Arrays.asList(Mutation.newInsertBuilder("T").set("C").to("x").build())); assertThat(timestamp.getSeconds()) .isEqualTo(utcTimeSeconds(2015, Calendar.OCTOBER, 1, 10, 54, 20)); assertThat(timestamp.getNanos()).isEqualTo(TimeUnit.MILLISECONDS.toNanos(21)); CommitRequest request = commit.getValue(); assertThat(request.getSingleUseTransaction()).isNotNull(); assertThat(request.getSingleUseTransaction().getReadWrite()).isNotNull(); com.google.spanner.v1.Mutation mutation = com.google.spanner.v1.Mutation.newBuilder() .setInsert( Write.newBuilder() .setTable("T") .addColumns("C") .addValues( ListValue.newBuilder() .addValues(com.google.protobuf.Value.newBuilder().setStringValue("x")))) .build(); assertThat(request.getMutationsList()).containsExactly(mutation); }
@Test @SuppressWarnings("all") public void commitTest() { CommitResponse expectedResponse = CommitResponse.newBuilder().build(); mockSpanner.addResponse(expectedResponse); SessionName session = SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]"); ByteString transactionId = ByteString.copyFromUtf8("28"); List<Mutation> mutations = new ArrayList<>(); CommitResponse actualResponse = client.commit(session, transactionId, mutations); Assert.assertEquals(expectedResponse, actualResponse); List<GeneratedMessageV3> actualRequests = mockSpanner.getRequests(); Assert.assertEquals(1, actualRequests.size()); CommitRequest actualRequest = (CommitRequest) actualRequests.get(0); Assert.assertEquals(session, SessionName.parse(actualRequest.getSession())); Assert.assertEquals(transactionId, actualRequest.getTransactionId()); Assert.assertEquals(mutations, actualRequest.getMutationsList()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
@Test @SuppressWarnings("all") public void commitTest2() { CommitResponse expectedResponse = CommitResponse.newBuilder().build(); mockSpanner.addResponse(expectedResponse); SessionName session = SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]"); TransactionOptions singleUseTransaction = TransactionOptions.newBuilder().build(); List<Mutation> mutations = new ArrayList<>(); CommitResponse actualResponse = client.commit(session, singleUseTransaction, mutations); Assert.assertEquals(expectedResponse, actualResponse); List<GeneratedMessageV3> actualRequests = mockSpanner.getRequests(); Assert.assertEquals(1, actualRequests.size()); CommitRequest actualRequest = (CommitRequest) actualRequests.get(0); Assert.assertEquals(session, SessionName.parse(actualRequest.getSession())); Assert.assertEquals(singleUseTransaction, actualRequest.getSingleUseTransaction()); Assert.assertEquals(mutations, actualRequest.getMutationsList()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
@java.lang.Override public Builder mergeFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { com.google.spanner.v1.CommitResponse parsedMessage = null; try { parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); } catch (com.google.protobuf.InvalidProtocolBufferException e) { parsedMessage = (com.google.spanner.v1.CommitResponse) e.getUnfinishedMessage(); throw e.unwrapIOException(); } finally { if (parsedMessage != null) { mergeFrom(parsedMessage); } } return this; }
public static Builder newBuilder(com.google.spanner.v1.CommitResponse prototype) { return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); }
private Builder() { maybeForceBuilderInitialization(); }
@java.lang.Override public Builder mergeFrom(com.google.protobuf.Message other) { if (other instanceof com.google.spanner.v1.CommitResponse) { return mergeFrom((com.google.spanner.v1.CommitResponse) other); } else { super.mergeFrom(other); return this; } }
@java.lang.Override public com.google.spanner.v1.CommitResponse build() { com.google.spanner.v1.CommitResponse result = buildPartial(); if (!result.isInitialized()) { throw newUninitializedMessageException(result); } return result; }
public Builder mergeFrom(com.google.spanner.v1.CommitResponse other) { if (other == com.google.spanner.v1.CommitResponse.getDefaultInstance()) return this; if (other.hasCommitTimestamp()) { mergeCommitTimestamp(other.getCommitTimestamp()); } this.mergeUnknownFields(other.unknownFields); onChanged(); return this; }
@java.lang.Override protected Builder newBuilderForType(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } /**
private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); }