fix reload ingest bug, remove when disabled. 0.9.196

pull/133/head
winlin 11 years ago
parent 2f5fa25f29
commit cf7504826b

@ -14,5 +14,9 @@ http_stream {
listen 8080;
dir ./objs/nginx/html;
}
stats {
network 0;
disk sda sdb xvda xvdb;
}
vhost __defaultVhost__ {
}

@ -414,11 +414,18 @@ int SrsConfig::reload()
}
srs_info("config reloader parse file success.");
return reload_conf(&conf);
}
int SrsConfig::reload_conf(SrsConfig* conf)
{
int ret = ERROR_SUCCESS;
SrsConfDirective* old_root = root;
SrsAutoFree(SrsConfDirective, old_root);
root = conf.root;
conf.root = NULL;
root = conf->root;
conf->root = NULL;
// merge config.
std::vector<ISrsReloadHandler*>::iterator it;
@ -954,44 +961,41 @@ int SrsConfig::reload_ingest(SrsConfDirective* new_vhost, SrsConfDirective* old_
for (int i = 0; i < (int)old_ingesters.size(); i++) {
SrsConfDirective* old_ingester = old_ingesters.at(i);
std::string ingest_id = old_ingester->arg0();
SrsConfDirective* new_ingester = new_vhost->get("ingest", ingest_id);
// if ingester exists in new vhost, not removed, ignore.
if (new_vhost->get("ingest", ingest_id)) {
continue;
}
// notice handler ingester removed.
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_ingest_removed(vhost, ingest_id)) != ERROR_SUCCESS) {
srs_error("vhost %s notify subscribes ingest=%s removed failed. ret=%d",
vhost.c_str(), ingest_id.c_str(), ret);
return ret;
// ENABLED => DISABLED
if (get_ingest_enabled(old_ingester) && !get_ingest_enabled(new_ingester)) {
// notice handler ingester removed.
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_ingest_removed(vhost, ingest_id)) != ERROR_SUCCESS) {
srs_error("vhost %s notify subscribes ingest=%s removed failed. ret=%d",
vhost.c_str(), ingest_id.c_str(), ret);
return ret;
}
}
srs_trace("vhost %s reload ingest=%s removed success.", vhost.c_str(), ingest_id.c_str());
}
srs_trace("vhost %s reload ingest=%s removed success.", vhost.c_str(), ingest_id.c_str());
}
// for added ingesters, start them.
for (int i = 0; i < (int)new_ingesters.size(); i++) {
SrsConfDirective* new_ingester = new_ingesters.at(i);
std::string ingest_id = new_ingester->arg0();
SrsConfDirective* old_ingester = old_vhost->get("ingest", ingest_id);
// if ingester exists in old vhost, not added, ignore.
if (old_vhost->get("ingest", ingest_id)) {
continue;
}
// notice handler ingester removed.
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_ingest_added(vhost, ingest_id)) != ERROR_SUCCESS) {
srs_error("vhost %s notify subscribes ingest=%s added failed. ret=%d",
vhost.c_str(), ingest_id.c_str(), ret);
return ret;
// DISABLED => ENABLED
if (!get_ingest_enabled(old_ingester) && get_ingest_enabled(new_ingester)) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_ingest_added(vhost, ingest_id)) != ERROR_SUCCESS) {
srs_error("vhost %s notify subscribes ingest=%s added failed. ret=%d",
vhost.c_str(), ingest_id.c_str(), ret);
return ret;
}
}
srs_trace("vhost %s reload ingest=%s added success.", vhost.c_str(), ingest_id.c_str());
}
srs_trace("vhost %s reload ingest=%s added success.", vhost.c_str(), ingest_id.c_str());
}
// for updated ingesters, restart them.
@ -1000,25 +1004,23 @@ int SrsConfig::reload_ingest(SrsConfDirective* new_vhost, SrsConfDirective* old_
std::string ingest_id = new_ingester->arg0();
SrsConfDirective* old_ingester = old_vhost->get("ingest", ingest_id);
// ignore the added ingester.
if (!old_ingester) {
continue;
}
if (srs_directive_equals(new_ingester, old_ingester)) {
continue;
}
// notice handler ingester removed.
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_ingest_updated(vhost, ingest_id)) != ERROR_SUCCESS) {
srs_error("vhost %s notify subscribes ingest=%s updated failed. ret=%d",
vhost.c_str(), ingest_id.c_str(), ret);
return ret;
// ENABLED => ENABLED
if (get_ingest_enabled(old_ingester) && get_ingest_enabled(new_ingester)) {
if (srs_directive_equals(new_ingester, old_ingester)) {
continue;
}
// notice handler ingester removed.
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_ingest_updated(vhost, ingest_id)) != ERROR_SUCCESS) {
srs_error("vhost %s notify subscribes ingest=%s updated failed. ret=%d",
vhost.c_str(), ingest_id.c_str(), ret);
return ret;
}
}
srs_trace("vhost %s reload ingest=%s updated success.", vhost.c_str(), ingest_id.c_str());
}
srs_trace("vhost %s reload ingest=%s updated success.", vhost.c_str(), ingest_id.c_str());
}
srs_trace("ingest not changed for vhost=%s", vhost.c_str());
@ -1270,11 +1272,11 @@ int SrsConfig::check_config()
}
}
}
for (int i = 0; i < (int)vhosts.size(); i++) {
SrsConfDirective* conf = vhosts[i];
for (int i = 0; conf && i < (int)conf->directives.size(); i++) {
SrsConfDirective* conf0 = conf->at(i);
string n = conf0->name;
for (int n = 0; n < (int)vhosts.size(); n++) {
SrsConfDirective* vhost = vhosts[n];
for (int i = 0; vhost && i < (int)vhost->directives.size(); i++) {
SrsConfDirective* conf = vhost->at(i);
string n = conf->name;
if (n != "enabled" && n != "chunk_size"
&& n != "mode" && n != "origin" && n != "token_traverse"
&& n != "dvr" && n != "ingest" && n != "http" && n != "hls" && n != "http_hooks"
@ -1290,8 +1292,8 @@ int SrsConfig::check_config()
}
// for each sub directives of vhost.
if (n == "dvr") {
for (int j = 0; j < (int)conf0->directives.size(); j++) {
string m = conf0->at(j)->name.c_str();
for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name.c_str();
if (m != "enabled" && m != "dvr_path" && m != "dvr_plan"
&& m != "dvr_duration" && m != "time_jitter"
) {
@ -1301,8 +1303,8 @@ int SrsConfig::check_config()
}
}
} else if (n == "ingest") {
for (int j = 0; j < (int)conf0->directives.size(); j++) {
string m = conf0->at(j)->name.c_str();
for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name.c_str();
if (m != "enabled" && m != "input" && m != "ffmpeg"
&& m != "engine"
) {
@ -1312,8 +1314,8 @@ int SrsConfig::check_config()
}
}
} else if (n == "http") {
for (int j = 0; j < (int)conf0->directives.size(); j++) {
string m = conf0->at(j)->name.c_str();
for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name.c_str();
if (m != "enabled" && m != "mount" && m != "dir") {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported vhost http directive %s, ret=%d", m.c_str(), ret);
@ -1321,8 +1323,8 @@ int SrsConfig::check_config()
}
}
} else if (n == "hls") {
for (int j = 0; j < (int)conf0->directives.size(); j++) {
string m = conf0->at(j)->name.c_str();
for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name.c_str();
if (m != "enabled" && m != "hls_path" && m != "hls_fragment" && m != "hls_window") {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported vhost hls directive %s, ret=%d", m.c_str(), ret);
@ -1330,8 +1332,8 @@ int SrsConfig::check_config()
}
}
} else if (n == "http_hooks") {
for (int j = 0; j < (int)conf0->directives.size(); j++) {
string m = conf0->at(j)->name.c_str();
for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name.c_str();
if (m != "enabled" && m != "on_connect" && m != "on_close" && m != "on_publish"
&& m != "on_unpublish" && m != "on_play" && m != "on_stop"
) {
@ -1342,8 +1344,8 @@ int SrsConfig::check_config()
}
} else if (n == "forward") {
// TODO: FIXME: implements it.
/*for (int j = 0; j < (int)conf0->directives.size(); j++) {
string m = conf0->at(j)->name.c_str();
/*for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name.c_str();
if (m != "enabled" && m != "vhost" && m != "refer") {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported vhost forward directive %s, ret=%d", m.c_str(), ret);
@ -1351,17 +1353,17 @@ int SrsConfig::check_config()
}
}*/
} else if (n == "transcode") {
for (int j = 0; j < (int)conf0->directives.size(); j++) {
SrsConfDirective* conf1 = conf0->at(j);
string m = conf1->name.c_str();
for (int j = 0; j < (int)conf->directives.size(); j++) {
SrsConfDirective* trans = conf->at(j);
string m = trans->name.c_str();
if (m != "enabled" && m != "ffmpeg" && m != "engine") {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported vhost transcode directive %s, ret=%d", m.c_str(), ret);
return ret;
}
if (m == "engine") {
for (int k = 0; k < (int)conf1->directives.size(); k++) {
string e = conf1->at(k)->name;
for (int k = 0; k < (int)trans->directives.size(); k++) {
string e = trans->at(k)->name;
if (e != "enabled" && e != "vfilter" && e != "vcodec"
&& e != "vbitrate" && e != "vfps" && e != "vwidth" && e != "vheight"
&& e != "vthreads" && e != "vprofile" && e != "vpreset" && e != "vparams"
@ -1377,8 +1379,8 @@ int SrsConfig::check_config()
}
}
} else if (n == "bandcheck") {
for (int j = 0; j < (int)conf0->directives.size(); j++) {
string m = conf0->at(j)->name.c_str();
for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name.c_str();
if (m != "enabled" && m != "key" && m != "interval" && m != "limit_kbps") {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported vhost bandcheck directive %s, ret=%d", m.c_str(), ret);
@ -1388,6 +1390,29 @@ int SrsConfig::check_config()
}
}
}
// check ingest id unique.
for (int i = 0; i < (int)vhosts.size(); i++) {
SrsConfDirective* vhost = vhosts[i];
std::vector<std::string> ids;
for (int j = 0; j < (int)vhost->directives.size(); j++) {
SrsConfDirective* conf = vhost->at(j);
if (conf->name != "ingest") {
continue;
}
std::string id = conf->arg0();
for (int k = 0; k < (int)ids.size(); k++) {
if (id == ids.at(k)) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("directive \"ingest\" id duplicated, vhost=%s, id=%s, ret=%d",
vhost->name.c_str(), id.c_str(), ret);
return ret;
}
}
ids.push_back(id);
}
}
////////////////////////////////////////////////////////////////////////
// check listen for rtmp.

@ -290,6 +290,12 @@ public:
* @remark, user can test the config before reload it.
*/
virtual int reload();
protected:
/**
* reload from the config.
* @remark, use protected for the utest to override with mock.
*/
virtual int reload_conf(SrsConfig* conf);
private:
/**
* reload the http_api section of config.
@ -334,7 +340,7 @@ protected:
/**
* parse config from the buffer.
* @param buffer, the config buffer, user must delete it.
* @remark, protected for the utest to override with mock.
* @remark, use protected for the utest to override with mock.
*/
virtual int parse_buffer(_srs_internal::SrsConfigBuffer* buffer);
private:

@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// current release version
#define VERSION_MAJOR "0"
#define VERSION_MINOR "9"
#define VERSION_REVISION "195"
#define VERSION_REVISION "196"
#define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
// server info.
#define RTMP_SIG_SRS_KEY "SRS"

@ -30,7 +30,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_app_log.hpp>
// kernel module.
ISrsLog* _srs_log = new MockEmptyLog(SrsLogLevel::Warn);
ISrsLog* _srs_log = new MockEmptyLog(SrsLogLevel::Disabled);
ISrsThreadContext* _srs_context = new ISrsThreadContext();
// app module.
SrsConfig* _srs_config = NULL;

@ -33,8 +33,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_app_log.hpp>
#define __UTEST_DEV
#undef __UTEST_DEV
// enable all utest.
#if 1
#ifndef __UTEST_DEV
#define ENABLE_UTEST_AMF0
#define ENABLE_UTEST_CONFIG
#define ENABLE_UTEST_CORE
@ -44,7 +47,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#endif
// disable some for fast dev, compile and startup.
#if 0
#ifdef __UTEST_DEV
#undef ENABLE_UTEST_AMF0
#undef ENABLE_UTEST_CONFIG
#undef ENABLE_UTEST_CORE
@ -53,6 +56,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#undef ENABLE_UTEST_RELOAD
#endif
#ifdef __UTEST_DEV
#define ENABLE_UTEST_RELOAD
#endif
// we add an empty macro for upp to show the smart tips.
#define VOID

@ -70,8 +70,6 @@ int MockSrsConfig::parse(string buf)
#ifdef ENABLE_UTEST_CONFIG
#define _MIN_OK_CONF "listen 1935; "
// full.conf
std::string __full_conf = ""
"# all config for srs \n"
@ -5454,5 +5452,13 @@ VOID TEST(ConfigMainTest, CheckConf_pithy_print)
}
}
VOID TEST(ConfigMainTest, CheckConf_vhost_ingest_id)
{
MockSrsConfig conf;
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{ingest id{}}"));
EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{ingest id{} ingest id{}}"));
EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"vhost v{ingest{} ingest{}}"));
}
#endif

@ -33,6 +33,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_app_config.hpp>
#define _MIN_OK_CONF "listen 1935; "
class MockSrsConfigBuffer : public _srs_internal::SrsConfigBuffer
{
public:

@ -23,7 +23,919 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_utest_reload.hpp>
using namespace std;
#include <srs_kernel_error.hpp>
MockReloadHandler::MockReloadHandler()
{
reset();
}
MockReloadHandler::~MockReloadHandler()
{
}
void MockReloadHandler::reset()
{
listen_reloaded = false;
pid_reloaded = false;
log_tank_reloaded = false;
log_level_reloaded = false;
log_file_reloaded = false;
pithy_print_reloaded = false;
http_api_enabled_reloaded = false;
http_api_disabled_reloaded = false;
http_stream_enabled_reloaded = false;
http_stream_disabled_reloaded = false;
http_stream_updated_reloaded = false;
vhost_http_updated_reloaded = false;
vhost_added_reloaded = false;
vhost_removed_reloaded = false;
vhost_atc_reloaded = false;
vhost_gop_cache_reloaded = false;
vhost_queue_length_reloaded = false;
vhost_time_jitter_reloaded = false;
vhost_forward_reloaded = false;
vhost_hls_reloaded = false;
vhost_dvr_reloaded = false;
vhost_transcode_reloaded = false;
ingest_removed_reloaded = false;
ingest_added_reloaded = false;
ingest_updated_reloaded = false;
}
int MockReloadHandler::count_total()
{
return 56 - 31;
}
int MockReloadHandler::count_true()
{
int count_true = 0;
if (listen_reloaded) count_true++;
if (pid_reloaded) count_true++;
if (log_tank_reloaded) count_true++;
if (log_level_reloaded) count_true++;
if (log_file_reloaded) count_true++;
if (pithy_print_reloaded) count_true++;
if (http_api_enabled_reloaded) count_true++;
if (http_api_disabled_reloaded) count_true++;
if (http_stream_enabled_reloaded) count_true++;
if (http_stream_disabled_reloaded) count_true++;
if (http_stream_updated_reloaded) count_true++;
if (vhost_http_updated_reloaded) count_true++;
if (vhost_added_reloaded) count_true++;
if (vhost_removed_reloaded) count_true++;
if (vhost_atc_reloaded) count_true++;
if (vhost_gop_cache_reloaded) count_true++;
if (vhost_queue_length_reloaded) count_true++;
if (vhost_time_jitter_reloaded) count_true++;
if (vhost_forward_reloaded) count_true++;
if (vhost_hls_reloaded) count_true++;
if (vhost_dvr_reloaded) count_true++;
if (vhost_transcode_reloaded) count_true++;
if (ingest_removed_reloaded) count_true++;
if (ingest_added_reloaded) count_true++;
if (ingest_updated_reloaded) count_true++;
return count_true;
}
int MockReloadHandler::count_false()
{
int count_false = 0;
if (!listen_reloaded) count_false++;
if (!pid_reloaded) count_false++;
if (!log_tank_reloaded) count_false++;
if (!log_level_reloaded) count_false++;
if (!log_file_reloaded) count_false++;
if (!pithy_print_reloaded) count_false++;
if (!http_api_enabled_reloaded) count_false++;
if (!http_api_disabled_reloaded) count_false++;
if (!http_stream_enabled_reloaded) count_false++;
if (!http_stream_disabled_reloaded) count_false++;
if (!http_stream_updated_reloaded) count_false++;
if (!vhost_http_updated_reloaded) count_false++;
if (!vhost_added_reloaded) count_false++;
if (!vhost_removed_reloaded) count_false++;
if (!vhost_atc_reloaded) count_false++;
if (!vhost_gop_cache_reloaded) count_false++;
if (!vhost_queue_length_reloaded) count_false++;
if (!vhost_time_jitter_reloaded) count_false++;
if (!vhost_forward_reloaded) count_false++;
if (!vhost_hls_reloaded) count_false++;
if (!vhost_dvr_reloaded) count_false++;
if (!vhost_transcode_reloaded) count_false++;
if (!ingest_removed_reloaded) count_false++;
if (!ingest_added_reloaded) count_false++;
if (!ingest_updated_reloaded) count_false++;
return count_false;
}
bool MockReloadHandler::all_false()
{
return count_true() == 0;
}
bool MockReloadHandler::all_true()
{
return count_true() == count_total();
}
int MockReloadHandler::on_reload_listen()
{
listen_reloaded = true;
return ERROR_SUCCESS;
}
int MockReloadHandler::on_reload_pid()
{
pid_reloaded = true;
return ERROR_SUCCESS;
}
int MockReloadHandler::on_reload_log_tank()
{
log_tank_reloaded = true;
return ERROR_SUCCESS;
}
int MockReloadHandler::on_reload_log_level()
{
log_level_reloaded = true;
return ERROR_SUCCESS;
}
int MockReloadHandler::on_reload_log_file()
{
log_file_reloaded = true;
return ERROR_SUCCESS;
}
int MockReloadHandler::on_reload_pithy_print()
{
pithy_print_reloaded = true;
return ERROR_SUCCESS;
}
int MockReloadHandler::on_reload_http_api_enabled()
{
http_api_enabled_reloaded = true;
return ERROR_SUCCESS;
}
int MockReloadHandler::on_reload_http_api_disabled()
{
http_api_disabled_reloaded = true;
return ERROR_SUCCESS;
}
int MockReloadHandler::on_reload_http_stream_enabled()
{
http_stream_enabled_reloaded = true;
return ERROR_SUCCESS;
}
int MockReloadHandler::on_reload_http_stream_disabled()
{
http_stream_disabled_reloaded = true;
return ERROR_SUCCESS;
}
int MockReloadHandler::on_reload_http_stream_updated()
{
http_stream_updated_reloaded = true;
return ERROR_SUCCESS;
}
int MockReloadHandler::on_reload_vhost_http_updated()
{
vhost_http_updated_reloaded = true;
return ERROR_SUCCESS;
}
int MockReloadHandler::on_reload_vhost_added(string /*vhost*/)
{
vhost_added_reloaded = true;
return ERROR_SUCCESS;
}
int MockReloadHandler::on_reload_vhost_removed(string /*vhost*/)
{
vhost_removed_reloaded = true;
return ERROR_SUCCESS;
}
int MockReloadHandler::on_reload_vhost_atc(string /*vhost*/)
{
vhost_atc_reloaded = true;
return ERROR_SUCCESS;
}
int MockReloadHandler::on_reload_vhost_gop_cache(string /*vhost*/)
{
vhost_gop_cache_reloaded = true;
return ERROR_SUCCESS;
}
int MockReloadHandler::on_reload_vhost_queue_length(string /*vhost*/)
{
vhost_queue_length_reloaded = true;
return ERROR_SUCCESS;
}
int MockReloadHandler::on_reload_vhost_time_jitter(string /*vhost*/)
{
vhost_time_jitter_reloaded = true;
return ERROR_SUCCESS;
}
int MockReloadHandler::on_reload_vhost_forward(string /*vhost*/)
{
vhost_forward_reloaded = true;
return ERROR_SUCCESS;
}
int MockReloadHandler::on_reload_vhost_hls(string /*vhost*/)
{
vhost_hls_reloaded = true;
return ERROR_SUCCESS;
}
int MockReloadHandler::on_reload_vhost_dvr(string /*vhost*/)
{
vhost_dvr_reloaded = true;
return ERROR_SUCCESS;
}
int MockReloadHandler::on_reload_vhost_transcode(string /*vhost*/)
{
vhost_transcode_reloaded = true;
return ERROR_SUCCESS;
}
int MockReloadHandler::on_reload_ingest_removed(string /*vhost*/, string /*ingest_id*/)
{
ingest_removed_reloaded = true;
return ERROR_SUCCESS;
}
int MockReloadHandler::on_reload_ingest_added(string /*vhost*/, string /*ingest_id*/)
{
ingest_added_reloaded = true;
return ERROR_SUCCESS;
}
int MockReloadHandler::on_reload_ingest_updated(string /*vhost*/, string /*ingest_id*/)
{
ingest_updated_reloaded = true;
return ERROR_SUCCESS;
}
MockSrsReloadConfig::MockSrsReloadConfig()
{
}
MockSrsReloadConfig::~MockSrsReloadConfig()
{
}
int MockSrsReloadConfig::reload(string buf)
{
int ret = ERROR_SUCCESS;
MockSrsReloadConfig conf;
if ((ret = conf.parse(buf)) != ERROR_SUCCESS) {
return ret;
}
return reload_conf(&conf);
}
#ifdef ENABLE_UTEST_RELOAD
VOID TEST(ConfigReloadTest, ReloadEmpty)
{
MockReloadHandler handler;
MockSrsReloadConfig conf;
conf.subscribe(&handler);
EXPECT_FALSE(ERROR_SUCCESS == conf.parse(""));
EXPECT_FALSE(ERROR_SUCCESS == conf.reload(""));
EXPECT_TRUE(handler.all_false());
}
VOID TEST(ConfigReloadTest, ReloadListen)
{
MockReloadHandler handler;
MockSrsReloadConfig conf;
conf.subscribe(&handler);
EXPECT_TRUE(ERROR_SUCCESS == conf.parse("listen 1935;"));
EXPECT_TRUE(ERROR_SUCCESS == conf.reload("listen 1935;"));
EXPECT_TRUE(handler.all_false());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload("listen 1936;"));
EXPECT_TRUE(handler.listen_reloaded);
EXPECT_EQ(1, handler.count_true());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload("listen 1936;"));
EXPECT_TRUE(handler.all_false());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload("listen 1936 1935;"));
EXPECT_TRUE(handler.listen_reloaded);
EXPECT_EQ(1, handler.count_true());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload("listen 1935;"));
EXPECT_TRUE(handler.listen_reloaded);
EXPECT_EQ(1, handler.count_true());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload("listen 1935 1935;"));
EXPECT_TRUE(handler.listen_reloaded);
EXPECT_EQ(1, handler.count_true());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload("listen 1935;"));
EXPECT_TRUE(handler.listen_reloaded);
EXPECT_EQ(1, handler.count_true());
handler.reset();
}
VOID TEST(ConfigReloadTest, ReloadPid)
{
MockReloadHandler handler;
MockSrsReloadConfig conf;
conf.subscribe(&handler);
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"pid srs.pid;"));
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"pid srs.pid;"));
EXPECT_TRUE(handler.all_false());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"pid srs1.pid;"));
EXPECT_TRUE(handler.pid_reloaded);
EXPECT_EQ(1, handler.count_true());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"pid srs.pid;"));
EXPECT_EQ(1, handler.count_true());
handler.reset();
}
VOID TEST(ConfigReloadTest, ReloadLogTank)
{
MockReloadHandler handler;
MockSrsReloadConfig conf;
conf.subscribe(&handler);
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"srs_log_tank console;"));
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"srs_log_tank console;"));
EXPECT_TRUE(handler.all_false());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"srs_log_tank file;"));
EXPECT_TRUE(handler.log_tank_reloaded);
EXPECT_EQ(1, handler.count_true());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"srs_log_tank console;"));
EXPECT_EQ(1, handler.count_true());
handler.reset();
}
VOID TEST(ConfigReloadTest, ReloadLogLevel)
{
MockReloadHandler handler;
MockSrsReloadConfig conf;
conf.subscribe(&handler);
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"srs_log_level trace;"));
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"srs_log_level trace;"));
EXPECT_TRUE(handler.all_false());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"srs_log_level warn;"));
EXPECT_TRUE(handler.log_level_reloaded);
EXPECT_EQ(1, handler.count_true());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"srs_log_level trace;"));
EXPECT_EQ(1, handler.count_true());
handler.reset();
}
VOID TEST(ConfigReloadTest, ReloadLogFile)
{
MockReloadHandler handler;
MockSrsReloadConfig conf;
conf.subscribe(&handler);
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"srs_log_file srs.log;"));
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"srs_log_file srs.log;"));
EXPECT_TRUE(handler.all_false());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"srs_log_file srs1.log;"));
EXPECT_TRUE(handler.log_file_reloaded);
EXPECT_EQ(1, handler.count_true());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"srs_log_file srs.log;"));
EXPECT_EQ(1, handler.count_true());
handler.reset();
}
VOID TEST(ConfigReloadTest, ReloadPithyPrint)
{
MockReloadHandler handler;
MockSrsReloadConfig conf;
conf.subscribe(&handler);
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"pithy_print {publish 1000;}"));
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"pithy_print {publish 1000;}"));
EXPECT_TRUE(handler.all_false());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"pithy_print {publish 2000;}"));
EXPECT_TRUE(handler.pithy_print_reloaded);
EXPECT_EQ(1, handler.count_true());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"pithy_print {publish 1000;}"));
EXPECT_EQ(1, handler.count_true());
handler.reset();
}
VOID TEST(ConfigReloadTest, ReloadHttpApiEnabled)
{
MockReloadHandler handler;
MockSrsReloadConfig conf;
conf.subscribe(&handler);
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"http_api {enabled off;}"));
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"http_api {enabled off;}"));
EXPECT_TRUE(handler.all_false());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"http_api {enabled on;}"));
EXPECT_TRUE(handler.http_api_enabled_reloaded);
EXPECT_EQ(1, handler.count_true());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"http_api {enabled off;}"));
EXPECT_EQ(1, handler.count_true());
handler.reset();
}
VOID TEST(ConfigReloadTest, ReloadHttpApiDisabled)
{
MockReloadHandler handler;
MockSrsReloadConfig conf;
conf.subscribe(&handler);
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"http_api {enabled on;}"));
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"http_api {enabled on;}"));
EXPECT_TRUE(handler.all_false());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"http_api {enabled off;}"));
EXPECT_TRUE(handler.http_api_disabled_reloaded);
EXPECT_EQ(1, handler.count_true());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"http_api {enabled on;}"));
EXPECT_EQ(1, handler.count_true());
handler.reset();
}
VOID TEST(ConfigReloadTest, ReloadHttpStreamEnabled)
{
MockReloadHandler handler;
MockSrsReloadConfig conf;
conf.subscribe(&handler);
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"http_stream {enabled off;}"));
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"http_stream {enabled off;}"));
EXPECT_TRUE(handler.all_false());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"http_stream {enabled on;}"));
EXPECT_TRUE(handler.http_stream_enabled_reloaded);
EXPECT_EQ(1, handler.count_true());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"http_stream {enabled off;}"));
EXPECT_EQ(1, handler.count_true());
handler.reset();
}
VOID TEST(ConfigReloadTest, ReloadHttpStreamDisabled)
{
MockReloadHandler handler;
MockSrsReloadConfig conf;
conf.subscribe(&handler);
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"http_stream {enabled on;}"));
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"http_stream {enabled on;}"));
EXPECT_TRUE(handler.all_false());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"http_stream {enabled off;}"));
EXPECT_TRUE(handler.http_stream_disabled_reloaded);
EXPECT_EQ(1, handler.count_true());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"http_stream {enabled on;}"));
EXPECT_EQ(1, handler.count_true());
handler.reset();
}
VOID TEST(ConfigReloadTest, ReloadHttpStreamUpdated)
{
MockReloadHandler handler;
MockSrsReloadConfig conf;
conf.subscribe(&handler);
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"http_stream {enabled on; listen 8080;}"));
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"http_stream {enabled on; listen 8080;}"));
EXPECT_TRUE(handler.all_false());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"http_stream {enabled on; listen 8000;}"));
EXPECT_TRUE(handler.http_stream_updated_reloaded);
EXPECT_EQ(1, handler.count_true());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"http_stream {enabled on; listen 8080;}"));
EXPECT_EQ(1, handler.count_true());
handler.reset();
}
VOID TEST(ConfigReloadTest, ReloadVhostHttpUpdated)
{
MockReloadHandler handler;
MockSrsReloadConfig conf;
conf.subscribe(&handler);
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost http.srs.com {http {enabled on;mount /hls;}}"));
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost http.srs.com {http {enabled on;mount /hls;}}"));
EXPECT_TRUE(handler.all_false());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost http.srs.com {http {enabled on;mount /hls1;}}"));
EXPECT_TRUE(handler.vhost_http_updated_reloaded);
EXPECT_EQ(1, handler.count_true());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost http.srs.com {http {enabled on;mount /hls;}}"));
EXPECT_EQ(1, handler.count_true());
handler.reset();
}
VOID TEST(ConfigReloadTest, ReloadVhostAdded)
{
MockReloadHandler handler;
MockSrsReloadConfig conf;
conf.subscribe(&handler);
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost a{}"));
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{}"));
EXPECT_TRUE(handler.all_false());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{} vhost b{}"));
EXPECT_TRUE(handler.vhost_added_reloaded);
EXPECT_EQ(1, handler.count_true());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{}"));
EXPECT_EQ(1, handler.count_true());
handler.reset();
}
VOID TEST(ConfigReloadTest, ReloadVhostRemoved)
{
MockReloadHandler handler;
MockSrsReloadConfig conf;
conf.subscribe(&handler);
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost a{}"));
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{}"));
EXPECT_TRUE(handler.all_false());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{enabled off;}"));
EXPECT_TRUE(handler.vhost_removed_reloaded);
EXPECT_EQ(1, handler.count_true());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{}"));
EXPECT_EQ(1, handler.count_true());
handler.reset();
}
VOID TEST(ConfigReloadTest, ReloadVhostRemoved2)
{
MockReloadHandler handler;
MockSrsReloadConfig conf;
conf.subscribe(&handler);
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost a{} vhost b{}"));
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{} vhost b{}"));
EXPECT_TRUE(handler.all_false());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{}"));
EXPECT_TRUE(handler.vhost_removed_reloaded);
EXPECT_EQ(1, handler.count_true());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{} vhost b{}"));
EXPECT_EQ(1, handler.count_true());
handler.reset();
}
VOID TEST(ConfigReloadTest, ReloadVhostAtc)
{
MockReloadHandler handler;
MockSrsReloadConfig conf;
conf.subscribe(&handler);
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost a{atc off;}"));
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{atc off;}"));
EXPECT_TRUE(handler.all_false());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{atc on;}"));
EXPECT_TRUE(handler.vhost_atc_reloaded);
EXPECT_EQ(1, handler.count_true());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{atc off;}"));
EXPECT_EQ(1, handler.count_true());
handler.reset();
}
VOID TEST(ConfigReloadTest, ReloadVhostGopCache)
{
MockReloadHandler handler;
MockSrsReloadConfig conf;
conf.subscribe(&handler);
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost a{gop_cache off;}"));
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{gop_cache off;}"));
EXPECT_TRUE(handler.all_false());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{gop_cache on;}"));
EXPECT_TRUE(handler.vhost_gop_cache_reloaded);
EXPECT_EQ(1, handler.count_true());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{gop_cache off;}"));
EXPECT_EQ(1, handler.count_true());
handler.reset();
}
VOID TEST(ConfigReloadTest, ReloadVhostQueueLength)
{
MockReloadHandler handler;
MockSrsReloadConfig conf;
conf.subscribe(&handler);
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost a{queue_length 10;}"));
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{queue_length 10;}"));
EXPECT_TRUE(handler.all_false());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{queue_length 20;}"));
EXPECT_TRUE(handler.vhost_queue_length_reloaded);
EXPECT_EQ(1, handler.count_true());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{queue_length 10;}"));
EXPECT_EQ(1, handler.count_true());
handler.reset();
}
VOID TEST(ConfigReloadTest, ReloadVhostTimeJitter)
{
MockReloadHandler handler;
MockSrsReloadConfig conf;
conf.subscribe(&handler);
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost a{time_jitter full;}"));
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{time_jitter full;}"));
EXPECT_TRUE(handler.all_false());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{time_jitter zero;}"));
EXPECT_TRUE(handler.vhost_time_jitter_reloaded);
EXPECT_EQ(1, handler.count_true());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{time_jitter full;}"));
EXPECT_EQ(1, handler.count_true());
handler.reset();
}
VOID TEST(ConfigReloadTest, ReloadVhostForward)
{
MockReloadHandler handler;
MockSrsReloadConfig conf;
conf.subscribe(&handler);
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost a{forward 127.0.0.1:1936;}"));
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{forward 127.0.0.1:1936;}"));
EXPECT_TRUE(handler.all_false());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{forward 127.0.0.1:1937;}"));
EXPECT_TRUE(handler.vhost_forward_reloaded);
EXPECT_EQ(1, handler.count_true());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{forward 127.0.0.1:1936;}"));
EXPECT_EQ(1, handler.count_true());
handler.reset();
}
VOID TEST(ConfigReloadTest, ReloadVhostHls)
{
MockReloadHandler handler;
MockSrsReloadConfig conf;
conf.subscribe(&handler);
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost a{hls {enabled on;}}"));
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{hls {enabled on;}}"));
EXPECT_TRUE(handler.all_false());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{hls {enabled off;}}"));
EXPECT_TRUE(handler.vhost_hls_reloaded);
EXPECT_EQ(1, handler.count_true());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{hls {enabled on;}}"));
EXPECT_EQ(1, handler.count_true());
handler.reset();
}
VOID TEST(ConfigReloadTest, ReloadVhostDvr)
{
MockReloadHandler handler;
MockSrsReloadConfig conf;
conf.subscribe(&handler);
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost a{dvr {enabled on;}}"));
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{dvr {enabled on;}}"));
EXPECT_TRUE(handler.all_false());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{dvr {enabled off;}}"));
EXPECT_TRUE(handler.vhost_dvr_reloaded);
EXPECT_EQ(1, handler.count_true());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{dvr {enabled on;}}"));
EXPECT_EQ(1, handler.count_true());
handler.reset();
}
VOID TEST(ConfigReloadTest, ReloadVhostTranscode)
{
MockReloadHandler handler;
MockSrsReloadConfig conf;
conf.subscribe(&handler);
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost a{transcode {enabled on;}}"));
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{transcode {enabled on;}}"));
EXPECT_TRUE(handler.all_false());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{transcode {enabled off;}}"));
EXPECT_TRUE(handler.vhost_transcode_reloaded);
EXPECT_EQ(1, handler.count_true());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{transcode {enabled on;}}"));
EXPECT_EQ(1, handler.count_true());
handler.reset();
}
VOID TEST(ConfigReloadTest, ReloadVhostIngestAdded)
{
MockReloadHandler handler;
MockSrsReloadConfig conf;
conf.subscribe(&handler);
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost a{}"));
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{}"));
EXPECT_TRUE(handler.all_false());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{ingest {enabled on;}}"));
EXPECT_TRUE(handler.ingest_added_reloaded);
EXPECT_EQ(1, handler.count_true());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{}"));
EXPECT_EQ(1, handler.count_true());
handler.reset();
}
VOID TEST(ConfigReloadTest, ReloadVhostIngestAdded2)
{
MockReloadHandler handler;
MockSrsReloadConfig conf;
conf.subscribe(&handler);
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost a{ingest a {enabled on;}}"));
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{ingest a {enabled on;}}"));
EXPECT_TRUE(handler.all_false());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{ingest a {enabled on;} ingest b {enabled on;}}"));
EXPECT_TRUE(handler.ingest_added_reloaded);
EXPECT_EQ(1, handler.count_true());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{ingest a {enabled on;}}"));
EXPECT_EQ(1, handler.count_true());
handler.reset();
}
VOID TEST(ConfigReloadTest, ReloadVhostIngestRemoved)
{
MockReloadHandler handler;
MockSrsReloadConfig conf;
conf.subscribe(&handler);
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost a{ingest {enabled on;}}"));
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{ingest {enabled on;}}"));
EXPECT_TRUE(handler.all_false());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{}"));
EXPECT_TRUE(handler.ingest_removed_reloaded);
EXPECT_EQ(1, handler.count_true());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{ingest {enabled on;}}"));
EXPECT_EQ(1, handler.count_true());
handler.reset();
}
VOID TEST(ConfigReloadTest, ReloadVhostIngestRemoved2)
{
MockReloadHandler handler;
MockSrsReloadConfig conf;
conf.subscribe(&handler);
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost a{ingest {enabled on;}}"));
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{ingest {enabled on;}}"));
EXPECT_TRUE(handler.all_false());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{ingest {enabled off;}}"));
EXPECT_TRUE(handler.ingest_removed_reloaded);
EXPECT_EQ(1, handler.count_true());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{ingest {enabled on;}}"));
EXPECT_EQ(1, handler.count_true());
handler.reset();
}
VOID TEST(ConfigReloadTest, ReloadVhostIngestUpdated)
{
MockReloadHandler handler;
MockSrsReloadConfig conf;
conf.subscribe(&handler);
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost a{ingest {enabled on;ffmpeg ffmpeg;}}"));
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{ingest {enabled on;ffmpeg ffmpeg;}}"));
EXPECT_TRUE(handler.all_false());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{ingest {enabled on;ffmpeg ffmpeg1;}}"));
EXPECT_TRUE(handler.ingest_updated_reloaded);
EXPECT_EQ(1, handler.count_true());
handler.reset();
EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{ingest {enabled on;ffmpeg ffmpeg;}}"));
EXPECT_EQ(1, handler.count_true());
handler.reset();
}
#endif

