<commit_before>#!/usr/bin/env python
"""Tests reparenting is picked up in topology."""

import json
import threading
import time

import numpy

import logging

import base_cluster_test
import vtctl_helper

from vtproto import topodata_pb2
from vttest import sharding_utils


def tearDownModule():
  pass


class ReparentTest(base_cluster_test.BaseClusterTest):

  @classmethod
  def setUpClass(cls):
    super(ReparentTest, cls).setUpClass()

    # number of reparent iterations
    cls.num_reparents = int(cls.test_params.get('num_reparents', '1'))

    # max allowable median master downtime in seconds
    cls.master_downtime_threshold = int(cls.test_params.get(
        'master_downtime_threshold', '20'))

    # seconds to wait for reparent to result in a new master
    cls.reparent_timeout_threshold = int(cls.test_params.get(
        'reparent_timeout_threshold', '30'))

    for keyspace, num_shards in zip(cls.env.keyspaces, cls.env.num_shards):
      for shard in xrange(num_shards):
        shard_name = sharding_utils.get_shard_name(shard, num_shards)
        backup_tablet_uid = cls.env.get_random_tablet(
            keyspace, shard_name, tablet_type='replica')
        logging.info('Taking a backup on tablet %s for %s/%s',
                     backup_tablet_uid, keyspace, shard_name)
        cls.env.vtctl_helper.execute_vtctl_command(
            ['Backup', backup_tablet_uid])

  @classmethod
  def tearDownClass(cls):
    logging.info('Tearing down ReparentTest, verifying tablets are healthy.')
    cls.env.wait_for_healthy_tablets()
    super(ReparentTest, cls).tearDownClass()

  @classmethod
  def create_default_local_environment(cls):
    pass

  def explicit_reparent(self, keyspace, num_shards, external=False,
                        cross_cell=False):
    """Performs an explicit reparent.

    This function will explicitly select a new master and verify that the
    topology is updated.

    Args:
      keyspace: Name of the keyspace to reparent (string)<commit_msg>Increase reparent timeout threshold, reparents with orchestrator seem to take longer.<commit_after>#!/usr/bin/env python
"""Tests reparenting is picked up in topology."""

import json
import threading
import time

import numpy

import logging

import base_cluster_test
import vtctl_helper

from vtproto import topodata_pb2
from vttest import sharding_utils


def tearDownModule():
  pass


class ReparentTest(base_cluster_test.BaseClusterTest):

  @classmethod
  def setUpClass(cls):
    super(ReparentTest, cls).setUpClass()

    # number of reparent iterations
    cls.num_reparents = int(cls.test_params.get('num_reparents', '1'))

    # max allowable median master downtime in seconds
    cls.master_downtime_threshold = int(cls.test_params.get(
        'master_downtime_threshold', '20'))

    # seconds to wait for reparent to result in a new master
    cls.reparent_timeout_threshold = int(cls.test_params.get(
        'reparent_timeout_threshold', '60'))

    for keyspace, num_shards in zip(cls.env.keyspaces, cls.env.num_shards):
      for shard in xrange(num_shards):
        shard_name = sharding_utils.get_shard_name(shard, num_shards)
        backup_tablet_uid = cls.env.get_random_tablet(
            keyspace, shard_name, tablet_type='replica')
        logging.info('Taking a backup on tablet %s for %s/%s',
                     backup_tablet_uid, keyspace, shard_name)
        cls.env.vtctl_helper.execute_vtctl_command(
            ['Backup', backup_tablet_uid])

  @classmethod
  def tearDownClass(cls):
    logging.info('Tearing down ReparentTest, verifying tablets are healthy.')
    cls.env.wait_for_healthy_tablets()
    super(ReparentTest, cls).tearDownClass()

  @classmethod
  def create_default_local_environment(cls):
    pass

  def explicit_reparent(self, keyspace, num_shards, external=False,
                        cross_cell=False):
    """Performs an explicit reparent.

    This function will explicitly select a new master and verify that the
    topology is updated.

    Args:
      keyspace: Name of the keyspace to reparent (string)
{'fraction_non_alphanumeric': 0.0819833087874325, 'fraction_numerical': 0.0029455081001472753, 'mean_word_length': 3.716435185185185, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2987957', 'n_tokens_mistral': 1289, 'n_tokens_neox': 1245, 'n_words': 323}