<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 ALTER_DSE_LEASES_FORMAT "ALTER KEYSPACE dse_leases " \
  " WITH REPLICATION = { " \
    "'class': 'NetworkTopologyStrategy', 'dc1' : '%d' " \
  "}"

#define GRAPH_OLAP_QUERY \
  "g.V().count();"

#define GRAPH_OLAP_TIMEOUT 240000 // 4 minutes

#define REPLICATION_STRATEGY "{ 'class': %s }"

#define SELECT_ALL_SYSTEM_LOCAL_CQL "SELECT * FROM system.local"

#define WAIT_FOR_WORKERS_SLEEP 120000 // 2 minutes

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

    // Call the parent setup function
    number_dc1_nodes_ = 2;
    replication_factor_ = 2;
    is_ccm_start_requested_ = false;
    is_session_requested_ = false;
    dse_workload_.push_back(CCM::DSE_WORKLOAD_SPARK);
    dse_workload_.push_back(CCM::DSE_WORKLOAD_GRAPH);
    DseIntegration::SetUp();

    // Wait for the spark master to become available
    ccm_->start_node(1);
    wait_for_port(1, 7080);
    master_host_ip_address_ = ccm_->cluster_ip_addresses(true)[0];

    /*
     * Update the `dse_leases` keyspace replication factor to the number of
     * nodes in the cluster. This will prevent the election of a new job tracker
     * until all nodes are available, preventing nodes from electing the wrong
     * master node.
     */
    Cluster cluster = Cluster::build()
      .with_contact_points(contact_points_);
    try {
      Session session = cluster.connect();
      session.execute(format_string(ALTER_DSE_LEASES_FORMAT,
        number_dc1_nodes_));
      session.close();
    } catch (Session::Exception e) {
      FAIL() << e.what();
    }

    // Bootstrap the remaining nodes
    for (unsigned int n = 2; n <= number_dc1_nodes_; ++n) {
      ccm_->start_node(n);
      std::stringstream worker_ip_address;
      worker_ip_address << ccm_->get_ip_prefix() << n;
      worker_hosts_ip_addresses_.push_back(worker_ip_address.str());
    }

    //TODO: Remove sleep and add parsing of HTML body from spark master to look for live workers
    LOG("Waiting for workers: Sleeping " << WAIT_FOR_WORKERS_SLEEP / 1000
      << "s");
    msleep(WAIT_FOR_WORKERS_SLEEP);

    // Create the DSE session
    cluster = default_cluster()
      .with_connection_heartbeat_interval(0)
      .with_request_timeout(GRAPH_OLAP_TIMEOUT);
    DseIntegration::connect(cluster);

    // Create the graph
    create_graph();
    CHECK_FAILURE;<commit_msg>test: Use only one contact point for OLAP initialization<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 ALTER_DSE_LEASES_FORMAT "ALTER KEYSPACE dse_leases " \
  " WITH REPLICATION = { " \
    "'class': 'NetworkTopologyStrategy', 'dc1' : '%d' " \
  "}"

#define GRAPH_OLAP_QUERY \
  "g.V().count();"

#define GRAPH_OLAP_TIMEOUT 240000 // 4 minutes

#define REPLICATION_STRATEGY "{ 'class': %s }"

#define SELECT_ALL_SYSTEM_LOCAL_CQL "SELECT * FROM system.local"

#define WAIT_FOR_WORKERS_SLEEP 120000 // 2 minutes

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

    // Call the parent setup function
    number_dc1_nodes_ = 2;
    replication_factor_ = 2;
    is_ccm_start_requested_ = false;
    is_session_requested_ = false;
    dse_workload_.push_back(CCM::DSE_WORKLOAD_SPARK);
    dse_workload_.push_back(CCM::DSE_WORKLOAD_GRAPH);
    DseIntegration::SetUp();

    // Wait for the spark master to become available
    ccm_->start_node(1);
    wait_for_port(1, 7080);
    master_host_ip_address_ = ccm_->cluster_ip_addresses(true)[0];

    /*
     * Update the `dse_leases` keyspace replication factor to the number of
     * nodes in the cluster. This will prevent the election of a new job tracker
     * until all nodes are available, preventing nodes from electing the wrong
     * master node.
     */
    Cluster cluster = Cluster::build()
      .with_contact_points(master_host_ip_address_);
    try {
      Session session = cluster.connect();
      session.execute(format_string(ALTER_DSE_LEASES_FORMAT,
        number_dc1_nodes_));
      session.close();
    } catch (Session::Exception e) {
      FAIL() << e.what();
    }

    // Bootstrap the remaining nodes
    for (unsigned int n = 2; n <= number_dc1_nodes_; ++n) {
      ccm_->start_node(n);
      std::stringstream worker_ip_address;
      worker_ip_address << ccm_->get_ip_prefix() << n;
      worker_hosts_ip_addresses_.push_back(worker_ip_address.str());
    }

    //TODO: Remove sleep and add parsing of HTML body from spark master to look for live workers
    LOG("Waiting for workers: Sleeping " << WAIT_FOR_WORKERS_SLEEP / 1000
      << "s");
    msleep(WAIT_FOR_WORKERS_SLEEP);

    // Create the DSE session
    cluster = default_cluster()
      .with_connection_heartbeat_interval(0)
      .with_request_timeout(GRAPH_OLAP_TIMEOUT);
    DseIntegration::connect(cluster);

    // Create the graph
    create_graph();
    CHECK_FAILURE;
{'fraction_non_alphanumeric': 0.10573248407643313, 'fraction_numerical': 0.01565059144676979, 'mean_word_length': 3.553438276719138, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 11, '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': '363683', 'n_tokens_mistral': 1912, 'n_tokens_neox': 1811, 'n_words': 431}