diff --git a/livesupport/products/scheduler/src/PostgresqlSchedule.cxx b/livesupport/products/scheduler/src/PostgresqlSchedule.cxx index 9568b7385..9ecb0a8c1 100644 --- a/livesupport/products/scheduler/src/PostgresqlSchedule.cxx +++ b/livesupport/products/scheduler/src/PostgresqlSchedule.cxx @@ -22,7 +22,7 @@ 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 $ ------------------------------------------------------------------------------*/ @@ -37,6 +37,7 @@ #include #include +#include "LiveSupport/Core/TimeConversion.h" #include "LiveSupport/Db/Conversion.h" #include "PostgresqlSchedule.h" @@ -133,6 +134,16 @@ const std::string PostgresqlSchedule::getScheduleEntriesStmt = "(? < ends) AND (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 * specified timepoint. @@ -417,6 +428,52 @@ PostgresqlSchedule :: getScheduleEntries( } +/*------------------------------------------------------------------------------ + * Get the currently playing entry + *----------------------------------------------------------------------------*/ +Ptr::Ref +PostgresqlSchedule :: getCurrentlyPlaying(void) throw () +{ + Ptr::Ref conn; + Ptr::Ref result; + Ptr::Ref now = TimeConversion::now(); + + try { + conn = cm->getConnection(); + Ptr::Ref timestamp; + Ptr::Ref pstmt(conn->prepareStatement( + getCurrentlyPlayingStmt)); + timestamp = Conversion::ptimeToTimestamp(now); + pstmt->setTimestamp(1, *timestamp); + pstmt->setTimestamp(2, *timestamp); + + Ptr::Ref rs(pstmt->executeQuery()); + if (rs->next()) { + Ptr::Ref id(new UniqueId(rs->getLong(1))); + Ptr::Ref playlistId(new UniqueId(rs->getLong(2))); + + *timestamp = rs->getTimestamp(3); + Ptr::Ref startTime = Conversion::timestampToPtime(timestamp); + + *timestamp = rs->getTimestamp(4); + Ptr::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 *----------------------------------------------------------------------------*/ @@ -437,7 +494,7 @@ PostgresqlSchedule :: getNextEntry(Ptr::Ref fromTime) Ptr::Ref rs(pstmt->executeQuery()); if (rs->next()) { - Ptr::Ref id(new UniqueId(rs->getLong(2))); + Ptr::Ref id(new UniqueId(rs->getLong(1))); Ptr::Ref playlistId(new UniqueId(rs->getLong(2))); *timestamp = rs->getTimestamp(3); diff --git a/livesupport/products/scheduler/src/PostgresqlSchedule.h b/livesupport/products/scheduler/src/PostgresqlSchedule.h index 8a07e310e..9b7bd1167 100644 --- a/livesupport/products/scheduler/src/PostgresqlSchedule.h +++ b/livesupport/products/scheduler/src/PostgresqlSchedule.h @@ -22,7 +22,7 @@ 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 $ ------------------------------------------------------------------------------*/ @@ -81,7 +81,7 @@ using namespace LiveSupport::Core; * * * @author $Author: maroy $ - * @version $Revision: 1.9 $ + * @version $Revision: 1.10 $ */ class PostgresqlSchedule : public Configurable, public ScheduleInterface @@ -137,6 +137,12 @@ class PostgresqlSchedule : public Configurable, */ 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 * timepoint. @@ -285,6 +291,15 @@ class PostgresqlSchedule : public Configurable, Ptr::Ref toTime) 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::Ref + getCurrentlyPlaying(void) throw (); + /** * Return the next schedule entry, after (but not including) * the specified timepoint. diff --git a/livesupport/products/scheduler/src/PostgresqlScheduleTest.cxx b/livesupport/products/scheduler/src/PostgresqlScheduleTest.cxx index 4ab6a76d3..eedc65c5e 100644 --- a/livesupport/products/scheduler/src/PostgresqlScheduleTest.cxx +++ b/livesupport/products/scheduler/src/PostgresqlScheduleTest.cxx @@ -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/PostgresqlScheduleTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -43,6 +43,7 @@ #include #include +#include "LiveSupport/Core/TimeConversion.h" #include "LiveSupport/Db/ConnectionManagerFactory.h" #include "SchedulerDaemon.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::Ref playlistId = UniqueId::generateId(); + Ptr::Ref playlength(new time_duration(1, 0, 0)); + Ptr::Ref playlist(new Playlist(playlistId, playlength)); + + Ptr::Ref from; + Ptr::Ref to; + Ptr::Ref duration; + + Ptr::Ref entryId; + + Ptr::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()); +} + + diff --git a/livesupport/products/scheduler/src/PostgresqlScheduleTest.h b/livesupport/products/scheduler/src/PostgresqlScheduleTest.h index 2948ce086..0d366be9b 100644 --- a/livesupport/products/scheduler/src/PostgresqlScheduleTest.h +++ b/livesupport/products/scheduler/src/PostgresqlScheduleTest.h @@ -22,7 +22,7 @@ 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 $ ------------------------------------------------------------------------------*/ @@ -65,7 +65,7 @@ using namespace LiveSupport::Core; * Unit test for the PostgresqlSchedule class. * * @author $Author: maroy $ - * @version $Revision: 1.6 $ + * @version $Revision: 1.7 $ * @see PostgresqlSchedule */ class PostgresqlScheduleTest : public CPPUNIT_NS::TestFixture @@ -79,6 +79,7 @@ class PostgresqlScheduleTest : public CPPUNIT_NS::TestFixture CPPUNIT_TEST(scheduleEntryExistsTest); CPPUNIT_TEST(removeFromScheduleTest); CPPUNIT_TEST(rescheduleTest); + CPPUNIT_TEST(currentlyPlayingTest); CPPUNIT_TEST_SUITE_END(); private: @@ -161,6 +162,15 @@ class PostgresqlScheduleTest : public CPPUNIT_NS::TestFixture void 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: /** diff --git a/livesupport/products/scheduler/src/RemoveFromScheduleMethod.cxx b/livesupport/products/scheduler/src/RemoveFromScheduleMethod.cxx index f06b4b153..c513acbcd 100644 --- a/livesupport/products/scheduler/src/RemoveFromScheduleMethod.cxx +++ b/livesupport/products/scheduler/src/RemoveFromScheduleMethod.cxx @@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Author : $Author: fgerlits $ - Version : $Revision: 1.8 $ + Author : $Author: maroy $ + Version : $Revision: 1.9 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RemoveFromScheduleMethod.cxx,v $ ------------------------------------------------------------------------------*/ @@ -123,8 +123,17 @@ RemoveFromScheduleMethod :: execute(XmlRpc::XmlRpcValue & rootParameter, Ptr::Ref sf = ScheduleFactory::getInstance(); Ptr::Ref schedule = sf->getSchedule(); + Ptr::Ref currentlyPlaying; 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); } catch (std::invalid_argument &e) { @@ -133,3 +142,4 @@ RemoveFromScheduleMethod :: execute(XmlRpc::XmlRpcValue & rootParameter, return; } } + diff --git a/livesupport/products/scheduler/src/RemoveFromScheduleMethod.h b/livesupport/products/scheduler/src/RemoveFromScheduleMethod.h index 928340894..bcf73c154 100644 --- a/livesupport/products/scheduler/src/RemoveFromScheduleMethod.h +++ b/livesupport/products/scheduler/src/RemoveFromScheduleMethod.h @@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Author : $Author: fgerlits $ - Version : $Revision: 1.7 $ + Author : $Author: maroy $ + Version : $Revision: 1.8 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RemoveFromScheduleMethod.h,v $ ------------------------------------------------------------------------------*/ @@ -86,11 +86,12 @@ using namespace LiveSupport::Core; *
  • 1201 - invalid argument format
  • *
  • 1202 - missing schedule entry ID argument
  • *
  • 1203 - schedule entry not found
  • + *
  • 1204 - the entry to be deleted is currently playing
  • *
  • 1220 - missing session ID argument
  • * * - * @author $Author: fgerlits $ - * @version $Revision: 1.7 $ + * @author $Author: maroy $ + * @version $Revision: 1.8 $ */ class RemoveFromScheduleMethod : public XmlRpc::XmlRpcServerMethod { diff --git a/livesupport/products/scheduler/src/RemoveFromScheduleMethodTest.cxx b/livesupport/products/scheduler/src/RemoveFromScheduleMethodTest.cxx index 818ab1cc9..f34dec9fc 100644 --- a/livesupport/products/scheduler/src/RemoveFromScheduleMethodTest.cxx +++ b/livesupport/products/scheduler/src/RemoveFromScheduleMethodTest.cxx @@ -22,7 +22,7 @@ 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 $ ------------------------------------------------------------------------------*/ @@ -45,6 +45,7 @@ #include #include "ScheduleFactory.h" +#include "LiveSupport/Core/TimeConversion.h" #include "LiveSupport/Authentication/AuthenticationClientFactory.h" #include "LiveSupport/Storage/StorageClientFactory.h" @@ -54,6 +55,8 @@ #include "RemoveFromScheduleMethodTest.h" +using namespace boost::posix_time; + using namespace LiveSupport::Authentication; using namespace LiveSupport::Storage; 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::Ref uploadMethod( + new UploadPlaylistMethod()); + Ptr::Ref removeMethod( + new RemoveFromScheduleMethod()); + XmlRpc::XmlRpcValue parameters; + XmlRpc::XmlRpcValue rootParameter; + rootParameter.setSize(1); + XmlRpc::XmlRpcValue result; + Ptr::Ref now; + struct tm time; + Ptr::Ref duration; + Ptr::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); +} + + diff --git a/livesupport/products/scheduler/src/RemoveFromScheduleMethodTest.h b/livesupport/products/scheduler/src/RemoveFromScheduleMethodTest.h index a8cf63ba6..b748e1a53 100644 --- a/livesupport/products/scheduler/src/RemoveFromScheduleMethodTest.h +++ b/livesupport/products/scheduler/src/RemoveFromScheduleMethodTest.h @@ -22,7 +22,7 @@ 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 $ ------------------------------------------------------------------------------*/ @@ -65,7 +65,7 @@ using namespace LiveSupport::Authentication; * Unit test for the RemoveFromScheduleMethod class. * * @author $Author: maroy $ - * @version $Revision: 1.5 $ + * @version $Revision: 1.6 $ * @see RemoveFromScheduleMethod */ class RemoveFromScheduleMethodTest : public CPPUNIT_NS::TestFixture @@ -73,6 +73,7 @@ class RemoveFromScheduleMethodTest : public CPPUNIT_NS::TestFixture CPPUNIT_TEST_SUITE(RemoveFromScheduleMethodTest); CPPUNIT_TEST(firstTest); CPPUNIT_TEST(negativeTest); + CPPUNIT_TEST(currentlyPlayingTest); CPPUNIT_TEST_SUITE_END(); private: @@ -111,6 +112,14 @@ class RemoveFromScheduleMethodTest : public CPPUNIT_NS::TestFixture void 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: /** diff --git a/livesupport/products/scheduler/src/RescheduleMethod.cxx b/livesupport/products/scheduler/src/RescheduleMethod.cxx index 1f7a92962..5da0e3f6b 100644 --- a/livesupport/products/scheduler/src/RescheduleMethod.cxx +++ b/livesupport/products/scheduler/src/RescheduleMethod.cxx @@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Author : $Author: fgerlits $ - Version : $Revision: 1.8 $ + Author : $Author: maroy $ + Version : $Revision: 1.9 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RescheduleMethod.cxx,v $ ------------------------------------------------------------------------------*/ @@ -136,12 +136,21 @@ RescheduleMethod :: execute(XmlRpc::XmlRpcValue & rootParameter, Ptr::Ref sf = ScheduleFactory::getInstance(); Ptr::Ref schedule = sf->getSchedule(); + Ptr::Ref currentlyPlaying; if (!schedule->scheduleEntryExists(entryId)) { XmlRpcTools::markError(errorId+4, "schedule entry not found", returnValue); 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 { schedule->reschedule(entryId, playschedule); } catch (std::invalid_argument &e) { diff --git a/livesupport/products/scheduler/src/RescheduleMethod.h b/livesupport/products/scheduler/src/RescheduleMethod.h index 2f172aec9..ac3b6ff53 100644 --- a/livesupport/products/scheduler/src/RescheduleMethod.h +++ b/livesupport/products/scheduler/src/RescheduleMethod.h @@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Author : $Author: fgerlits $ - Version : $Revision: 1.7 $ + Author : $Author: maroy $ + Version : $Revision: 1.8 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RescheduleMethod.h,v $ ------------------------------------------------------------------------------*/ @@ -89,11 +89,12 @@ using namespace LiveSupport::Core; *
  • 1303 - missing playtime argument
  • *
  • 1304 - schedule entry not found
  • *
  • 1305 - could not reschedule entry
  • + *
  • 1306 - the entry to be rescheduled is currently playing
  • *
  • 1320 - missing session ID argument
  • * * - * @author $Author: fgerlits $ - * @version $Revision: 1.7 $ + * @author $Author: maroy $ + * @version $Revision: 1.8 $ */ class RescheduleMethod : public XmlRpc::XmlRpcServerMethod { diff --git a/livesupport/products/scheduler/src/RescheduleMethodTest.cxx b/livesupport/products/scheduler/src/RescheduleMethodTest.cxx index b22ecd9cf..3632db448 100644 --- a/livesupport/products/scheduler/src/RescheduleMethodTest.cxx +++ b/livesupport/products/scheduler/src/RescheduleMethodTest.cxx @@ -22,7 +22,7 @@ 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 $ ------------------------------------------------------------------------------*/ @@ -44,6 +44,7 @@ #include #include +#include "LiveSupport/Core/TimeConversion.h" #include "LiveSupport/Db/ConnectionManagerFactory.h" #include "LiveSupport/Storage/StorageClientFactory.h" #include "LiveSupport/Authentication/AuthenticationClientFactory.h" @@ -80,6 +81,9 @@ RescheduleMethodTest :: setUp(void) throw () { Ptr::Ref scheduler = SchedulerDaemon::getInstance(); try { + Ptr::Ref storage = scheduler->getStorage(); + storage->reset(); + schedule = scheduler->getSchedule(); 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::Ref uploadMethod(new UploadPlaylistMethod()); + Ptr::Ref rescheduleMethod(new RescheduleMethod()); + XmlRpc::XmlRpcValue parameters; + XmlRpc::XmlRpcValue rootParameter; + rootParameter.setSize(1); + XmlRpc::XmlRpcValue result; + struct tm time; + Ptr::Ref now; + Ptr::Ref duration; + bool gotException; + Ptr::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); +} + diff --git a/livesupport/products/scheduler/src/RescheduleMethodTest.h b/livesupport/products/scheduler/src/RescheduleMethodTest.h index 6bbd19de1..49aeeb3ed 100644 --- a/livesupport/products/scheduler/src/RescheduleMethodTest.h +++ b/livesupport/products/scheduler/src/RescheduleMethodTest.h @@ -22,7 +22,7 @@ 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 $ ------------------------------------------------------------------------------*/ @@ -65,13 +65,14 @@ using namespace LiveSupport::Authentication; * Unit test for the RescheduleMethod class. * * @author $Author: maroy $ - * @version $Revision: 1.5 $ + * @version $Revision: 1.6 $ * @see RescheduleMethod */ class RescheduleMethodTest : public CPPUNIT_NS::TestFixture { CPPUNIT_TEST_SUITE(RescheduleMethodTest); CPPUNIT_TEST(firstTest); + CPPUNIT_TEST(currentlyPlayingTest); CPPUNIT_TEST_SUITE_END(); private: @@ -102,6 +103,15 @@ class RescheduleMethodTest : public CPPUNIT_NS::TestFixture void 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: /** diff --git a/livesupport/products/scheduler/src/RpcRemoveFromScheduleTest.cxx b/livesupport/products/scheduler/src/RpcRemoveFromScheduleTest.cxx index 3f5284e86..ffb3d28db 100644 --- a/livesupport/products/scheduler/src/RpcRemoveFromScheduleTest.cxx +++ b/livesupport/products/scheduler/src/RpcRemoveFromScheduleTest.cxx @@ -22,7 +22,7 @@ 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 $ ------------------------------------------------------------------------------*/ @@ -34,6 +34,7 @@ #include #include "SchedulerDaemon.h" +#include "LiveSupport/Core/TimeConversion.h" #include "RpcRemoveFromScheduleTest.h" @@ -183,3 +184,53 @@ RpcRemoveFromScheduleTest :: negativeTest(void) 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::Ref now; + struct tm time; + Ptr::Ref duration; + Ptr::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(); +} diff --git a/livesupport/products/scheduler/src/RpcRemoveFromScheduleTest.h b/livesupport/products/scheduler/src/RpcRemoveFromScheduleTest.h index 7fda7df15..cf17ec489 100644 --- a/livesupport/products/scheduler/src/RpcRemoveFromScheduleTest.h +++ b/livesupport/products/scheduler/src/RpcRemoveFromScheduleTest.h @@ -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/RpcRemoveFromScheduleTest.h,v $ ------------------------------------------------------------------------------*/ @@ -64,7 +64,7 @@ using namespace LiveSupport::Core; * Unit test to test the removeFromSchedule XML-RPC call. * * @author $Author: maroy $ - * @version $Revision: 1.4 $ + * @version $Revision: 1.5 $ * @see SchedulerDaemon */ class RpcRemoveFromScheduleTest : public BaseTestMethod @@ -72,6 +72,7 @@ class RpcRemoveFromScheduleTest : public BaseTestMethod CPPUNIT_TEST_SUITE(RpcRemoveFromScheduleTest); CPPUNIT_TEST(simpleTest); CPPUNIT_TEST(negativeTest); + CPPUNIT_TEST(currentlyPlayingTest); CPPUNIT_TEST_SUITE_END(); private: @@ -99,6 +100,14 @@ class RpcRemoveFromScheduleTest : public BaseTestMethod void 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: /** diff --git a/livesupport/products/scheduler/src/RpcRescheduleTest.cxx b/livesupport/products/scheduler/src/RpcRescheduleTest.cxx index 48022af1b..d39b18912 100644 --- a/livesupport/products/scheduler/src/RpcRescheduleTest.cxx +++ b/livesupport/products/scheduler/src/RpcRescheduleTest.cxx @@ -22,7 +22,7 @@ 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 $ ------------------------------------------------------------------------------*/ @@ -34,6 +34,7 @@ #include #include "SchedulerDaemon.h" +#include "LiveSupport/Core/TimeConversion.h" #include "RpcRescheduleTest.h" @@ -228,3 +229,63 @@ RpcRescheduleTest :: negativeTest(void) 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::Ref now; + struct tm time; + Ptr::Ref duration; + Ptr::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(); +} + + diff --git a/livesupport/products/scheduler/src/RpcRescheduleTest.h b/livesupport/products/scheduler/src/RpcRescheduleTest.h index eb4c7ec17..e36b47e53 100644 --- a/livesupport/products/scheduler/src/RpcRescheduleTest.h +++ b/livesupport/products/scheduler/src/RpcRescheduleTest.h @@ -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/RpcRescheduleTest.h,v $ ------------------------------------------------------------------------------*/ @@ -64,7 +64,7 @@ using namespace LiveSupport::Core; * Unit test to test the removeFromSchedule XML-RPC call. * * @author $Author: maroy $ - * @version $Revision: 1.4 $ + * @version $Revision: 1.5 $ * @see SchedulerDaemon */ class RpcRescheduleTest : public BaseTestMethod @@ -72,6 +72,7 @@ class RpcRescheduleTest : public BaseTestMethod CPPUNIT_TEST_SUITE(RpcRescheduleTest); CPPUNIT_TEST(simpleTest); CPPUNIT_TEST(negativeTest); + CPPUNIT_TEST(currentlyPlayingTest); CPPUNIT_TEST_SUITE_END(); private: @@ -99,6 +100,15 @@ class RpcRescheduleTest : public BaseTestMethod void 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: /** diff --git a/livesupport/products/scheduler/src/ScheduleInterface.h b/livesupport/products/scheduler/src/ScheduleInterface.h index 14605b261..d3c8899ba 100644 --- a/livesupport/products/scheduler/src/ScheduleInterface.h +++ b/livesupport/products/scheduler/src/ScheduleInterface.h @@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Author : $Author: fgerlits $ - Version : $Revision: 1.7 $ + Author : $Author: maroy $ + Version : $Revision: 1.8 $ 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. * - * @author $Author: fgerlits $ - * @version $Revision: 1.7 $ + * @author $Author: maroy $ + * @version $Revision: 1.8 $ */ class ScheduleInterface : virtual public Installable { @@ -117,6 +117,16 @@ class ScheduleInterface : virtual public Installable throw () = 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::Ref + getCurrentlyPlaying(void) throw () + = 0; + /** * Return the next schedule entry, after (but not including) * the specified timepoint.