Search in sources :

Example 1 with TestDatabean

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

the class SqsGroupNodeIntegrationTester method testPutMultiAndPollMulti.

@Test
public void testPutMultiAndPollMulti() {
    List<TestDatabean> databeans = new ArrayList<>(DATABEAN_COUNT);
    String longString = SqsTestHelper.makeStringOfByteSize(BaseSqsNode.MAX_BYTES_PER_MESSAGE / (DATABEAN_COUNT - 1));
    for (int i = 0; i < DATABEAN_COUNT; i++) {
        databeans.add(new TestDatabean(longString, makeRandomString(), makeRandomString()));
    }
    dao.putMulti(databeans);
    List<TestDatabean> retrievedDatabeans = dao.pollMulti(Duration.ofSeconds(5));
    retrievedDatabeans.addAll(dao.pollMulti(Duration.ofSeconds(5)));
    Assert.assertEquals(retrievedDatabeans.size(), DATABEAN_COUNT);
}
Also used : TestDatabean(io.datarouter.storage.test.TestDatabean) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 2 with TestDatabean

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

the class SqsNodeIntegrationTester method testPutAndPoll.

@Test
public void testPutAndPoll() {
    var databean = new TestDatabean(makeRandomString(), makeRandomString(), makeRandomString());
    dao.put(databean);
    TestDatabean retrievedDatabean = dao.poll(Duration.ofMillis(Long.MAX_VALUE));
    Assert.assertEquals(retrievedDatabean.getKey().getFoo(), databean.getKey().getFoo());
    Assert.assertEquals(retrievedDatabean.getBar(), databean.getBar());
    Assert.assertEquals(retrievedDatabean.getBaz(), databean.getBaz());
    Assert.assertNull(dao.poll());
}
Also used : TestDatabean(io.datarouter.storage.test.TestDatabean) Test(org.testng.annotations.Test)

Example 3 with TestDatabean

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

the class SqsNodeIntegrationTester method testPollTimeout.

@Test
public void testPollTimeout() {
    // extra cleanup
    drainQueue(Duration.ofSeconds(40));
    var databean = new TestDatabean(makeRandomString(), makeRandomString(), makeRandomString());
    dao.put(databean);
    long time = System.currentTimeMillis();
    TestDatabean retrievedDatabean = dao.poll(Duration.ofSeconds(5));
    Assert.assertNotNull(retrievedDatabean);
    Assert.assertTrue(System.currentTimeMillis() - time < 6000L);
    testPollNullWithTimeout(Duration.ofSeconds(25));
    testPollNullWithTimeout(Duration.ofSeconds(25));
}
Also used : TestDatabean(io.datarouter.storage.test.TestDatabean) Test(org.testng.annotations.Test)

Example 4 with TestDatabean

use of io.datarouter.storage.test.TestDatabean 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 5 with TestDatabean

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

the class BaseManagedIndexIntegrationTests method testLookupUnique.

private void testLookupUnique(DatarouterTestDatabeanWithIndexDao genericDao) {
    TestDatabean databean = genericDao.lookupUnique(new TestDatabeanWithManagedIndexByBarKey("martolod"));
    Assert.assertNull(databean);
    databean = genericDao.lookupUnique(new TestDatabeanWithManagedIndexByBarKey("tra"));
    Assert.assertEquals(databean.getKey().getFoo(), "alarc'h");
    Assert.assertEquals(databean.getBar(), "tra");
    Assert.assertEquals(databean.getBaz(), "mor");
}
Also used : TestDatabean(io.datarouter.storage.test.TestDatabean) TestDatabeanWithManagedIndexByBarKey(io.datarouter.storage.test.node.type.index.databean.TestDatabeanWithManagedIndexByBarKey)

Aggregations

TestDatabean (io.datarouter.storage.test.TestDatabean)15 Test (org.testng.annotations.Test)5 ArrayList (java.util.ArrayList)4 TestDatabeanKey (io.datarouter.storage.test.TestDatabeanKey)3 TestDatabeanWithManagedIndexByBarKey (io.datarouter.storage.test.node.type.index.databean.TestDatabeanWithManagedIndexByBarKey)3 PhaseTimer (io.datarouter.util.timer.PhaseTimer)3 ExecutorService (java.util.concurrent.ExecutorService)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 SqsDataTooLargeException (io.datarouter.aws.sqs.SqsDataTooLargeException)1 Counts (io.datarouter.util.Count.Counts)1 HashSet (java.util.HashSet)1