now removeFromSchedule and reschedule won't do anything if the

currently playing scheduled item is to be removed
see http://bugs.campware.org/view.php?id=835
This commit is contained in:
maroy 2005-05-02 15:01:17 +00:00
parent b7626fb2b5
commit 51ab0a1943
17 changed files with 487 additions and 35 deletions

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $ Author : $Author: maroy $
Version : $Revision: 1.13 $ Version : $Revision: 1.14 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PostgresqlSchedule.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PostgresqlSchedule.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -37,6 +37,7 @@
#include <odbc++/preparedstatement.h> #include <odbc++/preparedstatement.h>
#include <odbc++/resultset.h> #include <odbc++/resultset.h>
#include "LiveSupport/Core/TimeConversion.h"
#include "LiveSupport/Db/Conversion.h" #include "LiveSupport/Db/Conversion.h"
#include "PostgresqlSchedule.h" #include "PostgresqlSchedule.h"
@ -133,6 +134,16 @@ const std::string PostgresqlSchedule::getScheduleEntriesStmt =
"(? < ends) AND (starts < ?) " "(? < ends) AND (starts < ?) "
"ORDER BY starts"; "ORDER BY starts";
/*------------------------------------------------------------------------------
* The SQL statement for getting the currently playing schedule entry.
* The parameters for this call are: from
* and returns the properties: id, playlist, starts, ends for the next
* schedule entry after the specified timepoint
*----------------------------------------------------------------------------*/
const std::string PostgresqlSchedule::getCurrentlyPlayingStmt =
"SELECT id, playlist, starts, ends FROM schedule "
" WHERE starts <= ? AND ? < ends";
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
* The SQL statement for querying the next scheduled entry from the * The SQL statement for querying the next scheduled entry from the
* specified timepoint. * specified timepoint.
@ -417,6 +428,52 @@ PostgresqlSchedule :: getScheduleEntries(
} }
/*------------------------------------------------------------------------------
* Get the currently playing entry
*----------------------------------------------------------------------------*/
Ptr<ScheduleEntry>::Ref
PostgresqlSchedule :: getCurrentlyPlaying(void) throw ()
{
Ptr<Connection>::Ref conn;
Ptr<ScheduleEntry>::Ref result;
Ptr<ptime>::Ref now = TimeConversion::now();
try {
conn = cm->getConnection();
Ptr<Timestamp>::Ref timestamp;
Ptr<PreparedStatement>::Ref pstmt(conn->prepareStatement(
getCurrentlyPlayingStmt));
timestamp = Conversion::ptimeToTimestamp(now);
pstmt->setTimestamp(1, *timestamp);
pstmt->setTimestamp(2, *timestamp);
Ptr<ResultSet>::Ref rs(pstmt->executeQuery());
if (rs->next()) {
Ptr<UniqueId>::Ref id(new UniqueId(rs->getLong(1)));
Ptr<UniqueId>::Ref playlistId(new UniqueId(rs->getLong(2)));
*timestamp = rs->getTimestamp(3);
Ptr<ptime>::Ref startTime = Conversion::timestampToPtime(timestamp);
*timestamp = rs->getTimestamp(4);
Ptr<ptime>::Ref endTime = Conversion::timestampToPtime(timestamp);
result.reset(new ScheduleEntry(id, playlistId, startTime, endTime));
}
cm->returnConnection(conn);
} catch (std::exception &e) {
if (conn) {
cm->returnConnection(conn);
}
// TODO: report error
return result;
}
return result;
}
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
* Get the next schedule entry after a specified timepoint * Get the next schedule entry after a specified timepoint
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
@ -437,7 +494,7 @@ PostgresqlSchedule :: getNextEntry(Ptr<ptime>::Ref fromTime)
Ptr<ResultSet>::Ref rs(pstmt->executeQuery()); Ptr<ResultSet>::Ref rs(pstmt->executeQuery());
if (rs->next()) { if (rs->next()) {
Ptr<UniqueId>::Ref id(new UniqueId(rs->getLong(2))); Ptr<UniqueId>::Ref id(new UniqueId(rs->getLong(1)));
Ptr<UniqueId>::Ref playlistId(new UniqueId(rs->getLong(2))); Ptr<UniqueId>::Ref playlistId(new UniqueId(rs->getLong(2)));
*timestamp = rs->getTimestamp(3); *timestamp = rs->getTimestamp(3);

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $ Author : $Author: maroy $
Version : $Revision: 1.9 $ Version : $Revision: 1.10 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PostgresqlSchedule.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PostgresqlSchedule.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -81,7 +81,7 @@ using namespace LiveSupport::Core;
* </code></pre> * </code></pre>
* *
* @author $Author: maroy $ * @author $Author: maroy $
* @version $Revision: 1.9 $ * @version $Revision: 1.10 $
*/ */
class PostgresqlSchedule : public Configurable, class PostgresqlSchedule : public Configurable,
public ScheduleInterface public ScheduleInterface
@ -137,6 +137,12 @@ class PostgresqlSchedule : public Configurable,
*/ */
static const std::string getScheduleEntriesStmt; static const std::string getScheduleEntriesStmt;
/**
* The SQL statement for getting the currently playing schedule
* entry.
*/
static const std::string getCurrentlyPlayingStmt;
/** /**
* The SQL statement for getting the next schedule entry after a * The SQL statement for getting the next schedule entry after a
* timepoint. * timepoint.
@ -285,6 +291,15 @@ class PostgresqlSchedule : public Configurable,
Ptr<ptime>::Ref toTime) Ptr<ptime>::Ref toTime)
throw (); throw ();
/**
* Return the schedule entry that is being played at the moment.
*
* @return the schedule entry that is being played at the monent,
* or a reference to null, if nothing is playing currently.
*/
virtual Ptr<ScheduleEntry>::Ref
getCurrentlyPlaying(void) throw ();
/** /**
* Return the next schedule entry, after (but not including) * Return the next schedule entry, after (but not including)
* the specified timepoint. * the specified timepoint.

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $ Author : $Author: maroy $
Version : $Revision: 1.7 $ Version : $Revision: 1.8 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PostgresqlScheduleTest.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PostgresqlScheduleTest.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -43,6 +43,7 @@
#include <string> #include <string>
#include <iostream> #include <iostream>
#include "LiveSupport/Core/TimeConversion.h"
#include "LiveSupport/Db/ConnectionManagerFactory.h" #include "LiveSupport/Db/ConnectionManagerFactory.h"
#include "SchedulerDaemon.h" #include "SchedulerDaemon.h"
#include "PostgresqlSchedule.h" #include "PostgresqlSchedule.h"
@ -497,3 +498,46 @@ PostgresqlScheduleTest :: rescheduleTest(void)
} }
/*------------------------------------------------------------------------------
* Test the return of the currently playing entry
*----------------------------------------------------------------------------*/
void
PostgresqlScheduleTest :: currentlyPlayingTest(void)
throw (CPPUNIT_NS::Exception)
{
// create a 1 hour long playlist
Ptr<UniqueId>::Ref playlistId = UniqueId::generateId();
Ptr<time_duration>::Ref playlength(new time_duration(1, 0, 0));
Ptr<Playlist>::Ref playlist(new Playlist(playlistId, playlength));
Ptr<ptime>::Ref from;
Ptr<ptime>::Ref to;
Ptr<time_duration>::Ref duration;
Ptr<UniqueId>::Ref entryId;
Ptr<ScheduleEntry>::Ref entry;
// at the very first, see if null is returned if nothing is playing
// currently
entry = schedule->getCurrentlyPlaying();
CPPUNIT_ASSERT(!entry.get());
// schedule our playlist for 10 seconds from now
from = TimeConversion::now();
*from += seconds(10);
entryId = schedule->schedulePlaylist(playlist, from);
// wait 10 seconds, so that what we've scheduled is the currently
// playing entry
duration.reset(new time_duration(seconds(10)));
TimeConversion::sleep(duration);
// now see if the entry returned for currently playing is indeed
// what we've scheduled
entry = schedule->getCurrentlyPlaying();
CPPUNIT_ASSERT(entry.get());
CPPUNIT_ASSERT(entry->getId()->getId() == entryId->getId());
}

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $ Author : $Author: maroy $
Version : $Revision: 1.6 $ Version : $Revision: 1.7 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PostgresqlScheduleTest.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PostgresqlScheduleTest.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -65,7 +65,7 @@ using namespace LiveSupport::Core;
* Unit test for the PostgresqlSchedule class. * Unit test for the PostgresqlSchedule class.
* *
* @author $Author: maroy $ * @author $Author: maroy $
* @version $Revision: 1.6 $ * @version $Revision: 1.7 $
* @see PostgresqlSchedule * @see PostgresqlSchedule
*/ */
class PostgresqlScheduleTest : public CPPUNIT_NS::TestFixture class PostgresqlScheduleTest : public CPPUNIT_NS::TestFixture
@ -79,6 +79,7 @@ class PostgresqlScheduleTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST(scheduleEntryExistsTest); CPPUNIT_TEST(scheduleEntryExistsTest);
CPPUNIT_TEST(removeFromScheduleTest); CPPUNIT_TEST(removeFromScheduleTest);
CPPUNIT_TEST(rescheduleTest); CPPUNIT_TEST(rescheduleTest);
CPPUNIT_TEST(currentlyPlayingTest);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
private: private:
@ -161,6 +162,15 @@ class PostgresqlScheduleTest : public CPPUNIT_NS::TestFixture
void void
rescheduleTest(void) throw (CPPUNIT_NS::Exception); rescheduleTest(void) throw (CPPUNIT_NS::Exception);
/**
* A test to see if the currently playing scheduled entry is
* returned properly.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
currentlyPlayingTest(void) throw (CPPUNIT_NS::Exception);
public: public:
/** /**

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $ Author : $Author: maroy $
Version : $Revision: 1.8 $ Version : $Revision: 1.9 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RemoveFromScheduleMethod.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RemoveFromScheduleMethod.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -123,8 +123,17 @@ RemoveFromScheduleMethod :: execute(XmlRpc::XmlRpcValue & rootParameter,
Ptr<ScheduleFactory>::Ref sf = ScheduleFactory::getInstance(); Ptr<ScheduleFactory>::Ref sf = ScheduleFactory::getInstance();
Ptr<ScheduleInterface>::Ref schedule = sf->getSchedule(); Ptr<ScheduleInterface>::Ref schedule = sf->getSchedule();
Ptr<ScheduleEntry>::Ref currentlyPlaying;
try { try {
currentlyPlaying = schedule->getCurrentlyPlaying();
if (currentlyPlaying.get()
&& currentlyPlaying->getId()->getId() == entryId->getId()) {
XmlRpcTools::markError(errorId+4,
"the entry to be deleted is currently playing",
returnValue);
return;
}
schedule->removeFromSchedule(entryId); schedule->removeFromSchedule(entryId);
} catch (std::invalid_argument &e) { } catch (std::invalid_argument &e) {
@ -133,3 +142,4 @@ RemoveFromScheduleMethod :: execute(XmlRpc::XmlRpcValue & rootParameter,
return; return;
} }
} }

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $ Author : $Author: maroy $
Version : $Revision: 1.7 $ Version : $Revision: 1.8 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RemoveFromScheduleMethod.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RemoveFromScheduleMethod.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -86,11 +86,12 @@ using namespace LiveSupport::Core;
* <li>1201 - invalid argument format </li> * <li>1201 - invalid argument format </li>
* <li>1202 - missing schedule entry ID argument </li> * <li>1202 - missing schedule entry ID argument </li>
* <li>1203 - schedule entry not found </li> * <li>1203 - schedule entry not found </li>
* <li>1204 - the entry to be deleted is currently playing </li>
* <li>1220 - missing session ID argument </li> * <li>1220 - missing session ID argument </li>
* </ul> * </ul>
* *
* @author $Author: fgerlits $ * @author $Author: maroy $
* @version $Revision: 1.7 $ * @version $Revision: 1.8 $
*/ */
class RemoveFromScheduleMethod : public XmlRpc::XmlRpcServerMethod class RemoveFromScheduleMethod : public XmlRpc::XmlRpcServerMethod
{ {

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $ Author : $Author: maroy $
Version : $Revision: 1.9 $ Version : $Revision: 1.10 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RemoveFromScheduleMethodTest.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RemoveFromScheduleMethodTest.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -45,6 +45,7 @@
#include <XmlRpcValue.h> #include <XmlRpcValue.h>
#include "ScheduleFactory.h" #include "ScheduleFactory.h"
#include "LiveSupport/Core/TimeConversion.h"
#include "LiveSupport/Authentication/AuthenticationClientFactory.h" #include "LiveSupport/Authentication/AuthenticationClientFactory.h"
#include "LiveSupport/Storage/StorageClientFactory.h" #include "LiveSupport/Storage/StorageClientFactory.h"
@ -54,6 +55,8 @@
#include "RemoveFromScheduleMethodTest.h" #include "RemoveFromScheduleMethodTest.h"
using namespace boost::posix_time;
using namespace LiveSupport::Authentication; using namespace LiveSupport::Authentication;
using namespace LiveSupport::Storage; using namespace LiveSupport::Storage;
using namespace LiveSupport::Scheduler; using namespace LiveSupport::Scheduler;
@ -207,3 +210,70 @@ RemoveFromScheduleMethodTest :: negativeTest(void)
} }
} }
/*------------------------------------------------------------------------------
* A test to try to remove a currently playing entry.
*----------------------------------------------------------------------------*/
void
RemoveFromScheduleMethodTest :: currentlyPlayingTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<UploadPlaylistMethod>::Ref uploadMethod(
new UploadPlaylistMethod());
Ptr<RemoveFromScheduleMethod>::Ref removeMethod(
new RemoveFromScheduleMethod());
XmlRpc::XmlRpcValue parameters;
XmlRpc::XmlRpcValue rootParameter;
rootParameter.setSize(1);
XmlRpc::XmlRpcValue result;
Ptr<ptime>::Ref now;
struct tm time;
Ptr<time_duration>::Ref duration;
Ptr<UniqueId>::Ref entryId;
bool gotException;
// first schedule (upload) a playlist, for 10 seconds from now
now = TimeConversion::now();
*now += seconds(10);
TimeConversion::ptimeToTm(now, time);
parameters["sessionId"] = sessionId->getId();
parameters["playlistId"] = "0000000000000001";
parameters["playtime"] = &time;
rootParameter[0] = parameters;
result.clear();
try {
uploadMethod->execute(rootParameter, result);
} catch (XmlRpc::XmlRpcException &e) {
std::stringstream eMsg;
eMsg << "XML-RPC method returned error: " << e.getCode()
<< " - " << e.getMessage();
CPPUNIT_FAIL(eMsg.str());
}
CPPUNIT_ASSERT(result.hasMember("scheduleEntryId"));
CPPUNIT_ASSERT(result["scheduleEntryId"].getType()
== XmlRpc::XmlRpcValue::TypeString);
entryId.reset(new UniqueId(std::string(result["scheduleEntryId"])));
// wait 10 seconds, so that what we've scheduled is the currently playing
// entry
duration.reset(new time_duration(seconds(10)));
TimeConversion::sleep(duration);
// now try to remove what we've scheduled, this should fail
parameters.clear();
parameters["sessionId"] = sessionId->getId();
parameters["scheduleEntryId"] = std::string(*entryId);
rootParameter[0] = parameters;
result.clear();
gotException = false;
try {
removeMethod->execute(rootParameter, result);
} catch (XmlRpc::XmlRpcException &e) {
gotException = true;
}
CPPUNIT_ASSERT(gotException);
}

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $ Author : $Author: maroy $
Version : $Revision: 1.5 $ Version : $Revision: 1.6 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RemoveFromScheduleMethodTest.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RemoveFromScheduleMethodTest.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -65,7 +65,7 @@ using namespace LiveSupport::Authentication;
* Unit test for the RemoveFromScheduleMethod class. * Unit test for the RemoveFromScheduleMethod class.
* *
* @author $Author: maroy $ * @author $Author: maroy $
* @version $Revision: 1.5 $ * @version $Revision: 1.6 $
* @see RemoveFromScheduleMethod * @see RemoveFromScheduleMethod
*/ */
class RemoveFromScheduleMethodTest : public CPPUNIT_NS::TestFixture class RemoveFromScheduleMethodTest : public CPPUNIT_NS::TestFixture
@ -73,6 +73,7 @@ class RemoveFromScheduleMethodTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST_SUITE(RemoveFromScheduleMethodTest); CPPUNIT_TEST_SUITE(RemoveFromScheduleMethodTest);
CPPUNIT_TEST(firstTest); CPPUNIT_TEST(firstTest);
CPPUNIT_TEST(negativeTest); CPPUNIT_TEST(negativeTest);
CPPUNIT_TEST(currentlyPlayingTest);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
private: private:
@ -111,6 +112,14 @@ class RemoveFromScheduleMethodTest : public CPPUNIT_NS::TestFixture
void void
negativeTest(void) throw (CPPUNIT_NS::Exception); negativeTest(void) throw (CPPUNIT_NS::Exception);
/**
* A test to try to remove an entry that's currently playing.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
currentlyPlayingTest(void) throw (CPPUNIT_NS::Exception);
public: public:
/** /**

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $ Author : $Author: maroy $
Version : $Revision: 1.8 $ Version : $Revision: 1.9 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RescheduleMethod.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RescheduleMethod.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -136,12 +136,21 @@ RescheduleMethod :: execute(XmlRpc::XmlRpcValue & rootParameter,
Ptr<ScheduleFactory>::Ref sf = ScheduleFactory::getInstance(); Ptr<ScheduleFactory>::Ref sf = ScheduleFactory::getInstance();
Ptr<ScheduleInterface>::Ref schedule = sf->getSchedule(); Ptr<ScheduleInterface>::Ref schedule = sf->getSchedule();
Ptr<ScheduleEntry>::Ref currentlyPlaying;
if (!schedule->scheduleEntryExists(entryId)) { if (!schedule->scheduleEntryExists(entryId)) {
XmlRpcTools::markError(errorId+4, "schedule entry not found", XmlRpcTools::markError(errorId+4, "schedule entry not found",
returnValue); returnValue);
return; return;
} }
currentlyPlaying = schedule->getCurrentlyPlaying();
if (currentlyPlaying.get()
&& currentlyPlaying->getId()->getId() == entryId->getId()) {
XmlRpcTools::markError(errorId+6,
"the entry to be rescheduled is currently playing",
returnValue);
return;
}
try { try {
schedule->reschedule(entryId, playschedule); schedule->reschedule(entryId, playschedule);
} catch (std::invalid_argument &e) { } catch (std::invalid_argument &e) {

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $ Author : $Author: maroy $
Version : $Revision: 1.7 $ Version : $Revision: 1.8 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RescheduleMethod.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RescheduleMethod.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -89,11 +89,12 @@ using namespace LiveSupport::Core;
* <li>1303 - missing playtime argument </li> * <li>1303 - missing playtime argument </li>
* <li>1304 - schedule entry not found </li> * <li>1304 - schedule entry not found </li>
* <li>1305 - could not reschedule entry </li> * <li>1305 - could not reschedule entry </li>
* <li>1306 - the entry to be rescheduled is currently playing </li>
* <li>1320 - missing session ID argument </li> * <li>1320 - missing session ID argument </li>
* </ul> * </ul>
* *
* @author $Author: fgerlits $ * @author $Author: maroy $
* @version $Revision: 1.7 $ * @version $Revision: 1.8 $
*/ */
class RescheduleMethod : public XmlRpc::XmlRpcServerMethod class RescheduleMethod : public XmlRpc::XmlRpcServerMethod
{ {

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $ Author : $Author: maroy $
Version : $Revision: 1.9 $ Version : $Revision: 1.10 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RescheduleMethodTest.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RescheduleMethodTest.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -44,6 +44,7 @@
#include <iostream> #include <iostream>
#include <XmlRpcValue.h> #include <XmlRpcValue.h>
#include "LiveSupport/Core/TimeConversion.h"
#include "LiveSupport/Db/ConnectionManagerFactory.h" #include "LiveSupport/Db/ConnectionManagerFactory.h"
#include "LiveSupport/Storage/StorageClientFactory.h" #include "LiveSupport/Storage/StorageClientFactory.h"
#include "LiveSupport/Authentication/AuthenticationClientFactory.h" #include "LiveSupport/Authentication/AuthenticationClientFactory.h"
@ -80,6 +81,9 @@ RescheduleMethodTest :: setUp(void) throw ()
{ {
Ptr<SchedulerDaemon>::Ref scheduler = SchedulerDaemon::getInstance(); Ptr<SchedulerDaemon>::Ref scheduler = SchedulerDaemon::getInstance();
try { try {
Ptr<StorageClientInterface>::Ref storage = scheduler->getStorage();
storage->reset();
schedule = scheduler->getSchedule(); schedule = scheduler->getSchedule();
schedule->install(); schedule->install();
@ -203,3 +207,74 @@ RescheduleMethodTest :: firstTest(void)
} }
} }
/*------------------------------------------------------------------------------
* Test to see if rescheduling the currently playing entry works (should not)
*----------------------------------------------------------------------------*/
void
RescheduleMethodTest :: currentlyPlayingTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<UploadPlaylistMethod>::Ref uploadMethod(new UploadPlaylistMethod());
Ptr<RescheduleMethod>::Ref rescheduleMethod(new RescheduleMethod());
XmlRpc::XmlRpcValue parameters;
XmlRpc::XmlRpcValue rootParameter;
rootParameter.setSize(1);
XmlRpc::XmlRpcValue result;
struct tm time;
Ptr<ptime>::Ref now;
Ptr<time_duration>::Ref duration;
bool gotException;
Ptr<UniqueId>::Ref entryId;
// let's upload something so we can reschedule it
now = TimeConversion::now();
*now += seconds(10);
TimeConversion::ptimeToTm(now, time);
parameters["sessionId"] = sessionId->getId();
parameters["playlistId"] = "0000000000000001";
parameters["playtime"] = &time;
rootParameter[0] = parameters;
result.clear();
try {
uploadMethod->execute(rootParameter, result);
} catch (XmlRpc::XmlRpcException &e) {
std::stringstream eMsg;
eMsg << "XML-RPC method returned error: " << e.getCode()
<< " - " << e.getMessage();
CPPUNIT_FAIL(eMsg.str());
}
CPPUNIT_ASSERT(result.hasMember("scheduleEntryId"));
CPPUNIT_ASSERT(result["scheduleEntryId"].getType()
== XmlRpc::XmlRpcValue::TypeString);
entryId.reset(new UniqueId(std::string(result["scheduleEntryId"])));
// wait 10 seconds, so that what we've scheduled is the currently playing
// entry
duration.reset(new time_duration(seconds(10)));
TimeConversion::sleep(duration);
// now let's try reschedule it, which should fail
parameters.clear();
parameters["sessionId"] = sessionId->getId();
parameters["scheduleEntryId"] = std::string(*entryId);
time.tm_year = 2001;
time.tm_mon = 11;
time.tm_mday = 12;
time.tm_hour = 12;
time.tm_min = 31;
time.tm_sec = 1;
parameters["playtime"] = &time;
rootParameter[0] = parameters;
result.clear();
gotException = false;
try {
rescheduleMethod->execute(rootParameter, result);
} catch (XmlRpc::XmlRpcException &e) {
gotException = true;
}
CPPUNIT_ASSERT(gotException);
}

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $ Author : $Author: maroy $
Version : $Revision: 1.5 $ Version : $Revision: 1.6 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RescheduleMethodTest.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RescheduleMethodTest.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -65,13 +65,14 @@ using namespace LiveSupport::Authentication;
* Unit test for the RescheduleMethod class. * Unit test for the RescheduleMethod class.
* *
* @author $Author: maroy $ * @author $Author: maroy $
* @version $Revision: 1.5 $ * @version $Revision: 1.6 $
* @see RescheduleMethod * @see RescheduleMethod
*/ */
class RescheduleMethodTest : public CPPUNIT_NS::TestFixture class RescheduleMethodTest : public CPPUNIT_NS::TestFixture
{ {
CPPUNIT_TEST_SUITE(RescheduleMethodTest); CPPUNIT_TEST_SUITE(RescheduleMethodTest);
CPPUNIT_TEST(firstTest); CPPUNIT_TEST(firstTest);
CPPUNIT_TEST(currentlyPlayingTest);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
private: private:
@ -102,6 +103,15 @@ class RescheduleMethodTest : public CPPUNIT_NS::TestFixture
void void
firstTest(void) throw (CPPUNIT_NS::Exception); firstTest(void) throw (CPPUNIT_NS::Exception);
/**
* A test to see if rescheduling the currently playing entry works.
* (should not)
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
currentlyPlayingTest(void) throw (CPPUNIT_NS::Exception);
public: public:
/** /**

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $ Author : $Author: maroy $
Version : $Revision: 1.8 $ Version : $Revision: 1.9 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RpcRemoveFromScheduleTest.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RpcRemoveFromScheduleTest.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -34,6 +34,7 @@
#include <XmlRpcValue.h> #include <XmlRpcValue.h>
#include "SchedulerDaemon.h" #include "SchedulerDaemon.h"
#include "LiveSupport/Core/TimeConversion.h"
#include "RpcRemoveFromScheduleTest.h" #include "RpcRemoveFromScheduleTest.h"
@ -183,3 +184,53 @@ RpcRemoveFromScheduleTest :: negativeTest(void)
xmlRpcClient.close(); xmlRpcClient.close();
} }
/*------------------------------------------------------------------------------
* A test to try to remove a currently playing entry.
*----------------------------------------------------------------------------*/
void
RpcRemoveFromScheduleTest :: currentlyPlayingTest(void)
throw (CPPUNIT_NS::Exception)
{
XmlRpcValue parameters;
XmlRpcValue result;
Ptr<ptime>::Ref now;
struct tm time;
Ptr<time_duration>::Ref duration;
Ptr<UniqueId>::Ref entryId;
XmlRpc::XmlRpcClient xmlRpcClient(getXmlRpcHost().c_str(),
getXmlRpcPort(),
"/RPC2",
false);
// first schedule (upload) a playlist, for 15 seconds from now
now = TimeConversion::now();
*now += seconds(10);
TimeConversion::ptimeToTm(now, time);
parameters["sessionId"] = sessionId->getId();
parameters["playlistId"] = "0000000000000001";
parameters["playtime"] = &time;
result.clear();
xmlRpcClient.execute("uploadPlaylist", parameters, result);
CPPUNIT_ASSERT(!xmlRpcClient.isFault());
CPPUNIT_ASSERT(result.hasMember("scheduleEntryId"));
CPPUNIT_ASSERT(result["scheduleEntryId"].getType()
== XmlRpcValue::TypeString);
entryId.reset(new UniqueId(std::string(result["scheduleEntryId"] )));
// wait 10 seconds, so that what we've scheduled is the currently playing
// entry
duration.reset(new time_duration(seconds(10)));
TimeConversion::sleep(duration);
// now try to remove what we've scheduled, this should fail
parameters["scheduleEntryId"] = std::string(*entryId);
result.clear();
xmlRpcClient.execute("removeFromSchedule", parameters, result);
CPPUNIT_ASSERT(xmlRpcClient.isFault());
xmlRpcClient.close();
}

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $ Author : $Author: maroy $
Version : $Revision: 1.4 $ Version : $Revision: 1.5 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RpcRemoveFromScheduleTest.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RpcRemoveFromScheduleTest.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -64,7 +64,7 @@ using namespace LiveSupport::Core;
* Unit test to test the removeFromSchedule XML-RPC call. * Unit test to test the removeFromSchedule XML-RPC call.
* *
* @author $Author: maroy $ * @author $Author: maroy $
* @version $Revision: 1.4 $ * @version $Revision: 1.5 $
* @see SchedulerDaemon * @see SchedulerDaemon
*/ */
class RpcRemoveFromScheduleTest : public BaseTestMethod class RpcRemoveFromScheduleTest : public BaseTestMethod
@ -72,6 +72,7 @@ class RpcRemoveFromScheduleTest : public BaseTestMethod
CPPUNIT_TEST_SUITE(RpcRemoveFromScheduleTest); CPPUNIT_TEST_SUITE(RpcRemoveFromScheduleTest);
CPPUNIT_TEST(simpleTest); CPPUNIT_TEST(simpleTest);
CPPUNIT_TEST(negativeTest); CPPUNIT_TEST(negativeTest);
CPPUNIT_TEST(currentlyPlayingTest);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
private: private:
@ -99,6 +100,14 @@ class RpcRemoveFromScheduleTest : public BaseTestMethod
void void
negativeTest(void) throw (CPPUNIT_NS::Exception); negativeTest(void) throw (CPPUNIT_NS::Exception);
/**
* A test to see if removing the currently playing entry works
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
currentlyPlayingTest(void) throw (CPPUNIT_NS::Exception);
public: public:
/** /**

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $ Author : $Author: maroy $
Version : $Revision: 1.8 $ Version : $Revision: 1.9 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RpcRescheduleTest.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RpcRescheduleTest.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -34,6 +34,7 @@
#include <XmlRpcValue.h> #include <XmlRpcValue.h>
#include "SchedulerDaemon.h" #include "SchedulerDaemon.h"
#include "LiveSupport/Core/TimeConversion.h"
#include "RpcRescheduleTest.h" #include "RpcRescheduleTest.h"
@ -228,3 +229,63 @@ RpcRescheduleTest :: negativeTest(void)
xmlRpcClient.close(); xmlRpcClient.close();
} }
/*------------------------------------------------------------------------------
* A test to see if the currently playing entry can be rescheduled (should not)
*----------------------------------------------------------------------------*/
void
RpcRescheduleTest :: currentlyPlayingTest(void)
throw (CPPUNIT_NS::Exception)
{
XmlRpc::XmlRpcValue parameters;
XmlRpc::XmlRpcValue result;
Ptr<ptime>::Ref now;
struct tm time;
Ptr<time_duration>::Ref duration;
Ptr<UniqueId>::Ref entryId;
XmlRpc::XmlRpcClient xmlRpcClient(getXmlRpcHost().c_str(),
getXmlRpcPort(),
"/RPC2",
false);
// first schedule (upload) a playlist, for 10 seconds from now
now = TimeConversion::now();
*now += seconds(10);
TimeConversion::ptimeToTm(now, time);
parameters["sessionId"] = sessionId->getId();
parameters["playlistId"] = "0000000000000001";
parameters["playtime"] = &time;
result.clear();
xmlRpcClient.execute("uploadPlaylist", parameters, result);
CPPUNIT_ASSERT(!xmlRpcClient.isFault());
CPPUNIT_ASSERT(result.hasMember("scheduleEntryId"));
CPPUNIT_ASSERT(result["scheduleEntryId"].getType()
== XmlRpcValue::TypeString);
entryId.reset(new UniqueId(std::string(result["scheduleEntryId"] )));
// wait 10 seconds, so that what we've scheduled is the currently playing
// entry
duration.reset(new time_duration(seconds(10)));
TimeConversion::sleep(duration);
// now try to reschedule it, should faile
parameters["sessionId"] = sessionId->getId();
parameters["scheduleEntryId"] = std::string(*entryId);
time.tm_year = 2001;
time.tm_mon = 11;
time.tm_mday = 12;
time.tm_hour = 8;
time.tm_min = 0;
time.tm_sec = 0;
parameters["playtime"] = &time;
result.clear();
xmlRpcClient.execute("reschedule", parameters, result);
CPPUNIT_ASSERT(xmlRpcClient.isFault());
xmlRpcClient.close();
}

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $ Author : $Author: maroy $
Version : $Revision: 1.4 $ Version : $Revision: 1.5 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RpcRescheduleTest.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RpcRescheduleTest.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -64,7 +64,7 @@ using namespace LiveSupport::Core;
* Unit test to test the removeFromSchedule XML-RPC call. * Unit test to test the removeFromSchedule XML-RPC call.
* *
* @author $Author: maroy $ * @author $Author: maroy $
* @version $Revision: 1.4 $ * @version $Revision: 1.5 $
* @see SchedulerDaemon * @see SchedulerDaemon
*/ */
class RpcRescheduleTest : public BaseTestMethod class RpcRescheduleTest : public BaseTestMethod
@ -72,6 +72,7 @@ class RpcRescheduleTest : public BaseTestMethod
CPPUNIT_TEST_SUITE(RpcRescheduleTest); CPPUNIT_TEST_SUITE(RpcRescheduleTest);
CPPUNIT_TEST(simpleTest); CPPUNIT_TEST(simpleTest);
CPPUNIT_TEST(negativeTest); CPPUNIT_TEST(negativeTest);
CPPUNIT_TEST(currentlyPlayingTest);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
private: private:
@ -99,6 +100,15 @@ class RpcRescheduleTest : public BaseTestMethod
void void
negativeTest(void) throw (CPPUNIT_NS::Exception); negativeTest(void) throw (CPPUNIT_NS::Exception);
/**
* A test to see if the currently playing entry can be reschuled
* (should not)
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
currentlyPlayingTest(void) throw (CPPUNIT_NS::Exception);
public: public:
/** /**

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $ Author : $Author: maroy $
Version : $Revision: 1.7 $ Version : $Revision: 1.8 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/ScheduleInterface.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/ScheduleInterface.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -69,8 +69,8 @@ using namespace LiveSupport::Core;
/** /**
* The generic interface for the component scheduling events. * The generic interface for the component scheduling events.
* *
* @author $Author: fgerlits $ * @author $Author: maroy $
* @version $Revision: 1.7 $ * @version $Revision: 1.8 $
*/ */
class ScheduleInterface : virtual public Installable class ScheduleInterface : virtual public Installable
{ {
@ -117,6 +117,16 @@ class ScheduleInterface : virtual public Installable
throw () throw ()
= 0; = 0;
/**
* Return the schedule entry that is being played at the moment.
*
* @return the schedule entry that is being played at the monent,
* or a reference to null, if nothing is playing currently.
*/
virtual Ptr<ScheduleEntry>::Ref
getCurrentlyPlaying(void) throw ()
= 0;
/** /**
* Return the next schedule entry, after (but not including) * Return the next schedule entry, after (but not including)
* the specified timepoint. * the specified timepoint.