Search in sources :

Example 1 with Counts

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));
}
Also used : Counts(io.datarouter.util.Count.Counts) TestDatabean(io.datarouter.storage.test.TestDatabean) Test(org.testng.annotations.Test)

Example 2 with 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);
}
Also used : Scanner(io.datarouter.scanner.Scanner) ParallelScannerContext(io.datarouter.scanner.ParallelScannerContext) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) Test(org.testng.annotations.Test) TestDatabeanKey(io.datarouter.storage.test.TestDatabeanKey) Inject(javax.inject.Inject) Counts(io.datarouter.util.Count.Counts) Assert(org.testng.Assert) ClientId(io.datarouter.storage.client.ClientId) Config(io.datarouter.storage.config.Config) SortedMapStorageNode(io.datarouter.storage.node.op.combo.SortedMapStorage.SortedMapStorageNode) ExecutorService(java.util.concurrent.ExecutorService) AfterClass(org.testng.annotations.AfterClass) Logger(org.slf4j.Logger) Executors(java.util.concurrent.Executors) Guice(org.testng.annotations.Guice) NodeFactory(io.datarouter.storage.node.factory.NodeFactory) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) ErrorCode(com.google.cloud.spanner.ErrorCode) SpannerException(com.google.cloud.spanner.SpannerException) SpannerTestNgModuleFactory(io.datarouter.gcp.spanner.SpannerTestNgModuleFactory) TestDatabeanFielder(io.datarouter.storage.test.TestDatabeanFielder) SpannerClientOptions(io.datarouter.gcp.spanner.client.SpannerClientOptions) TestDatabean(io.datarouter.storage.test.TestDatabean) Counts(io.datarouter.util.Count.Counts) Config(io.datarouter.storage.config.Config) ParallelScannerContext(io.datarouter.scanner.ParallelScannerContext) SpannerException(com.google.cloud.spanner.SpannerException) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) Test(org.testng.annotations.Test)

Aggregations

TestDatabean (io.datarouter.storage.test.TestDatabean)2 Counts (io.datarouter.util.Count.Counts)2 Test (org.testng.annotations.Test)2 ErrorCode (com.google.cloud.spanner.ErrorCode)1 SpannerException (com.google.cloud.spanner.SpannerException)1 SpannerTestNgModuleFactory (io.datarouter.gcp.spanner.SpannerTestNgModuleFactory)1 SpannerClientOptions (io.datarouter.gcp.spanner.client.SpannerClientOptions)1 ParallelScannerContext (io.datarouter.scanner.ParallelScannerContext)1 Scanner (io.datarouter.scanner.Scanner)1 ClientId (io.datarouter.storage.client.ClientId)1 Config (io.datarouter.storage.config.Config)1 NodeFactory (io.datarouter.storage.node.factory.NodeFactory)1 SortedMapStorageNode (io.datarouter.storage.node.op.combo.SortedMapStorage.SortedMapStorageNode)1 TestDatabeanFielder (io.datarouter.storage.test.TestDatabeanFielder)1 TestDatabeanKey (io.datarouter.storage.test.TestDatabeanKey)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1 TimeUnit (java.util.concurrent.TimeUnit)1 TimeoutException (java.util.concurrent.TimeoutException)1