Example #1
0
END_TEST

START_TEST (GetSetGetSetManyTimes) // Added 12
{
	struct storage_record record;
	int fields = 0;
	int intval = 0;

	// Do several sets
	strncpy(record.value, "col 5000", sizeof record.value);
	storage_set(INTTABLE, KEY, &record, test_conn);
	strncpy(record.value, "col 5001", sizeof record.value);
	storage_set(INTTABLE, KEY, &record, test_conn);
	strncpy(record.value, "col 5002", sizeof record.value);
	storage_set(INTTABLE, KEY, &record, test_conn);
	strncpy(record.value, "col 5003", sizeof record.value);
	storage_set(INTTABLE, KEY, &record, test_conn);
	
	
	// Do several gets
	strncpy(record.value, "", sizeof record.value);
	storage_get(INTTABLE, KEY, &record, test_conn);
	storage_get(INTTABLE, KEY, &record, test_conn);
	storage_get(INTTABLE, KEY, &record, test_conn);

	strncpy(record.value, "col 5004", sizeof record.value);
	int status = storage_set(INTTABLE, KEY, &record, test_conn);
	fail_unless(status == 0, "Error setting a key/value pair.");

	status = storage_get(INTTABLE, KEY, &record, test_conn);
	fail_unless(status == 0, "Error getting a value.");
	fields = sscanf(record.value, "col %d", &intval);
	fail_unless(fields == 1 && intval == 5004, "Got wrong value.");
}
Example #2
0
END_TEST


START_TEST (DeletionTest) // For testing deleting records
{
	struct storage_record record;
	int fields = 0;
	int intval = 0;

	// Do several sets
	strncpy(record.value, "col 5000", sizeof record.value);
	storage_set(INTTABLE, KEY, &record, test_conn);
	strncpy(record.value, "col 5001", sizeof record.value);
	storage_set(INTTABLE, KEY, &record, test_conn);
	strncpy(record.value, "col 5002", sizeof record.value);
	storage_set(INTTABLE, KEY, &record, test_conn);
	strncpy(record.value, "col NULL", sizeof record.value); //We deleted it here
	storage_set(INTTABLE, KEY, &record, test_conn);
	
	
	// Do several gets
	strncpy(record.value, "", sizeof record.value);
	storage_get(INTTABLE, KEY, &record, test_conn);
	storage_get(INTTABLE, KEY, &record, test_conn);
	storage_get(INTTABLE, KEY, &record, test_conn);

	strncpy(record.value, "col 5004", sizeof record.value);
	int status = storage_set(INTTABLE, KEY, &record, test_conn);
	fail_unless(status == 0, "Error setting a key/value pair.");

	status = storage_get(INTTABLE, KEY, &record, test_conn);
	fail_unless(status == 0, "Error getting a value.");
	fields = sscanf(record.value, "col %d", &intval);
	fail_unless(fields == 1 && intval == 5004, "Got wrong value.");
}
Example #3
0
END_TEST

START_TEST (test_setget_setmultipletimesandget) // Added 10 
{
	struct storage_record record;
	int fields = 0;
	int intval = 0;

	// Do a set
	strncpy(record.value, "col 5000", sizeof record.value);
	storage_set(INTTABLE, KEY, &record, test_conn);
	strncpy(record.value, "col 5001", sizeof record.value);
	storage_set(INTTABLE, KEY, &record, test_conn);
	strncpy(record.value, "col 5002", sizeof record.value);
	storage_set(INTTABLE, KEY, &record, test_conn);
	strncpy(record.value, "col 5003", sizeof record.value);
	storage_set(INTTABLE, KEY, &record, test_conn);
	strncpy(record.value, "col 5004", sizeof record.value);
	int status = storage_set(INTTABLE, KEY, &record, test_conn);
	fail_unless(status == 0, "Error setting a key/value pair.");

	// Do a get
	strncpy(record.value, "", sizeof record.value);
	status = storage_get(INTTABLE, KEY, &record, test_conn);
	fail_unless(status == 0, "Error getting a value.");
	fields = sscanf(record.value, "col %d", &intval);
	fail_unless(fields == 1 && intval == 5004, "Got wrong value.");
}
Example #4
0
static int _vacation_user_load(mod_instance_t mi, user_t user) {
    module_t mod = mi->mod;
    vacation_t v;
    os_t os;
    os_object_t o;

    v = (vacation_t) calloc(1, sizeof(struct _vacation_st));
    user->module_data[mod->index] = v;

    if(storage_get(mod->mm->sm->st, "vacation-settings", jid_user(user->jid), NULL, &os) == st_SUCCESS) {
        if(os_iter_first(os)) {
            o = os_iter_object(os);

            if(os_object_get_time(os, o, "start", &v->start) &&
               os_object_get_time(os, o, "end", &v->end) &&
               os_object_get_str(os, o, "message", &v->msg))
                v->msg = strdup(v->msg);
            else {
                v->start = 0;
                v->end = 0;
                v->msg = NULL;
            }
        }

        os_free(os);
    }

    pool_cleanup(user->p, (void (*))(void *) _vacation_user_free, v);

    return 0;
}
Example #5
0
END_TEST




