Преглед на файлове

2009-01-24 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Replaced FileAllocationMan with
	SequentialPicker<FileAllocationEntry>.
	* src/BtCheckIntegrityEntry.cc
	* src/ConsoleStatCalc.cc
	* src/DownloadEngine.cc
	* src/DownloadEngine.h
	* src/DownloadEngineFactory.cc
	* src/FileAllocationCommand.cc
	* src/FileAllocationDispatcherCommand.cc
	* src/FileAllocationMan.h
	* src/Makefile.am
	* src/SequentialPicker.h
	* src/StatCalc.h
	* src/StreamCheckIntegrityEntry.cc
	* test/Makefile.am
	* test/SequentialPickerTest.cc
Tatsuhiro Tsujikawa преди 16 години
родител
ревизия
8ca9db9f3e

+ 19 - 0
ChangeLog

@@ -1,3 +1,22 @@
+2009-01-24  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Replaced FileAllocationMan with
+	SequentialPicker<FileAllocationEntry>.
+	* src/BtCheckIntegrityEntry.cc
+	* src/ConsoleStatCalc.cc
+	* src/DownloadEngine.cc
+	* src/DownloadEngine.h
+	* src/DownloadEngineFactory.cc
+	* src/FileAllocationCommand.cc
+	* src/FileAllocationDispatcherCommand.cc
+	* src/FileAllocationMan.h
+	* src/Makefile.am
+	* src/SequentialPicker.h
+	* src/StatCalc.h
+	* src/StreamCheckIntegrityEntry.cc
+	* test/Makefile.am
+	* test/SequentialPickerTest.cc
+
 2009-01-19  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	Added doc for adaptive URI selector.

+ 1 - 1
src/BtCheckIntegrityEntry.cc

