Exemplo n.º 1
0
 test_utils::CassResultPtr select_all_from_bytes_by_name() {
   test_utils::CassResultPtr result;
   test_utils::execute_query(session, "SELECT * FROM bytes_by_name", &result);
   BOOST_REQUIRE(cass_result_column_count(result.get()) == 3);
   BOOST_REQUIRE(cass_result_row_count(result.get()) > 0);
   return result;
 }
Exemplo n.º 2
0
void select_from_perf(CassSession* session, const char* query, const CassPrepared* prepared) {
  int i;
  CassFuture* futures[NUM_CONCURRENT_REQUESTS];

  for (i = 0; i < NUM_CONCURRENT_REQUESTS; ++i) {
    CassStatement* statement;

    if (prepared != NULL) {
      statement = cass_prepared_bind(prepared);
    } else {
      statement = cass_statement_new(query, 0);
    }

    futures[i] = cass_session_execute(session, statement);

    cass_statement_free(statement);
  }

  for (i = 0; i < NUM_CONCURRENT_REQUESTS; ++i) {
    CassFuture* future = futures[i];
    CassError rc = cass_future_error_code(future);
    if (rc != CASS_OK) {
      print_error(future);
    } else {
      const CassResult* result = cass_future_get_result(future);
      assert(cass_result_column_count(result) == 6);
      cass_result_free(result);
    }
    cass_future_free(future);
  }
}
Exemplo n.º 3
0
 cass_int64_t get_timestamp(const std::string table_name, const std::string& key) {
   cass_int64_t timestamp;
   test_utils::CassResultPtr result;
   std::string query = str(boost::format("SELECT writetime(value) FROM %s WHERE key = '%s'") % table_name % key);
   test_utils::execute_query(session, query, &result);
   BOOST_REQUIRE(cass_result_row_count(result.get()) > 0);
   BOOST_REQUIRE(cass_result_column_count(result.get()) > 0);
   const CassRow* row = cass_result_first_row(result.get());
   const CassValue* writetime = cass_row_get_column(row, 0);
   cass_value_get_int64(writetime, &timestamp);
   return timestamp;
 }
Exemplo n.º 4
0
  /**
   * Test established connection with a high load query
   */
  void test_high_load() {
    //Create and use the simple keyspace
    test_utils::execute_query(session_, str(boost::format(test_utils::CREATE_KEYSPACE_SIMPLE_FORMAT) % test_utils::SIMPLE_KEYSPACE % "1"));
    test_utils::execute_query(session_, str(boost::format("USE %s") % test_utils::SIMPLE_KEYSPACE));

    //Create a table to fill with large text fields
    test_utils::execute_query(session_, "CREATE TABLE high_load (key int PRIMARY KEY, a text, b text, c text)");

    //Perform queries and validate inserted data
    for (int n = 0; n < NUMBER_OF_ITERATIONS; ++n) {
      std::string text_a = test_utils::generate_random_string(10240);
      std::string text_b = test_utils::generate_random_string(20480);
      std::string text_c = test_utils::generate_random_string(40960);
      test_utils::execute_query(session_, str(boost::format("INSERT INTO high_load (key, a, b, c) VALUES (%d, '%s', '%s', '%s')") % n % text_a % text_b % text_c));

      test_utils::CassResultPtr result;
      test_utils::execute_query(session_, str(boost::format("SELECT * FROM high_load WHERE key = %d") % n), &result);
      BOOST_REQUIRE_EQUAL(cass_result_column_count(result.get()), 4u);
      BOOST_REQUIRE_EQUAL(cass_result_row_count(result.get()), 1u);

      const CassRow* row = cass_result_first_row(result.get());
      const CassValue* value;
      value = cass_row_get_column_by_name(row, "key");
      BOOST_REQUIRE(value != NULL);
      cass_int32_t key;
      BOOST_REQUIRE_EQUAL(cass_value_get_int32(value, &key), CASS_OK);
      BOOST_CHECK_EQUAL(key, n);

      value = cass_row_get_column_by_name(row, "a");
      BOOST_REQUIRE(value != NULL);
      CassString a;
      BOOST_REQUIRE_EQUAL(cass_value_get_string(value, &a.data, &a.length), CASS_OK);
      BOOST_CHECK(test_utils::Value<CassString>::equal(a, CassString(text_a.c_str())));

      value = cass_row_get_column_by_name(row, "b");
      BOOST_REQUIRE(value != NULL);
      CassString b;
      BOOST_REQUIRE_EQUAL(cass_value_get_string(value, &b.data, &b.length), CASS_OK);
      BOOST_CHECK(test_utils::Value<CassString>::equal(b, CassString(text_b.c_str())));

      value = cass_row_get_column_by_name(row, "c");
      BOOST_REQUIRE(value != NULL);
      CassString c;
      BOOST_REQUIRE_EQUAL(cass_value_get_string(value, &c.data, &c.length), CASS_OK);
      BOOST_CHECK(test_utils::Value<CassString>::equal(c, CassString(text_c.c_str())));
    }

    //Drop the table and keyspace
    test_utils::execute_query(session_, "DROP TABLE high_load");
    test_utils::execute_query(session_, str(boost::format("DROP KEYSPACE %s")  % test_utils::SIMPLE_KEYSPACE));
  }
  /**
   * Check the column count of a bound statement before and after adding a
   * column to a table.
   *
   * @param expected_column_count_after_update
   */
  void prepared_check_column_count_after_alter(size_t expected_column_count_after_update) {
    test_utils::CassSessionPtr session(test_utils::create_session(cluster));

    test_utils::execute_query(session.get(), str(boost::format("USE %s") % keyspace));

    test_utils::CassFuturePtr future(cass_session_prepare(session.get(), "SELECT * FROM test WHERE k = 'key1'"));
    BOOST_REQUIRE_EQUAL(cass_future_error_code(future.get()), CASS_OK);

    test_utils::CassPreparedPtr prepared(cass_future_get_prepared(future.get()));
    BOOST_REQUIRE(prepared);

    test_utils::CassStatementPtr bound_statement(cass_prepared_bind(prepared.get()));
    BOOST_REQUIRE(bound_statement);

    // Verify that the table has two columns in the metadata
    {
      test_utils::CassFuturePtr result_future(cass_session_execute(session.get(), bound_statement.get()));
      BOOST_REQUIRE_EQUAL(cass_future_error_code(result_future.get()), CASS_OK);

      test_utils::CassResultPtr result(cass_future_get_result(result_future.get()));

      BOOST_CHECK_EQUAL(cass_result_column_count(result.get()), 2u);
    }

    // Add a column to the table
    test_utils::execute_query(session.get(), "ALTER TABLE test ADD v2 int");

    // The column count shouldn't have changed
    {
      test_utils::CassFuturePtr result_future(cass_session_execute(session.get(), bound_statement.get()));
      BOOST_REQUIRE_EQUAL(cass_future_error_code(result_future.get()), CASS_OK);

      test_utils::CassResultPtr result(cass_future_get_result(result_future.get()));

      BOOST_CHECK_EQUAL(cass_result_column_count(result.get()), expected_column_count_after_update);
    }
  }
