@Test
public void pollMessagesTest() {

	final List<Message> messages = new ArrayList<>();
	final String queueName = "issue399_testQueue";
	final int totalSize = 10;
	for(int i = 0; i < totalSize; i++) {
		String payload = "{\"id\": " + i + ", \"msg\":\"test " + i + "\"}";
		Message m = new Message("testmsg-" + i, payload, "");
		if (i % 2 == 0) {
			// Set priority on message with pair id
			m.setPriority(99-i);
		}
		messages.add(m);
	}
	// Populate the queue with our test message batch
	dao.push(queueName, ImmutableList.copyOf(messages));
	// Assert that all messages were persisted and no extras are in there
	assertEquals("Queue size mismatch", totalSize, dao.getSize(queueName));
	final int firstPollSize = 3;
	List<Message> firstPoll = dao.pollMessages(queueName, firstPollSize, 10_000);
	assertNotNull("First poll was null", firstPoll);
	assertFalse("First poll was empty", firstPoll.isEmpty());
	assertEquals("First poll size mismatch", firstPollSize, firstPoll.size());
	final int secondPollSize = 4;
	List<Message> secondPoll = dao.pollMessages(queueName, secondPollSize, 10_000);
	assertNotNull("Second poll was null", secondPoll);
	assertFalse("Second poll was empty", secondPoll.isEmpty());
	assertEquals("Second poll size mismatch", secondPollSize, secondPoll.size());
	// Assert that the total queue size hasn't changed
	assertEquals("Total queue size should have remained the same", totalSize, dao.getSize(queueName));
	// Assert that our un-popped messages match our expected size
	final long expectedSize = totalSize - firstPollSize - secondPollSize;
	try(Connection c = testUtil.getDataSource().getConnection()) {
		String UNPOPPED = "SELECT COUNT(*) FROM queue_message WHERE queue_name = ? AND popped = false";
		try(Query q = new Query(testUtil.getObjectMapper(), c, UNPOPPED)) {
			long count = q.addParameter(queueName).executeCount();
			assertEquals("Remaining queue size mismatch", expectedSize, count);
		}
	} catch (Exception ex) {
		fail(ex.getMessage());
	}
}