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();
}
Ejemplo n.º 2
0
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);
    g_assert(&cfg == election_manager_get_config0(m));

    err = election_init(m, "name", "type");
    g_assert_no_error(err);

    election_manager_clean(m);
}
Ejemplo n.º 3
0
int
main(int argc, char **argv)
{
    int rc = pcmk_ok;
    int flag = 0;
    int index = 0;
    int argerr = 0;
    qb_ipcs_service_t *ipcs = NULL;

    mloop = g_main_new(FALSE);
    crm_log_preinit(NULL, argc, argv);
    crm_set_options(NULL, "[options]", long_options,
                    "Daemon for aggregating and atomically storing node attribute updates into the CIB");

    mainloop_add_signal(SIGTERM, attrd_shutdown);

     while (1) {
        flag = crm_get_option(argc, argv, &index);
        if (flag == -1)
            break;

        switch (flag) {
            case 'V':
                crm_bump_log_level(argc, argv);
                break;
            case 'h':          /* Help message */
                crm_help(flag, EX_OK);
                break;
            default:
                ++argerr;
                break;
        }
    }

    if (optind > argc) {
        ++argerr;
    }

    if (argerr) {
        crm_help('?', EX_USAGE);
    }

    crm_log_init(T_ATTRD, LOG_INFO, TRUE, FALSE, argc, argv, FALSE);
    crm_info("Starting up");
    attributes = g_hash_table_new_full(crm_str_hash, g_str_equal, NULL, free_attribute);

    attrd_cluster = malloc(sizeof(crm_cluster_t));

    attrd_cluster->destroy = attrd_cpg_destroy;
    attrd_cluster->cpg.cpg_deliver_fn = attrd_cpg_dispatch;
    attrd_cluster->cpg.cpg_confchg_fn = pcmk_cpg_membership;

    crm_set_status_callback(attrd_peer_change_cb);

    if (crm_cluster_connect(attrd_cluster) == FALSE) {
        crm_err("Cluster connection failed");
        rc = DAEMON_RESPAWN_STOP;
        goto done;
    }
    crm_info("Cluster connection active");

    writer = election_init(T_ATTRD, attrd_cluster->uname, 120000, attrd_election_cb);
    attrd_ipc_server_init(&ipcs, &ipc_callbacks);
    crm_info("Accepting attribute updates");

    the_cib = attrd_cib_connect(10);
    if (the_cib == NULL) {
        rc = DAEMON_RESPAWN_STOP;
        goto done;
    }

    crm_info("CIB connection active");
    g_main_run(mloop);

  done:
    crm_notice("Cleaning up before exit");

    election_fini(writer);
    crm_client_disconnect_all(ipcs);
    qb_ipcs_destroy(ipcs);
    g_hash_table_destroy(attributes);

    if (the_cib) {
        the_cib->cmds->signoff(the_cib);
        cib_delete(the_cib);
    }

    if(attrd_error) {
        return crm_exit(attrd_error);
    }
    return crm_exit(rc);
}