@ -29,5 +29,83 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <srs_core.hpp>
#include <srs_utest_config.hpp>
#include <srs_app_reload.hpp>
class MockReloadHandler : public ISrsReloadHandler
{
public:
bool listen_reloaded;
bool pid_reloaded;
bool log_tank_reloaded;
bool log_level_reloaded;
bool log_file_reloaded;
bool pithy_print_reloaded;
bool http_api_enabled_reloaded;
bool http_api_disabled_reloaded;
bool http_stream_enabled_reloaded;
bool http_stream_disabled_reloaded;
bool http_stream_updated_reloaded;
bool vhost_http_updated_reloaded;
bool vhost_added_reloaded;
bool vhost_removed_reloaded;
bool vhost_atc_reloaded;
bool vhost_gop_cache_reloaded;
bool vhost_queue_length_reloaded;
bool vhost_time_jitter_reloaded;
bool vhost_forward_reloaded;
bool vhost_hls_reloaded;
bool vhost_dvr_reloaded;
bool vhost_transcode_reloaded;
bool ingest_removed_reloaded;
bool ingest_added_reloaded;
bool ingest_updated_reloaded;
public:
MockReloadHandler();
virtual ~MockReloadHandler();
public:
virtual void reset();
virtual bool all_false();
virtual bool all_true();
virtual int count_total();
virtual int count_true();
virtual int count_false();
public:
virtual int on_reload_listen();
virtual int on_reload_pid();
virtual int on_reload_log_tank();
virtual int on_reload_log_level();
virtual int on_reload_log_file();
virtual int on_reload_pithy_print();
virtual int on_reload_http_api_enabled();
virtual int on_reload_http_api_disabled();
virtual int on_reload_http_stream_enabled();
virtual int on_reload_http_stream_disabled();
virtual int on_reload_http_stream_updated();
virtual int on_reload_vhost_http_updated();
virtual int on_reload_vhost_added(std::string vhost);
virtual int on_reload_vhost_removed(std::string vhost);
virtual int on_reload_vhost_atc(std::string vhost);
virtual int on_reload_vhost_gop_cache(std::string vhost);
virtual int on_reload_vhost_queue_length(std::string vhost);
virtual int on_reload_vhost_time_jitter(std::string vhost);
virtual int on_reload_vhost_forward(std::string vhost);
virtual int on_reload_vhost_hls(std::string vhost);
virtual int on_reload_vhost_dvr(std::string vhost);
virtual int on_reload_vhost_transcode(std::string vhost);
virtual int on_reload_ingest_removed(std::string vhost, std::string ingest_id);
virtual int on_reload_ingest_added(std::string vhost, std::string ingest_id);
virtual int on_reload_ingest_updated(std::string vhost, std::string ingest_id);
};
class MockSrsReloadConfig : public MockSrsConfig
{
public:
MockSrsReloadConfig();
virtual ~MockSrsReloadConfig();
public:
virtual int reload(std::string buf);
};
#endif

Loading…
Cancel
Save