@@ -54,7 +54,7 @@ void BtCheckIntegrityEntry::onDownloadIncomplete(std::deque<Command*>& commands,
 {
   FileAllocationEntryHandle entry(new BtFileAllocationEntry(_requestGroup));
   if(_requestGroup->needsFileAllocation()) {
-    e->_fileAllocationMan->pushFileAllocationEntry(entry);
+    e->_fileAllocationMan->pushEntry(entry);
   } else {
     entry->prepareForNextAction(commands, e);
   }

+ 7 - 6
src/ConsoleStatCalc.cc

@@ -162,9 +162,10 @@ ConsoleStatCalc::ConsoleStatCalc(time_t summaryInterval):
 {}
 
 void
-ConsoleStatCalc::calculateStat(const RequestGroupManHandle& requestGroupMan,
-			       const FileAllocationManHandle& fileAllocationMan,
-			       const CheckIntegrityManHandle& checkIntegrityMan)
+ConsoleStatCalc::calculateStat
+(const RequestGroupManHandle& requestGroupMan,
+ const SharedHandle<FileAllocationMan>& fileAllocationMan,
+ const CheckIntegrityManHandle& checkIntegrityMan)
 {
   if(!_cp.elapsed(1)) {
     return;
@@ -211,7 +212,7 @@ ConsoleStatCalc::calculateStat(const RequestGroupManHandle& requestGroupMan,
   }
 
   {
-    FileAllocationEntryHandle entry = fileAllocationMan->getCurrentFileAllocationEntry();
+    SharedHandle<FileAllocationEntry> entry=fileAllocationMan->getPickedEntry();
     if(!entry.isNull()) {
       o << " "
 	<< "[FileAlloc:"
@@ -229,9 +230,9 @@ ConsoleStatCalc::calculateStat(const RequestGroupManHandle& requestGroupMan,
       }
       o << "%)"
 	<< "]";
-      if(fileAllocationMan->countFileAllocationEntryInQueue() > 0) {
+      if(fileAllocationMan->hasNext()) {
 	o << "("
-	  << fileAllocationMan->countFileAllocationEntryInQueue()
+	  << fileAllocationMan->countEntryInQueue()
 	  << "waiting...)";
       }
     }

+ 1 - 1
src/DownloadEngine.cc

@@ -44,7 +44,6 @@
 #include "StatCalc.h"
 #include "RequestGroup.h"
 #include "RequestGroupMan.h"
-#include "FileAllocationMan.h"
 #include "CheckIntegrityMan.h"
 #include "DownloadResult.h"
 #include "StatCalc.h"
@@ -65,6 +64,7 @@
 #include "Request.h"
 #include "EventPoll.h"
 #include "Command.h"
+#include "FileAllocationEntry.h"
 
 #include "BtRegistry.h"
 #include "BtContext.h"

+ 1 - 1
src/DownloadEngine.h

@@ -49,13 +49,13 @@
 # include "AsyncNameResolver.h"
 #endif // ENABLE_ASYNC_DNS
 #include "CUIDCounter.h"
+#include "FileAllocationMan.h"
 
 namespace aria2 {
 
 class Logger;
 class Option;
 class RequestGroupMan;
-class FileAllocationMan;
 class StatCalc;
 class CheckIntegrityMan;
 class SocketCore;

+ 1 - 0
src/DownloadEngineFactory.cc

@@ -60,6 +60,7 @@
 #endif // HAVE_EPOLL
 #include "SelectEventPoll.h"
 #include "DlAbortEx.h"
+#include "FileAllocationEntry.h"
 
 namespace aria2 {
 

+ 2 - 2
src/FileAllocationCommand.cc

@@ -60,7 +60,7 @@ bool FileAllocationCommand::executeInternal()
     logger->debug(MSG_ALLOCATION_COMPLETED,
 		  _timer.difference(),
 		  Util::itos(_requestGroup->getTotalLength(), true).c_str());
-    _e->_fileAllocationMan->markCurrentFileAllocationEntryDone();
+    _e->_fileAllocationMan->dropPickedEntry();
     
     std::deque<Command*> commands;
     _fileAllocationEntry->prepareForNextAction(commands, _e);
@@ -75,7 +75,7 @@ bool FileAllocationCommand::executeInternal()
 
 bool FileAllocationCommand::handleException(Exception& e)
 {
-  _e->_fileAllocationMan->markCurrentFileAllocationEntryDone();
+  _e->_fileAllocationMan->dropPickedEntry();
   logger->error(MSG_FILE_ALLOCATION_FAILURE, e, cuid);
   logger->error(MSG_DOWNLOAD_NOT_COMPLETE, cuid, _requestGroup->getFilePath().c_str());
   return true;

+ 2 - 3
src/FileAllocationDispatcherCommand.cc

@@ -56,9 +56,8 @@ bool FileAllocationDispatcherCommand::execute()
   if(_e->_requestGroupMan->downloadFinished() || _e->isHaltRequested()) {
     return true;
   }
-  if(_e->_fileAllocationMan->nextFileAllocationEntryExists() &&
-     !_e->_fileAllocationMan->isFileAllocationBeingExecuted()) {
-    FileAllocationEntryHandle entry = _e->_fileAllocationMan->popNextFileAllocationEntry();
+  if(_e->_fileAllocationMan->hasNext() && !_e->_fileAllocationMan->isPicked()) {
+    FileAllocationEntryHandle entry = _e->_fileAllocationMan->pickNext();
     int32_t newCUID = _e->newCUID();
     logger->info(MSG_FILE_ALLOCATION_DISPATCH, newCUID);
     FileAllocationCommand* command =

+ 2 - 27
src/FileAllocationMan.h

@@ -36,38 +36,13 @@
 #define _D_FILE_ALLOCATION_MAN_H_
 
 #include "common.h"
-#include "SharedHandle.h"
-#include <deque>
+#include "SequentialPicker.h"
 
 namespace aria2 {
 
 class FileAllocationEntry;
 
-class FileAllocationMan {
-private:
-  std::deque<SharedHandle<FileAllocationEntry> > _fileAllocationEntries;
-  SharedHandle<FileAllocationEntry> _currentFileAllocationEntry;
-public:
-  FileAllocationMan();
-
-  ~FileAllocationMan();
-
-  bool isFileAllocationBeingExecuted() const;
-
-  SharedHandle<FileAllocationEntry> getCurrentFileAllocationEntry();
-
-  void markCurrentFileAllocationEntryDone();
-
-  bool nextFileAllocationEntryExists() const;
-
-  SharedHandle<FileAllocationEntry> popNextFileAllocationEntry();
-
-  void pushFileAllocationEntry(const SharedHandle<FileAllocationEntry>& entry);
-
-  size_t countFileAllocationEntryInQueue() const;
-};
-
-typedef SharedHandle<FileAllocationMan> FileAllocationManHandle;
+typedef SequentialPicker<FileAllocationEntry> FileAllocationMan;
 
 } // namespace aria2
 

+ 3 - 2
src/Makefile.am

@@ -84,7 +84,7 @@ SRCS =  Socket.h\
 	RequestGroup.cc RequestGroup.h\
 	RequestGroupAware.cc RequestGroupAware.h\
 	RequestGroupMan.cc RequestGroupMan.h\
-	FileAllocationMan.cc FileAllocationMan.h\
+	FileAllocationMan.h\
 	FileAllocationCommand.cc FileAllocationCommand.h\
 	FillRequestGroupCommand.cc FillRequestGroupCommand.h\
 	FileAllocationDispatcherCommand.cc FileAllocationDispatcherCommand.h\
@@ -198,7 +198,8 @@ SRCS =  Socket.h\
 	bencode.cc bencode.h\
 	URIResult.cc URIResult.h\
 	EventPoll.h\
-	SelectEventPoll.cc SelectEventPoll.h
+	SelectEventPoll.cc SelectEventPoll.h\
+	SequentialPicker.h
 
 if HAVE_EPOLL
 SRCS += EpollEventPoll.cc EpollEventPoll.h

+ 17 - 19
src/Makefile.in

@@ -341,10 +341,9 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
 	NameMatchOptionHandler.h NameResolver.cc NameResolver.h \
 	RequestGroup.cc RequestGroup.h RequestGroupAware.cc \
 	RequestGroupAware.h RequestGroupMan.cc RequestGroupMan.h \
-	FileAllocationMan.cc FileAllocationMan.h \
-	FileAllocationCommand.cc FileAllocationCommand.h \
-	FillRequestGroupCommand.cc FillRequestGroupCommand.h \
-	FileAllocationDispatcherCommand.cc \
+	FileAllocationMan.h FileAllocationCommand.cc \
+	FileAllocationCommand.h FillRequestGroupCommand.cc \
+	FillRequestGroupCommand.h FileAllocationDispatcherCommand.cc \
 	FileAllocationDispatcherCommand.h FileAllocationEntry.cc \
 	FileAllocationEntry.h StreamFileAllocationEntry.cc \
 	StreamFileAllocationEntry.h MultiUrlRequestInfo.cc \
@@ -414,8 +413,8 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
 	SocketBuffer.h OptionHandlerException.cc \
 	OptionHandlerException.h bencode.cc bencode.h URIResult.cc \
 	URIResult.h EventPoll.h SelectEventPoll.cc SelectEventPoll.h \
-	EpollEventPoll.cc EpollEventPoll.h TLSContext.h \
-	LibgnutlsTLSContext.cc LibgnutlsTLSContext.h \
+	SequentialPicker.h EpollEventPoll.cc EpollEventPoll.h \
+	TLSContext.h LibgnutlsTLSContext.cc LibgnutlsTLSContext.h \
 	LibsslTLSContext.cc LibsslTLSContext.h GZipDecoder.cc \
 	GZipDecoder.h Sqlite3MozCookieParser.cc \
 	Sqlite3MozCookieParser.h AsyncNameResolver.cc \
@@ -764,7 +763,7 @@ am__objects_22 = SocketCore.$(OBJEXT) Command.$(OBJEXT) \
 	OptionHandlerFactory.$(OBJEXT) OptionHandler.$(OBJEXT) \
 	NameResolver.$(OBJEXT) RequestGroup.$(OBJEXT) \
 	RequestGroupAware.$(OBJEXT) RequestGroupMan.$(OBJEXT) \
-	FileAllocationMan.$(OBJEXT) FileAllocationCommand.$(OBJEXT) \
+	FileAllocationCommand.$(OBJEXT) \
 	FillRequestGroupCommand.$(OBJEXT) \
 	FileAllocationDispatcherCommand.$(OBJEXT) \
 	FileAllocationEntry.$(OBJEXT) \
@@ -1068,10 +1067,9 @@ SRCS = Socket.h SocketCore.cc SocketCore.h BinaryStream.h Command.cc \
 	NameMatchOptionHandler.h NameResolver.cc NameResolver.h \
 	RequestGroup.cc RequestGroup.h RequestGroupAware.cc \
 	RequestGroupAware.h RequestGroupMan.cc RequestGroupMan.h \
-	FileAllocationMan.cc FileAllocationMan.h \
-	FileAllocationCommand.cc FileAllocationCommand.h \
-	FillRequestGroupCommand.cc FillRequestGroupCommand.h \
-	FileAllocationDispatcherCommand.cc \
+	FileAllocationMan.h FileAllocationCommand.cc \
+	FileAllocationCommand.h FillRequestGroupCommand.cc \
+	FillRequestGroupCommand.h FileAllocationDispatcherCommand.cc \
 	FileAllocationDispatcherCommand.h FileAllocationEntry.cc \
 	FileAllocationEntry.h StreamFileAllocationEntry.cc \
 	StreamFileAllocationEntry.h MultiUrlRequestInfo.cc \
@@ -1141,13 +1139,14 @@ SRCS = Socket.h SocketCore.cc SocketCore.h BinaryStream.h Command.cc \
 	SocketBuffer.h OptionHandlerException.cc \
 	OptionHandlerException.h bencode.cc bencode.h URIResult.cc \
 	URIResult.h EventPoll.h SelectEventPoll.cc SelectEventPoll.h \
-	$(am__append_1) $(am__append_2) $(am__append_3) \
-	$(am__append_4) $(am__append_5) $(am__append_6) \
-	$(am__append_7) $(am__append_8) $(am__append_9) \
-	$(am__append_10) $(am__append_11) $(am__append_12) \
-	$(am__append_13) $(am__append_14) $(am__append_15) \
-	$(am__append_16) $(am__append_17) $(am__append_18) \
-	$(am__append_19) $(am__append_20) $(am__append_21)
+	SequentialPicker.h $(am__append_1) $(am__append_2) \
+	$(am__append_3) $(am__append_4) $(am__append_5) \
+	$(am__append_6) $(am__append_7) $(am__append_8) \
+	$(am__append_9) $(am__append_10) $(am__append_11) \
+	$(am__append_12) $(am__append_13) $(am__append_14) \
+	$(am__append_15) $(am__append_16) $(am__append_17) \
+	$(am__append_18) $(am__append_19) $(am__append_20) \
+	$(am__append_21)
 noinst_LIBRARIES = libaria2c.a
 libaria2c_a_SOURCES = $(SRCS)
 aria2c_LDADD = libaria2c.a @LIBINTL@ @ALLOCA@ @LIBGNUTLS_LIBS@\
@@ -1382,7 +1381,6 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/FileAllocationCommand.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/FileAllocationDispatcherCommand.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/FileAllocationEntry.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/FileAllocationMan.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/FileEntry.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/FileMetalinkParserState.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/FilesMetalinkParserState.Po@am__quote@

+ 96 - 0
src/SequentialPicker.h

@@ -0,0 +1,96 @@
+/* <!-- copyright */
+/*
+ * aria2 - The high speed download utility
+ *
+ * Copyright (C) 2009 Tatsuhiro Tsujikawa
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * In addition, as a special exception, the copyright holders give
+ * permission to link the code of portions of this program with the
+ * OpenSSL library under certain conditions as described in each
+ * individual source file, and distribute linked combinations
+ * including the two.
+ * You must obey the GNU General Public License in all respects
+ * for all of the code used other than OpenSSL.  If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so.  If you
+ * do not wish to do so, delete this exception statement from your
+ * version.  If you delete this exception statement from all source
+ * files in the program, then also delete it here.
+ */
+/* copyright --> */
+#ifndef _D_SEQUENTIAL_PICKER_H_
+#define _D_SEQUENTIAL_PICKER_H_
+
+#include "common.h"
+
+#include <deque>
+
+#include "SharedHandle.h"
+
+namespace aria2 {
+
+template<typename T>
+class SequentialPicker {
+private:
+  std::deque<SharedHandle<T> > _entries;
+  SharedHandle<T> _pickedEntry;
+public:
+  bool isPicked() const
+  {
+    return !_pickedEntry.isNull();
+  }
+
+  SharedHandle<T> getPickedEntry() const
+  {
+    return _pickedEntry;
+  }
+
+  void dropPickedEntry()
+  {
+    _pickedEntry.reset();
+  }
+
+  bool hasNext() const
+  {
+    return !_entries.empty();
+  }
+
+  SharedHandle<T> pickNext()
+  {
+    SharedHandle<T> r;
+    if(hasNext()) {
+      r = _entries.front();
+      _entries.pop_front();
+      _pickedEntry = r;
+    }
+    return r;
+  }
+
+  void pushEntry(const SharedHandle<T>& entry)
+  {
+    _entries.push_back(entry);
+  }
+
+  size_t countEntryInQueue() const
+  {
+    return _entries.size();
+  }
+};
+
+} // namespace aria2
+
+#endif // _D_SEQUENTIAL_PICKER_H_

+ 1 - 1
src/StatCalc.h

@@ -37,11 +37,11 @@
 
 #include "common.h"
 #include "SharedHandle.h"
+#include "FileAllocationMan.h"
 
 namespace aria2 {
 
 class RequestGroupMan;
-class FileAllocationMan;
 class CheckIntegrityMan;
 
 class StatCalc {

+ 1 - 1
src/StreamCheckIntegrityEntry.cc

@@ -57,7 +57,7 @@ void StreamCheckIntegrityEntry::onDownloadIncomplete(std::deque<Command*>& comma
     (new StreamFileAllocationEntry(_currentRequest, _requestGroup,
 				   popNextCommand()));
   if(_requestGroup->needsFileAllocation()) {
-    e->_fileAllocationMan->pushFileAllocationEntry(entry);
+    e->_fileAllocationMan->pushEntry(entry);
   } else {
     entry->prepareForNextAction(commands, e);
   }

+ 2 - 1
test/Makefile.am

@@ -64,7 +64,8 @@ aria2c_SOURCES = AllTest.cc\
 	OptionParserTest.cc\
 	SimpleDNSCacheTest.cc\
 	DownloadHelperTest.cc\
-	BencodeTest.cc
+	BencodeTest.cc\
+	SequentialPickerTest.cc
 
 if HAVE_LIBZ
 aria2c_SOURCES += GZipDecoderTest.cc

+ 10 - 7
test/Makefile.in

@@ -192,8 +192,9 @@ am__aria2c_SOURCES_DIST = AllTest.cc TestUtil.cc TestUtil.h \
 	DirectDiskAdaptorTest.cc CookieTest.cc CookieStorageTest.cc \
 	TimeTest.cc CopyDiskAdaptorTest.cc FtpConnectionTest.cc \
 	OptionParserTest.cc SimpleDNSCacheTest.cc \
-	DownloadHelperTest.cc BencodeTest.cc GZipDecoderTest.cc \
-	Sqlite3MozCookieParserTest.cc MessageDigestHelperTest.cc \
+	DownloadHelperTest.cc BencodeTest.cc SequentialPickerTest.cc \
+	GZipDecoderTest.cc Sqlite3MozCookieParserTest.cc \
+	MessageDigestHelperTest.cc \
 	IteratableChunkChecksumValidatorTest.cc \
 	IteratableChecksumValidatorTest.cc BtAllowedFastMessageTest.cc \
 	BtBitfieldMessageTest.cc BtCancelMessageTest.cc \
@@ -360,8 +361,9 @@ am_aria2c_OBJECTS = AllTest.$(OBJEXT) TestUtil.$(OBJEXT) \
 	TimeTest.$(OBJEXT) CopyDiskAdaptorTest.$(OBJEXT) \
 	FtpConnectionTest.$(OBJEXT) OptionParserTest.$(OBJEXT) \
 	SimpleDNSCacheTest.$(OBJEXT) DownloadHelperTest.$(OBJEXT) \
-	BencodeTest.$(OBJEXT) $(am__objects_1) $(am__objects_2) \
-	$(am__objects_3) $(am__objects_4) $(am__objects_5)
+	BencodeTest.$(OBJEXT) SequentialPickerTest.$(OBJEXT) \
+	$(am__objects_1) $(am__objects_2) $(am__objects_3) \
+	$(am__objects_4) $(am__objects_5)
 aria2c_OBJECTS = $(am_aria2c_OBJECTS)
 am__DEPENDENCIES_1 =
 aria2c_DEPENDENCIES = ../src/libaria2c.a ../src/download_helper.o \
@@ -584,9 +586,9 @@ aria2c_SOURCES = AllTest.cc TestUtil.cc TestUtil.h SocketCoreTest.cc \
 	DirectDiskAdaptorTest.cc CookieTest.cc CookieStorageTest.cc \
 	TimeTest.cc CopyDiskAdaptorTest.cc FtpConnectionTest.cc \
 	OptionParserTest.cc SimpleDNSCacheTest.cc \
-	DownloadHelperTest.cc BencodeTest.cc $(am__append_1) \
-	$(am__append_2) $(am__append_3) $(am__append_4) \
-	$(am__append_5)
+	DownloadHelperTest.cc BencodeTest.cc SequentialPickerTest.cc \
+	$(am__append_1) $(am__append_2) $(am__append_3) \
+	$(am__append_4) $(am__append_5)
 
 #aria2c_CXXFLAGS = ${CPPUNIT_CFLAGS} -I../src -I../lib -Wall -D_FILE_OFFSET_BITS=64
 #aria2c_LDFLAGS = ${CPPUNIT_LIBS}
@@ -796,6 +798,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SegmentManTest.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SegmentTest.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SequenceTest.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SequentialPickerTest.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ServerStatManTest.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ServerStatTest.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ServerStatURISelectorTest.Po@am__quote@

+ 51 - 0
test/SequentialPickerTest.cc

@@ -0,0 +1,51 @@
+#include "SequentialPicker.h"
+
+#include <cppunit/extensions/HelperMacros.h>
+
+namespace aria2 {
+
+typedef SharedHandle<int> Integer;
+
+class SequentialPickerTest:public CppUnit::TestFixture {
+
+  CPPUNIT_TEST_SUITE(SequentialPickerTest);
+  CPPUNIT_TEST(testPick);
+  CPPUNIT_TEST_SUITE_END();
+public:
+  void testPick();
+};
+
+
+CPPUNIT_TEST_SUITE_REGISTRATION(SequentialPickerTest);
+
+void SequentialPickerTest::testPick()
+{
+  SequentialPicker<int> picker;
+  
+  CPPUNIT_ASSERT(!picker.isPicked());
+  CPPUNIT_ASSERT(!picker.hasNext());
+  CPPUNIT_ASSERT_EQUAL((size_t)0, picker.countEntryInQueue());
+
+  picker.pushEntry(Integer(new int(1)));
+  picker.pushEntry(Integer(new int(2)));
+
+  CPPUNIT_ASSERT(picker.hasNext());
+  CPPUNIT_ASSERT_EQUAL((size_t)2, picker.countEntryInQueue());
+
+  picker.pickNext();
+
+  CPPUNIT_ASSERT(picker.isPicked());
+  CPPUNIT_ASSERT_EQUAL(Integer(new int(1)), picker.getPickedEntry());
+
+  picker.dropPickedEntry();
+
+  CPPUNIT_ASSERT(!picker.isPicked());
+  CPPUNIT_ASSERT(picker.hasNext());
+
+  picker.pickNext();
+
+  CPPUNIT_ASSERT_EQUAL(Integer(new int(2)), picker.getPickedEntry());
+  CPPUNIT_ASSERT(!picker.hasNext());
+}
+
+} // namespace aria2