aria2/test/FallocFileAllocationIteratorTest.cc
Tatsuhiro Tsujikawa 29c5ef9215 2009-03-25 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added 'falloc' parameter for --file-allocation option.  'falloc'
	allocation mode uses posix_fallocate() system call to allocate
	file on disk.  If you are using newer file systems such as ext4
        (with extents support), btrfs or xfs, 'falloc' is your best
	choice. It allocates large(few GiB) files almost instantly.
	Don't use 'falloc' with legacy file systems such as ext3 because
	it takes almost same time as 'prealloc' and it blocks aria2
	entirely until allocation finishes. 'falloc' may not be
	available if your system doesn't have posix_fallocate() system
	call.
	* configure.ac
	* src/AbstractDiskWriter.cc
	* src/AbstractDiskWriter.h
	* src/AbstractSingleDiskAdaptor.cc
	* src/BinaryStream.h
	* src/BtCheckIntegrityEntry.cc
	* src/ByteArrayDiskWriter.h
	* src/CheckIntegrityEntry.cc
	* src/CheckIntegrityEntry.h
	* src/DefaultPieceStorage.cc
	* src/DiskAdaptor.cc
	* src/DiskAdaptor.h
	* src/DiskWriter.h
	* src/FallocFileAllocationIterator.cc
	* src/FallocFileAllocationIterator.h
	* src/FileAllocationEntry.cc
	* src/FileAllocationEntry.h
	* src/Makefile.am
	* src/MultiFileAllocationIterator.cc
	* src/MultiFileAllocationIterator.h
	* src/OptionHandlerFactory.cc
	* src/RequestGroup.cc
	* src/StreamCheckIntegrityEntry.cc
	* src/prefs.cc
	* src/prefs.h
	* src/usage_text.h
	* test/FallocFileAllocationIteratorTest.cc
	* test/Makefile.am
2009-03-25 05:43:07 +00:00

54 lines
1.2 KiB
C++

#include "FallocFileAllocationIterator.h"
#include <fstream>
#include <cppunit/extensions/HelperMacros.h>
#include "File.h"
#include "DefaultDiskWriter.h"
namespace aria2 {
class FallocFileAllocationIteratorTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(FallocFileAllocationIteratorTest);
CPPUNIT_TEST(testAllocate);
CPPUNIT_TEST_SUITE_END();
private:
public:
void setUp() {}
void testAllocate();
};
CPPUNIT_TEST_SUITE_REGISTRATION( FallocFileAllocationIteratorTest );
void FallocFileAllocationIteratorTest::testAllocate()
{
std::string dir = "/tmp";
std::string fname = "aria2_FallocFileAllocationIteratorTest_testAllocate";
std::string fn = dir+"/"+fname;
std::ofstream of(fn.c_str(), std::ios::binary);
of << "0123456789";
of.close();
File f(fn);
CPPUNIT_ASSERT_EQUAL((uint64_t)10, f.size());
DefaultDiskWriter writer;
int64_t offset = 10;
int64_t totalLength = 40960;
// we have to open file first.
writer.openExistingFile(fn);
FallocFileAllocationIterator itr(&writer, offset, totalLength);
itr.allocateChunk();
CPPUNIT_ASSERT(itr.finished());
CPPUNIT_ASSERT_EQUAL((uint64_t)40960, f.size());
}
} // namespace aria2