Exemplo n.º 6
0
  /**
   * Test established connection with a normal load query
   */
  void test_normal_load() {
    //Create and use the simple keyspace
    test_utils::execute_query(session_, str(boost::format(test_utils::CREATE_KEYSPACE_SIMPLE_FORMAT) % test_utils::SIMPLE_KEYSPACE % "1"));
    test_utils::execute_query(session_, str(boost::format("USE %s") % test_utils::SIMPLE_KEYSPACE));

    //Create a table to fill with numbers and characters
    test_utils::execute_query(session_, "CREATE TABLE normal_load (key int PRIMARY KEY, a int, b float, c text)");

    //Perform queries and validate inserted data
    for (int n = 0; n < NUMBER_OF_ITERATIONS; ++n) {
      std::string text = test_utils::generate_random_string(16);
      test_utils::execute_query(session_, str(boost::format("INSERT INTO normal_load (key, a, b, c) VALUES (%d, %d, %f, '%s')") % n % (n * 100) % (n * .001f) % text));

      test_utils::CassResultPtr result;
      test_utils::execute_query(session_, str(boost::format("SELECT * FROM normal_load WHERE key = %d") % n), &result);
      BOOST_REQUIRE_EQUAL(cass_result_column_count(result.get()), 4u);
      BOOST_REQUIRE_EQUAL(cass_result_row_count(result.get()), 1u);

      const CassRow* row = cass_result_first_row(result.get());
      const CassValue* value;
      value = cass_row_get_column_by_name(row, "key");
      BOOST_REQUIRE(value != NULL);
      cass_int32_t key;
      BOOST_REQUIRE_EQUAL(cass_value_get_int32(value, &key), CASS_OK);
      BOOST_CHECK_EQUAL(key, n);

      value = cass_row_get_column_by_name(row, "a");
      BOOST_REQUIRE(value != NULL);
      cass_int32_t a;
      BOOST_REQUIRE_EQUAL(cass_value_get_int32(value, &a), CASS_OK);
      BOOST_CHECK_EQUAL(a, (n * 100));

      value = cass_row_get_column_by_name(row, "b");
      BOOST_REQUIRE(value != NULL);
      cass_float_t b;
      BOOST_REQUIRE_EQUAL(cass_value_get_float(value, &b), CASS_OK);
      BOOST_CHECK_EQUAL(b, (n * .001f));

      value = cass_row_get_column_by_name(row, "c");
      BOOST_REQUIRE(value != NULL);
      CassString c;
      BOOST_REQUIRE_EQUAL(cass_value_get_string(value, &c.data, &c.length), CASS_OK);
      BOOST_CHECK(test_utils::Value<CassString>::equal(c, CassString(text.c_str())));
    }

    //Drop the table and keyspace
    test_utils::execute_query(session_, "DROP TABLE normal_load");
    test_utils::execute_query(session_, str(boost::format("DROP KEYSPACE %s")  % test_utils::SIMPLE_KEYSPACE));
  }