/*
 * One server instance tests:
 * 	set/get from simple tables.
 */

START_TEST (test_setget_posint)
{
	struct storage_record record;
	int fields = 0;
	int intval = 0;

	// Do a set
	strncpy(record.value, "col 2", sizeof record.value);
	int status = storage_set(INTTABLE, KEY, &record, test_conn);
	fail_unless(status == 0, "Error setting a key/value pair.");

	// Do a get
	strncpy(record.value, "", sizeof record.value);
	status = storage_get(INTTABLE, KEY, &record, test_conn);
	fail_unless(status == 0, "Error getting a value.");
	fields = sscanf(record.value, "col %d", &intval);
	fail_unless(fields == 1 && intval == 2, "Got wrong value.");
}
Example #6
0
END_TEST


START_TEST (test_setcomplex_updatethreecols) {
	struct storage_record record;
	int fields = 0;
	int intval = 0;
	float floatval = 0;
	char strval[MAX_VALUE_LEN];
	strncpy(strval, "", sizeof strval);

	// Update the value
	strncpy(record.value, "col1 -8,col2 -8,col3 ABC", sizeof record.value);
	int status = storage_set(THREECOLSTABLE, KEY1, &record, test_conn);
	fail_unless(status == 0, "Error updating a value.");

	// Get the new value.
	strncpy(record.value, "", sizeof record.value);
	status = storage_get(THREECOLSTABLE, KEY1, &record, test_conn);
	fail_unless(status == 0, "Error getting a value.");
	fields = sscanf(record.value, "col1 %d , col2 %f , col3 %[a-zA-Z0-9 ]", &intval, &floatval, strval);
	fail_unless(fields == 3, "Got wrong number of fields.");
	fail_unless(intval == -8, "Got wrong value.");
	fail_unless(floatval == -8, "Got wrong value.");
	fail_unless(strcmp(trimtrailingspc(strval), "ABC") == 0, "Got wrong value.");
}
Example #7
0
END_TEST


/*
 * One server instance get/set pass tests:
 * 	set/get basic table/key/value names from one table.
 * 	set/get extended table/key/value names from one table.
 * 	set/get extended table/key/value names from two tables.
 */

START_TEST (test_oneserver_onetable)
{
	struct storage_record r;

	// Start and connect to the server.
	void *conn = start_connect(ONETABLE_CONF, "test_oneserver_onetable.serverout", NULL);
	fail_unless(conn != NULL, "Couldn't start or connect to server.");

	// Set a key/value.
	strncpy(r.value, VALUE, sizeof r.value);
	int status = storage_set(TABLE, KEY, &r, conn);
	fail_unless(status == 0, "Error setting a key/value pair.");

	// Get a value.
	strncpy(r.value, "", sizeof r.value);
	status = storage_get(TABLE, KEY, &r, conn);
	fail_unless(status == 0, "Error getting a value.");
	fail_unless(strcmp(r.value, VALUE) == 0, "Got wrong value.");

	// Disconnect from the server.
	status = storage_disconnect(conn);
	//fail_unless(status == 0, "Error disconnecting from the server.");
}
Example #8
0
    /** helper to compare to debug solution */
    void helper_check(std::string const& name, std::string const& mechanism, std::string const& path){
        //extract what we need d and rhs
        NrnThread * nt = (NrnThread *) storage_get (name.c_str(),
                                                    make_nrnthread, (void*)path.c_str(), free_nrnthread);

        int size = nt->end;
        double* rhs = nt->_actual_rhs; // compute solutiom rhs
        double* d = nt->_actual_d;  // compute solutiom d

        double* ref_rhs = new double[size];
        double* ref_d = new double[size];

        std::string data = mapp::data_ref() + "rhs_d_"+mechanism;

//      std::ofstream outfile(data.c_str());
//      for(int i=0; i < size;++i)
//          outfile << " "  << d[i] << " " <<  rhs[i] << "\n";

        std::ifstream infile(data.c_str(),std::ifstream::in);

        if(infile.good())
            for(int i=0; i < size;++i)
                infile >> ref_d[i] >> ref_rhs[i];

        infile.close();

        for(int i=0; i < size;++i){
            BOOST_CHECK_CLOSE( ref_d[i], d[i], 0.01 );
            BOOST_CHECK_CLOSE( ref_rhs[i], rhs[i], 0.01 );
        }

        delete [] ref_rhs;
        delete [] ref_d;
    }
