use of com.zimbra.client.ZSearchParams in project zm-mailbox by Zimbra.
the class TestBug89152 method testMessagesWithDifferentTimestamps.
@Test
public void testMessagesWithDifferentTimestamps() {
try {
int numMessages = 2207;
int firstLimit = 100;
int incLimit = 50;
int offset = 0;
Mailbox recieverMbox = TestUtil.getMailbox(RECIPIENT1);
long timestamp = System.currentTimeMillis() - 3600 * 60 * 1000;
byte[] msgBytes = Files.readAllBytes(FileSystems.getDefault().getPath(TEST_MESSAGE_FILE));
for (int i = 0; i < numMessages; i++) {
ParsedMessage pm = new ParsedMessage(msgBytes, timestamp, true);
Message msg = TestUtil.addMessage(recieverMbox, pm);
timestamp += 1001;
//Thread.sleep(300);
}
Thread.sleep(150);
ZMailbox zmbx = TestUtil.getZMailbox(RECIPIENT1);
ZSearchParams searchParams = new ZSearchParams("in:inbox " + SEARCH_STRING);
searchParams.setSortBy(SearchSortBy.dateDesc);
searchParams.setLimit(firstLimit);
searchParams.setTypes(ZSearchParams.TYPE_MESSAGE);
List<ZMessage> resultSet = TestUtil.search(zmbx, searchParams);
assertEquals(firstLimit, resultSet.size());
int gotMessages = resultSet.size();
List<String> seenIds = new ArrayList<String>();
ZMessage lastHit = null;
for (ZMessage m : resultSet) {
seenIds.add(m.getId());
lastHit = m;
}
int recCount = 1;
offset += firstLimit;
while (gotMessages > 0) {
searchParams = new ZSearchParams("in:inbox " + SEARCH_STRING);
searchParams.setCursor((new Cursor(lastHit.getId(), Long.toString(lastHit.getReceivedDate()))));
searchParams.setSortBy(SearchSortBy.dateDesc);
searchParams.setLimit(incLimit);
searchParams.setTypes(ZSearchParams.TYPE_MESSAGE);
searchParams.setOffset(offset);
resultSet = TestUtil.search(zmbx, searchParams);
recCount++;
gotMessages = resultSet.size();
int resCount = 0;
for (ZMessage m : resultSet) {
assertFalse(String.format("Request %d, result %d, encountered duplicate ID %s. Previously seen at %d", recCount, resCount, m.getId(), seenIds.indexOf(m.getId())), seenIds.contains(m.getId()));
seenIds.add(m.getId());
resCount++;
lastHit = m;
}
Thread.sleep(300);
offset += incLimit;
}
assertEquals("expecting " + numMessages + " messages. Got " + seenIds.size(), numMessages, seenIds.size());
} catch (ServiceException e) {
e.printStackTrace();
fail(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of com.zimbra.client.ZSearchParams in project zm-mailbox by Zimbra.
the class TestLongSearchResultSets method testConversations.
@Test
public void testConversations() {
try {
Mailbox recieverMbox = TestUtil.getMailbox(RECIPIENT);
long timestamp = System.currentTimeMillis() - 3600 * 60 * 1000;
int numMessages = 3207;
int firstLimit = 100;
int incLimit = 50;
int offset = 0;
ArrayList<String> expectedIds = new ArrayList<String>();
for (int i = 0; i < numMessages; i++) {
Message msg = TestUtil.addMessage(recieverMbox, TestUtil.getAddress(RECIPIENT), TestUtil.getAddress(SENDER), NAME_PREFIX + " testing bug " + i, String.format("this message contains a search string %s which we are searching for and a number %d and timestamp %d", SEARCH_STRING, i, timestamp), timestamp);
expectedIds.add(Integer.toString(msg.getId()));
timestamp += 1000;
Thread.sleep(100);
}
Collections.reverse(expectedIds);
Thread.sleep(100);
ZMailbox zmbx = TestUtil.getZMailbox(RECIPIENT);
ZSearchParams searchParams = new ZSearchParams("in:inbox " + SEARCH_STRING);
searchParams.setSortBy(SearchSortBy.dateDesc);
searchParams.setLimit(firstLimit);
searchParams.setTypes(ZSearchParams.TYPE_CONVERSATION);
List<String> msgIds = TestUtil.searchMessageIds(zmbx, searchParams);
assertEquals(firstLimit, msgIds.size());
int gotMessages = msgIds.size();
List<String> seenIds = new ArrayList<String>();
seenIds.addAll(msgIds);
int recCount = 1;
offset += firstLimit;
// int numDups = 0;
while (gotMessages > 0) {
searchParams = new ZSearchParams("in:inbox " + SEARCH_STRING);
searchParams.setSortBy(SearchSortBy.dateDesc);
searchParams.setLimit(incLimit);
searchParams.setTypes(ZSearchParams.TYPE_CONVERSATION);
searchParams.setOffset(offset);
msgIds = TestUtil.searchMessageIds(zmbx, searchParams);
recCount++;
gotMessages = msgIds.size();
int resCount = 0;
for (String szId : msgIds) {
assertFalse(String.format("Request %d, result %d, encountered duplicate ID %s. Previously seen at %d", recCount, resCount, szId, seenIds.indexOf(szId)), seenIds.contains(szId));
seenIds.add(szId);
resCount++;
}
//jetty sometimes crashes on Mac when bombarded with request without a timeout
Thread.sleep(100);
offset += incLimit;
}
assertEquals("Returned incorrect number of conversations", numMessages, seenIds.size());
} catch (ServiceException e) {
e.printStackTrace();
fail(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of com.zimbra.client.ZSearchParams in project zm-mailbox by Zimbra.
the class TestLongSearchResultSets method testMessages2.
@Test
public void testMessages2() {
try {
Mailbox recieverMbox = TestUtil.getMailbox(RECIPIENT2);
long timestamp = System.currentTimeMillis() - 3600 * 60 * 1000;
int numMessages = 2257;
int firstLimit = 100;
int incLimit = 50;
int offset = 0;
ArrayList<String> expectedIds = new ArrayList<String>();
for (int i = 0; i < numMessages; i++) {
Message msg = TestUtil.addMessage(recieverMbox, TestUtil.getAddress(RECIPIENT2), TestUtil.getAddress(SENDER), NAME_PREFIX + " testing bug " + i, String.format("this message contains a search string %s which we are searching for and a number %d and timestamp %d", SEARCH_STRING, i, timestamp), timestamp);
expectedIds.add(Integer.toString(msg.getId()));
timestamp += 1000;
Thread.sleep(100);
}
Collections.reverse(expectedIds);
Thread.sleep(100);
ZMailbox zmbx = TestUtil.getZMailbox(RECIPIENT2);
ZSearchParams searchParams = new ZSearchParams("in:inbox " + SEARCH_STRING);
searchParams.setSortBy(SearchSortBy.dateDesc);
searchParams.setLimit(firstLimit);
searchParams.setTypes(ZSearchParams.TYPE_MESSAGE);
List<String> msgIds = TestUtil.searchMessageIds(zmbx, searchParams);
assertEquals(firstLimit, msgIds.size());
int gotMessages = msgIds.size();
List<String> seenIds = new ArrayList<String>();
seenIds.addAll(msgIds);
int recCount = 1;
offset += firstLimit;
while (gotMessages > 0) {
searchParams = new ZSearchParams("in:inbox " + SEARCH_STRING);
searchParams.setSortBy(SearchSortBy.dateDesc);
searchParams.setLimit(incLimit);
searchParams.setTypes(ZSearchParams.TYPE_MESSAGE);
searchParams.setOffset(offset);
msgIds = TestUtil.searchMessageIds(zmbx, searchParams);
recCount++;
gotMessages = msgIds.size();
int resCount = 0;
for (String szId : msgIds) {
assertFalse(String.format("Request %d, result %d, encountered duplicate ID %s. Previously seen at %d", recCount, resCount, szId, seenIds.indexOf(szId)), seenIds.contains(szId));
seenIds.add(szId);
resCount++;
}
//jetty sometimes crashes on Mac when bombarded with request without a timeout
Thread.sleep(100);
offset += incLimit;
}
for (int i = 0; i < expectedIds.size(); i++) {
assertEquals("IDs at index " + i + " do not match", expectedIds.get(i), seenIds.get(i));
}
assertEquals("Returned incorrect number of messages", numMessages, seenIds.size());
} catch (ServiceException e) {
e.printStackTrace();
fail(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of com.zimbra.client.ZSearchParams in project zm-mailbox by Zimbra.
the class TestMinusOperator method testExcludeText.
@Test
public void testExcludeText() throws ServiceException {
ZSearchResult search1 = mbox.search(new ZSearchParams("in:sent test"));
//control
assertEquals(search1.getHits().size(), 1);
ZSearchResult search2 = mbox.search(new ZSearchParams("in:sent -test"));
assertEquals(search2.getHits().size(), 0);
}
use of com.zimbra.client.ZSearchParams in project zm-mailbox by Zimbra.
the class TestUtil method deleteMessages.
private static void deleteMessages(ZMailbox mbox, String query) throws ServiceException {
// Delete messages
ZSearchParams params = new ZSearchParams(query);
params.setTypes(ZSearchParams.TYPE_MESSAGE);
List<ZSearchHit> hits = mbox.search(params).getHits();
if (hits.size() > 0) {
List<String> ids = new ArrayList<String>();
for (ZSearchHit hit : hits) {
ids.add(hit.getId());
}
mbox.deleteMessage(StringUtil.join(",", ids));
}
}
Aggregations