summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Mollekopf <mollekopf@kolabsys.com>2013-03-17 10:16:14 (GMT)
committerChristian Mollekopf <mollekopf@kolabsys.com>2013-03-17 10:16:14 (GMT)
commit8ab8333a3b3fcfea2b35ca0a931e933cc4762997 (patch)
treecf5bc6e6b233c2bed49e78c84a715658da95d748
parent9c49b2a7fe2709223bf5589b4b0291cdacea74d6 (diff)
downloadkolab-utils-statefile.tar.gz
Skip messages which are already in the statefile, and added statfile test.statefile
-rw-r--r--lib/jobs/fetchmessagesjob.cpp15
-rw-r--r--lib/jobs/fetchmessagesjob.h2
-rw-r--r--migrationutility/sourceaccount.cpp5
-rw-r--r--migrationutility/statefile.cpp7
-rw-r--r--migrationutility/statefile.h1
-rw-r--r--migrationutility/tests/migrationscenariotest.cpp46
6 files changed, 69 insertions, 7 deletions
diff --git a/lib/jobs/fetchmessagesjob.cpp b/lib/jobs/fetchmessagesjob.cpp
index ad7bafd..9f8d380 100644
--- a/lib/jobs/fetchmessagesjob.cpp
+++ b/lib/jobs/fetchmessagesjob.cpp
@@ -46,6 +46,11 @@ void FetchMessagesJob::setUidsToFetch(const QList< qint64 >& uids)
mUidsToFetch = uids;
}
+void FetchMessagesJob::setUidsToSkip(const QList< qint64 >& uids)
+{
+ mUidsToSkip = uids;
+}
+
void FetchMessagesJob::setTransient(bool transient)
{
mTransient = transient;
@@ -121,6 +126,10 @@ void FetchMessagesJob::onHeadersReceived( const QString &/*mailBox*/,
{
QMap <qint64, qint64 >::const_iterator it = sizes.begin();
for (;it != sizes.end(); it++) {
+ const qint64 uid = uids.value(it.key());
+ if (mUidsToSkip.contains(uid)) {
+ continue;
+ }
if ((mBatchSize + it.value()) >= mBatchSizeLimit) {
// Debug() << "Batch full " << (int)mBatchSize;
mBatchSize = 0;
@@ -130,7 +139,7 @@ void FetchMessagesJob::onHeadersReceived( const QString &/*mailBox*/,
}
}
mBatchSize += it.value();
- mTempSet.add(uids.value(it.key()));
+ mTempSet.add(uid);
}
}
@@ -139,7 +148,9 @@ void FetchMessagesJob::onHeadersFetchDone( KJob *job )
if ( job->error() ) {
Warning() << job->errorString();
}
- mBatches.append(mTempSet);
+ if (!mTempSet.isEmpty()) {
+ mBatches.append(mTempSet);
+ }
fetchNextBatch();
}
diff --git a/lib/jobs/fetchmessagesjob.h b/lib/jobs/fetchmessagesjob.h
index dcb8956..913ed5a 100644
--- a/lib/jobs/fetchmessagesjob.h
+++ b/lib/jobs/fetchmessagesjob.h
@@ -31,6 +31,7 @@ public:
virtual void start();
void setMaxNumberOfMessagesToFetch(int);
void setUidsToFetch(const QList<qint64> &uids);
+ void setUidsToSkip(const QList<qint64> &uids);
KIMAP::FetchJob::FetchScope &fetchScope();
//Controls wether mapping are collected or not (otherwise the functions below return nothing)
@@ -66,6 +67,7 @@ private:
QMap<qint64, KIMAP::MessageFlags> mFlags;
QMap<qint64, KIMAP::MessagePtr> mMessages;
QList<qint64> mUidsToFetch;
+ QList<qint64> mUidsToSkip;
int mNumberOfMessagesToFetch;
bool mTransient;
KIMAP::ImapSet mTempSet;
diff --git a/migrationutility/sourceaccount.cpp b/migrationutility/sourceaccount.cpp
index f365d1b..ed8ffaf 100644
--- a/migrationutility/sourceaccount.cpp
+++ b/migrationutility/sourceaccount.cpp
@@ -205,7 +205,7 @@ void KolabSourceAccount::recordSuccessfulMigration(const QList<Object> &objects,
foreach (const Object &obj, objects) {
uids << obj.imapUid;
}
- mStatefile.setMigratedUids(folder, uids);
+ mStatefile.appendMigratedUids(folder, uids);
}
}
@@ -251,6 +251,9 @@ QList< Object > KolabSourceAccount::getObjects(const QString& folder, const QLis
FetchMessagesJob* KolabSourceAccount::fetchObjects(const QString& folder)
{
FetchMessagesJob *fetchJob = new FetchMessagesJob(folder, mSession, this);
+ if (mStatefile.isValid()) {
+ fetchJob->setUidsToSkip(mStatefile.getMigratedUids(folder));
+ }
return fetchJob;
}
diff --git a/migrationutility/statefile.cpp b/migrationutility/statefile.cpp
index 6894135..5f378bd 100644
--- a/migrationutility/statefile.cpp
+++ b/migrationutility/statefile.cpp
@@ -59,6 +59,13 @@ void StateFile::setMigratedUids(const QString& folder, const QList<qint64> &uids
settings.endGroup();
}
+void StateFile::appendMigratedUids(const QString& folder, const QList< qint64 >& uids)
+{
+ QList<qint64> list = getMigratedUids(folder);
+ list.append(uids);
+ setMigratedUids(folder, list);
+}
+
bool StateFile::isValid()
{
return (!mFilename.isEmpty() && !mUser.isEmpty());
diff --git a/migrationutility/statefile.h b/migrationutility/statefile.h
index 4821498..8d30860 100644
--- a/migrationutility/statefile.h
+++ b/migrationutility/statefile.h
@@ -33,6 +33,7 @@ public:
QList<qint64> getMigratedUids(const QString &folder);
// void addMigratedUid(const QString &folder, qint64 uid);
void setMigratedUids(const QString& folder, const QList<qint64> &uids);
+ void appendMigratedUids(const QString& folder, const QList<qint64> &uids);
bool isValid();
private:
QString mFilename;
diff --git a/migrationutility/tests/migrationscenariotest.cpp b/migrationutility/tests/migrationscenariotest.cpp
index 5f4fb10..b659de8 100644
--- a/migrationutility/tests/migrationscenariotest.cpp
+++ b/migrationutility/tests/migrationscenariotest.cpp
@@ -18,6 +18,7 @@
#include <QObject>
#include <QTest>
#include <QDebug>
+#include <QFile>
#include <kolabobject.h>
#include "migrationutility/coordinationjob.h"
#include "migrationutility/kolabserver.h"
@@ -45,6 +46,7 @@ class MigrationScenarioTest: public QObject
QString adminpw;
qint16 port;
QList<Folder> folders;
+ QString statefilename;
Object createEvent(const QString &uid)
{
@@ -65,7 +67,8 @@ public:
user("john.doe@example.org"),
admin("cyrus-admin"),
adminpw("admin"),
- port(143)
+ port(143),
+ statefilename("/tmp/migrationscenarioteststatefile")
{
}
@@ -97,7 +100,7 @@ private:
account->cleanAccount();
}
- void executeMigration()
+ void executeMigration(bool useStatefile = false)
{
QObject obj;
//Copy main.cpp
@@ -105,6 +108,9 @@ private:
kolabSourceServer->setHost(sourcehost, port);
kolabSourceServer->setAdminCredentials(admin, adminpw);
kolabSourceServer->setSingleUser(user);
+ if (useStatefile) {
+ kolabSourceServer->setStatefile(statefilename);
+ }
KolabServer *kolabServer = new KolabServer(&obj);
kolabServer->setHost(targethost, port);
@@ -161,6 +167,8 @@ private slots:
void init()
{
+ QFile file(statefilename);
+ file.remove();
folders.clear();
}
@@ -233,11 +241,41 @@ private slots:
checkTargetAccount();
checkSourceAccount();
}
+
+ void testStatefile()
+ {
+ QList<Object> events;
+ events << createEvent(QString("uid1"));
+ events << createEvent(QString("uid2"));
+ const Object event3 = createEvent(QString("uid3"));
+ events << event3;
+ folders << Folder("Calendar", Kolab::EventType, events);
setupSourceAccount();
setupTargetAccount();
- executeMigration();
+ executeMigration(true);
+
+ //Check statefile
+ StateFile statefile(statefilename, user);
+ QList<qint64> migratedUids = statefile.getMigratedUids("Calendar");
+ QCOMPARE(migratedUids.size(), 3);
+
+ //Remove one event from statefile
+ qint64 toMigrate = migratedUids.takeLast();
+ statefile.setMigratedUids("Calendar", migratedUids);
+
+ //Redo migration, this time with the statefile
+ setupTargetAccount();
+ executeMigration(true);
+ StateFile statefile2(statefilename, user);
+ migratedUids = statefile2.getMigratedUids("Calendar");
+ QCOMPARE(migratedUids.size(), 3);
+ QVERIFY(migratedUids.contains(toMigrate));
+
+ //onyl one event was migrated
+ folders.clear();
+ folders << Folder("Calendar", Kolab::EventType, QList<Object>() << event3);
+ fillDefaultFolders(folders);
checkTargetAccount();
- checkSourceAccount();
}
};