Search in sources :

Example 1 with TestDatabeanKey

use of io.datarouter.storage.test.TestDatabeanKey in project datarouter by hotpads.

the class SqsPerformanceTester method drainGroupQueueViaPeek.

// timeout is needed, otherwise it will poll forever
private void drainGroupQueueViaPeek(DatarouterSqsGroupTestDao dao, int numThreads) {
    var timer = new PhaseTimer("drain queue");
    var numDatabeansDrained = new AtomicLong(0L);
    var numMessagesDrained = new AtomicLong(0L);
    ExecutorService exec = Executors.newCachedThreadPool();
    for (int i = 0; i < numThreads; ++i) {
        exec.submit(() -> {
            for (GroupQueueMessage<TestDatabeanKey, TestDatabean> message : dao.peekUntilEmpty(Duration.ofSeconds(3)).iterable()) {
                List<TestDatabean> databeans = message.getDatabeans();
                numDatabeansDrained.addAndGet(databeans.size());
                dao.ack(message.getKey());
                numMessagesDrained.incrementAndGet();
                if (numMessagesDrained.get() % 5 == 0) {
                    logger.info("groupNode drained {}, latest={}", numDatabeansDrained.get(), ListTool.getLast(databeans).getKey());
                }
            }
        });
    }
    ExecutorServiceTool.shutdown(exec, Duration.ofDays(1));
    timer.add("drained " + numMessagesDrained.intValue() + " messages with " + numDatabeansDrained.intValue() + " databeans");
    logger.info(timer.toString() + "@" + timer.getItemsPerSecond(numDatabeansDrained.intValue()));
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) PhaseTimer(io.datarouter.util.timer.PhaseTimer) TestDatabean(io.datarouter.storage.test.TestDatabean) ExecutorService(java.util.concurrent.ExecutorService) TestDatabeanKey(io.datarouter.storage.test.TestDatabeanKey)

Example 2 with TestDatabeanKey

use of io.datarouter.storage.test.TestDatabeanKey in project datarouter by hotpads.

the class BaseManagedIndexIntegrationTests method testDeleteMultiUnique.

private void testDeleteMultiUnique(DatarouterTestDatabeanWithIndexDao genericDao) {
    List<TestDatabean> databeans = List.of(new TestDatabean("tri", "martolod", "yaouank"), new TestDatabean("i vonet", "da", "veajiƱ"));
    List<TestDatabeanKey> keys = Scanner.of(databeans).map(Databean::getKey).list();
    List<TestDatabeanWithManagedIndexByBarKey> entryKeys = new ArrayList<>();
    for (TestDatabean databean : databeans) {
        entryKeys.add(new TestDatabeanWithManagedIndexByBarKey(databean.getBar()));
    }
    Assert.assertEquals(genericDao.getMulti(keys).size(), 0);
    Assert.assertEquals(genericDao.lookupMultiUnique(entryKeys).size(), 0);
    genericDao.putMulti(databeans);
    Assert.assertEquals(genericDao.getMulti(keys).size(), 2);
    Assert.assertEquals(genericDao.lookupMultiUnique(entryKeys).size(), 2);
    genericDao.deleteMultiUnique(entryKeys);
    Assert.assertEquals(genericDao.getMulti(keys).size(), 0);
    Assert.assertEquals(genericDao.lookupMultiUnique(entryKeys).size(), 0);
}
Also used : TestDatabean(io.datarouter.storage.test.TestDatabean) ArrayList(java.util.ArrayList) TestDatabeanKey(io.datarouter.storage.test.TestDatabeanKey) TestDatabeanWithManagedIndexByBarKey(io.datarouter.storage.test.node.type.index.databean.TestDatabeanWithManagedIndexByBarKey)

Example 3 with TestDatabeanKey

use of io.datarouter.storage.test.TestDatabeanKey in project datarouter by hotpads.

the class HbaseRangeIntegrationTests method testRange.

@Test
public void testRange() {
    testDatabeanDao.deleteAll();
    testDatabeanDao.putMulti(DATABEANS);
    List<TestDatabeanKey> list = testDatabeanDao.scanKeys(new Range<>(new TestDatabeanKey("12"), false)).list();
    Assert.assertFalse(list.isEmpty());
    Assert.assertEquals(list.get(0), new TestDatabeanKey("120"));
}
Also used : TestDatabeanKey(io.datarouter.storage.test.TestDatabeanKey) Range(io.datarouter.util.tuple.Range) Test(org.testng.annotations.Test)

Example 4 with TestDatabeanKey

use of io.datarouter.storage.test.TestDatabeanKey in project datarouter by hotpads.

the class SqsPerformanceTester method drainQueueViaPeek.

// timeout, otherwise it will poll forever
private void drainQueueViaPeek(DatarouterSqsTestDao dao, int numThreads) {
    var timer = new PhaseTimer("drain queue");
    var numDatabeansDrained = new AtomicLong(0L);
    var numMessagesDrained = new AtomicLong(0L);
    ExecutorService exec = Executors.newCachedThreadPool();
    for (int i = 0; i < numThreads; ++i) {
        exec.submit(() -> {
            for (QueueMessage<TestDatabeanKey, TestDatabean> message : dao.peekUntilEmpty(Duration.ofSeconds(3)).iterable()) {
                TestDatabean databean = message.getDatabean();
                numDatabeansDrained.incrementAndGet();
                dao.ack(message.getKey());
                numMessagesDrained.incrementAndGet();
                if (numMessagesDrained.get() % 200 == 0) {
                    logger.info("queue drained {}, latest={}", numDatabeansDrained.get(), databean.getKey());
                }
            }
        });
    }
    ExecutorServiceTool.shutdown(exec, Duration.ofDays(1));
    timer.add("drained " + numMessagesDrained.intValue() + " messages with " + numDatabeansDrained.intValue() + " databeans");
    logger.info(timer.toString() + "@" + timer.getItemsPerSecond(numDatabeansDrained.intValue()));
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) PhaseTimer(io.datarouter.util.timer.PhaseTimer) TestDatabean(io.datarouter.storage.test.TestDatabean) ExecutorService(java.util.concurrent.ExecutorService) TestDatabeanKey(io.datarouter.storage.test.TestDatabeanKey)

Aggregations

TestDatabeanKey (io.datarouter.storage.test.TestDatabeanKey)4 TestDatabean (io.datarouter.storage.test.TestDatabean)3 PhaseTimer (io.datarouter.util.timer.PhaseTimer)2 ExecutorService (java.util.concurrent.ExecutorService)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 TestDatabeanWithManagedIndexByBarKey (io.datarouter.storage.test.node.type.index.databean.TestDatabeanWithManagedIndexByBarKey)1 Range (io.datarouter.util.tuple.Range)1 ArrayList (java.util.ArrayList)1 Test (org.testng.annotations.Test)1