use of io.datarouter.util.Count.Counts in project datarouter by hotpads.
the class SpannerSessionPoolIntegrationTester method seedData.
@Test
public void seedData() {
var counts = new Counts();
var count = counts.add("put");
Scanner.iterate(0, i -> i + 1).limit(10_000).map(i -> new TestDatabean(Integer.toString(i), "hello-" + i, "world-" + i)).batch(1_000).each(node::putMulti).each(count::incrementBySize).forEach(batch -> logger.warn("{}", counts));
}
use of io.datarouter.util.Count.Counts 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