use of com.google.cloud.spanner.ErrorCode in project java-spanner by googleapis.
the class ConnectionImplTest method testExecuteSetAutocommitDmlModeInvalidValue.
@Test
public void testExecuteSetAutocommitDmlModeInvalidValue() {
try (ConnectionImpl subject = createConnection(ConnectionOptions.newBuilder().setCredentials(NoCredentials.getInstance()).setUri(URI).build())) {
assertThat(subject.isAutocommit(), is(true));
assertThat(subject.getAutocommitDmlMode(), is(equalTo(AutocommitDmlMode.TRANSACTIONAL)));
ErrorCode expected = null;
try {
subject.execute(Statement.of("set autocommit_dml_mode='NON_EXISTENT_VALUE'"));
} catch (SpannerException e) {
expected = e.getErrorCode();
}
assertThat(expected, is(equalTo(ErrorCode.INVALID_ARGUMENT)));
}
}
use of com.google.cloud.spanner.ErrorCode in project java-spanner by googleapis.
the class ConnectionImplTest method testExecuteSetStatementTimeoutInvalidValue.
@Test
public void testExecuteSetStatementTimeoutInvalidValue() {
try (ConnectionImpl subject = createConnection(ConnectionOptions.newBuilder().setCredentials(NoCredentials.getInstance()).setUri(URI).build())) {
assertThat(subject.getStatementTimeout(TimeUnit.MILLISECONDS), is(equalTo(0L)));
ErrorCode expected = null;
try {
subject.execute(Statement.of("set statement_timeout=-1"));
} catch (SpannerException e) {
expected = e.getErrorCode();
}
assertThat(expected, is(equalTo(ErrorCode.INVALID_ARGUMENT)));
}
}
use of com.google.cloud.spanner.ErrorCode in project datarouter by hotpads.
the class SpannerSessionPoolIntegrationTester method scanWithInterrupts.
@Test
public void scanWithInterrupts() {
// init client in parent thread without timeout
node.scan().findFirst();
var counts = new Counts();
var callCount = counts.add("call");
var cancelledCount = counts.add("cancelled");
var resourceExhaustedCount = counts.add("resourceExhausted");
var otherErrorCount = counts.add("otherError");
var successCount = counts.add("success");
int numIterations = maxSessions + 2;
int numThreads = 1;
boolean paralleScan = false;
var config = new Config().setResponseBatchSize(2_000);
int timeoutMs = 300;
boolean cancelFutures = true;
boolean mayInterruptIfRunning = true;
int logEveryN = 20;
Scanner.iterate(0, i -> i + 1).limit(numIterations).parallel(new ParallelScannerContext(scannerExec, numThreads, false, paralleScan)).each(i -> {
var future = opExec.submit(() -> {
try {
callCount.increment();
node.scan(config).count();
successCount.increment();
return null;
} catch (SpannerException spannerException) {
if (spannerException.getErrorCode().equals(ErrorCode.CANCELLED)) {
cancelledCount.increment();
} else if (spannerException.getErrorCode().equals(ErrorCode.RESOURCE_EXHAUSTED)) {
resourceExhaustedCount.increment();
} else {
otherErrorCount.increment();
}
logger.info("spannerException errorCode={} {}", spannerException.getErrorCode(), counts);
logger.warn("spannerException errorCode={} {}", spannerException.getErrorCode(), counts, spannerException);
throw spannerException;
}
});
try {
future.get(timeoutMs, TimeUnit.MILLISECONDS);
} catch (ExecutionException e) {
logger.warn("", e);
} catch (TimeoutException e) {
logger.warn("", e);
if (cancelFutures) {
future.cancel(mayInterruptIfRunning);
}
} catch (InterruptedException e) {
logger.warn("", e);
}
}).sample(logEveryN, true).forEach($ -> logger.warn("{}", counts));
Assert.assertEquals(resourceExhaustedCount.value(), 0);
}
Aggregations