<commit_before>/*
  Copyright (c) 2016 DataStax, Inc.

  This software can be used solely with DataStax Enterprise. Please consult the
  license at http://www.datastax.com/terms/datastax-dse-driver-license-terms
*/

#include "dse_integration.hpp"
#include "options.hpp"

#define GRAPH_READ_QUERY \
  "g.V().limit(1);"

#define GRAPH_WRITE_QUERY \
  "graph.addVertex(label, 'person', 'name', 'michael', 'age', 27);"

/**
 * Graph consistency integration tests
 *
 * @dse_version 5.0.0
 */
class GraphConsistencyIntegrationTest : public DseIntegration {
public:
  void SetUp() {
    CHECK_VERSION(5.0.0);

    // Call the parent setup function
    dse_workload_.push_back(CCM::DSE_WORKLOAD_GRAPH);
    number_dc1_nodes_ = 3;
    replication_factor_ = 3; // Force RF=3 instead of default calculated RF=2
    DseIntegration::SetUp();

    // Create the graph
    create_graph();
    CHECK_FAILURE;
    populate_classic_graph(test_name_);
    CHECK_FAILURE;
  }

  void TearDown() {
    // Restart all stopped nodes
    for (std::vector<unsigned int>::iterator iterator = stopped_nodes_.begin();
      iterator != stopped_nodes_.end(); ++iterator) {
      LOG("Restarting Node Stopped in " << test_name_ << ": " << *iterator);
      ccm_->start_node(*iterator);
    }
    stopped_nodes_.clear();
  }

  /**
   * Execute a graph read query with the specified read consistencies
   *
   * @param consistency Read consistency to apply to statement
   * @param is_assert True if error code for future should be asserted; false
   *                  otherwise
   * @return DSE graph result from the executed query
   */
  test::driver::DseGraphResultSet execute_read_query(CassConsistency consistency,
    bool assert_ok = true) {
    // Initialize the graph options
    test::driver::DseGraphOptions graph_options;
    graph_options.set_name(test_name_);
    graph_options.set_read_consistency(consistency);

    // Execute the graph query and return the result set
    return dse_session_.execute(GRAPH_READ_QUERY, graph_options, assert_ok);
  }

  /**
   * Execute a graph write query with the specified write consistencies
   *
   * @param consistency Write consistency to apply to statement
   * @param is_assert True if error code for future should be asserted; false
   *                  otherwise
   * @return DSE graph result from the executed query
   */
  test::driver::DseGraphResultSet execute_write_query(CassConsistency consistency,
    bool assert_ok = true) {
    // Initialize the graph options
    test::driver::DseGraphOptions graph_options;
    graph_options.set_name(test_name_);
    graph_options.set_write_consistency(consistency);

    // Execute the graph query and return the result set
    return dse_session_.execute(GRAPH_WRITE_QUERY, graph_options, assert_ok);
  }

  /**
   * Helper method to stop a node during the graph consistency test to ensure
   * schema operations have been propagated through the cluster before a node
   * is stopped.
   *
   * @param node Node that should be stopped
   */
  void stop_node(unsigned int node) {
    // Determine if schema operations should be triggered across cluster nodes
    if (!propagate_schema_) {
      LOG("Performing Graph Query to Propagate Schema Across Cluster: "
        << "Waiting 10s");
      execute_read_query(CASS_CONSISTENCY_ANY);
      msleep(10000);
      propagate_schema_ = true;
    }

    // Stop the requested node
    ccm_->stop_node(node);
    stopped_nodes_.push_back(node);
  }

  /**<commit_msg>test: Fixing use of invalid consistency for read query<commit_after>/*
  Copyright (c) 2016 DataStax, Inc.

  This software can be used solely with DataStax Enterprise. Please consult the
  license at http://www.datastax.com/terms/datastax-dse-driver-license-terms
*/

#include "dse_integration.hpp"
#include "options.hpp"

#define GRAPH_READ_QUERY \
  "g.V().limit(1);"

#define GRAPH_WRITE_QUERY \
  "graph.addVertex(label, 'person', 'name', 'michael', 'age', 27);"

/**
 * Graph consistency integration tests
 *
 * @dse_version 5.0.0
 */
class GraphConsistencyIntegrationTest : public DseIntegration {
public:
  void SetUp() {
    CHECK_VERSION(5.0.0);

    // Call the parent setup function
    dse_workload_.push_back(CCM::DSE_WORKLOAD_GRAPH);
    number_dc1_nodes_ = 3;
    replication_factor_ = 3; // Force RF=3 instead of default calculated RF=2
    DseIntegration::SetUp();

    // Create the graph
    create_graph();
    CHECK_FAILURE;
    populate_classic_graph(test_name_);
    CHECK_FAILURE;
  }

  void TearDown() {
    // Restart all stopped nodes
    for (std::vector<unsigned int>::iterator iterator = stopped_nodes_.begin();
      iterator != stopped_nodes_.end(); ++iterator) {
      LOG("Restarting Node Stopped in " << test_name_ << ": " << *iterator);
      ccm_->start_node(*iterator);
    }
    stopped_nodes_.clear();
  }

  /**
   * Execute a graph read query with the specified read consistencies
   *
   * @param consistency Read consistency to apply to statement
   * @param is_assert True if error code for future should be asserted; false
   *                  otherwise
   * @return DSE graph result from the executed query
   */
  test::driver::DseGraphResultSet execute_read_query(CassConsistency consistency,
    bool assert_ok = true) {
    // Initialize the graph options
    test::driver::DseGraphOptions graph_options;
    graph_options.set_name(test_name_);
    graph_options.set_read_consistency(consistency);

    // Execute the graph query and return the result set
    return dse_session_.execute(GRAPH_READ_QUERY, graph_options, assert_ok);
  }

  /**
   * Execute a graph write query with the specified write consistencies
   *
   * @param consistency Write consistency to apply to statement
   * @param is_assert True if error code for future should be asserted; false
   *                  otherwise
   * @return DSE graph result from the executed query
   */
  test::driver::DseGraphResultSet execute_write_query(CassConsistency consistency,
    bool assert_ok = true) {
    // Initialize the graph options
    test::driver::DseGraphOptions graph_options;
    graph_options.set_name(test_name_);
    graph_options.set_write_consistency(consistency);

    // Execute the graph query and return the result set
    return dse_session_.execute(GRAPH_WRITE_QUERY, graph_options, assert_ok);
  }

  /**
   * Helper method to stop a node during the graph consistency test to ensure
   * schema operations have been propagated through the cluster before a node
   * is stopped.
   *
   * @param node Node that should be stopped
   */
  void stop_node(unsigned int node) {
    // Determine if schema operations should be triggered across cluster nodes
    if (!propagate_schema_) {
      LOG("Performing Graph Query to Propagate Schema Across Cluster: "
        << "Waiting 10s");
      execute_read_query(CASS_CONSISTENCY_ONE);
      msleep(10000);
      propagate_schema_ = true;
    }

    // Stop the requested node
    ccm_->stop_node(node);
    stopped_nodes_.push_back(node);
  }

  /**
{'fraction_non_alphanumeric': 0.09178881457236374, 'fraction_numerical': 0.0071154119823537785, 'mean_word_length': 3.485003190810466, 'pattern_counts': {'":': 2, '<': 21, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5321453', 'n_tokens_mistral': 2151, 'n_tokens_neox': 2060, 'n_words': 604}