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);
}
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());
}
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));
}
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()));
}
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");
}
Aggregations