<commit_before>/*
 * Copyright (c) 2012 by <NAME>, Zuse Institute Berlin
 *
 * Licensed under the BSD License, see LICENSE file for details.
 *
 */

#include "common/test_environment.h"

#include "common/test_rpc_server_dir.h"
#include "common/test_rpc_server_mrc.h"
#include "common/test_rpc_server_osd.h"
#include "libxtreemfs/client.h"

using namespace xtreemfs::rpc;

namespace xtreemfs {

TestEnvironment::TestEnvironment()
    : options(), user_credentials() {
  user_credentials.set_username("ClientTest");
  user_credentials.add_groups("ClientTest");

  dir.reset(new TestRPCServerDIR());
  mrc.reset(new TestRPCServerMRC());
  osds.push_back(new TestRPCServerOSD());

  volume_name_ = "test";
}

TestEnvironment::~TestEnvironment() {
  for (size_t i = 0; i < osds.size(); i++) {
    delete osds[i];
  }
}

void TestEnvironment::AddOSDs(int num_of_osds) {
  for (int i = 1; i < num_of_osds; i++) {
    osds.push_back(new TestRPCServerOSD());
  }
}

bool TestEnvironment::Start() {
  if (!dir->Start()) {
    return false;
  }
  if (!mrc->Start()) {
    return false;
  }
  dir->RegisterVolume(volume_name_, mrc->GetAddress());
  for (size_t i = 0; i < osds.size(); i++) {
    if (!osds[i]->Start()) {
      return false;
    }
    mrc->RegisterOSD(osds[i]->GetAddress());
  }
  // TODO(mberlin): Register OSDs at MRC.

  // If the DIR server address was not explicitly overridden, set it to the
  // started test DIR server.
  if (options.service_addresses.empty()) {
    options.service_addresses.push_back(dir->GetAddress());
  }

  client.reset(Client::CreateClient(
      options.service_addresses,
      user_credentials,
      NULL,  // No SSL options.
      options));

  // Start the client (a connection to the DIR service will be setup).
  client->Start();

  return true;
}

void TestEnvironment::Stop() {
  if (client.get()) {
    client->Shutdown();<commit_msg>client: log test server ports so that they can be correlated with rpc error messages.<commit_after>/*
 * Copyright (c) 2012 by <NAME>, Zuse Institute Berlin
 *
 * Licensed under the BSD License, see LICENSE file for details.
 *
 */

#include "common/test_environment.h"

#include "common/test_rpc_server_dir.h"
#include "common/test_rpc_server_mrc.h"
#include "common/test_rpc_server_osd.h"
#include "libxtreemfs/client.h"
#include "util/logging.h"

using namespace xtreemfs::rpc;
using xtreemfs::util::Logging;

namespace xtreemfs {

TestEnvironment::TestEnvironment()
    : options(), user_credentials() {
  user_credentials.set_username("ClientTest");
  user_credentials.add_groups("ClientTest");

  dir.reset(new TestRPCServerDIR());
  mrc.reset(new TestRPCServerMRC());
  osds.push_back(new TestRPCServerOSD());

  volume_name_ = "test";
}

TestEnvironment::~TestEnvironment() {
  for (size_t i = 0; i < osds.size(); i++) {
    delete osds[i];
  }
}

void TestEnvironment::AddOSDs(int num_of_osds) {
  for (int i = 1; i < num_of_osds; i++) {
    osds.push_back(new TestRPCServerOSD());
  }
}

bool TestEnvironment::Start() {
  if (!dir->Start()) {
    return false;
  }
  Logging::log->getLog(xtreemfs::util::LEVEL_INFO)
      << "DIR running at: " << dir->GetAddress() << std::endl;
  if (!mrc->Start()) {
    return false;
  }
  Logging::log->getLog(xtreemfs::util::LEVEL_INFO)
      << "MRC running at: " << mrc->GetAddress() << std::endl;
  dir->RegisterVolume(volume_name_, mrc->GetAddress());
  for (size_t i = 0; i < osds.size(); i++) {
    if (!osds[i]->Start()) {
      return false;
    }
    Logging::log->getLog(xtreemfs::util::LEVEL_INFO)
        << "OSD running at: " << osds[i]->GetAddress() << std::endl;
    mrc->RegisterOSD(osds[i]->GetAddress());
  }
  // TODO(mberlin): Register OSDs at MRC.

  // If the DIR server address was not explicitly overridden, set it to the
  // started test DIR server.
  if (options.service_addresses.empty()) {
    options.service_addresses.push_back(dir->GetAddress());
  }

  client.reset(Client::CreateClient(
      options.service_addresses,
      user_credentials,
      NULL,  // No SSL options.
      options));

  // Start the client (a connection to the DIR service will be setup).
  client->Start();

  return true;
}

void TestEnvironment::Stop() {
  if (client.get()) {
    client->Shutdown();
{'fraction_non_alphanumeric': 0.15413622436954985, 'fraction_numerical': 0.0032995522036295072, 'mean_word_length': 3.957943925233645, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6421492', 'n_tokens_mistral': 1492, 'n_tokens_neox': 1462, 'n_words': 327}