Exemplo n.º 7
0
void check_result(CassSession* session) {
  test_utils::CassResultPtr result;
  test_utils::execute_query(session, "SELECT * FROM test", &result);
  BOOST_REQUIRE(cass_result_column_count(result.get()) == 5);
  BOOST_REQUIRE(cass_result_row_count(result.get()) > 0);

  const CassRow* row = cass_result_first_row(result.get());

  cass_int32_t key;
  BOOST_REQUIRE(cass_value_get_int32(cass_row_get_column(row, 0), &key) == CASS_OK);

  cass_int32_t v1;
  BOOST_REQUIRE(cass_value_get_int32(cass_row_get_column(row, 1), &v1) == CASS_OK);

  CassString v2;
  BOOST_REQUIRE(cass_value_get_string(cass_row_get_column(row, 2), &v2.data, &v2.length) == CASS_OK);

  test_utils::CassIteratorPtr v3(cass_iterator_from_collection(cass_row_get_column(row, 3)));

  cass_int32_t i = 0;
  while (cass_iterator_next(v3.get())) {
    const CassValue* value =  cass_iterator_get_value(v3.get());
    BOOST_REQUIRE(cass_value_type(value) == CASS_VALUE_TYPE_INT);

    cass_int32_t output;
    cass_value_get_int32(value, &output);
    BOOST_REQUIRE(i == output);
    i++;
  }

  test_utils::CassIteratorPtr v4(cass_iterator_from_collection(cass_row_get_column(row, 4)));

  cass_int32_t j = 0;
  while (cass_iterator_next(v4.get())) {
    const CassValue* value =  cass_iterator_get_value(v4.get());
    BOOST_REQUIRE(cass_value_type(value) == CASS_VALUE_TYPE_VARCHAR);

    CassString output;
    cass_value_get_string(value, &output.data, &output.length);
    BOOST_REQUIRE(output.length == 1 && output.data[0] == 'd' + j);
    j++;
  }
}
Exemplo n.º 8
0
/**
* Executes a statement on a given session. Currently builds an array of rows.
* That will hopefully change.
* Also, I may expose the iterator instead, so you can go crazy in Lua-land.
*/
int lua_cass_session_execute(lua_State* L)
{
	CassSession* session = lua_session_get_ptr(L, 1);
	CassStatement* statement = lua_statement_get_ptr(L, 2);

	CassFuture* future = cass_session_execute(session, statement);
	cass_future_wait(future);

	CassError rc = cass_future_error_code(future);
	if (rc != CASS_OK) {
		int num = lua_cass_push_future_error(L, future);
		cass_future_free(future);
		return num;
	}

	const CassResult* result = cass_future_get_result(future);
	cass_future_free(future);
	CassIterator* iterator = cass_iterator_from_result(result);

	// TODO: devolver un iterador ?
	int row_count = cass_result_row_count(result);
	int column_count = cass_result_column_count(result);

	int i = 0;
	lua_newtable(L);
	int rows_table = lua_gettop(L);

	/* iterate over rows */
	while (cass_iterator_next(iterator)) {
		const CassRow* row = cass_iterator_get_row(iterator);
		
		lua_newtable(L);
		int columns_table = lua_gettop(L);
		/* loop over columns */
		for (int j = 0; j < column_count; ++j) {
			CassString name = cass_result_column_name(result, j);
			lua_pushlstring(L, name.data, name.length);
			lua_cass_value_to_lua(L, cass_row_get_column(row, j));
			
			lua_settable(L, columns_table);
			//lua_rawseti(L, columns_table, j + 1);
		}
		
		/*int j = 0;
		CassIterator* it_columns = cass_iterator_from_row(row);
		while (cass_iterator_next(it_columns)) {
			const CassValue* column = cass_iterator_get_column(it_columns);
			
			CassString name = cass_result_column_name(result, j);
			lua_pushlstring(L, name.data, name.length);
			lua_cass_value_to_lua(L, column);
			lua_settable(L, columns_table);
			j++;
		}*/
		lua_rawseti(L, rows_table, ++i);
	}
	
	cass_result_free(result);
	cass_iterator_free(iterator);

	return 1;
}