コード例 #1
0
int 
do_loop_test ( )
{
	fprintf(stderr, "starting test\n");
	
	// this hash is the rendez-vous for all the worker threads, to make sure they're not working
	// on the same keys at the same time. It starts out empty. When a worker wants to use a key, it
	// drops an element in the hash unique.
	shash_create(&g_config.in_progress_hash, progress_hash_fn, sizeof(uint32_t), 0, g_config.n_threads * 2, SHASH_CR_MT_BIGLOCK);

	// Create the aerospike cluster
	g_config.asc = citrusleaf_cluster_create();
	citrusleaf_cluster_add_host(g_config.asc, g_config.host, g_config.port, 0);

	if (g_config.follow == false) 
		citrusleaf_cluster_follow(g_config.asc, false);
	
	
	// This array is the current value of a given key. Starts out as uninitialized.
	g_config.values = malloc( sizeof(uint64_t) * g_config.n_keys);
	if (g_config.values == 0) {
		fprintf(stderr, " could not malloc %d, use fewer keys",(int)(sizeof(uint64_t)*g_config.n_keys));
		return(-1);
	}
	for (uint i=0;i<g_config.n_keys;i++)
		g_config.values[i] = VALUE_UNINIT;

	g_config.read_counter = atomic_int_create(0);
	g_config.write_counter = atomic_int_create(0);
	g_config.delete_counter = atomic_int_create(0);
	g_config.key_counter = atomic_int_create(0);
	
	void *counter_control = start_counter_thread( g_config.read_counter, g_config.write_counter, g_config.delete_counter, g_config.key_counter);
	
	// Create the threads and send them on their way
	pthread_t	*thr_array = malloc(sizeof(pthread_t) * g_config.n_threads);

	fprintf(stderr, "starting threads for test\n");
	for (uint i=0;i<g_config.n_threads;i++)
		pthread_create(&thr_array[i], 0, work_fn, 0); 
	
	for (uint i=0;i<g_config.n_threads;i++) {
		void *value_ptr;
		pthread_join(thr_array[i], &value_ptr);
		if ( ((int)(ssize_t)value_ptr) )
			fprintf(stderr, "thread %d returned value %d\n",i,(int) (ssize_t) value_ptr);
	}
	
	free(g_config.values);
	free(thr_array);
	citrusleaf_cluster_destroy(g_config.asc);
	
	stop_counter_thread(counter_control);
	
	return(-1);	
}
コード例 #2
0
int main(int argc, char **argv){
	cl_cluster   *clc;
	cl_rv        return_value;
	cl_object key1;
	cl_object key2;

	printf(" STARTING TESTS\n");
	// initialize internal citrusleaf structures just once
	citrusleaf_init();

	// Create a cluster with a particular starting host
	printf(" STARTING CLUSTER CREATION TEST .... \n");
	clc = citrusleaf_cluster_create();
	if (!clc){
		printf("TEST FAILED: Could not create cluster object");
	    return(-1);
	}

	return_value = citrusleaf_cluster_add_host(clc, host, 3000, 1000);
	if( return_value != CITRUSLEAF_OK ){
		printf("TEST FAILED - cannot connect to host\n");
		return -1;
	}

	// XXX - need to do some info calls with a bigger cluster!

	printf(" DONE\n");


	// set up the key. Create a stack object, set its value to a string
	cl_object    key_obj;
	citrusleaf_object_init_str(&key_obj, myKey);

	// set up a specific bins to fetch
	// the response will be in this value
	cl_bin       values[3];
	strcpy( &values[0].bin_name[0], bin1 );
	citrusleaf_object_init_str( &values[0].object, strData);
	strcpy( &values[1].bin_name[0], bin2);
	citrusleaf_object_init_int( &values[1].object, intData );
	strcpy( &values[2].bin_name[0], bin3);
	citrusleaf_object_init_blob( &values[2].object, blobData, strlen(blobData)+1);

	printf("params to put are clc %p, ns %s, set %s, key %p, values %p\n", clc, ns, myset, &key_obj, values);
	return_value = citrusleaf_put(clc, ns, myset, &key_obj, values, 3, NULL);
	if( return_value != CITRUSLEAF_OK ){
		printf(" TEST FAILS - INITIAL PUT FAILS, value is %d\n", return_value);
		return(-1);
	}

	citrusleaf_object_init(&values[0].object);
	citrusleaf_object_init(&values[1].object);
	citrusleaf_object_init(&values[2].object);

	return_value = citrusleaf_get(clc, ns, myset, &key_obj, 
		values, 3, 0, NULL); 

	switch (return_value) {
    	case CITRUSLEAF_OK:
       		if (values[0].object.type != CL_STR) {
			printf(" TEST FAILS - value has unexpected type %d\n",values[0].object.type);
			goto cleanup;
       		} else if( strcmp(values[0].object.u.str, strData) ){
			printf("TEST FAILS - WRITE DOES NOT RETURN WHAT WAS WRITTEN: %s, %s\n", values[0].object.u.str, strData);
			goto cleanup;
		} 
	
       		if (values[1].object.type != CL_INT) {     
			printf(" TEST FAILS - value has unexpected type %d\n",values[1].object.type);
			goto cleanup;
       		} else if( values[1].object.u.i64 != intData){
			printf("TEST FAILS - WRITE DOES NOT RETURN WHAT WAS WRITTEN, %lu, %lu\n", values[1].object.u.i64, intData);
			goto cleanup;
       		} 
		if( values[2].object.type != CL_BLOB) {
			printf(" TEST FAILS - value has unexpected type %d\n",values[1].object.type);
			goto cleanup;
		}else if( strcmp(values[2].object.u.blob, blobData) ){
			printf(" TEST FAILS - WRITE DOES NOT RETURN CORRECT BLOB DATA\n");
			goto cleanup;
		}
      		break;
    	case CITRUSLEAF_FAIL_NOTFOUND:
    		printf(" TEST FAILS - citrusleaf says that key does not exist\n");
		goto cleanup;
    		break;
    	case CITRUSLEAF_FAIL_CLIENT:
    		printf(" TEST FAILS - citrusleaf client error: local error\n");
		goto cleanup;
    		break;
    	case CITRUSLEAF_FAIL_PARAMETER:
    		printf(" TEST FAILS - citrusleaf - bad parameter passed in \n");
		goto cleanup;
    		break;
    	case CITRUSLEAF_FAIL_TIMEOUT:
		printf(" TEST FAILS - citrusleaf - timeout on get\n");
		goto cleanup;
		break;
    	case CITRUSLEAF_FAIL_UNKNOWN:
		printf(" TEST _FAILS - citrusleaf - unknown server error\n");
		goto cleanup;
		break;
    	default :
		printf(" TEST_FAILS - error %d\n", return_value);
		goto cleanup;

	}
	// clean up the retrieved objects
	citrusleaf_object_free(&values[0].object);
	citrusleaf_object_free(&values[1].object);

	if( test_getall(clc) )    goto cleanup;
	if( read_mod_write(clc) ) goto cleanup;
	if( test_unique(clc) )    goto cleanup;
	if( test_operate(clc) )   goto cleanup;
	if( test_batch(clc) )     goto cleanup;
	
	printf("TEST SUCCESSFUL!\n");

cleanup:

	citrusleaf_object_init_str(&key1,myKey);
	citrusleaf_object_init_str(&key2,myKey2);
	citrusleaf_delete(clc, ns, myset, &key1, NULL);
	citrusleaf_delete(clc, ns, myset, &key2, NULL);
	// Clean up the cluster object
	citrusleaf_cluster_destroy(clc);
	// Clean up the unit
	citrusleaf_shutdown();
  
}