static void *worker_thread( void *context )
#endif
{
	/* 
	worker thread set an error, request the error stack and validate it contains the error saved.
	later it appends another error to the error stack, and validate it contains the two errors.
	*/
	TEST_THREAD_DATA *thread_context = (TEST_THREAD_DATA *)context;
	char first_error_buffer[1024] = "";
	char second_error_buffer[1024] = "";
	char full_error_buffer[1024] = "";
	const char *error_stack = NULL;
	int index = thread_context->index;
	unsigned sleep_interval_millis = thread_context->sleep_interval_millis;

	//set a thread specific error
	snprintf( first_error_buffer, sizeof(first_error_buffer), "thread %d set an error", index );
	avro_set_error( "%s", first_error_buffer );

	SLEEP_MILLIS( sleep_interval_millis );

	//validate error stack contains the thread specific error
	error_stack = avro_strerror();
	if ( strcmp( error_stack, first_error_buffer ) != 0 )
	{
		thread_context->error_occured = 1;
		snprintf( thread_context->error_message, 
				  sizeof(thread_context->error_message),
				  "invalid error stack found: expected '%s' found '%s'", first_error_buffer, error_stack );
	}

	//set another thread specific error
	SLEEP_MILLIS( sleep_interval_millis );
	snprintf( second_error_buffer, sizeof(second_error_buffer), "thread %d set ANOTHER error...", index );
	avro_prefix_error( "%s", second_error_buffer );
	snprintf( full_error_buffer, sizeof(full_error_buffer), "%s%s", second_error_buffer, first_error_buffer );

	//validate error stack contains the 2 errors as expected
	SLEEP_MILLIS( sleep_interval_millis );
	error_stack = avro_strerror();
	if ( strcmp( error_stack, full_error_buffer ) != 0 )
	{
		thread_context->error_occured = 1;
		snprintf( thread_context->error_message, 
				  sizeof(thread_context->error_message),
				  "invalid error stack found: expected '%s' found '%s'", full_error_buffer, error_stack );
	}

	return 0;

}
Exemplo n.º 2
0
Arquivo: io.c Projeto: 1ack/Impala
static int
avro_read_memory(struct _avro_reader_memory_t *reader, void *buf, int64_t len)
{
	if (len > 0) {
		if ((reader->len - reader->read) < len) {
			avro_prefix_error("Cannot read %" PRIsz " bytes from memory buffer",
					  (size_t) len);
			return ENOSPC;
		}
		memcpy(buf, reader->buf + reader->read, len);
		reader->read += len;
	}
	return 0;
}
Exemplo n.º 3
0
int
avro_consume_binary(avro_reader_t reader, avro_consumer_t *consumer, void *ud)
{
	int rval;
	const avro_encoding_t *enc = &avro_binary_encoding;

	check_param(EINVAL, reader, "reader");
	check_param(EINVAL, consumer, "consumer");

	switch (avro_typeof(consumer->schema)) {
	case AVRO_NULL:
		check_prefix(rval, enc->read_null(reader),
			     "Cannot read null value: ");
		check(rval, avro_consumer_call(consumer, null_value, ud));
		break;

	case AVRO_BOOLEAN:
		{
			int8_t b;
			check_prefix(rval, enc->read_boolean(reader, &b),
				     "Cannot read boolean value: ");
			check(rval, avro_consumer_call(consumer, boolean_value, b, ud));
		}
		break;

	case AVRO_STRING:
		{
			int64_t len;
			char *s;
			check_prefix(rval, enc->read_string(reader, &s, &len),
				     "Cannot read string value: ");
			check(rval, avro_consumer_call(consumer, string_value, s, len, ud));
		}
		break;

	case AVRO_INT32:
		{
			int32_t i;
			check_prefix(rval, enc->read_int(reader, &i),
				    "Cannot read int value: ");
			check(rval, avro_consumer_call(consumer, int_value, i, ud));
		}
		break;

	case AVRO_INT64:
		{
			int64_t l;
			check_prefix(rval, enc->read_long(reader, &l),
				     "Cannot read long value: ");
			check(rval, avro_consumer_call(consumer, long_value, l, ud));
		}
		break;

	case AVRO_FLOAT:
		{
			float f;
			check_prefix(rval, enc->read_float(reader, &f),
				     "Cannot read float value: ");
			check(rval, avro_consumer_call(consumer, float_value, f, ud));
		}
		break;

	case AVRO_DOUBLE:
		{
			double d;
			check_prefix(rval, enc->read_double(reader, &d),
				     "Cannot read double value: ");
			check(rval, avro_consumer_call(consumer, double_value, d, ud));
		}
		break;

	case AVRO_BYTES:
		{
			char *bytes;
			int64_t len;
			check_prefix(rval, enc->read_bytes(reader, &bytes, &len),
				     "Cannot read bytes value: ");
			check(rval, avro_consumer_call(consumer, bytes_value, bytes, len, ud));
		}
		break;

	case AVRO_FIXED:
		{
			char *bytes;
			int64_t size =
			    avro_schema_to_fixed(consumer->schema)->size;

			bytes = avro_malloc(size);
			if (!bytes) {
				avro_prefix_error("Cannot allocate new fixed value");
				return ENOMEM;
			}
			rval = avro_read(reader, bytes, size);
			if (rval) {
				avro_prefix_error("Cannot read fixed value: ");
				avro_free(bytes, size);
				return rval;
			}

			rval = avro_consumer_call(consumer, fixed_value, bytes, size, ud);
			if (rval) {
				avro_free(bytes, size);
				return rval;
			}
		}
		break;

	case AVRO_ENUM:
		check(rval, read_enum(reader, enc, consumer, ud));
		break;

	case AVRO_ARRAY:
		check(rval, read_array(reader, enc, consumer, ud));
		break;

	case AVRO_MAP:
		check(rval, read_map(reader, enc, consumer, ud));
		break;

	case AVRO_UNION:
		check(rval, read_union(reader, enc, consumer, ud));
		break;

	case AVRO_RECORD:
		check(rval, read_record(reader, enc, consumer, ud));
		break;

	case AVRO_LINK:
		avro_set_error("Consumer can't consume a link schema directly");
		return EINVAL;
	}

	return 0;
}