[SF 2632636] FileChannel Purge Unit Tests Broken

This commit is contained in:
Aleksandar Fabijanic
2009-04-02 13:10:20 +00:00
parent 614c87b4be
commit 8fe9757195
3 changed files with 46 additions and 10 deletions

View File

@@ -302,8 +302,14 @@ void FileChannel::setCompress(const std::string& compress)
void FileChannel::setPurgeAge(const std::string& age)
{
delete _pPurgeStrategy;
_pPurgeStrategy = 0;
_purgeAge = "none";
if (age.empty() || 0 == icompare(age, "none")) return;
std::string::const_iterator it = age.begin();
std::string::const_iterator end = age.end();
int n = 0;
while (it != end && std::isspace(*it)) ++it;
while (it != end && std::isdigit(*it)) { n *= 10; n += *it++ - '0'; }
@@ -324,8 +330,10 @@ void FileChannel::setPurgeAge(const std::string& age)
factor = 30*Timespan::DAYS;
else if (unit != "seconds")
throw InvalidArgumentException("purgeAge", age);
delete _pPurgeStrategy;
if (0 == n)
throw InvalidArgumentException("Zero is not valid purge age.");
_pPurgeStrategy = new PurgeByAgeStrategy(Timespan(factor*n));
_purgeAge = age;
}
@@ -333,14 +341,22 @@ void FileChannel::setPurgeAge(const std::string& age)
void FileChannel::setPurgeCount(const std::string& count)
{
delete _pPurgeStrategy;
_pPurgeStrategy = 0;
_purgeAge = "none";
if (count.empty() || 0 == icompare(count, "none")) return;
int n = 0;
std::string::const_iterator it = count.begin();
std::string::const_iterator end = count.end();
int n = 0;
while (it != end && std::isspace(*it)) ++it;
while (it != end && std::isdigit(*it)) { n *= 10; n += *it++ - '0'; }
while (it != end && std::isspace(*it)) ++it;
delete _pPurgeStrategy;
if (0 == n)
throw InvalidArgumentException("Zero is not valid purge count.");
_pPurgeStrategy = new PurgeByCountStrategy(n);
_purgeCount = count;
}