use of com.google.cloud.spanner.Struct in project google-cloud-java by GoogleCloudPlatform.
the class ITWriteTest method writeStringArrayEmpty.
@Test
public void writeStringArrayEmpty() {
write(baseInsert().set("StringArrayValue").toStringArray(Arrays.<String>asList()).build());
Struct row = readLastRow("StringArrayValue");
assertThat(row.isNull(0)).isFalse();
assertThat(row.getStringList(0)).containsExactly();
}
use of com.google.cloud.spanner.Struct in project google-cloud-java by GoogleCloudPlatform.
the class ITWriteTest method writeDateArrayNull.
@Test
public void writeDateArrayNull() {
write(baseInsert().set("DateArrayValue").toDateArray(null).build());
Struct row = readLastRow("DateArrayValue");
assertThat(row.isNull(0)).isTrue();
}
use of com.google.cloud.spanner.Struct in project google-cloud-java by GoogleCloudPlatform.
the class ITWriteTest method writeTimestampArray.
@Test
public void writeTimestampArray() {
Timestamp t1 = Timestamp.parseTimestamp("2016-09-18T00:00:00Z");
Timestamp t2 = Timestamp.parseTimestamp("2016-09-19T00:00:00Z");
write(baseInsert().set("TimestampArrayValue").toTimestampArray(Arrays.asList(t1, null, t2)).build());
Struct row = readLastRow("TimestampArrayValue");
assertThat(row.isNull(0)).isFalse();
assertThat(row.getTimestampList(0)).containsExactly(t1, null, t2).inOrder();
}
use of com.google.cloud.spanner.Struct in project google-cloud-java by GoogleCloudPlatform.
the class ITWriteTest method writeTimestampArrayNull.
@Test
public void writeTimestampArrayNull() {
write(baseInsert().set("TimestampArrayValue").toTimestampArray(null).build());
Struct row = readLastRow("TimestampArrayValue");
assertThat(row.isNull(0)).isTrue();
}
use of com.google.cloud.spanner.Struct in project google-cloud-java by GoogleCloudPlatform.
the class ITTransactionTest method doBasicsTest.
private void doBasicsTest(final ReadStrategy strategy) throws InterruptedException {
final String key = uniqueKey();
// Initial value.
client.write(Arrays.asList(Mutation.newInsertBuilder("T").set("K").to(key).set("V").to(0).build()));
final int numThreads = 3;
final CountDownLatch commitBarrier = new CountDownLatch(numThreads);
final CountDownLatch complete = new CountDownLatch(numThreads);
final TransactionCallable<Long> callable = new TransactionCallable<Long>() {
@Override
public Long run(TransactionContext transaction) throws SpannerException {
Struct row = strategy.read(transaction, key);
long newValue = row.getLong(0) + 1;
transaction.buffer(Mutation.newUpdateBuilder("T").set("K").to(key).set("V").to(newValue).build());
commitBarrier.countDown();
// Synchronize so that all threads attempt to commit at the same time.
Uninterruptibles.awaitUninterruptibly(commitBarrier);
return newValue;
}
};
// We start multiple threads all attempting to update the same value concurrently. We expect
// to see at least some of the corresponding transactions abort.
final Vector<Long> results = new Vector<>();
final Vector<Timestamp> commitTimestamps = new Vector<>();
class TxnThread extends Thread {
@Override
public void run() {
TransactionRunner runner = client.readWriteTransaction();
Long result = runner.run(callable);
results.add(result);
commitTimestamps.add(runner.getCommitTimestamp());
complete.countDown();
}
}
for (int i = 0; i < numThreads; ++i) {
new TxnThread().start();
}
complete.await();
assertThat(results).hasSize(numThreads);
List<Long> expectedResults = new ArrayList<>();
for (int i = 0; i < numThreads; ++i) {
expectedResults.add(i + 1L);
}
assertThat(results).containsAllIn(expectedResults);
assertThat(Sets.newHashSet(commitTimestamps)).hasSize(numThreads);
assertThat(client.singleUse(TimestampBound.strong()).readRow("T", Key.of(key), Arrays.asList("V")).getLong(0)).isEqualTo(Long.valueOf(numThreads));
}
Aggregations