diff options
| author | yangwei <[email protected]> | 2024-11-26 14:44:44 +0800 |
|---|---|---|
| committer | yangwei <[email protected]> | 2024-11-26 14:44:44 +0800 |
| commit | 9895e932143ef65313bd1b49726e60fd63c497ed (patch) | |
| tree | 49af0f3d0324c842da7cada43776d546291a253c /infra/module_manager | |
| parent | 78562a8dd879a3753debae14198f00fe2dc0112a (diff) | |
🦄 refactor(remove mq): remove mq in stellar
Diffstat (limited to 'infra/module_manager')
| -rw-r--r-- | infra/module_manager/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | infra/module_manager/module_manager.c | 22 | ||||
| -rw-r--r-- | infra/module_manager/module_manager_interna.h | 4 | ||||
| -rw-r--r-- | infra/module_manager/test/gtest_module_manager_main.cpp | 46 |
4 files changed, 17 insertions, 57 deletions
diff --git a/infra/module_manager/CMakeLists.txt b/infra/module_manager/CMakeLists.txt index 131cf93..dddde31 100644 --- a/infra/module_manager/CMakeLists.txt +++ b/infra/module_manager/CMakeLists.txt @@ -3,6 +3,6 @@ target_include_directories(module_manager PUBLIC ${CMAKE_CURRENT_LIST_DIR}) target_include_directories(module_manager PUBLIC ${CMAKE_SOURCE_DIR}/include/) target_include_directories(module_manager PUBLIC ${CMAKE_SOURCE_DIR}/infra/) target_include_directories(module_manager PUBLIC ${CMAKE_SOURCE_DIR}/deps/) -target_link_libraries(module_manager PUBLIC toml mq ${CMAKE_DL_LIBS}) +target_link_libraries(module_manager PUBLIC toml ${CMAKE_DL_LIBS}) add_subdirectory(test)
\ No newline at end of file diff --git a/infra/module_manager/module_manager.c b/infra/module_manager/module_manager.c index 600327d..a8a3233 100644 --- a/infra/module_manager/module_manager.c +++ b/infra/module_manager/module_manager.c @@ -13,11 +13,10 @@ * module manager API * *******************************************/ -struct module_manager *module_manager_new(struct module_hooks mod_hooks[], size_t n_mod, int max_thread_num, const char *toml_path, struct mq_schema *mq_schema, struct logger *logger) +struct module_manager *module_manager_new(struct module_hooks mod_hooks[], size_t n_mod, int max_thread_num, const char *toml_path, struct logger *logger) { struct module_manager *mod_mgr = CALLOC(struct module_manager, 1); mod_mgr->config.max_thread_num=max_thread_num; - mod_mgr->config.mq_schema=mq_schema; mod_mgr->config.logger=logger; if(toml_path)mod_mgr->config.toml_path=strdup(toml_path); @@ -47,22 +46,22 @@ struct module_manager *module_manager_new(struct module_hooks mod_hooks[], size_ return mod_mgr; } -struct module_manager *module_manager_new_with_toml(const char *toml_path, int max_thread_num, struct mq_schema *mq_schema, struct logger *logger) +struct module_manager *module_manager_new_with_toml(const char *toml_path, int max_thread_num, struct logger *logger) { FILE *fp=fopen(toml_path, "r"); - if(!fp)return module_manager_new(NULL, 0, max_thread_num, toml_path, mq_schema, logger); + if(!fp)return module_manager_new(NULL, 0, max_thread_num, toml_path,logger); toml_table_t *conf = toml_parse_file(fp, NULL, 0); fclose(fp); - if(conf==NULL)return module_manager_new(NULL, 0, max_thread_num, toml_path, mq_schema, logger); + if(conf==NULL)return module_manager_new(NULL, 0, max_thread_num, toml_path, logger); toml_array_t* mod_array = toml_array_in(conf, "module"); if(mod_array==NULL) { toml_free(conf); - return module_manager_new(NULL, 0, max_thread_num, toml_path, mq_schema, logger); + return module_manager_new(NULL, 0, max_thread_num, toml_path, logger); } int mod_num = toml_array_nelem(mod_array); @@ -128,7 +127,7 @@ struct module_manager *module_manager_new_with_toml(const char *toml_path, int m } toml_free(conf); - return module_manager_new(mod_hooks, mod_num, max_thread_num, toml_path, mq_schema, logger); + return module_manager_new(mod_hooks, mod_num, max_thread_num, toml_path, logger); } @@ -164,11 +163,6 @@ int module_manager_get_max_thread_num(struct module_manager*mod_mgr) return mod_mgr->config.max_thread_num; } -struct mq_schema *module_manager_get_mq_schema(struct module_manager *mod_mgr) -{ - if(mod_mgr==NULL)return NULL; - return mod_mgr->config.mq_schema; -} struct logger *module_manager_get_logger(struct module_manager *mod_mgr) { @@ -195,11 +189,9 @@ struct mq_runtime *module_manager_get_mq_runtime(struct module_manager *mod_mgr return local_mq_rt; } -void module_manager_register_thread(struct module_manager* mod_mgr, int thread_id, struct mq_runtime *mq_rt) +void module_manager_register_thread(struct module_manager* mod_mgr, int thread_id) { local_thread_id=thread_id; - local_mq_rt=mq_rt; - for(int i=0; i<mod_mgr->n_descriptor; i++) { if(mod_mgr->descriptors[i].mod == NULL)break; diff --git a/infra/module_manager/module_manager_interna.h b/infra/module_manager/module_manager_interna.h index 1b27bd7..1022da5 100644 --- a/infra/module_manager/module_manager_interna.h +++ b/infra/module_manager/module_manager_interna.h @@ -7,10 +7,7 @@ extern "C" #include "stellar/module.h" -#include "stellar/mq.h" - #include <limits.h> - #include <stdbool.h> struct module @@ -43,7 +40,6 @@ struct module_manager { char *toml_path; int max_thread_num; - struct mq_schema *mq_schema; struct logger *logger; }config; diff --git a/infra/module_manager/test/gtest_module_manager_main.cpp b/infra/module_manager/test/gtest_module_manager_main.cpp index 32d5f0c..7d9760b 100644 --- a/infra/module_manager/test/gtest_module_manager_main.cpp +++ b/infra/module_manager/test/gtest_module_manager_main.cpp @@ -23,7 +23,6 @@ const char *gtest_mock_spec_toml = TEST(module_manager_internal, stellar_module_manager_new_with_toml) { - struct mq_schema *mq_schema=NULL; char toml_template[] = "./stellar.toml.XXXXXX"; int fd = mkstemp(toml_template); @@ -31,16 +30,14 @@ TEST(module_manager_internal, stellar_module_manager_new_with_toml) { write(fd, gtest_mock_spec_toml, strlen(gtest_mock_spec_toml)); close(fd); - struct module_manager *mod_mgr=module_manager_new_with_toml(toml_template, 10, mq_schema, NULL); + struct module_manager *mod_mgr=module_manager_new_with_toml(toml_template, 10, NULL); EXPECT_TRUE(mod_mgr!=NULL); EXPECT_TRUE(module_manager_get_module(mod_mgr, "test")==NULL); EXPECT_EQ(module_manager_get_max_thread_num(mod_mgr), 10); - EXPECT_EQ(module_manager_get_mq_schema(mod_mgr), mq_schema); EXPECT_STREQ(module_manager_get_toml_path(mod_mgr), toml_template); EXPECT_EQ(module_manager_get_thread_id(mod_mgr), -1);// no thread registered - EXPECT_TRUE(module_manager_get_mq_runtime(mod_mgr)==NULL); module_manager_free(mod_mgr); @@ -71,14 +68,11 @@ TEST(stellar_module, basic_new_and_free) { TEST(stellar_module_manager, new_with_null_toml) { - struct mq_schema *mq_schema=NULL; - struct module_manager *mod_mgr = module_manager_new_with_toml(NULL, 10, mq_schema, NULL); + struct module_manager *mod_mgr = module_manager_new_with_toml(NULL, 10, NULL); EXPECT_TRUE(mod_mgr!=NULL); EXPECT_TRUE(module_manager_get_module(mod_mgr, "test")==NULL); EXPECT_EQ(module_manager_get_max_thread_num(mod_mgr), 10); - EXPECT_EQ(module_manager_get_mq_schema(mod_mgr), mq_schema); - EXPECT_TRUE(module_manager_get_mq_runtime(mod_mgr)==NULL); EXPECT_EQ(module_manager_get_thread_id(mod_mgr), -1);// no thread registered module_manager_free(mod_mgr); @@ -86,41 +80,32 @@ TEST(stellar_module_manager, new_with_null_toml) { TEST(stellar_module_manager, new_with_empty_toml) { - struct mq_schema *mq_schema=NULL; - struct module_manager *mod_mgr = module_manager_new_with_toml("/dev/null", 10, mq_schema, NULL); + struct module_manager *mod_mgr = module_manager_new_with_toml("/dev/null", 10, NULL); EXPECT_TRUE(mod_mgr!=NULL); EXPECT_TRUE(module_manager_get_module(mod_mgr, "test")==NULL); EXPECT_EQ(module_manager_get_max_thread_num(mod_mgr), 10); - EXPECT_EQ(module_manager_get_mq_schema(mod_mgr), mq_schema); EXPECT_EQ(module_manager_get_thread_id(mod_mgr), -1);// no thread registered - EXPECT_TRUE(module_manager_get_mq_runtime(mod_mgr)==NULL); module_manager_free(mod_mgr); } TEST(stellar_module_manager, register_thread) { - struct mq_schema *mq_schema=(struct mq_schema*)1; - struct module_manager *mod_mgr=module_manager_new_with_toml(NULL, 10, mq_schema, NULL); + struct module_manager *mod_mgr=module_manager_new_with_toml(NULL, 10, NULL); EXPECT_TRUE(mod_mgr!=NULL); - EXPECT_EQ((long)module_manager_get_mq_schema(mod_mgr), 1); EXPECT_EQ(module_manager_get_thread_id(mod_mgr), -1);// no thread registered - EXPECT_TRUE(module_manager_get_mq_runtime(mod_mgr)==NULL); - struct mq_runtime *mq_rt = (struct mq_runtime*)2; - module_manager_register_thread(mod_mgr, 1, mq_rt); + module_manager_register_thread(mod_mgr, 1); EXPECT_EQ(module_manager_get_thread_id(mod_mgr), 1); - EXPECT_EQ((long)module_manager_get_mq_runtime(mod_mgr), 2); module_manager_unregister_thread(mod_mgr, 1); EXPECT_EQ(module_manager_get_thread_id(mod_mgr), -1); - EXPECT_EQ((long)module_manager_get_mq_runtime(mod_mgr), 0); module_manager_free(mod_mgr); @@ -147,7 +132,6 @@ extern "C" void gtest_module_exit(struct module_manager *mod_mgr, struct module EXPECT_EQ(module_manager_get_module(mod_mgr, "gtest"), mod); EXPECT_EQ(module_manager_get_thread_id(mod_mgr), -1); - EXPECT_EQ((long)module_manager_get_mq_runtime(mod_mgr), 0); module_free(mod); } @@ -174,7 +158,6 @@ const char *gtest_module_spec_toml = TEST(module_manager, basic_module) { - struct mq_schema *mq_schema=(struct mq_schema *)1; char toml_template[] = "./stellar.toml.XXXXXX"; int fd = mkstemp(toml_template); @@ -182,24 +165,20 @@ TEST(module_manager, basic_module) { write(fd, gtest_module_spec_toml, strlen(gtest_module_spec_toml)); close(fd); - struct module_manager *mod_mgr=module_manager_new_with_toml(toml_template, 10, mq_schema, NULL); + struct module_manager *mod_mgr=module_manager_new_with_toml(toml_template, 10, NULL); EXPECT_TRUE(mod_mgr!=NULL); EXPECT_TRUE(module_manager_get_module(mod_mgr, "gtest")!=NULL); EXPECT_EQ(module_manager_get_max_thread_num(mod_mgr), 10); - EXPECT_EQ((long)module_manager_get_mq_schema(mod_mgr), 1); EXPECT_STREQ(module_manager_get_toml_path(mod_mgr), toml_template); - struct mq_runtime *mq_rt = (struct mq_runtime*)2; - module_manager_register_thread(mod_mgr, 1, mq_rt); + module_manager_register_thread(mod_mgr, 1); EXPECT_EQ((long)module_manager_get_thread_id(mod_mgr), 1); - EXPECT_EQ((long)module_manager_get_mq_runtime(mod_mgr), 2); module_manager_unregister_thread(mod_mgr, 1); EXPECT_EQ((long)module_manager_get_thread_id(mod_mgr), -1); - EXPECT_EQ((long)module_manager_get_mq_runtime(mod_mgr), 0); module_manager_free(mod_mgr); unlink(toml_template); @@ -230,25 +209,20 @@ struct test_module_polling_env TEST(module_manager, basic_polling_module) { - struct mq_schema *mq_schema=mq_schema_new(); - - struct module_manager *mod_mgr=module_manager_new_with_toml(NULL, 10, mq_schema, NULL); + struct module_manager *mod_mgr=module_manager_new_with_toml(NULL, 10, NULL); EXPECT_TRUE(mod_mgr!=NULL); EXPECT_EQ(module_manager_get_max_thread_num(mod_mgr), 10); - EXPECT_EQ(module_manager_get_mq_schema(mod_mgr), mq_schema); struct test_module_polling_env env={}; env.N_round=10; module_manager_register_polling_node(mod_mgr, test_module_on_polling, &env); - struct mq_runtime *mq_rt = mq_runtime_new(mq_schema); - module_manager_register_thread(mod_mgr, 1, mq_rt); + module_manager_register_thread(mod_mgr, 1); EXPECT_EQ((long)module_manager_get_thread_id(mod_mgr), 1); - EXPECT_EQ(module_manager_get_mq_runtime(mod_mgr), mq_rt); for(int i=0; i<env.N_round; i++) { @@ -257,8 +231,6 @@ TEST(module_manager, basic_polling_module) { module_manager_unregister_thread(mod_mgr, 1); - mq_runtime_free(mq_rt); - mq_schema_free(mq_schema); module_manager_free(mod_mgr); EXPECT_EQ(env.polling_count, env.N_round+env.polling_active_count); |
