}
}
@Test
public void testSynchronize() {
ILogResourceManager mgr = UIPlugin.getDefault().getLogResourceManager();
try {
int size = mgr.getAll().length;
loadLogFile("sample-1.log.xml");
createLogResource("UTF-8", Locale.getDefault(), getTimeZone());
assertNotNull(getLogResource());
assertTrue(getLogResource().getPK() == null);
mgr.add(getLogResource());
assertTrue(getLogResource().getPK() != null);
assertEquals(size + 1, mgr.getAll().length);
final SynchronizationResult[] result = new SynchronizationResult[1];
final CountDownLatch countDown = new CountDownLatch(1);
mgr.synchronize(getLogResource(), new IGenericCallback<SynchronizationResult>() {
/* (non-Javadoc)
* @see net.sf.logsaw.ui.IGenericCallback#doCallback(java.lang.Object)
*/
@Override
public void doCallback(SynchronizationResult payload) {
result[0] = payload;
countDown.countDown();
}
});
countDown.await();
assertTrue(IndexPlugin.getDefault().getIndexFile(getLogResource()).exists());
assertEquals(5, result[0].getNumberOfEntriesAdded());
assertEquals(5, IndexPlugin.getDefault().getIndexService().count(getLogResource()));
mgr.remove(getLogResource());
assertTrue(!IndexPlugin.getDefault().getIndexFile(getLogResource()).exists());
assertEquals(size, mgr.getAll().length);
} catch (Exception e) {
getLogger().error(e.getLocalizedMessage(), e);
fail("Exception should not occur: " + e.getLocalizedMessage());
}
}