Example #9
0
File: cli.c Project: abudrys/rss
void do_add_source(array_t *args)
{
	feed_t *feed;
	
	if (array_count(args) != 3) {
		FAIL("add: należy podać dwa argumenty! (aby uzyskać pomoc "
		     "na temat tego polecenia, wpisz: help add)\n");
		return;
	}
	
	feed = feed_create(xstrdup(array_get(args, 2)));
	feed->f_name = xstrdup(array_get(args, 1));
	feed_save(storage_get(), feed);
	
	if (cli_ask("Czy pobrać nowe wpisy z nowo dodanego źródła? [T/n]"))
		feed_download(storage_get(), feed);
}
Example #10
0
/*
 * get group's descriptive name by it's text id
 * returned value needs to be freed by caller
 */
static const char *_roster_publish_get_group_name(sm_t sm, roster_publish_t rp, const char *groupid)
{
    os_t os;
    os_object_t o;
    char *str;
    char *group;

#ifndef NO_SM_CACHE
    _roster_publish_group_cache_t group_cached;
#endif

    if(!groupid) return groupid;

#ifndef NO_SM_CACHE
    /* check for remembered group value in cache */
    if( rp->group_cache_ttl ) {
        if( rp->group_cache ) {
            group_cached = xhash_get(rp->group_cache, groupid);
            if( group_cached != NULL ) {
                if( (time(NULL) - group_cached->time) >= rp->group_cache_ttl ) {
                    log_debug(ZONE,"group cache: expiring cached value for %s",groupid);
                    xhash_zap(rp->group_cache, groupid);
                    free(group_cached);
                } else {
                    log_debug(ZONE,"group cache: returning cached value for %s",groupid);
                    return strdup(group_cached->groupname);
                }
            }
        } else {
            log_debug(ZONE,"group cache: creating cache");
            rp->group_cache = xhash_new(401);
        }
    }
#endif

    if(storage_get(sm->st, "published-roster-groups", groupid, NULL, &os) == st_SUCCESS && os_iter_first(os)) {
        o = os_iter_object(os);
        if( os_object_get_str(os, o, "groupname", &str) && str ) {
            group=strdup(str);
        } else {
            group=NULL;
        }
        os_free(os);
#ifndef NO_SM_CACHE
        if( rp->group_cache_ttl && group ) {
            log_debug(ZONE,"group cache: updating cache value for %s",groupid);
            group_cached = calloc(1, sizeof(struct _roster_publish_group_cache_st));
            group_cached->time = time(NULL);
            group_cached->groupid = strdup(groupid);
            group_cached->groupname = strdup(group);
            xhash_put(rp->group_cache, group_cached->groupid, group_cached);
        }
#endif
        return group;
    } else {
        return NULL;
    }
}
Example #11
0
File: cli.c Project: abudrys/rss
void do_remove_source(array_t *args)
{
	const char *name;
	hash_t *feeds = config_get_feeds(storage_get());

	if (array_count(args) != 2) {
		FAIL("remove: należy podać jeden argument! (aby uzyskać pomoc "
	    	     "na temat tego polecenia, wpisz: help remove)\n");
		return;
	}
	
	name = array_get(args, 1);

	if (hash_key_exists(feeds, name))
		feed_remove(storage_get(), hash_get(feeds, name));

	hash_free(feeds, TRUE, TRUE);
	xprintf("Źródło %s zostało usunięte.\n", name);
}
Example #12
0
END_TEST


