now playlists scheduled too late (after init but before start) will
not get executed. solution for bug http://bugs.campware.org/view.php?id=757
This commit is contained in:
parent
bbd8fd552b
commit
3d402962aa
9 changed files with 189 additions and 21 deletions
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.1 $
|
||||
Version : $Revision: 1.2 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/eventScheduler/src/EventSchedulerTest.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -181,3 +181,56 @@ EventSchedulerTest :: firstTest(void)
|
|||
eventScheduler->stop();
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* A test to see what happens, when an event is scheduled after it should
|
||||
* have been initialized, but not to be started yet.
|
||||
* See http://bugs.campware.org/view.php?id=757 for details.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
EventSchedulerTest :: postInitTest(void)
|
||||
throw (CPPUNIT_NS::Exception)
|
||||
{
|
||||
Ptr<TestScheduledEvent>::Ref event;
|
||||
Ptr<TestEventContainer>::Ref container;
|
||||
Ptr<EventScheduler>::Ref eventScheduler;
|
||||
Ptr<ptime>::Ref now;
|
||||
Ptr<ptime>::Ref when;
|
||||
Ptr<time_duration>::Ref initTime;
|
||||
Ptr<time_duration>::Ref eventLength;
|
||||
Ptr<time_duration>::Ref granularity;
|
||||
TestScheduledEvent::State state;
|
||||
|
||||
/* time timeline for this test is:
|
||||
initialize - 10 sec
|
||||
start - now + 5sec
|
||||
stop - start + 3 sec
|
||||
*/
|
||||
|
||||
now = TimeConversion::now();
|
||||
when.reset(new ptime(*now + seconds(5)));
|
||||
initTime.reset(new time_duration(seconds(10)));
|
||||
eventLength.reset(new time_duration(seconds(3)));
|
||||
granularity.reset(new time_duration(seconds(1)));
|
||||
|
||||
event.reset(new TestScheduledEvent(when, initTime, eventLength));
|
||||
container.reset(new TestEventContainer(event));
|
||||
|
||||
eventScheduler.reset(new EventScheduler(container, granularity));
|
||||
|
||||
eventScheduler->start();
|
||||
|
||||
CPPUNIT_ASSERT(event->getState() == TestScheduledEvent::created);
|
||||
state = event->getState();
|
||||
|
||||
Ptr<ptime>::Ref end(new ptime(*when + seconds(10)));
|
||||
while (*TimeConversion::now() < *end) {
|
||||
// nothing should happen here, just wait for some to see that
|
||||
// indeed it doesn't
|
||||
CPPUNIT_ASSERT(event->getState() == TestScheduledEvent::created);
|
||||
TimeConversion::sleep(granularity);
|
||||
}
|
||||
|
||||
eventScheduler->stop();
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.1 $
|
||||
Version : $Revision: 1.2 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/eventScheduler/src/EventSchedulerTest.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -58,13 +58,14 @@ namespace EventScheduler {
|
|||
* Unit test for the EventScheduler class.
|
||||
*
|
||||
* @author $Author: maroy $
|
||||
* @version $Revision: 1.1 $
|
||||
* @version $Revision: 1.2 $
|
||||
* @see EventScheduler
|
||||
*/
|
||||
class EventSchedulerTest : public CPPUNIT_NS::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE(EventSchedulerTest);
|
||||
CPPUNIT_TEST(firstTest);
|
||||
CPPUNIT_TEST(postInitTest);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
private:
|
||||
|
@ -80,6 +81,15 @@ class EventSchedulerTest : public CPPUNIT_NS::TestFixture
|
|||
void
|
||||
firstTest(void) throw (CPPUNIT_NS::Exception);
|
||||
|
||||
/**
|
||||
* A test to see if an event is scheduled after it should have
|
||||
* been initialized (see http://bugs.campware.org/view.php?id=757)
|
||||
*
|
||||
* @exception CPPUNIT_NS::Exception on test failures.
|
||||
*/
|
||||
void
|
||||
postInitTest(void) throw (CPPUNIT_NS::Exception);
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.1 $
|
||||
Version : $Revision: 1.2 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/eventScheduler/src/TestEventContainer.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -74,7 +74,7 @@ TestEventContainer :: TestEventContainer(
|
|||
Ptr<ScheduledEventInterface>::Ref
|
||||
TestEventContainer :: getNextEvent(Ptr<ptime>::Ref when) throw ()
|
||||
{
|
||||
if (*when < *event->getScheduledTime()) {
|
||||
if (*when < (*event->getScheduledTime() - *event->maxTimeToInitialize())) {
|
||||
return event;
|
||||
} else {
|
||||
// return an empty reference
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#
|
||||
#
|
||||
# Author : $Author: maroy $
|
||||
# Version : $Revision: 1.1 $
|
||||
# Version : $Revision: 1.2 $
|
||||
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/bin/scheduler_devenv.sh,v $
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
|
@ -81,6 +81,12 @@ case "$mode" in
|
|||
sleep 2
|
||||
;;
|
||||
|
||||
'run')
|
||||
echo "Running the LiveSupport scheduler..."
|
||||
$scheduler_exe -c $config_file --debug start
|
||||
sleep 2
|
||||
;;
|
||||
|
||||
'stop')
|
||||
echo "Stopping the LiveSupport scheduler..."
|
||||
$scheduler_exe -c $config_file stop
|
||||
|
@ -113,7 +119,7 @@ case "$mode" in
|
|||
echo "LiveSupport scheduler System V runlevel init script."
|
||||
echo ""
|
||||
echo "Usage:"
|
||||
echo " $0 start|stop|status|install|uninstall|kill"
|
||||
echo " $0 start|run|stop|status|install|uninstall|kill"
|
||||
echo ""
|
||||
|
||||
esac
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#
|
||||
#
|
||||
# Author : $Author: maroy $
|
||||
# Version : $Revision: 1.52 $
|
||||
# Version : $Revision: 1.53 $
|
||||
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/etc/Makefile.in,v $
|
||||
#
|
||||
# @configure_input@
|
||||
|
@ -122,6 +122,7 @@ SCHEDULER_SH = ${BIN_DIR}/scheduler_devenv.sh
|
|||
SCHEDULER_CFG = ${ETC_DIR}/scheduler.xml
|
||||
SCHEDULER_WEB_CFG = ${ETC_DIR}/scheduler-web.xml
|
||||
TEST_RUNNER = ${TMP_DIR}/testRunner
|
||||
TEST_RUNNER_SH = ${BIN_DIR}/run_tests.sh
|
||||
|
||||
DOXYGEN_CONFIG = ${ETC_DIR}/doxygen.config
|
||||
|
||||
|
@ -295,13 +296,12 @@ depclean: clean
|
|||
distclean: clean docclean
|
||||
${RMDIR} ${TMP_DIR}/config* ${TMP_DIR}/autom4te*
|
||||
|
||||
check: all ${TEST_RUNNER} storage_server_init start run_tests stop
|
||||
check: all ${TEST_RUNNER} storage_server_init start run run_tests stop
|
||||
|
||||
check_local: all ${TEST_RUNNER} start_local run_tests stop_local
|
||||
|
||||
run_tests: ${TEST_RUNNER}
|
||||
./bin/run_tests.sh -o ${TEST_RESULTS} -s ${TEST_XSLT}
|
||||
# ${TEST_RUNNER} -o ${TEST_RESULTS} -s ${TEST_XSLT}
|
||||
${TEST_RUNNER_SH} -o ${TEST_RESULTS} -s ${TEST_XSLT}
|
||||
|
||||
install: ${SCHEDULER_EXE}
|
||||
${SCHEDULER_SH} install
|
||||
|
@ -310,6 +310,9 @@ start: ${SCHEDULER_EXE}
|
|||
${SCHEDULER_SH} start
|
||||
sleep 2
|
||||
|
||||
run: ${SCHEDULER_EXE}
|
||||
${SCHEDULER_SH} run
|
||||
|
||||
stop: ${SCHEDULER_EXE}
|
||||
${SCHEDULER_SH} stop
|
||||
sleep 2
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.7 $
|
||||
Version : $Revision: 1.8 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PlaylistEvent.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -81,6 +81,8 @@ PlaylistEvent :: PlaylistEvent(
|
|||
|
||||
// this init time is a wild guess, say 5 seconds should be enough
|
||||
initTime.reset(new posix_time::time_duration(0, 0, 5, 0));
|
||||
|
||||
state = created;
|
||||
}
|
||||
|
||||
|
||||
|
@ -90,10 +92,16 @@ PlaylistEvent :: PlaylistEvent(
|
|||
void
|
||||
PlaylistEvent :: initialize(void) throw (std::exception)
|
||||
{
|
||||
if (state != created) {
|
||||
throw std::logic_error("PlaylistEvent in bad state");
|
||||
}
|
||||
|
||||
state = initializing;
|
||||
// some ugliness because getPlaylistId() returns a const pointer
|
||||
Ptr<UniqueId>::Ref playlistId(new UniqueId(scheduleEntry->getPlaylistId()
|
||||
->getId()));
|
||||
playlist = storage->acquirePlaylist(sessionId, playlistId);
|
||||
state = initialized;
|
||||
}
|
||||
|
||||
|
||||
|
@ -103,8 +111,14 @@ PlaylistEvent :: initialize(void) throw (std::exception)
|
|||
void
|
||||
PlaylistEvent :: deInitialize(void) throw ()
|
||||
{
|
||||
if (state != stopped) {
|
||||
// TODO: handle error?
|
||||
return;
|
||||
}
|
||||
|
||||
storage->releasePlaylist(sessionId, playlist);
|
||||
playlist.reset();
|
||||
state = deInitialized;
|
||||
}
|
||||
|
||||
|
||||
|
@ -114,6 +128,11 @@ PlaylistEvent :: deInitialize(void) throw ()
|
|||
void
|
||||
PlaylistEvent :: start(void) throw ()
|
||||
{
|
||||
if (state != initialized) {
|
||||
// TODO: handle error?
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
audioPlayer->open(*playlist->getUri());
|
||||
audioPlayer->start();
|
||||
|
@ -123,6 +142,7 @@ PlaylistEvent :: start(void) throw ()
|
|||
std::cerr << e.what() << std::endl;
|
||||
// TODO: handle error?
|
||||
}
|
||||
state = running;
|
||||
}
|
||||
|
||||
|
||||
|
@ -132,7 +152,13 @@ PlaylistEvent :: start(void) throw ()
|
|||
void
|
||||
PlaylistEvent :: stop(void) throw ()
|
||||
{
|
||||
if (state != running) {
|
||||
// TODO: handle error?
|
||||
return;
|
||||
}
|
||||
|
||||
audioPlayer->stop();
|
||||
audioPlayer->close();
|
||||
state = stopped;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.7 $
|
||||
Version : $Revision: 1.8 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PlaylistEvent.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -72,10 +72,21 @@ using namespace LiveSupport::Storage;
|
|||
* A scheduled event for playing a playlist.
|
||||
*
|
||||
* @author $Author: maroy $
|
||||
* @version $Revision: 1.7 $
|
||||
* @version $Revision: 1.8 $
|
||||
*/
|
||||
class PlaylistEvent : public virtual ScheduledEventInterface
|
||||
{
|
||||
private:
|
||||
/**
|
||||
* Enumeration describing the possible states of the event.
|
||||
*/
|
||||
typedef enum { created,
|
||||
initializing,
|
||||
initialized,
|
||||
running,
|
||||
stopped,
|
||||
deInitialized } State;
|
||||
|
||||
private:
|
||||
/**
|
||||
* The audio player to play the playlist with.
|
||||
|
@ -95,23 +106,28 @@ class PlaylistEvent : public virtual ScheduledEventInterface
|
|||
/**
|
||||
* The schedule entry this event is playing.
|
||||
*/
|
||||
Ptr<ScheduleEntry>::Ref scheduleEntry;
|
||||
Ptr<ScheduleEntry>::Ref scheduleEntry;
|
||||
|
||||
/**
|
||||
* The maximum time this event should get initialized in.
|
||||
*/
|
||||
Ptr<time_duration>::Ref initTime;
|
||||
Ptr<time_duration>::Ref initTime;
|
||||
|
||||
/**
|
||||
* The Playlist this event is playing.
|
||||
*/
|
||||
Ptr<Playlist>::Ref playlist;
|
||||
Ptr<Playlist>::Ref playlist;
|
||||
|
||||
/**
|
||||
* The session ID used for authentication at the storage server.
|
||||
*/
|
||||
Ptr<SessionId>::Ref sessionId;
|
||||
Ptr<SessionId>::Ref sessionId;
|
||||
|
||||
/**
|
||||
* The current state of the event.
|
||||
*/
|
||||
State state;
|
||||
|
||||
|
||||
public:
|
||||
/**
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.10 $
|
||||
Version : $Revision: 1.11 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RpcUploadPlaylistTest.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -168,3 +168,45 @@ RpcUploadPlaylistTest :: simpleTest(void)
|
|||
xmlRpcClient.close();
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* A test to try to schedule something that would have to have
|
||||
* been already initialized (thus, the start time is in the
|
||||
* future, but the initialize time is already in the past.)
|
||||
* see http://bugs.campware.org/view.php?id=757
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
RpcUploadPlaylistTest :: postInitTest(void)
|
||||
throw (CPPUNIT_NS::Exception)
|
||||
{
|
||||
XmlRpc::XmlRpcValue parameters;
|
||||
XmlRpc::XmlRpcValue result;
|
||||
struct tm time;
|
||||
|
||||
XmlRpc::XmlRpcClient xmlRpcClient(getXmlRpcHost().c_str(),
|
||||
getXmlRpcPort(),
|
||||
"/RPC2",
|
||||
false);
|
||||
|
||||
// first, get the scheduler time
|
||||
result.clear();
|
||||
xmlRpcClient.execute("getSchedulerTime", parameters, result);
|
||||
CPPUNIT_ASSERT(!xmlRpcClient.isFault());
|
||||
CPPUNIT_ASSERT(result.hasMember("schedulerTime"));
|
||||
time = result["schedulerTime"];
|
||||
|
||||
// try to schedule playlist #1 in 4 seconds from now
|
||||
parameters.clear();
|
||||
parameters["sessionId"] = sessionId->getId();
|
||||
parameters["playlistId"] = "0000000000000001";
|
||||
// TODO: hopefully time conversion will handle seconds > 60 OK
|
||||
time.tm_sec += 4;
|
||||
parameters["playtime"] = &time;
|
||||
|
||||
result.clear();
|
||||
xmlRpcClient.execute("uploadPlaylist", parameters, result);
|
||||
CPPUNIT_ASSERT(!xmlRpcClient.isFault());
|
||||
|
||||
xmlRpcClient.close();
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.4 $
|
||||
Version : $Revision: 1.5 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RpcUploadPlaylistTest.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -64,13 +64,14 @@ using namespace LiveSupport::Core;
|
|||
* Unit test to test the uploadPlaylist XML-RPC call.
|
||||
*
|
||||
* @author $Author: maroy $
|
||||
* @version $Revision: 1.4 $
|
||||
* @version $Revision: 1.5 $
|
||||
* @see SchedulerDaemon
|
||||
*/
|
||||
class RpcUploadPlaylistTest : public BaseTestMethod
|
||||
{
|
||||
CPPUNIT_TEST_SUITE(RpcUploadPlaylistTest);
|
||||
CPPUNIT_TEST(simpleTest);
|
||||
CPPUNIT_TEST(postInitTest);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
private:
|
||||
|
@ -90,6 +91,17 @@ class RpcUploadPlaylistTest : public BaseTestMethod
|
|||
void
|
||||
simpleTest(void) throw (CPPUNIT_NS::Exception);
|
||||
|
||||
/**
|
||||
* A test to try to schedule something that would have to have
|
||||
* been already initialized (thus, the start time is in the
|
||||
* future, but the initialize time is already in the past.)
|
||||
* see http://bugs.campware.org/view.php?id=757
|
||||
*
|
||||
* @exception CPPUNIT_NS::Exception on test failures.
|
||||
*/
|
||||
void
|
||||
postInitTest(void) throw (CPPUNIT_NS::Exception);
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue