use of com.google.spanner.v1.SpannerGrpc.SpannerBlockingStub in project grpc-gcp-java by GoogleCloudPlatform.
the class SpannerIntegrationTest method testBatchCreateSessionsBlocking.
@Test
public void testBatchCreateSessionsBlocking() throws Exception {
int sessionCount = 10;
SpannerBlockingStub stub = getSpannerBlockingStub();
BatchCreateSessionsRequest req = BatchCreateSessionsRequest.newBuilder().setDatabase(DATABASE_PATH).setSessionCount(sessionCount).build();
List<Session> sessions = new ArrayList<>();
// The first MAX_CHANNEL requests (without affinity) should be distributed 1 per channel.
for (int j = 0; j < MAX_CHANNEL; j++) {
BatchCreateSessionsResponse resp = stub.batchCreateSessions(req);
assertThat(resp.getSessionCount()).isEqualTo(sessionCount);
sessions.addAll(resp.getSessionList());
}
checkChannelRefs(MAX_CHANNEL, 0, sessionCount);
for (Session session : sessions) {
deleteSession(stub, session);
}
checkChannelRefs(MAX_CHANNEL, 0, 0);
}
use of com.google.spanner.v1.SpannerGrpc.SpannerBlockingStub in project grpc-gcp-java by GoogleCloudPlatform.
the class SpannerIntegrationTest method testUnbindWithInvalidAffinityKey.
@Test
public void testUnbindWithInvalidAffinityKey() {
SpannerBlockingStub stub = getSpannerBlockingStub();
CreateSessionRequest req = CreateSessionRequest.newBuilder().setDatabase(DATABASE_PATH).build();
Session session = stub.createSession(req);
expectedEx.expect(StatusRuntimeException.class);
expectedEx.expectMessage("INVALID_ARGUMENT: Invalid DeleteSession request.");
// No channel bound with the key "invalid_session", will use the least busy one.
stub.deleteSession(DeleteSessionRequest.newBuilder().setName("invalid_session").build());
}
use of com.google.spanner.v1.SpannerGrpc.SpannerBlockingStub in project grpc-gcp-java by GoogleCloudPlatform.
the class SpannerIntegrationTest method cleanupSessions.
private static void cleanupSessions() {
ManagedChannel channel = builder.build();
GoogleCredentials creds = getCreds();
SpannerBlockingStub stub = SpannerGrpc.newBlockingStub(channel).withCallCredentials(MoreCallCredentials.from(creds));
ListSessionsResponse responseList = stub.listSessions(ListSessionsRequest.newBuilder().setDatabase(DATABASE_PATH).build());
for (Session s : responseList.getSessionsList()) {
deleteSession(stub, s);
}
channel.shutdownNow();
}
use of com.google.spanner.v1.SpannerGrpc.SpannerBlockingStub in project grpc-gcp-java by GoogleCloudPlatform.
the class SpannerIntegrationTest method testBoundWithInvalidAffinityKey.
@Test
public void testBoundWithInvalidAffinityKey() {
SpannerBlockingStub stub = getSpannerBlockingStub();
CreateSessionRequest req = CreateSessionRequest.newBuilder().setDatabase(DATABASE_PATH).build();
Session session = stub.createSession(req);
expectedEx.expect(StatusRuntimeException.class);
expectedEx.expectMessage("INVALID_ARGUMENT: Invalid GetSession request.");
// No channel bound with the key "invalid_session", will use the least busy one.
stub.getSession(GetSessionRequest.newBuilder().setName("invalid_session").build());
}
use of com.google.spanner.v1.SpannerGrpc.SpannerBlockingStub in project grpc-gcp-java by GoogleCloudPlatform.
the class SpannerTestCases method prepareTestData.
void prepareTestData() throws InterruptedException {
ManagedChannel channel = getChannel();
SpannerBlockingStub stub = getBlockingStub(channel);
// Because of max data size, we need to separate into different rows.
int columnBytes = Integer.min(payload, MAX_SIZE_PER_COLUMN);
int rows = (payload - 1) / columnBytes + 1;
char[] charArray = new char[columnBytes];
Arrays.fill(charArray, 'z');
String colContent = new String(charArray);
Session session = stub.createSession(CreateSessionRequest.newBuilder().setDatabase(database).build());
long start = System.currentTimeMillis();
// Clean the data in the table.
BeginTransactionRequest request = BeginTransactionRequest.newBuilder().setSession(session.getName()).setOptions(TransactionOptions.newBuilder().setReadWrite(TransactionOptions.ReadWrite.getDefaultInstance()).build()).build();
Transaction txn = stub.beginTransaction(request);
stub.commit(CommitRequest.newBuilder().addMutations(Mutation.newBuilder().setDelete(Mutation.Delete.newBuilder().setTable(LARGE_TABLE).setKeySet(KeySet.newBuilder().setAll(true).build()).build()).build()).setSession(session.getName()).setTransactionId(txn.getId()).build());
System.out.println(String.format("\nDeleted the previous large_table in %d ms.", System.currentTimeMillis() - start));
// Add the payload data.
start = System.currentTimeMillis();
for (int i = 0; i < rows; i++) {
txn = stub.beginTransaction(request);
stub.commit(CommitRequest.newBuilder().addMutations(Mutation.newBuilder().setInsertOrUpdate(Mutation.Write.newBuilder().addColumns("id").addColumns("data").addValues(ListValue.newBuilder().addValues(Value.newBuilder().setStringValue("payload" + i)).addValues(Value.newBuilder().setStringValue(colContent)).build()).setTable(LARGE_TABLE).build()).build()).setSession(session.getName()).setTransactionId(txn.getId()).build());
}
System.out.println(String.format("Successfully added ColumnBytes: %d, Rows: %d to large_table in %d ms.", columnBytes, rows, System.currentTimeMillis() - start));
stub.deleteSession(DeleteSessionRequest.newBuilder().setName(session.getName()).build());
channel.shutdown().awaitTermination(5, TimeUnit.SECONDS);
}
Aggregations