START_TEST (test_getnumberbasedtable) //Added 14
{
	struct storage_record record;
	int status = storage_get(123456, KEY, &record, test_conn);
	fail_unless(status == -1, "storage_get with missing table should fail.");
	fail_unless(errno == ERR_TABLE_NOT_FOUND, "storage_get with missing table not setting errno properly.");
}
Example #13
0
END_TEST


START_TEST (test_toughbadtable) //Addd 12
{
	struct storage_record record;
	int status = storage_get(BADTABLE, KEY, &record, test_conn);
	fail_unless(status == -1, "storage_get with bad table name should fail.");
	fail_unless(errno == ERR_INVALID_PARAM, "storage_get with bad table name not setting errno properly.");
}
Example #14
0
END_TEST


START_TEST (test_getmissing_missingtable)
{
	struct storage_record record;
	int status = storage_get(MISSINGTABLE, KEY, &record, test_conn);
	fail_unless(status == -1, "storage_get with missing table should fail.");
	fail_unless(errno == ERR_TABLE_NOT_FOUND, "storage_get with missing table not setting errno properly.");
}
Example #15
0
END_TEST

/*
START_TEST (test_query_float0)
{
	// Do a query.  Expect no matches.
	int foundkeys = storage_query(FLOATTABLE, "col > 10.0", test_keys, MAX_RECORDS_PER_TABLE, test_conn);
	fail_unless(foundkeys == 0, "Query didn't find the correct number of keys.");

	// Make sure next key is not set to anything.
	fail_unless(strcmp(test_keys[0], "") == 0, "No extra keys should be modified.\n");
}
END_TEST


START_TEST (test_query_float1)
{
	// Do a query.  Expect one match.
	int foundkeys = storage_query(FLOATTABLE, "col < -1.0", test_keys, MAX_RECORDS_PER_TABLE, test_conn);
	fail_unless(foundkeys == 1, "Query didn't find the correct number of keys.");

	// Check the matching keys.
	fail_unless(
		( strcmp(test_keys[0], KEY1) == 0 ),
		"The returned keys don't match the query.\n");

	// Make sure next key is not set to anything.
	fail_unless(strcmp(test_keys[1], "") == 0, "No extra keys should be modified.\n");
}
END_TEST
*/



/*
 * Set operations with simple tables.
 * 	update an existing record (pass).
 * 	delete an existing record (pass).
 */

