static void
test_election_init(void)
{
	struct replication_config_s cfg = { _get_id, _get_peers, _get_vers,
		NULL, ELECTION_MODE_NONE};
	struct election_manager_s *m = NULL;
	GError *err = NULL;

	err = election_manager_create(&cfg, &m);
	g_assert_no_error(err);

	for (int i=0; i<8 ;++i) {
		struct sqlx_name_mutable_s n = {
			.ns="NS",
			.base="base",
			.type="type"
		};
		n.base = g_strdup_printf("base-%"G_GUINT32_FORMAT, g_random_int());
		err = election_init(m, sqlx_name_mutable_to_const(&n));
		g_assert_no_error(err);
		err = election_exit(m, sqlx_name_mutable_to_const(&n));
		g_assert_no_error(err);
		g_free (n.base);
	}

	election_manager_clean(m);
}

static void
test_create_ok(void)
{
	struct replication_config_s cfg = { _get_id, _get_peers, _get_vers,
		NULL, ELECTION_MODE_NONE};
	for (int i=0; i<8 ;++i) {
		struct election_manager_s *m = NULL;
		GError *err = election_manager_create(&cfg, &m);
		g_assert_no_error(err);
		election_manager_clean(m);
	}
}

int
main(int argc, char **argv)
{
	HC_TEST_INIT(argc,argv);
	g_test_add_func("/sqlx/election/create_bad_config",
			test_create_bad_config);
	g_test_add_func("/sqlx/election/create_ok",
			test_create_ok);
	g_test_add_func("/sqlx/election/election_init",
			test_election_init);
	return g_test_run();
}
Exemplo n.º 2
0
static void
test_create_ok(void)
{
    struct replication_config_s cfg = { _get_id, _get_peers, _get_vers,
               NULL, ELECTION_MODE_NONE
    };
    struct election_manager_s *m = NULL;
    GError *err;

    err = election_manager_create(&cfg, &m);
    g_assert_no_error(err);
    g_assert(&cfg == election_manager_get_config0(m));
    election_manager_clean(m);
}
Exemplo n.º 3
0
static void
sqlx_service_specific_fini(void)
{
	// soft stop
	if (SRV.gtq_reload)
		grid_task_queue_stop(SRV.gtq_reload);
	if (SRV.gtq_admin)
		grid_task_queue_stop(SRV.gtq_admin);

	if (SRV.server) {
		network_server_close_servers(SRV.server);
		network_server_stop(SRV.server);
	}

	if (SRV.thread_reload)
		g_thread_join(SRV.thread_reload);
	if (SRV.thread_admin)
		g_thread_join(SRV.thread_admin);
	if (SRV.thread_client)
		g_thread_join(SRV.thread_client);
	if (SRV.thread_queue)
		g_thread_join(SRV.thread_queue);

	if (SRV.repository) {
		sqlx_repository_stop(SRV.repository);
		struct sqlx_cache_s *cache = sqlx_repository_get_cache(SRV.repository);
		if (cache)
			sqlx_cache_expire(cache, G_MAXUINT, 0);
	}
	if (SRV.election_manager)
		election_manager_exit_all(SRV.election_manager, 0, TRUE);
	if (SRV.sync)
		sqlx_sync_close(SRV.sync);
	if (SRV.peering)
		sqlx_peering__destroy(SRV.peering);

	// Cleanup
	if (SRV.gtq_admin) {
		grid_task_queue_destroy(SRV.gtq_admin);
		SRV.gtq_admin = NULL;
	}
	if (SRV.gtq_reload) {
		grid_task_queue_destroy(SRV.gtq_reload);
		SRV.gtq_reload = NULL;
	}

	if (SRV.server) {
		network_server_clean(SRV.server);
		SRV.server = NULL;
	}
	if (SRV.dispatcher) {
		gridd_request_dispatcher_clean(SRV.dispatcher);
		SRV.dispatcher = NULL;
	}
	if (SRV.repository) {
		sqlx_repository_clean(SRV.repository);
		SRV.repository = NULL;
	}
	if (SRV.sync) {
		sqlx_sync_clear(SRV.sync);
		SRV.sync = NULL;
	}
	if (SRV.resolver) {
		hc_resolver_destroy(SRV.resolver);
		SRV.resolver = NULL;
	}

	if (SRV.announce) {
		g_string_free(SRV.announce, TRUE);
		SRV.announce = NULL;
	}
	if (SRV.url) {
		g_string_free(SRV.url, TRUE);
		SRV.url = NULL;
	}
	if (SRV.zk_url)
		oio_str_clean(&SRV.zk_url);

	if (SRV.clients_pool) {
		gridd_client_pool_destroy (SRV.clients_pool);
		SRV.clients_pool = NULL;
	}

	// Must be freed after SRV.clients_pool
	if (SRV.election_manager) {
		election_manager_clean(SRV.election_manager);
		SRV.election_manager = NULL;
	}

	if (SRV.lb) {
		grid_lbpool_destroy (SRV.lb);
		SRV.lb = NULL;
	}

	if (SRV.events_queue) {
		oio_events_queue__destroy (SRV.events_queue);
		SRV.events_queue = NULL;
	}

	if (SRV.nsinfo) {
		namespace_info_free(SRV.nsinfo);
		SRV.nsinfo = NULL;
	}
	if (all_options) {
		g_free (all_options);
		all_options = NULL;
	}
}
Exemplo n.º 4
0
static void
sqlx_service_specific_fini(void)
{
	// soft stop
	if (SRV.gtq_reload)
		grid_task_queue_stop(SRV.gtq_reload);
	if (SRV.gtq_register)
		grid_task_queue_stop(SRV.gtq_register);
	if (SRV.gtq_admin)
		grid_task_queue_stop(SRV.gtq_admin);

	if (SRV.server) {
		network_server_close_servers(SRV.server);
		network_server_stop(SRV.server);
	}

	if (SRV.thread_reload)
		g_thread_join(SRV.thread_reload);
	if (SRV.thread_register)
		g_thread_join(SRV.thread_register);
	if (SRV.thread_admin)
		g_thread_join(SRV.thread_admin);
	if (SRV.thread_client)
		g_thread_join(SRV.thread_client);
	if (SRV.thread_queue)
		g_thread_join(SRV.thread_queue);

	if (SRV.repository) {
		sqlx_repository_stop(SRV.repository);
		struct sqlx_cache_s *cache = sqlx_repository_get_cache(SRV.repository);
		if (cache)
			sqlx_cache_expire(cache, G_MAXUINT, 0);
	}
	if (SRV.election_manager)
		election_manager_exit_all(SRV.election_manager, 0, TRUE);
	if (SRV.sync)
		sqlx_sync_close(SRV.sync);

	// Cleanup
	if (SRV.gtq_admin)
		grid_task_queue_destroy(SRV.gtq_admin);
	if (SRV.gtq_reload)
		grid_task_queue_destroy(SRV.gtq_reload);
	if (SRV.gtq_register)
		grid_task_queue_destroy(SRV.gtq_register);

	if (SRV.server)
		network_server_clean(SRV.server);
	if (SRV.dispatcher)
		gridd_request_dispatcher_clean(SRV.dispatcher);
	if (SRV.repository)
		sqlx_repository_clean(SRV.repository);
	if (SRV.election_manager)
		election_manager_clean(SRV.election_manager);
	if (SRV.sync)
		sqlx_sync_clear(SRV.sync);
	if (SRV.resolver)
		hc_resolver_destroy(SRV.resolver);

	if (SRV.gsr_reqtime)
		grid_single_rrd_destroy(SRV.gsr_reqtime);
	if (SRV.gsr_reqcounter)
		grid_single_rrd_destroy(SRV.gsr_reqcounter);

	if (SRV.custom_tags)
		g_slist_free_full(SRV.custom_tags, g_free);
	if (SRV.si)
		service_info_clean(SRV.si);
	if (SRV.announce)
		g_string_free(SRV.announce, TRUE);
	if (SRV.url)
		g_string_free(SRV.url, TRUE);
	if (SRV.zk_url)
		oio_str_clean(&SRV.zk_url);

	if (SRV.clients_pool)
		gridd_client_pool_destroy (SRV.clients_pool);

	if (SRV.lb)
		grid_lbpool_destroy (SRV.lb);

	if (SRV.events_queue)
		oio_events_queue__destroy (SRV.events_queue);

	if (SRV.nsinfo)
		namespace_info_free(SRV.nsinfo);
	if (all_options) {
		g_free (all_options);
		all_options = NULL;
	}
}