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

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

Loading…
Cancel
Save