START_TEST (test_set_deleteint)
{
	// Delete a key/value pair.
	int status = storage_set(INTTABLE, KEY1, NULL, test_conn);
	fail_unless(status == 0, "Error deleting the key/value pair.");

	// Try to get the deleted value.
	struct storage_record record;
	strncpy(record.value, "", sizeof record.value);
	status = storage_get(INTTABLE, KEY1, &record, test_conn);
	fail_unless(status == -1, "storage_get for deleted key should fail.");
	fail_unless(errno == ERR_KEY_NOT_FOUND, "storage_get for deleted key not setting errno properly.");
}
Example #16
0
File: cli.c Project: abudrys/rss
void do_list_sources(array_t *args)
{
	int i;
	const char *key;
	void *value;
	hash_t *feeds = config_get_feeds(storage_get());
	
	xprintf("Nazwa źródła (URL):\n");
	
	FOREACH_HASH(feeds, i, key, value) {
		feed_t *feed = (feed_t *)value;
		xprintf("%s (%s)\t%s\n", key, feed->f_url, feed->f_description);
		
	}
Example #17
0
END_TEST

START_TEST (test_set_deletestr)
{
	// Delete a key/value pair.
	int status = storage_set(STRTABLE, KEY1, NULL, test_conn);
	fail_unless(status == 0, "Error deleting the key/value pair.");

	// Try to get the deleted value.
	struct storage_record record;
	strncpy(record.value, "", sizeof record.value);
	status = storage_get(STRTABLE, KEY1, &record, test_conn);
	fail_unless(status == -1, "storage_get for deleted key should fail.");
	fail_unless(errno == ERR_KEY_NOT_FOUND, "storage_get for deleted key not setting errno properly.");
}
Example #18
0
static int _active_user_load(mod_instance_t mi, user_t user) {
    os_t os;
    os_object_t o;

    /* get their active status */
    if(storage_get(user->sm->st, "active", jid_user(user->jid), NULL, &os) == st_SUCCESS && os_iter_first(os)) {
        o = os_iter_object(os);
        os_object_get_time(os, o, "time", &user->active);
        os_free(os);
    } else
        /* can't load them if they're inactive */
        return 1;

    return 0;
}
Example #19
0
/*
   Request:
      MUST NOT have extras.
      MUST have key.
      MUST have value.
   Ignore CAS.
*/
ST_RES *cmd_qlist_add(ST_REQ *req, ST_RES *res) {
	if(req->extras_sz || !req->key_sz || !req->value_sz) {
		return(set_error_code(res, MEMCACHE_STATUS_INVALID_ARGUMENTS));
	}
	MC_METADATA md;
	memset(&md, 0, sizeof(md));

	uint8_t *qla = buf_a;
	int qla_sz = sizeof(buf_a);
	uint8_t *qlb = (uint8_t *)req->value;
	uint8_t *qlc = buf_b;
	int qlc_sz = sizeof(buf_b);
	
	int r = storage_get(&md, (char*)qla, qla_sz, req->key, req->key_sz);
	if(r < 0){
		r = qlist_pack(qla, qla_sz, NULL, 0);
		if(r < 0) {
			set_error_code(res, MEMCACHE_STATUS_ITEM_NOT_STORED);
			goto exit;
		}
		md.flags = FLAG_QLIST;
		md.cas = ++unique_number || ++unique_number;
	}

	if( (md.flags & FLAG_QLIST) == 0) {
		set_error_code(res, MEMCACHE_STATUS_ITEM_NOT_STORED);
		goto exit;
	}
	
	r = qlist_or(qlc, qlc_sz, qla, qlb);
	if(r < 0) {
		set_error_code(res, MEMCACHE_STATUS_ITEM_NOT_STORED);
		goto exit;
	}
	
	md.cas = (md.cas+1) || (md.cas+2);
	r = storage_set(&md, (char*)qlc, r, req->key, req->key_sz);
	if(r < 0) {
		set_error_code(res, MEMCACHE_STATUS_ITEM_NOT_STORED);
		goto exit;
	}

	res->status = MEMCACHE_STATUS_OK;
	res->cas = md.cas;
exit:
	return(res);
}
Example #20
0
END_TEST



/* Added
 * Two client instance get/set pass tests:
 *      set/get basic table/key/value names from one table.
 *      set/get extended table/key/value names from one table.
 *      set/get extended table/key/value names from two tables.
 */

START_TEST (test_restartclient_onetable)
{
        struct storage_record r;

        // Start and connect to the server.
        int serverpid = 0;
        void *conn = start_connect(ONETABLE_CONF, "test_restartclient_onetable.serverout", &serverpid);
        fail_unless(conn != NULL, "Couldn't start or connect to server.");

        // Set a key/value.
        strncpy(r.value, VALUE, sizeof r.value);
        int status = storage_set(TABLE, KEY, &r, conn);
        fail_unless(status == 0, "Error setting a key/value pair.");

        // Disconnect from the server.
        status = storage_disconnect(conn);
        //fail_unless(status == 0, "Error disconnecting from the server.");

        // Reconnect to the server
	conn = storage_connect(SERVERHOST, server_port);
        fail_unless(conn != NULL, "Couldn't connect to server.");
	
	// Authenticate with the server.
	status = storage_auth(SERVERUSERNAME, SERVERPASSWORD, conn);
	fail_unless(status == 0, "Authentication failed.");

        // Get a value.
        strncpy(r.value, "", sizeof r.value);
        status = storage_get(TABLE, KEY, &r, conn);
        fail_unless(status == 0, "Error getting a value.");
        fail_unless(strcmp(r.value, VALUE) == 0, "Got wrong value.");

        // Disconnect from the server.
        status = storage_disconnect(conn);
        //fail_unless(status == 0, "Error disconnecting from the server.");
}
Example #21
0
END_TEST


/* Added/Modified
 * Two server instance get/set pass tests:
 * 	set/get basic table/key/value names from one table.
 * 	set/get extended table/key/value names from one table.
 * 	set/get extended table/key/value names from two tables.
 */

START_TEST (test_restartserver_onetable)
{
	struct storage_record r;

	// Start and connect to the server.
	int serverpid = 0;
	void *conn = start_connect(ONETABLE_CONF, "test_restartserver_onetable.serverout", &serverpid);
	fail_unless(conn != NULL, "Couldn't start or connect to server.");

	// Set a key/value.
	strncpy(r.value, VALUE, sizeof r.value);
	int status = storage_set(TABLE, KEY, &r, conn);
	fail_unless(status == 0, "Error setting a key/value pair.");

	// Disconnect from the server.
	status = storage_disconnect(conn);
	//fail_unless(status == 0, "Error disconnecting from the server.");
	
	// Kill the server.
	status = kill_server(serverpid);
	fail_unless(status == 0, "Couldn't kill server.");

	// Start the server.
	conn = start_connect(ONETABLE_CONF, "test_restartserver_onetable-2.serverout", &serverpid);
	fail_unless(conn != NULL, "Couldn't start or connect to server.");

	// Get a value.
	strncpy(r.value, "", sizeof r.value);
	status = storage_get(TABLE, KEY, &r, conn);
	fail_unless(status == -1, "storage_get with missing key should fail.");
        fail_unless(errno == ERR_KEY_NOT_FOUND, "storage_get with missing key not setting errno properly.");

	// Disconnect from the server.
	status = storage_disconnect(conn);
	//fail_unless(status == 0, "Error disconnecting from the server.");
}
Example #22
0
END_TEST


/*
 * Get failure tests:
 * 	get without server running (fail) [don't test this since they can assume programs won't crash.]
 * 	get with invalid table/key/record/conn parameter (fail)
 * 	get with bad table/key (fail)
 * 	get with non-existent table/key (fail)
 */

START_TEST (test_getinvalid_invalidtable)
{
	struct storage_record record;
	int status = storage_get(NULL, KEY, &record, test_conn);
	fail_unless(status == -1, "storage_get with invalid param should fail.");
	fail_unless(errno == ERR_INVALID_PARAM, "storage_get with invalid param not setting errno properly.");
}
Example #23
0
static enum CMD_TYPE parse_cmd(char* str, size_t len, char** output_val) {
    if (len > 0) {
        if (strcmp(str,"q")==0)return CMD_QUIT;
        char* dup_str = strdup(str);
        char cmd[16]="",key[32]="",val[2048]="";
        char *saveptr=NULL;
        char *token = strtok_r(dup_str," ",&saveptr);
        int token_len = token ? strlen(token) : 0;
        // required
        if (token_len == 0 || token_len > 16) { free(dup_str);return CMD_ERR; }
        memcpy(cmd,token,token_len);
        // optional
        token = strtok_r(NULL," ",&saveptr);
        token_len = token ? strlen(token) : 0;
        if (token_len && token_len <= 32) memcpy(key,token,token_len);
        // optional
        token = strtok_r(NULL," ",&saveptr);
        token_len = token ? strlen(token) : 0;
        if (token_len) {
            if (token_len <= 2048) {
                memcpy(val,token,token_len);
            } else {
                free(dup_str);return CMD_ERR;
            }
        }
        free(dup_str);

        if (strncmp(cmd,"set",3)==0) {
            if (strlen(key)==0)return CMD_ERR;
            storage_set(key,val);
            // todo check mmap limit
            return CMD_OK;
        } else if (strncmp(cmd,"get",3)==0) {
            if (strlen(key)==0)return CMD_ERR;
            char* val = storage_get(key);
            *output_val = val;
            return val == NULL ? CMD_NULL : CMD_GET;
        } else if (strncmp(cmd,"ping",4)==0) {
            *output_val = "pong";
            return CMD_ECHO;
        }
    }
    return CMD_UNKNOWN;
}
Example #24
0
END_TEST


/*
 * Get failure tests:
 * 	get without server running (fail) [don't test this since they can assume programs won't crash.]
 * 	get with invalid table/key/record/conn parameter (fail)
 * 	get with bad table/key (fail)
 * 	get with non-existent table/key (fail)
 */


START_TEST (test_getmissing_missingtable)
{
	struct storage_record record;
	int status = storage_get(MISSINGTABLE, KEY, &record, test_conn);
	fail_unless(status == -1, "storage_get with missing table should fail.");
	fail_unless(errno == ERR_TABLE_NOT_FOUND, "storage_get with missing table not setting errno properly.");
}
Example #25
0
END_TEST

START_TEST (test_setget_largefloat) // Added 18
{
	struct storage_record record;
	int fields = 0;
	int intval = 0;

	// Do a set
	strncpy(record.value, "col 500.2", sizeof record.value);
	int status = storage_set(INTTABLE, KEY, &record, test_conn);
	fail_unless(status == 0, "Error setting a key/value pair.");

	// Do a get
	strncpy(record.value, "", sizeof record.value);
	status = storage_get(INTTABLE, KEY, &record, test_conn);
	fail_unless(status == 0, "Error getting a value.");
	fields = sscanf(record.value, "col %f", &intval);
	fail_unless(fields == 1 && intval == 500.2, "Got wrong value.");
}
Example #26
0
END_TEST
/*
START_TEST (test_set_updatefloat)
{
	struct storage_record record;
	float floatval = 0;

	// Update the value
	strncpy(record.value, "col 8.8", sizeof record.value);
	int status = storage_set(FLOATTABLE, KEY1, &record, test_conn);
	fail_unless(status == 0, "Error updating a value.");

	// Get the new value.
	strncpy(record.value, "", sizeof record.value);
	status = storage_get(FLOATTABLE, KEY1, &record, test_conn);
	fail_unless(status == 0, "Error getting a value.");
	int fields = sscanf(record.value, "col %f", &floatval);
	fail_unless(fields == 1 && floatcmp(floatval, 8.8) == 0, "Got wrong value.");
}
END_TEST
*/

/*
 * Set operations with complex tables.
 * 	update an existing record (pass).
 * 	delete an existing record (pass).
 */

START_TEST (test_setcomplex_deletethreecols)
{
	// Delete a key/value pair.
	int status = storage_set(THREECOLSTABLE, KEY1, NULL, test_conn);
	fail_unless(status == 0, "Error deleting the key/value pair.");

	// Try to get the deleted value.
	struct storage_record record;
	strncpy(record.value, "", sizeof record.value);
	status = storage_get(THREECOLSTABLE, KEY1, &record, test_conn);
	fail_unless(status == -1, "storage_get for deleted key should fail.");
	fail_unless(errno == ERR_KEY_NOT_FOUND, "storage_get for deleted key not setting errno properly.");
}
Example #27
0
/**
 * @brief Attempts to get a value given table and key names from server.
 *
 * Reports the error number set by the storage server.
 * Does not exit if an error occurs.
 * @param r A pointer to a record structure.
 * @return Returns 0 on success, -1 otherwise.
 */
int client_get(struct storage_record *r)
{
    
    char table[MAX_TABLE_LEN] = {0}, key[MAX_KEY_LEN] = {0};
    
    bool read_success = false;
    while(read_success == false)
    {
        printf("Please enter the table name: ");
        char *l = fgets(input_buffer, sizeof input_buffer, stdin);
        if(l != input_buffer || (sscanf(input_buffer, "%[a-zA-Z0-9] %s", table, trash) != 1))
            printf("Please enter a valid table name (only alphanumeric characters).\n");
        else
            read_success = true;
    }
    
    read_success = false;
    while(read_success == false)
    {
        printf("Please enter the key: ");
        char *l = fgets(input_buffer, sizeof input_buffer, stdin);
        if(l != input_buffer || (sscanf(input_buffer, "%[a-zA-Z0-9] %s", key, trash) != 1))
            printf("Please enter a valid key (only alphanumeric characters).\n");
        else
            read_success = true;
    }
    
    gettimeofday(&start_time, NULL);
    int status = storage_get(table, key, r, conn);
    gettimeofday(&end_time, NULL);
    get_processing_time.tv_usec += (end_time.tv_sec - start_time.tv_sec)*1000000L + (end_time.tv_usec - start_time.tv_usec);
    sprintf(trash, "storage_get performed in %ld microseconds\n", (end_time.tv_sec - start_time.tv_sec)*1000000L + (end_time.tv_usec - start_time.tv_usec));
    logger(client_time_log, trash);
    
    if(status != 0)
        printf("storage_get failed. Error code: %d.\n", errno);
    else
        printf("storage_get: the value returned for key '%s' is '%s'.\n", key, r->value);
    
    return status;
}
Example #28
0
/*
   Request:
      MUST NOT have extras.
      MUST have key.
      MUST have value.
   Ignore CAS.
*/
ST_RES *cmd_qlist_del(ST_REQ *req, ST_RES *res) {
	if(req->extras_sz || !req->key_sz || !req->value_sz)
		return(set_error_code(res, MEMCACHE_STATUS_INVALID_ARGUMENTS));
	
	MC_METADATA md;
	memset(&md, 0, sizeof(md));

	uint8_t *qla = buf_a;
	int qla_sz = sizeof(buf_a);
	uint8_t *qlb = (uint8_t *)req->value;
	uint8_t *qlc = buf_b;
	int qlc_sz = sizeof(buf_b);

	int r = storage_get(&md, (char*)qla, qla_sz, req->key, req->key_sz);
	if(r < 0)
		goto exit_ok;
		
	if( (md.flags & FLAG_QLIST) == 0) {
		set_error_code(res, MEMCACHE_STATUS_ITEM_NOT_STORED);
		goto exit;
	}
	
	r = qlist_andnot(qlc, qlc_sz, qla, qlb);
	
	if(r == EMPTY_QLIST_SIZE) {
		storage_delete(req->key, req->key_sz);
	}else{
		md.cas = (md.cas+1) || (md.cas+2);
		r = storage_set(&md, (char*)qlc, r, req->key, req->key_sz);
		if(r < 0) {
			set_error_code(res, MEMCACHE_STATUS_ITEM_NOT_STORED);
			goto exit;
		}
	}

exit_ok:
	res->status = MEMCACHE_STATUS_OK;
	res->cas = md.cas;
exit:
	return(res);
}
Example #29
0
/* read file block from cache */ 
int get_fblock(const char *name, int fblock, char *block) { 
    Content *f = content_get(name); 
    if (strlen(name)>255) { 
	flog("name %s too long",name); 
	return FALSE;
    } 
    if (f<0) { 
	flog("no blocks for name %s",name); 
	return FALSE; 
    } 
    if (!block) { 
	flog("can't write to NULL pointer"); 
	return FALSE; 
    } 
    Map *b = content_fblock_stored(f,fblock); 
    if (b==NULL) { 
	flog("block %d of %s not stored",fblock,name); 
	return FALSE; 
    } 
    storage_get(b->cblock,block); 
    flog("retrieved block %d of %s (cblock %d)",fblock,name,b->cblock); 
    return TRUE; 
} 
Example #30
0
int coreneuron10_cstep_execute(int argc, char * const argv[]) {
    struct input_parameters p;

    int error = MAPP_OK;
    error = cstep_help(argc, argv, &p);
    if(error != MAPP_OK)
        return error;

    //Gets the data
    NrnThread * nt = (NrnThread *) storage_get(p.name, make_nrnthread, p.d, free_nrnthread);
    if(nt == NULL){
        storage_clear(p.name);
        return MAPP_BAD_DATA;
    }

    //Initial mechanisms set-up already done in the input date (no need to call mech_init_Ih, etc)
    gettimeofday(&tvBegin, NULL);

    //Load mechanisms
    mech_current_NaTs2_t(nt,&(nt->ml[17]));
    mech_current_Ih(nt,&(nt->ml[10]));
    mech_current_ProbAMPANMDA_EMS(nt,&(nt->ml[18]));

    //Call solver
    nrn_solve_minimal(nt);

    //Update the states
    mech_state_NaTs2_t(nt,&(nt->ml[17]));
    mech_state_Ih(nt,&(nt->ml[10]));
    mech_state_ProbAMPANMDA_EMS(nt,&(nt->ml[18]));

    gettimeofday(&tvEnd, NULL);
    timeval_subtract(&tvDiff, &tvEnd, &tvBegin);
    
    printf("\nTime for full computational step: %ld [s] %ld [us]\n", tvDiff.tv_sec, (long) tvDiff.tv_usec);
    return error;
}