static bool before(atf_plan * plan) {

    if ( as ) {
        error("aerospike was already initialized");
        return false;
    }

	// Initialize logging.
	as_log_set_level(AS_LOG_LEVEL_INFO);
	as_log_set_callback(as_client_log_callback);
	
	if (g_use_async) {
		if (as_event_create_loops(1) == 0) {
			error("failed to create event loops");
			return false;
		}
	}
	
	// Initialize global lua configuration.
	as_config_lua lua;
	as_config_lua_init(&lua);
	strcpy(lua.system_path, "modules/lua-core/src");
	strcpy(lua.user_path, "src/test/lua");
	aerospike_init_lua(&lua);

	// Initialize cluster configuration.
	as_config config;
	as_config_init(&config);
	as_config_add_host(&config, g_host, g_port);
	as_config_set_user(&config, g_user, g_password);
    as_policies_init(&config.policies);

	as_error err;
	as_error_reset(&err);

	as = aerospike_new(&config);

	if ( aerospike_connect(as, &err) == AEROSPIKE_OK ) {
		debug("connected to %s:%d", g_host, g_port);
    	return true;
	}
	else {
		error("%s @ %s[%s:%d]", err.message, err.func, err.file, err.line);
		return false;
	}
}
Ejemplo n.º 2
0
static bool before(atf_plan * plan) {

    if ( as ) {
        error("aerospike was already initialized");
        return false;
    }

    if (! parse_opts(g_argc, g_argv)) {
        error("failed to parse options");
    	return false;
    }
	
	as_log_set_level(AS_LOG_LEVEL_INFO);
	as_log_set_callback(as_client_log_callback);
	
	if (g_use_async) {
		if (as_event_create_loops(1) == 0) {
			error("failed to create event loops");
			return false;
		}
	}
	
	as_config config;
	as_config_init(&config);
	as_config_add_host(&config, g_host, g_port);
	as_config_set_user(&config, g_user, g_password);
	config.lua.cache_enabled = false;
	strcpy(config.lua.system_path, "modules/lua-core/src");
	strcpy(config.lua.user_path, "src/test/lua");
    as_policies_init(&config.policies);

	as_error err;
	as_error_reset(&err);

	as = aerospike_new(&config);

	if ( aerospike_connect(as, &err) == AEROSPIKE_OK ) {
		debug("connected to %s:%d", g_host, g_port);
    	return true;
	}
	else {
		error("%s @ %s[%s:%d]", err.message, err.func, err.file, err.line);
		return false;
	}
}
Ejemplo n.º 3
0
//------------------------------------------------
// Connect to database cluster, setting UDF
// configuration.
//
void
example_connect_to_aerospike_with_udf_config(aerospike* p_as,
		const char* lua_user_path)
{
	// Start with default configuration.
	as_config cfg;
	as_config_init(&cfg);
	as_config_add_host(&cfg, g_host, g_port);
	as_config_set_user(&cfg, g_user, g_password);

	// Examples can be run from client binary package-installed lua files or
	// from git client source tree lua files. If client binary package is not
	// installed, look for lua system files in client source tree.
	int rc = access(cfg.lua.system_path, R_OK);

	if (rc != 0) {
		// Use lua files in source tree if they exist.
		char* path = "../../../modules/lua-core/src";

		rc = access(path, R_OK);

		if (rc == 0) {
			strcpy(cfg.lua.system_path, path);
		}
	}

	if (lua_user_path) {
		strcpy(cfg.lua.user_path, lua_user_path);
	}

	aerospike_init(p_as, &cfg);

	as_error err;

	// Connect to the Aerospike database cluster. Assume this is the first thing
	// done after calling example_get_opts(), so it's ok to exit on failure.
	if (aerospike_connect(p_as, &err) != AEROSPIKE_OK) {
		LOG("aerospike_connect() returned %d - %s", err.code, err.message);
		aerospike_destroy(p_as);
		exit(-1);
	}
}
Ejemplo n.º 4
0
bool asc_init(aerospike *p_as)
{
    as_status status;
    as_error err;

    // Start with default configuration.
    as_config cfg;
    as_config_init(&cfg);
    as_config_add_host(&cfg, HOST, PORT);
    as_config_set_user(&cfg, USER, PASS);
    aerospike_init(p_as, &cfg);

    // Connect to the Aerospike database cluster.
    status = aerospike_connect(p_as, &err);
    if (status != AEROSPIKE_OK) {
        ERROR("aerospike_connect() returned %d - %s", err.code, err.message);
        aerospike_destroy(p_as);
    }

    return (status == AEROSPIKE_OK);
}