void ConfigureTest::testConfigure() { ofstream config(configFile.c_str()); config << Configure::CacheFreeMinPercent << " : 5" << endl; config << Configure::CacheFreeMaxPercent << " : 10" << endl; config << Configure::CacheFileSizeRead << " : 1000000000" << endl; config << Configure::FileMaxSize << " : 8000000000" << endl; Configure configure; configure.Refresh(fileConfig); CPPUNIT_ASSERT( configure.GetValue(Configure::CacheFreeMinPercent) == "5"); CPPUNIT_ASSERT( configure.GetValueSize(Configure::CacheFreeMinPercent) == 5); CPPUNIT_ASSERT( configure.GetValue(Configure::CacheFreeMaxPercent) == "10"); CPPUNIT_ASSERT( configure.GetValueSize(Configure::CacheFreeMaxPercent) == 10); CPPUNIT_ASSERT( configure.GetValue(Configure::CacheFileSizeRead) == "1000000000"); CPPUNIT_ASSERT( configure.GetValueSize(Configure::CacheFileSizeRead) == 1000000000LL ); CPPUNIT_ASSERT( configure.GetValue(Configure::FileMaxSize) == "8000000000"); CPPUNIT_ASSERT( configure.GetValueSize(Configure::FileMaxSize) == 8000000000LL ); }
CacheMonitorServer::CacheMonitorServer() : folderCache_(Factory::GetCacheFolder()), folderMeta_(Factory::GetMetaFolder()), run_(true), minFreeSize_(0), maxFreeSize_(0), thread_(boost::thread(&CacheMonitorServer::ServerThread,this)) { struct statfs stat; if ( 0 != statfs(folderCache_.string().c_str(),&stat) ) { LogWarn(folderCache_); return; } off_t sizeFileSystemOnePercent = (off_t)stat.f_bsize * stat.f_blocks / 100; Configure * config = Factory::GetConfigure(); minFreeSize_ = config->GetValueSize(Configure::CacheFreeMinSize); off_t sizeMinFreePercent = sizeFileSystemOnePercent * config->GetValueSize(Configure::CacheFreeMinPercent); minFreeSize_ = max(minFreeSize_,sizeMinFreePercent); LogDebug(minFreeSize_); maxFreeSize_ = config->GetValueSize(Configure::CacheFreeMaxSize); off_t sizeMaxFreePercent = sizeFileSystemOnePercent * config->GetValueSize(Configure::CacheFreeMaxPercent); maxFreeSize_ = max(maxFreeSize_,sizeMaxFreePercent); LogDebug(maxFreeSize_); }