use of com.google.cloud.spanner.BatchReadOnlyTransaction in project spanner-jdbc by olavloite.
the class CloudSpannerPartitionResultSetTest method createSubject.
private CloudSpannerPartitionResultSet createSubject() {
Partition partition = mock(Partition.class);
BatchReadOnlyTransaction transaction = mock(BatchReadOnlyTransaction.class);
ResultSet rs = CloudSpannerResultSetTest.getMockResultSet();
when(transaction.execute(partition)).thenReturn(rs);
return new CloudSpannerPartitionResultSet(mock(CloudSpannerStatement.class), transaction, partition, "SELECT * FROM FOO");
}
use of com.google.cloud.spanner.BatchReadOnlyTransaction in project beam by apache.
the class CreateTransactionFn method processElement.
@ProcessElement
public void processElement(ProcessContext c) throws Exception {
BatchReadOnlyTransaction tx = spannerAccessor.getBatchClient().batchReadOnlyTransaction(timestampBound);
c.output(Transaction.create(tx.getBatchTransactionId()));
}
use of com.google.cloud.spanner.BatchReadOnlyTransaction in project spanner-jdbc by olavloite.
the class BatchReadOnlyTest method testExecuteBatchReadOnly.
@Test
public void testExecuteBatchReadOnly() throws SQLException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
for (int testRun = 0; testRun < 2; testRun++) {
final int numberOfPartitions = 6;
BatchClient batchClient = mock(BatchClient.class);
BatchReadOnlyTransaction tx = mock(BatchReadOnlyTransaction.class);
List<Partition> partitions = new ArrayList<>(numberOfPartitions);
for (int i = 0; i < numberOfPartitions; i++) partitions.add(mock(Partition.class));
when(tx.partitionQuery(any(), any())).then(new Returns(partitions));
when(batchClient.batchReadOnlyTransaction(TimestampBound.strong())).then(new Returns(tx));
Field field = CloudSpannerTransaction.class.getDeclaredField("batchClient");
field.setAccessible(true);
field.set(connection.getTransaction(), batchClient);
connection.setBatchReadOnly(true);
Statement statement;
if (testRun % 2 == 0) {
statement = connection.createStatement();
assertTrue(statement.execute(SELECT_ALL_FROM_FOO));
} else {
PreparedStatement ps = connection.prepareStatement(SELECT_ALL_FROM_FOO);
assertTrue(ps.execute());
statement = ps;
}
List<ResultSet> resultSets = new ArrayList<>();
do {
resultSets.add(statement.getResultSet());
} while (statement.getMoreResults());
assertEquals(numberOfPartitions, resultSets.size());
}
}
Aggregations