Fixes some history searches where some files were skipped if the the start timestamp we filter is the same as the filename (filename is the time it was created) and filtering some dates by period now is inclusive for the start of the period.

cusax-fix
Damian Minkov 12 years ago
parent 1a94b834dd
commit e130c9ece9

@ -602,7 +602,7 @@ private QueryResultSet<HistoryRecord> find(
}
}
// if maximum value is not reached fire an event
// if maximum value is not reached fire an event
if((int)currentProgress
< HistorySearchProgressListener.PROGRESS_MAXIMUM_VALUE)
{
@ -624,21 +624,21 @@ private QueryResultSet<HistoryRecord> find(
*/
static boolean isInPeriod(Date timestamp, Date startDate, Date endDate)
{
Long startLong;
Long endLong;
Long tsLong = timestamp.getTime();
if(startDate == null)
{
if(endDate == null)
return true;
else
return timestamp.before(endDate);
}
startLong = Long.MIN_VALUE;
else
{
if(endDate == null)
return timestamp.after(startDate);
else
return
timestamp.after(startDate) && timestamp.before(endDate);
}
startLong = startDate.getTime();
if(endDate == null)
endLong = Long.MAX_VALUE;
else
endLong = endDate.getTime();
return startLong <= tsLong && tsLong < endLong;
}
/**
@ -803,70 +803,40 @@ public int compare(String o1, String o2)
// Temporary fix of a NoSuchElementException
if(files.size() == 0)
{
Vector<String> result = new Vector<String>();
Iterator<Long> iter = resultAsLong.iterator();
while (iter.hasNext())
{
Long item = iter.next();
result.add(item.toString() + ".xml");
}
return result;
return new Vector<String>();
}
// if there is no startDate limit only to end date
Long startLong;
Long endLong;
if(startDate == null)
{
Long endLong = Long.valueOf(endDate.getTime());
files.add(endLong);
startLong = Long.MIN_VALUE;
else
startLong = startDate.getTime();
resultAsLong.addAll(files.subSet(files.first(), endLong));
if(endDate == null)
endLong = Long.MAX_VALUE;
else
endLong = endDate.getTime();
resultAsLong.remove(endLong);
}
else if(endDate == null)
// get all records inclusive the one before the startdate
for(Long f : files)
{
// end date is null get all the inclusive the one record before the startdate
Long startLong = Long.valueOf(startDate.getTime());
if(files.size() > 0 &&
(startLong.longValue() < (files.first()).longValue()))
if(startLong <= f
&& f <= endLong)
{
// if the start date is before any existing file date
// then return all the files
resultAsLong = files;
}
else
{
files.add(startLong);
resultAsLong.addAll(files.subSet(startLong, files.last()));
resultAsLong.add(files.last());
// here we must get and the element before startLong
resultAsLong.add(files.subSet(files.first(), startLong).last());
resultAsLong.remove(startLong);
resultAsLong.add(f);
}
}
else
// get the subset before the start date, to get its last element
// if exists
if(!files.isEmpty() && files.first() <= startLong)
{
// if both are present we must return all the elements between
// the two dates and the one before the start date
Long startLong = Long.valueOf(startDate.getTime());
Long endLong = Long.valueOf(endDate.getTime());
files.add(startLong);
files.add(endLong);
resultAsLong.addAll(files.subSet(startLong, endLong));
// here we must get and the element before startLong
SortedSet<Long> theFirstToStart
= files.subSet(files.first(), startLong);
if(!theFirstToStart.isEmpty())
resultAsLong.add(theFirstToStart.last());
resultAsLong.remove(startLong);
resultAsLong.remove(endLong);
SortedSet<Long> setBeforeTheInterval =
files.subSet(files.first(), true, startLong, true);
if(!setBeforeTheInterval.isEmpty())
resultAsLong.add(setBeforeTheInterval.last());
}
Vector<String> result = new Vector<String>();

@ -199,6 +199,7 @@ public void writeRecords()
mockBImOpSet.deliverMessage(TEST_CONTACT_NAME_2, messagesToSend[0]);
TestMsgHistoryService.controlDate1 = new Date();
logger.info("controlDate1:" + controlDate1.getTime());
Object lock = new Object();
synchronized (lock)
@ -218,6 +219,7 @@ public void writeRecords()
mockBImOpSet.deliverMessage(TEST_CONTACT_NAME_2, messagesToSend[2]);
TestMsgHistoryService.controlDate2 = new Date();
logger.info("controlDate2:" + controlDate1.getTime());
synchronized (lock)
{
// wait a moment
@ -314,7 +316,7 @@ public void readRecords()
msgs = getMessages(rs);
assertEquals("Messages must be 2", msgs.size(), 2);
assertEquals("Messages must be 2", 2, msgs.size());
assertTrue("Message no found",
msgs.contains(messagesToSend[1].getContent()));
@ -331,7 +333,7 @@ public void readRecords()
msgs = getMessages(rs);
assertEquals("Messages must be 1", msgs.size(), 1);
assertEquals("Messages must be 1", 1, msgs.size());
assertTrue("Message no found",
msgs.contains(messagesToSend[1].getContent()));
@ -342,7 +344,7 @@ public void readRecords()
assertTrue("Nothing found findByStartDate", !rs.isEmpty());
msgs = getMessages(rs);
assertEquals("Messages must be 2", msgs.size(), 2);
assertEquals("Messages must be 2", 2, msgs.size());
assertTrue("Message no found",
msgs.contains(messagesToSend[3].getContent()));
assertTrue("Message no found",
@ -355,7 +357,7 @@ public void readRecords()
assertTrue("Nothing found 8", !rs.isEmpty());
msgs = getMessages(rs);
assertEquals("Messages must be 3", msgs.size(), 3);
assertEquals("Messages must be 3", 3, msgs.size());
assertTrue("Message no found",
msgs.contains(messagesToSend[2].getContent()));
assertTrue("Message no found",
@ -370,7 +372,7 @@ public void readRecords()
assertTrue("Nothing found 9", !rs.isEmpty());
msgs = getMessages(rs);
assertEquals("Messages must be 3", msgs.size(), 3);
assertEquals("Messages must be 3", 3, msgs.size());
assertTrue("Message no found",
msgs.contains(messagesToSend[1].getContent()));
assertTrue("Message no found",
@ -385,7 +387,7 @@ public void readRecords()
assertTrue("Nothing found 10", !rs.isEmpty());
msgs = getMessages(rs);
assertEquals("Messages must be 3", msgs.size(), 3);
assertEquals("Messages must be 3", 3, msgs.size());
assertTrue("Message no found",
msgs.contains(messagesToSend[0].getContent()));
assertTrue("Message no found",
@ -408,7 +410,7 @@ private static void waitWrite(long timeout)
}
}
}
public void writeRecordsToMultiChat()
{
try
@ -422,28 +424,31 @@ public void writeRecordsToMultiChat()
// First deliver message, so they are stored by the message history service
room.sendMessage(messagesToSend[0]);
waitWrite(100);
TestMsgHistoryService.controlDate1 = new Date();
logger.info("controlDate1:" + controlDate1.getTime());
waitWrite(200);
waitWrite(100);
room.sendMessage(messagesToSend[1]);
waitWrite(200);
waitWrite(100);
room.sendMessage(messagesToSend[2]);
TestMsgHistoryService.controlDate2 = new Date();
waitWrite(200);
logger.info("controlDate2:" + controlDate2.getTime());
waitWrite(100);
room.sendMessage(messagesToSend[3]);
waitWrite(200);
waitWrite(100);
room.sendMessage(messagesToSend[4]);
waitWrite(200);
waitWrite(100);
}
catch(OperationFailedException ex)
{
@ -542,7 +547,7 @@ public void readRecordsFromMultiChat()
msgs = getChatMessages(rs);
assertEquals("Messages must be 2", msgs.size(), 2);
assertEquals("Messages must be 2", 2, msgs.size());
assertTrue("Message no found",
msgs.contains(messagesToSend[1].getContent()));
@ -559,7 +564,7 @@ public void readRecordsFromMultiChat()
msgs = getChatMessages(rs);
assertEquals("Messages must be 1", msgs.size(), 1);
assertEquals("Messages must be 1", 1, msgs.size());
assertTrue("Message no found",
msgs.contains(messagesToSend[1].getContent()));
@ -570,7 +575,7 @@ public void readRecordsFromMultiChat()
assertTrue("Nothing found findByStartDate", !rs.isEmpty());
msgs = getChatMessages(rs);
assertEquals("Messages must be 2", msgs.size(), 2);
assertEquals("Messages must be 2", 2, msgs.size());
assertTrue("Message no found",
msgs.contains(messagesToSend[3].getContent()));
assertTrue("Message no found",
@ -583,7 +588,7 @@ public void readRecordsFromMultiChat()
assertTrue("Nothing found 8", !rs.isEmpty());
msgs = getChatMessages(rs);
assertEquals("Messages must be 3", msgs.size(), 3);
assertEquals("Messages must be 3", 3, msgs.size());
assertTrue("Message no found",
msgs.contains(messagesToSend[2].getContent()));
assertTrue("Message no found",
@ -598,7 +603,7 @@ public void readRecordsFromMultiChat()
assertTrue("Nothing found 9", !rs.isEmpty());
msgs = getChatMessages(rs);
assertEquals("Messages must be 3", msgs.size(), 3);
assertEquals("Messages must be 3", 3, msgs.size());
assertTrue("Message no found",
msgs.contains(messagesToSend[1].getContent()));
assertTrue("Message no found",
@ -613,7 +618,7 @@ public void readRecordsFromMultiChat()
assertTrue("Nothing found 10", !rs.isEmpty());
msgs = getChatMessages(rs);
assertEquals("Messages must be 3", msgs.size(), 3);
assertEquals("Messages must be 3", 3, msgs.size());
assertTrue("Message no found",
msgs.contains(messagesToSend[0].getContent()));
assertTrue("Message no found",

Loading…
Cancel
Save