use of com.google.spanner.v1.TransactionSelector in project java-spanner by googleapis.
the class MockSpannerServiceImpl method getTransactionId.
private ByteString getTransactionId(Session session, TransactionSelector tx) {
ByteString transactionId = null;
switch(tx.getSelectorCase()) {
case SELECTOR_NOT_SET:
case SINGLE_USE:
transactionId = null;
break;
case BEGIN:
transactionId = beginTransaction(session, tx.getBegin()).getId();
break;
case ID:
Transaction transaction = transactions.get(tx.getId());
if (transaction == null) {
Optional<Boolean> aborted = Optional.fromNullable(abortedTransactions.get(tx.getId()));
if (aborted.or(Boolean.FALSE)) {
throwTransactionAborted(tx.getId());
} else {
throwTransactionNotFound(tx.getId());
}
} else {
transactionId = transaction.getId();
transactionLastUsed.put(transactionId, Instant.now());
}
break;
default:
throw Status.UNIMPLEMENTED.asRuntimeException();
}
return transactionId;
}
use of com.google.spanner.v1.TransactionSelector in project java-spanner by googleapis.
the class MockSpannerServiceImpl method returnPartialResultSet.
private void returnPartialResultSet(ResultSet resultSet, ByteString transactionId, TransactionSelector transactionSelector, StreamObserver<PartialResultSet> responseObserver, SimulatedExecutionTime executionTime) {
ResultSetMetadata metadata = resultSet.getMetadata();
if (transactionId == null) {
Transaction transaction = getTemporaryTransactionOrNull(transactionSelector);
metadata = metadata.toBuilder().setTransaction(transaction).build();
} else {
metadata = metadata.toBuilder().setTransaction(ignoreNextInlineBeginRequest.getAndSet(false) ? Transaction.getDefaultInstance() : Transaction.newBuilder().setId(transactionId).build()).build();
}
resultSet = resultSet.toBuilder().setMetadata(metadata).build();
PartialResultSetsIterator iterator = new PartialResultSetsIterator(resultSet);
long index = 0L;
while (iterator.hasNext()) {
SimulatedExecutionTime.checkStreamException(index, executionTime.exceptions, executionTime.streamIndices);
responseObserver.onNext(iterator.next());
index++;
}
responseObserver.onCompleted();
}
use of com.google.spanner.v1.TransactionSelector in project grpc-gcp-java by GoogleCloudPlatform.
the class SpannerProbes method partitionProber.
/**
* Probe to test PartitionQuery and PartitionRead grpc call from Spanner stub.
*/
public static void partitionProber(SpannerGrpc.SpannerBlockingStub stub) {
Session session = null;
try {
session = stub.createSession(CreateSessionRequest.newBuilder().setDatabase(DATABASE).build());
// Probing partition query call.
TransactionOptions options = TransactionOptions.newBuilder().setReadOnly(TransactionOptions.ReadOnly.getDefaultInstance()).build();
TransactionSelector selector = TransactionSelector.newBuilder().setBegin(options).build();
stub.partitionQuery(PartitionQueryRequest.newBuilder().setSession(session.getName()).setSql("select * FROM " + TABLE).setTransaction(selector).build());
// Probing partition read call.
stub.partitionRead(PartitionReadRequest.newBuilder().setSession(session.getName()).setTable(TABLE).setTransaction(selector).setKeySet(KeySet.newBuilder().setAll(true).build()).addColumns("username").addColumns("firstname").addColumns("lastname").build());
} finally {
deleteSession(stub, session);
}
}
use of com.google.spanner.v1.TransactionSelector in project grpc-gcp-java by GoogleCloudPlatform.
the class GcpManagedChannelTest method testGetKeysFromRequest.
@Test
public void testGetKeysFromRequest() {
String expected = "thisisaname";
TransactionSelector selector = TransactionSelector.getDefaultInstance();
PartitionReadRequest req = PartitionReadRequest.newBuilder().setSession(expected).setTable("jenny").setTransaction(selector).addColumns("users").build();
List<String> result = getKeysFromMessage(req, "session");
assertEquals(expected, result.get(0));
result = getKeysFromMessage(req, "fakesession");
assertEquals(0, result.size());
}
use of com.google.spanner.v1.TransactionSelector in project grpc-gcp-java by GoogleCloudPlatform.
the class SpannerTestCases method testPartitionQuery.
void testPartitionQuery() throws InterruptedException {
System.out.println("\nTestPartitionQuery");
ManagedChannel channel = getChannel();
SpannerBlockingStub stub = getBlockingStub(channel);
Session session = stub.createSession(CreateSessionRequest.newBuilder().setDatabase(database).build());
TransactionOptions options = TransactionOptions.newBuilder().setReadOnly(TransactionOptions.ReadOnly.getDefaultInstance()).build();
TransactionSelector selector = TransactionSelector.newBuilder().setBegin(options).build();
PartitionQueryRequest request = PartitionQueryRequest.newBuilder().setSession(session.getName()).setSql("select * FROM " + LARGE_TABLE).setTransaction(selector).build();
BlockingCall<PartitionQueryRequest, PartitionResponse> blockingCall = (PartitionQueryRequest req) -> stub.partitionQuery(req);
doTestBlocking(channel, request, blockingCall);
stub.deleteSession(DeleteSessionRequest.newBuilder().setName(session.getName()).build());
channel.shutdown().awaitTermination(5, TimeUnit.SECONDS);
}
Aggregations