def test_cancellation(self):
   impalad = ImpaladService(socket.getfqdn())
   impalad.wait_for_num_in_flight_queries(0)
   command = "select sleep(10000);"
   p = self._start_new_shell_process()
   self._send_cmd_to_shell(p, command)
   sleep(3)
   os.kill(p.pid, signal.SIGINT)
   get_shell_cmd_result(p)
   assert impalad.wait_for_num_in_flight_queries(0)
示例#2
0
class ImpaladProcess(BaseImpalaProcess):
  def __init__(self, cmd, container_id=None, port_map=None):
    super(ImpaladProcess, self).__init__(cmd, container_id, port_map)
    self.service = ImpaladService(self.hostname, self.get_webserver_port(),
                                  self.__get_beeswax_port(), self.__get_be_port(),
                                  self.__get_hs2_port(),
                                  self._get_webserver_certificate_file())

  def _get_default_webserver_port(self):
    return DEFAULT_IMPALAD_WEBSERVER_PORT

  def __get_beeswax_port(self):
    return int(self._get_port('beeswax_port', DEFAULT_BEESWAX_PORT))

  def __get_be_port(self):
    return int(self._get_port('be_port', DEFAULT_BE_PORT))

  def __get_hs2_port(self):
    return int(self._get_port('hs2_port', DEFAULT_HS2_PORT))

  def start(self, wait_until_ready=True):
    """Starts the impalad and waits until the service is ready to accept connections."""
    restart_args = self.cmd[1:]
    LOG.info("Starting Impalad process with args: {0}".format(restart_args))
    run_daemon("impalad", restart_args)
    if wait_until_ready:
      self.service.wait_for_metric_value('impala-server.ready',
                                         expected_value=1, timeout=30)

  def wait_for_catalog(self):
    """Waits for a catalog copy to be received by the impalad. When its received,
       additionally waits for client ports to be opened."""
    start_time = time.time()
    beeswax_port_is_open = False
    hs2_port_is_open = False
    num_dbs = 0
    num_tbls = 0
    while ((time.time() - start_time < CLUSTER_WAIT_TIMEOUT_IN_SECONDS) and
        not (beeswax_port_is_open and hs2_port_is_open)):
      try:
        num_dbs, num_tbls = self.service.get_metric_values(
            ["catalog.num-databases", "catalog.num-tables"])
        beeswax_port_is_open = self.service.beeswax_port_is_open()
        hs2_port_is_open = self.service.hs2_port_is_open()
      except Exception:
        LOG.exception(("Client services not ready. Waiting for catalog cache: "
            "({num_dbs} DBs / {num_tbls} tables). Trying again ...").format(
                num_dbs=num_dbs,
                num_tbls=num_tbls))
      sleep(0.5)

    if not hs2_port_is_open or not beeswax_port_is_open:
      raise RuntimeError(
          "Unable to open client ports within {num_seconds} seconds.".format(
              num_seconds=CLUSTER_WAIT_TIMEOUT_IN_SECONDS))
示例#3
0
 def test_cancellation(self):
   impalad = ImpaladService(socket.getfqdn())
   impalad.wait_for_num_in_flight_queries(0)
   command = "select sleep(10000);"
   p = self._start_new_shell_process()
   self._send_cmd_to_shell(p, command)
   sleep(3)
   os.kill(p.pid, signal.SIGINT)
   result = get_shell_cmd_result(p)
   assert "Cancelled" not in result.stderr
   assert impalad.wait_for_num_in_flight_queries(0)
示例#4
0
 def test_cancellation(self):
   impalad = ImpaladService(socket.getfqdn())
   impalad.wait_for_num_in_flight_queries(0)
   command = "select sleep(10000);"
   p = ImpalaShell()
   p.send_cmd(command)
   sleep(3)
   os.kill(p.pid(), signal.SIGINT)
   result = p.get_result()
   assert "Cancelled" not in result.stderr
   assert impalad.wait_for_num_in_flight_queries(0)
 def test_cancellation(self):
   impalad = ImpaladService(socket.getfqdn())
   impalad.wait_for_num_in_flight_queries(0)
   command = "select sleep(10000);"
   p = ImpalaShell()
   p.send_cmd(command)
   sleep(3)
   os.kill(p.pid(), signal.SIGINT)
   result = p.get_result()
   assert "Cancelled" not in result.stderr
   assert impalad.wait_for_num_in_flight_queries(0)
示例#6
0
    def test_reconnect(self, vector):
        """Regression Test for IMPALA-1235

    Verifies that a connect command by the user is honoured.
    """
        # Disconnect existing clients so there are no open sessions.
        self.client.close()
        self.hs2_client.close()

        hostname = socket.getfqdn()
        initial_impala_service = ImpaladService(hostname)
        target_impala_service = ImpaladService(hostname,
                                               webserver_port=25001,
                                               beeswax_port=21001,
                                               be_port=22001,
                                               hs2_port=21051,
                                               hs2_http_port=28001)
        protocol = vector.get_value("protocol").lower()
        if protocol == "hs2":
            target_port = 21051
        elif protocol == "hs2-http":
            target_port = 28001
        else:
            assert protocol == "beeswax"
            target_port = 21001
        # This test is running serially, so there shouldn't be any open sessions, but wait
        # here in case a session from a previous test hasn't been fully closed yet.
        self._wait_for_num_open_sessions(
            vector, initial_impala_service, 0,
            "first impalad should not have any remaining open sessions.")
        self._wait_for_num_open_sessions(
            vector, target_impala_service, 0,
            "second impalad should not have any remaining open sessions.")
        # Connect to the first impalad
        p = ImpalaShell(vector)

        # Make sure we're connected <hostname>:<port>
        self._wait_for_num_open_sessions(
            vector, initial_impala_service, 1,
            "Not connected to %s:%d" % (hostname, get_impalad_port(vector)))
        p.send_cmd("connect %s:%d" % (hostname, target_port))

        # The number of sessions on the target impalad should have been incremented.
        self._wait_for_num_open_sessions(
            vector, target_impala_service, 1,
            "Not connected to %s:%d" % (hostname, target_port))
        assert "[%s:%d] default>" % (hostname,
                                     target_port) in p.get_result().stdout

        # The number of sessions on the initial impalad should have been decremented.
        self._wait_for_num_open_sessions(
            vector, initial_impala_service, 0,
            "Connection to %s:%d should have been closed" %
            (hostname, get_impalad_port(vector)))
示例#7
0
 def test_cancellation(self):
   impalad = ImpaladService(socket.getfqdn())
   impalad.wait_for_num_in_flight_queries(0)
   command = "select sleep(10000);"
   p = self._start_new_shell_process()
   self._send_cmd_to_shell(p, command)
   sleep(1)
   # iterate through all processes with psutil
   shell_pid = cancellation_helper()
   sleep(2)
   os.kill(shell_pid, signal.SIGINT)
   result = get_shell_cmd_result(p)
   assert impalad.wait_for_num_in_flight_queries(0)
示例#8
0
 def test_cancellation(self):
     impalad = ImpaladService(socket.getfqdn())
     impalad.wait_for_num_in_flight_queries(0)
     command = "select sleep(10000);"
     p = self._start_new_shell_process()
     self._send_cmd_to_shell(p, command)
     sleep(1)
     # iterate through all processes with psutil
     shell_pid = cancellation_helper()
     sleep(2)
     os.kill(shell_pid, signal.SIGINT)
     result = get_shell_cmd_result(p)
     assert impalad.wait_for_num_in_flight_queries(0)
  def test_queries_closed(self, vector):
    """Regression test for IMPALA-897."""
    args = ['-f', '{0}/test_close_queries.sql'.format(QUERY_FILE_PATH), '--quiet', '-B']
    # Execute the shell command async
    p = ImpalaShell(vector, args)

    impalad_service = ImpaladService(get_impalad_host_port(vector).split(':')[0])
    # The last query in the test SQL script will sleep for 10 seconds, so sleep
    # here for 5 seconds and verify the number of in-flight queries is 1.
    sleep(5)
    assert 1 == impalad_service.get_num_in_flight_queries()
    assert p.get_result().rc == 0
    assert 0 == impalad_service.get_num_in_flight_queries()
示例#10
0
  def test_queries_closed(self, vector):
    """Regression test for IMPALA-897."""
    args = ['-f', '{0}/test_close_queries.sql'.format(QUERY_FILE_PATH), '--quiet', '-B']
    # Execute the shell command async
    p = ImpalaShell(vector, args)

    impalad_service = ImpaladService(get_impalad_host_port(vector).split(':')[0])
    # The last query in the test SQL script will sleep for 10 seconds, so sleep
    # here for 5 seconds and verify the number of in-flight queries is 1.
    sleep(5)
    assert 1 == impalad_service.get_num_in_flight_queries()
    assert p.get_result().rc == 0
    assert 0 == impalad_service.get_num_in_flight_queries()
  def test_queries_closed(self):
    """Regression test for IMPALA-897."""
    args = '-f %s/test_close_queries.sql --quiet -B' % QUERY_FILE_PATH
    cmd = "%s %s" % (SHELL_CMD, args)
    # Execute the shell command async
    p = ImpalaShell(args)

    impalad_service = ImpaladService(IMPALAD.split(':')[0])
    # The last query in the test SQL script will sleep for 10 seconds, so sleep
    # here for 5 seconds and verify the number of in-flight queries is 1.
    sleep(5)
    assert 1 == impalad_service.get_num_in_flight_queries()
    assert p.get_result().rc == 0
    assert 0 == impalad_service.get_num_in_flight_queries()
  def test_queries_closed(self):
    """Regression test for IMPALA-897."""
    args = '-f %s/test_close_queries.sql --quiet -B' % QUERY_FILE_PATH
    cmd = "%s %s" % (SHELL_CMD, args)
    # Execute the shell command async
    p = ImpalaShell(args)

    impalad_service = ImpaladService(IMPALAD.split(':')[0])
    # The last query in the test SQL script will sleep for 10 seconds, so sleep
    # here for 5 seconds and verify the number of in-flight queries is 1.
    sleep(5)
    assert 1 == impalad_service.get_num_in_flight_queries()
    assert p.get_result().rc == 0
    assert 0 == impalad_service.get_num_in_flight_queries()
示例#13
0
    def setup_class(cls):
        """Setup section that runs before each test suite"""
        cls.hive_client, cls.client = [None, None]
        # Create a Hive Metastore Client (used for executing some test SETUP steps
        metastore_host, metastore_port = pytest.config.option.metastore_server.split(
            ':')
        trans_type = 'buffered'
        if pytest.config.option.use_kerberos:
            trans_type = 'kerberos'
        cls.hive_transport = create_transport(
            host=metastore_host,
            port=metastore_port,
            service=pytest.config.option.hive_service_name,
            transport_type=trans_type)
        protocol = TBinaryProtocol.TBinaryProtocol(cls.hive_transport)
        cls.hive_client = ThriftHiveMetastore.Client(protocol)
        cls.hive_transport.open()

        # Create a connection to Impala.
        cls.client = cls.create_impala_client(IMPALAD)

        cls.impalad_test_service = ImpaladService(IMPALAD.split(':')[0])
        if pytest.config.option.namenode_http_address is None:
            cls.hdfs_client = get_hdfs_client_from_conf(HDFS_CONF)
        else:
            host, port = pytest.config.option.namenode_http_address.split(":")
            cls.hdfs_client = get_hdfs_client()
示例#14
0
    def test_ssl(self, vector):

        self._verify_negative_cases(vector)
        # TODO: This is really two different tests, but the custom cluster takes too long to
        # start. Make it so that custom clusters can be specified across test suites.
        self._validate_positive_cases(vector,
                                      "%s/server-cert.pem" % self.CERT_DIR)

        # No certificate checking: will accept any cert.
        self._validate_positive_cases(vector, )

        # Test cancelling a query
        impalad = ImpaladService(socket.getfqdn())
        assert impalad.wait_for_num_in_flight_queries(0)
        impalad.wait_for_metric_value(
            'impala-server.backend-num-queries-executing', 0)
        p = ImpalaShell(vector, args=["--ssl"])
        p.send_cmd("SET DEBUG_ACTION=0:OPEN:WAIT")
        p.send_cmd("select count(*) from functional.alltypes")
        # Wait until the query has been planned and started executing, at which point it
        # should be cancellable.
        impalad.wait_for_metric_value(
            'impala-server.backend-num-queries-executing', 1, timeout=60)

        LOG = logging.getLogger('test_client_ssl')
        LOG.info("Cancelling query")
        num_tries = 0
        # In practice, sending SIGINT to the shell process doesn't always seem to get caught
        # (and a search shows up some bugs in Python where SIGINT might be ignored). So retry
        # for 30s until one signal takes.
        while impalad.get_num_in_flight_queries() == 1:
            time.sleep(1)
            LOG.info("Sending signal...")
            os.kill(p.pid(), signal.SIGINT)
            num_tries += 1
            assert num_tries < 30, (
                "SIGINT was not caught by shell within 30s. Queries: " +
                json.dumps(impalad.get_queries_json(), indent=2))

        p.send_cmd("profile")
        result = p.get_result()

        print result.stderr
        assert "Query Status: Cancelled" in result.stdout
        assert impalad.wait_for_num_in_flight_queries(0)
示例#15
0
    def test_auto_reconnect_after_impalad_died(self):
        """Test reconnect after restarting the remote impalad without using connect;"""
        # Use pexpect instead of ImpalaShell() since after using get_result() in ImpalaShell()
        # to check Disconnect, send_cmd() will no longer have any effect so we can not check
        # reconnect.
        impalad = ImpaladService(socket.getfqdn())
        start_num_queries = impalad.get_metric_value(NUM_QUERIES)

        proc = pexpect.spawn(' '.join([SHELL_CMD, "-i localhost:21000"]))
        proc.expect("21000] default>")
        proc.sendline("use tpch;")

        # wait for the USE command to finish
        impalad.wait_for_metric_value(NUM_QUERIES, start_num_queries + 1)
        impalad.wait_for_num_in_flight_queries(0)

        # Disconnect
        self.cluster.impalads[0].kill()
        proc.sendline("show tables;")
        # Search from [1:] since the square brackets "[]" are special characters in regex
        proc.expect(ImpalaShellClass.DISCONNECTED_PROMPT[1:])
        # Restarting Impalad
        self.cluster.impalads[0].start()
        # Check reconnect
        proc.sendline("show tables;")
        proc.expect("nation")
        proc.expect("21000] tpch>")
  def test_reconnect(self, vector):
    """Regression Test for IMPALA-1235

    Verifies that a connect command by the user is honoured.
    """
    # Disconnect existing clients so there are no open sessions.
    self.client.close()
    self.hs2_client.close()

    def wait_for_num_open_sessions(impala_service, num, err):
      """Helper method to wait for the number of open sessions to reach 'num'."""
      metric_name = get_open_sessions_metric(vector)
      assert impala_service.wait_for_metric_value(metric_name, num) == num, err

    hostname = socket.getfqdn()
    initial_impala_service = ImpaladService(hostname)
    target_impala_service = ImpaladService(hostname, webserver_port=25001,
        beeswax_port=21001, be_port=22001, hs2_port=21051)
    if vector.get_value("protocol") == "hs2":
      target_port = 21051
    else:
      target_port = 21001
    # This test is running serially, so there shouldn't be any open sessions, but wait
    # here in case a session from a previous test hasn't been fully closed yet.
    wait_for_num_open_sessions(initial_impala_service, 0,
        "first impalad should not have any remaining open sessions.")
    wait_for_num_open_sessions(target_impala_service, 0,
        "second impalad should not have any remaining open sessions.")
    # Connect to the first impalad
    p = ImpalaShell(vector)

    # Make sure we're connected <hostname>:<port>
    wait_for_num_open_sessions(initial_impala_service, 1,
        "Not connected to %s:%d" % (hostname, get_impalad_port(vector)))
    p.send_cmd("connect %s:%d" % (hostname, target_port))

    # The number of sessions on the target impalad should have been incremented.
    wait_for_num_open_sessions(
        target_impala_service, 1, "Not connected to %s:%d" % (hostname, target_port))
    assert "[%s:%d] default>" % (hostname, target_port) in p.get_result().stdout

    # The number of sessions on the initial impalad should have been decremented.
    wait_for_num_open_sessions(initial_impala_service, 0,
        "Connection to %s:%d should have been closed" % (
          hostname, get_impalad_port(vector)))
 def __init__(self, cmd, container_id=None, port_map=None):
   super(ImpaladProcess, self).__init__(cmd, container_id, port_map)
   self.service = ImpaladService(self.hostname,
                                 self._get_webserver_port(
                                     default=DEFAULT_IMPALAD_WEBSERVER_PORT),
                                 self.__get_beeswax_port(),
                                 self.__get_be_port(),
                                 self.__get_hs2_port(),
                                 self._get_webserver_certificate_file())
    def test_reconnect(self):
        """Regression Test for IMPALA-1235

    Verifies that a connect command by the user is honoured.
    """
        def wait_for_num_open_sessions(impala_service, num, err):
            """Helper method to wait for the number of open sessions to reach 'num'."""
            assert impala_service.wait_for_metric_value(
                'impala-server.num-open-beeswax-sessions', num) == num, err

        hostname = socket.getfqdn()
        initial_impala_service = ImpaladService(hostname)
        target_impala_service = ImpaladService(hostname,
                                               webserver_port=25001,
                                               beeswax_port=21001,
                                               be_port=22001)
        # This test is running serially, so there shouldn't be any open sessions, but wait
        # here in case a session from a previous test hasn't been fully closed yet.
        wait_for_num_open_sessions(
            initial_impala_service, 0,
            "21000 should not have any remaining open sessions.")
        wait_for_num_open_sessions(
            target_impala_service, 0,
            "21001 should not have any remaining open sessions.")
        # Connect to localhost:21000 (default)
        p = ImpalaShell()

        # Make sure we're connected <hostname>:21000
        wait_for_num_open_sessions(initial_impala_service, 1,
                                   "Not connected to %s:21000" % hostname)
        p.send_cmd("connect %s:21001" % hostname)

        # The number of sessions on the target impalad should have been incremented.
        wait_for_num_open_sessions(target_impala_service, 1,
                                   "Not connected to %s:21001" % hostname)
        assert "[%s:21001] default>" % hostname in p.get_result().stdout

        # The number of sessions on the initial impalad should have been decremented.
        wait_for_num_open_sessions(
            initial_impala_service, 0,
            "Connection to %s:21000 should have been closed" % hostname)
示例#19
0
  def wait_for_query_state(self, vector, stmt, state, max_retry=15):
    """Checks the in flight queries on Impala debug page. Polls the state of
    the query statement from parameter every second until the query gets to
    a state given via parameter or a maximum retry count is reached.
    Restriction: Only works if there is only one in flight query."""
    impalad_service = ImpaladService(get_impalad_host_port(vector).split(':')[0])
    if not impalad_service.wait_for_num_in_flight_queries(1):
      raise Exception("No in flight query found")

    retry_count = 0
    while retry_count <= max_retry:
      query_info = impalad_service.get_in_flight_queries()[0]
      if query_info['stmt'] != stmt:
        exc_text = "The found in flight query is not the one under test: " + \
            query_info['stmt']
        raise Exception(exc_text)
      if query_info['state'] == state:
        return
      retry_count += 1
      sleep(1.0)
    raise Exception("Query didn't reach desired state: " + state)
  def wait_for_query_state(self, stmt, state, max_retry=15):
    """Checks the in flight queries on Impala debug page. Polls the state of
    the query statement from parameter every second until the query gets to
    a state given via parameter or a maximum retry count is reached.
    Restriction: Only works if there is only one in flight query."""
    impalad_service = ImpaladService(IMPALAD.split(':')[0])
    if not impalad_service.wait_for_num_in_flight_queries(1):
      raise Exception("No in flight query found")

    retry_count = 0
    while retry_count <= max_retry:
      query_info = impalad_service.get_in_flight_queries()[0]
      if query_info['stmt'] != stmt:
        exc_text = "The found in flight query is not the one under test: " + \
            query_info['stmt']
        raise Exception(exc_text)
      if query_info['state'] == state:
        return
      retry_count += 1
      sleep(1.0)
    raise Exception("Query didn't reach desired state: " + state)
    def test_auto_reconnect_after_impalad_died(self):
        """Test reconnect after restarting the remote impalad without using connect;"""
        # Use pexpect instead of ImpalaShell() since after using get_result() in ImpalaShell()
        # to check Disconnect, send_cmd() will no longer have any effect so we can not check
        # reconnect.
        impalad = ImpaladService(socket.getfqdn())

        # Iterate over test vector within test function to avoid restarting cluster.
        for vector in [
                ImpalaTestVector([value])
                for value in create_beeswax_dimension()
        ]:
            cmd = get_shell_cmd(vector)
            proc = pexpect.spawn(cmd[0], cmd[1:])
            proc.expect("{0}] default>".format(get_impalad_port(vector)))
            # ImpalaShell startup may issue query to get server info - get num queries after
            # starting shell.
            start_num_queries = impalad.get_metric_value(NUM_QUERIES)
            proc.sendline("use tpch;")

            # wait for the USE command to finish
            impalad.wait_for_metric_value(NUM_QUERIES, start_num_queries + 1)
            assert impalad.wait_for_num_in_flight_queries(0)

            # Disconnect
            self.cluster.impalads[0].kill()
            proc.sendline("show tables;")
            # Search from [1:] since the square brackets "[]" are special characters in regex
            proc.expect(ImpalaShellClass.DISCONNECTED_PROMPT[1:])
            # Restarting Impalad
            self.cluster.impalads[0].start()
            # Check reconnect
            proc.sendline("show tables;")
            proc.expect("nation")
            proc.expect("{0}] tpch>".format(get_impalad_port(vector)))
示例#22
0
文件: run-tests.py 项目: zl03/impala
def print_metrics(substring):
  """Prints metrics with the given substring in the name"""
  for impalad in ImpalaCluster.get_e2e_test_cluster().impalads:
    print ">" * 80
    port = impalad.get_webserver_port()
    cert = impalad._get_webserver_certificate_file()
    print "connections metrics for impalad at port {0}:".format(port)
    debug_info = json.loads(ImpaladService(impalad.hostname, webserver_port=port,
        webserver_certificate_file=cert).read_debug_webpage('metrics?json'))
    for metric in debug_info['metric_group']['metrics']:
      if substring in metric['name']:
        print json.dumps(metric, indent=1)
    print "<" * 80
class ImpaladProcess(BaseImpalaProcess):
  def __init__(self, cmd):
    super(ImpaladProcess, self).__init__(cmd, socket.gethostname())
    self.service = ImpaladService(self.hostname, self._get_webserver_port(default=25000),
                                  self.__get_beeswax_port(default=21000),
                                  self.__get_be_port(default=22000),
                                  self.__get_hs2_port(default=21050))

  def __get_beeswax_port(self, default=None):
    return int(self._get_arg_value('beeswax_port', default))

  def __get_be_port(self, default=None):
    return int(self._get_arg_value('be_port', default))

  def __get_hs2_port(self, default=None):
    return int(self._get_arg_value('hs2_port', default))

  def start(self, wait_until_ready=True):
    """Starts the impalad and waits until the service is ready to accept connections."""
    super(ImpaladProcess, self).start()
    self.service.wait_for_metric_value('impala-server.ready',
        expected_value=1, timeout=30)
示例#24
0
def wait_for_query_state(vector, stmt, state, max_retry=15):
  """Waits for the given query 'stmt' to reach the given query 'state'. The state of the
  query is taken from the debug web ui. Polls the state of 'stmt' every second until the
  query gets to a state given via 'state' or a maximum retry count is reached.
  Restriction: Only works if there is only one in flight query."""
  impalad_service = ImpaladService(get_impalad_host_port(vector).split(':')[0])
  if not impalad_service.wait_for_num_in_flight_queries(1):
    raise Exception("No in flight query found")

  retry_count = 0
  while retry_count <= max_retry:
    query_info = impalad_service.get_in_flight_queries()[0]
    print(str(query_info))
    if query_info['stmt'] != stmt:
      exc_text = "The found in flight query is not the one under test: " + \
          query_info['stmt']
      raise Exception(exc_text)
    if query_info['state'] == state:
      return
    retry_count += 1
    time.sleep(1.0)
  raise Exception("Query didn't reach desired state: " + state)
示例#25
0
 def test_compute_stats_with_live_progress_options(self):
   """Test that setting LIVE_PROGRESS options won't cause COMPUTE STATS query fail"""
   impalad = ImpaladService(socket.getfqdn())
   p = self._start_new_shell_process()
   self._send_cmd_to_shell(p, "set live_progress=True")
   self._send_cmd_to_shell(p, "set live_summary=True")
   self._send_cmd_to_shell(p, 'create table test_live_progress_option(col int);')
   try:
     self._send_cmd_to_shell(p, 'compute stats test_live_progress_option;')
   finally:
     self._send_cmd_to_shell(p, 'drop table if exists test_live_progress_option;')
   result = get_shell_cmd_result(p)
   assert "Updated 1 partition(s) and 1 column(s)" in result.stdout
示例#26
0
    def test_reconnect(self):
        """Regression Test for IMPALA-1235

    Verifies that a connect command by the user is honoured.
    """
        def get_num_open_sessions(impala_service):
            """Helper method to retrieve the number of open sessions"""
            return impala_service.get_metric_value(
                'impala-server.num-open-beeswax-sessions')

        hostname = socket.getfqdn()
        initial_impala_service = ImpaladService(hostname)
        target_impala_service = ImpaladService(hostname,
                                               webserver_port=25001,
                                               beeswax_port=21001,
                                               be_port=22001)
        # Get the initial state for the number of sessions.
        num_sessions_initial = get_num_open_sessions(initial_impala_service)
        num_sessions_target = get_num_open_sessions(target_impala_service)
        # Connect to localhost:21000 (default)
        p = ImpalaShell()
        sleep(5)
        # Make sure we're connected <hostname>:21000
        assert get_num_open_sessions(initial_impala_service) == num_sessions_initial + 1, \
            "Not connected to %s:21000" % hostname
        p.send_cmd("connect %s:21001" % hostname)

        # Wait for a little while
        sleep(5)
        # The number of sessions on the target impalad should have been incremented.
        assert get_num_open_sessions(target_impala_service) == num_sessions_target + 1, \
            "Not connected to %s:21001" % hostname
        assert "[%s:21001] default>" % hostname in p.get_result().stdout

        # The number of sessions on the initial impalad should have been decremented.
        assert get_num_open_sessions(initial_impala_service) == num_sessions_initial, \
            "Connection to %s:21000 should have been closed" % hostname
示例#27
0
class ImpaladProcess(BaseImpalaProcess):
    def __init__(self, cmd):
        super(ImpaladProcess, self).__init__(cmd, socket.gethostname())
        self.service = ImpaladService(self.hostname,
                                      self._get_webserver_port(default=25000),
                                      self.__get_beeswax_port(default=21000),
                                      self.__get_be_port(default=22000),
                                      self.__get_hs2_port(default=21050))

    def __get_beeswax_port(self, default=None):
        return int(self._get_arg_value('beeswax_port', default))

    def __get_be_port(self, default=None):
        return int(self._get_arg_value('be_port', default))

    def __get_hs2_port(self, default=None):
        return int(self._get_arg_value('hs2_port', default))

    def start(self, wait_until_ready=True):
        """Starts the impalad and waits until the service is ready to accept connections."""
        super(ImpaladProcess, self).start()
        self.service.wait_for_metric_value('impala-server.ready',
                                           expected_value=1,
                                           timeout=30)
示例#28
0
    def test_auto_reconnect(self):
        impalad = ImpaladService(socket.getfqdn())
        start_num_queries = impalad.get_metric_value(NUM_QUERIES)

        p = ImpalaShell()
        p.send_cmd("USE functional")

        # wait for the USE command to finish
        impalad.wait_for_metric_value(NUM_QUERIES, start_num_queries + 1)
        impalad.wait_for_num_in_flight_queries(0)

        self._start_impala_cluster([])

        p.send_cmd("SHOW TABLES")
        result = p.get_result()
        assert "alltypesaggmultifilesnopart" in result.stdout
示例#29
0
    def test_ssl(self, vector):

        self._verify_negative_cases()
        # TODO: This is really two different tests, but the custom cluster takes too long to
        # start. Make it so that custom clusters can be specified across test suites.
        self._validate_positive_cases("%s/server-cert.pem" % self.CERT_DIR)

        # No certificate checking: will accept any cert.
        self._validate_positive_cases()

        # Test cancelling a query
        impalad = ImpaladService(socket.getfqdn())
        impalad.wait_for_num_in_flight_queries(0)
        p = ImpalaShell(args="--ssl")
        p.send_cmd("SET DEBUG_ACTION=0:OPEN:WAIT")
        p.send_cmd("select count(*) from functional.alltypes")
        impalad.wait_for_num_in_flight_queries(1)

        LOG = logging.getLogger('test_client_ssl')
        LOG.info("Cancelling query")
        num_tries = 0
        # In practice, sending SIGINT to the shell process doesn't always seem to get caught
        # (and a search shows up some bugs in Python where SIGINT might be ignored). So retry
        # for 30s until one signal takes.
        while impalad.get_num_in_flight_queries() == 1:
            time.sleep(1)
            LOG.info("Sending signal...")
            os.kill(p.pid(), signal.SIGINT)
            num_tries += 1
            assert num_tries < 30, "SIGINT was not caught by shell within 30s"

        p.send_cmd("profile")
        result = p.get_result()

        print result.stderr
        assert result.rc == 0
        assert "Query Status: Cancelled" in result.stdout
        assert impalad.wait_for_num_in_flight_queries(0)
示例#30
0
  def test_ssl(self, vector):
    # TODO: This is really two different tests, but the custom cluster takes too long to
    # start. Make it so that custom clusters can be specified across test suites.
    result = run_impala_shell_cmd("--ssl --ca_cert=%s/server-cert.pem -q 'select 1 + 2'"
                                  % self.CERT_DIR)
    for msg in [self.SSL_ENABLED, self.CONNECTED, self.FETCHED]:
      assert msg in result.stderr

    # No certificate checking: will accept any cert.
    result = run_impala_shell_cmd("--ssl -q 'select 1 + 2'")
    for msg in [self.SSL_ENABLED, self.CONNECTED, self.FETCHED]:
      assert msg in result.stderr

    # Test cancelling a query
    impalad = ImpaladService(socket.getfqdn())
    impalad.wait_for_num_in_flight_queries(0)
    p = ImpalaShell(args="--ssl")
    p.send_cmd("SET DEBUG_ACTION=0:OPEN:WAIT")
    p.send_cmd("select count(*) from functional.alltypes")
    impalad.wait_for_num_in_flight_queries(1)

    LOG = logging.getLogger('test_client_ssl')
    LOG.info("Cancelling query")
    num_tries = 0
    # In practice, sending SIGINT to the shell process doesn't always seem to get caught
    # (and a search shows up some bugs in Python where SIGINT might be ignored). So retry
    # for 30s until one signal takes.
    while impalad.get_num_in_flight_queries() == 1:
      time.sleep(1)
      LOG.info("Sending signal...")
      os.kill(p.pid(), signal.SIGINT)
      num_tries += 1
      assert num_tries < 30, "SIGINT was not caught by shell within 30s"

    p.send_cmd("profile")
    result = p.get_result()

    print result.stderr
    assert result.rc == 0
    assert "Query Status: Cancelled" in result.stdout
    assert impalad.wait_for_num_in_flight_queries(0)
    def test_auto_reconnect(self):
        impalad = ImpaladService(socket.getfqdn())

        # Iterate over test vector within test function to avoid restarting cluster.
        for vector in\
            [ImpalaTestVector([value]) for value in create_client_protocol_dimension()]:
            p = ImpalaShell(vector)
            # ImpalaShell startup may issue query to get server info - get num queries after
            # starting shell.
            start_num_queries = impalad.get_metric_value(NUM_QUERIES)
            p.send_cmd("USE functional")

            # wait for the USE command to finish
            impalad.wait_for_metric_value(NUM_QUERIES, start_num_queries + 1)
            assert impalad.wait_for_num_in_flight_queries(0)

            self._start_impala_cluster([])

            p.send_cmd("SHOW TABLES")
            result = p.get_result()
            assert "alltypesaggmultifilesnopart" in result.stdout, result.stdout
示例#32
0
class ImpaladProcess(BaseImpalaProcess):
    def __init__(self, cmd, container_id=None, port_map=None):
        super(ImpaladProcess, self).__init__(cmd, container_id, port_map)
        self.service = ImpaladService(self.hostname, self.webserver_interface,
                                      self.get_webserver_port(),
                                      self.__get_beeswax_port(),
                                      self.__get_krpc_port(),
                                      self.__get_hs2_port(),
                                      self.__get_hs2_http_port(),
                                      self._get_webserver_certificate_file())

    def _get_default_webserver_port(self):
        return DEFAULT_IMPALAD_WEBSERVER_PORT

    def __get_beeswax_port(self):
        return int(self._get_port('beeswax_port', DEFAULT_BEESWAX_PORT))

    def __get_krpc_port(self):
        return int(self._get_port('krpc_port', DEFAULT_KRPC_PORT))

    def __get_hs2_port(self):
        return int(self._get_port('hs2_port', DEFAULT_HS2_PORT))

    def __get_hs2_http_port(self):
        return int(self._get_port('hs2_http_port', DEFAULT_HS2_HTTP_PORT))

    def start(self, wait_until_ready=True, timeout=30):
        """Starts the impalad and waits until the service is ready to accept connections.
    'timeout' is the amount of time to wait for the Impala server to be in the
    ready state."""
        restart_args = self.cmd[1:]
        LOG.info(
            "Starting Impalad process with args: {0}".format(restart_args))
        run_daemon("impalad", restart_args)
        if wait_until_ready:
            self.service.wait_for_metric_value('impala-server.ready',
                                               expected_value=1,
                                               timeout=timeout)

    def wait_for_catalog(self):
        """Waits for a catalog copy to be received by the impalad. When its received,
       additionally waits for client ports to be opened."""
        start_time = time.time()
        beeswax_port_is_open = False
        hs2_port_is_open = False
        num_dbs = 0
        num_tbls = 0
        while ((time.time() - start_time < CLUSTER_WAIT_TIMEOUT_IN_SECONDS)
               and not (beeswax_port_is_open and hs2_port_is_open)):
            try:
                num_dbs, num_tbls = self.service.get_metric_values(
                    ["catalog.num-databases", "catalog.num-tables"])
                beeswax_port_is_open = self.service.beeswax_port_is_open()
                hs2_port_is_open = self.service.hs2_port_is_open()
            except Exception:
                LOG.exception(
                    ("Client services not ready. Waiting for catalog cache: "
                     "({num_dbs} DBs / {num_tbls} tables). Trying again ..."
                     ).format(num_dbs=num_dbs, num_tbls=num_tbls))
            sleep(0.5)

        if not hs2_port_is_open or not beeswax_port_is_open:
            raise RuntimeError(
                "Unable to open client ports within {num_seconds} seconds.".
                format(num_seconds=CLUSTER_WAIT_TIMEOUT_IN_SECONDS))
  def test_ddl_queries_are_closed(self):
    """Regression test for IMPALA-1317

    The shell does not call close() for alter, use and drop queries, leaving them in
    flight. This test issues those queries in interactive mode, and checks the debug
    webpage to confirm that they've been closed.
    TODO: Add every statement type.
    """

    TMP_DB = 'inflight_test_db'
    TMP_TBL = 'tmp_tbl'
    MSG = '%s query should be closed'
    NUM_QUERIES = 'impala-server.num-queries'

    impalad = ImpaladService(socket.getfqdn())
    p = ImpalaShell()
    try:
      start_num_queries = impalad.get_metric_value(NUM_QUERIES)
      p.send_cmd('create database if not exists %s' % TMP_DB)
      p.send_cmd('use %s' % TMP_DB)
      impalad.wait_for_metric_value(NUM_QUERIES, start_num_queries + 2)
      assert impalad.wait_for_num_in_flight_queries(0), MSG % 'use'
      p.send_cmd('create table %s(i int)' % TMP_TBL)
      p.send_cmd('alter table %s add columns (j int)' % TMP_TBL)
      impalad.wait_for_metric_value(NUM_QUERIES, start_num_queries + 4)
      assert impalad.wait_for_num_in_flight_queries(0), MSG % 'alter'
      p.send_cmd('drop table %s' % TMP_TBL)
      impalad.wait_for_metric_value(NUM_QUERIES, start_num_queries + 5)
      assert impalad.wait_for_num_in_flight_queries(0), MSG % 'drop'
    finally:
      run_impala_shell_interactive("drop table if exists %s.%s;" % (TMP_DB, TMP_TBL))
      run_impala_shell_interactive("drop database if exists foo;")
 def __init__(self, cmd):
   super(ImpaladProcess, self).__init__(cmd, socket.gethostname())
   self.service = ImpaladService(self.hostname, self._get_webserver_port(default=25000),
                                 self.__get_beeswax_port(default=21000),
                                 self.__get_be_port(default=22000),
                                 self.__get_hs2_port(default=21050))
示例#35
0
 def __init__(self, cmd, container_id=None, port_map=None):
   super(ImpaladProcess, self).__init__(cmd, container_id, port_map)
   self.service = ImpaladService(self.hostname, self.get_webserver_port(),
                                 self.__get_beeswax_port(), self.__get_be_port(),
                                 self.__get_hs2_port(),
                                 self._get_webserver_certificate_file())
示例#36
0
 def __init__(self, cmd, container_id=None, port_map=None):
   super(ImpaladProcess, self).__init__(cmd, container_id, port_map)
   self.service = ImpaladService(self.hostname, self.webserver_interface,
       self.get_webserver_port(), self.__get_beeswax_port(), self.__get_be_port(),
       self.__get_hs2_port(), self.__get_hs2_http_port(),
       self._get_webserver_certificate_file())
示例#37
0
 def create_impala_service(cls, host_port=IMPALAD):
     return ImpaladService(IMPALAD.split(':')[0])
示例#38
0
    def test_ddl_queries_are_closed(self, vector):
        """Regression test for IMPALA-1317

    The shell does not call close() for alter, use and drop queries, leaving them in
    flight. This test issues those queries in interactive mode, and checks the debug
    webpage to confirm that they've been closed.
    TODO: Add every statement type.
    """
        # Disconnect existing clients so there are no open sessions.
        self.close_impala_clients()

        TMP_DB = 'inflight_test_db'
        TMP_TBL = 'tmp_tbl'
        MSG = '%s query should be closed'
        NUM_QUERIES = 'impala-server.num-queries'

        impalad = ImpaladService(socket.getfqdn())
        self._wait_for_num_open_sessions(
            vector, impalad, 0,
            "Open sessions found after closing all clients.")
        p = ImpalaShell(vector)
        try:
            start_num_queries = impalad.get_metric_value(NUM_QUERIES)
            p.send_cmd('create database if not exists %s' % TMP_DB)
            p.send_cmd('use %s' % TMP_DB)
            impalad.wait_for_metric_value(NUM_QUERIES, start_num_queries + 2)
            assert impalad.wait_for_num_in_flight_queries(0), MSG % 'use'
            p.send_cmd('create table %s(i int)' % TMP_TBL)
            p.send_cmd('alter table %s add columns (j int)' % TMP_TBL)
            impalad.wait_for_metric_value(NUM_QUERIES, start_num_queries + 4)
            assert impalad.wait_for_num_in_flight_queries(0), MSG % 'alter'
            p.send_cmd('drop table %s' % TMP_TBL)
            impalad.wait_for_metric_value(NUM_QUERIES, start_num_queries + 5)
            assert impalad.wait_for_num_in_flight_queries(0), MSG % 'drop'
        finally:
            # get_result() must be called to exit the shell.
            p.get_result()
            self._wait_for_num_open_sessions(vector, impalad, 0,
                                             "shell should close sessions.")
            run_impala_shell_interactive(
                vector, "drop table if exists %s.%s;" % (TMP_DB, TMP_TBL))
            run_impala_shell_interactive(vector,
                                         "drop database if exists foo;")
            self.create_impala_clients()
示例#39
0
 def __init__(self, cmd):
   super(ImpaladProcess, self).__init__(cmd, socket.gethostname())
   self.service = ImpaladService(self.hostname, self._get_webserver_port(default=25000),
                                 self.__get_beeswax_port(default=21000),
                                 self.__get_be_port(default=22000),
                                 self.__get_hs2_port(default=21050))
示例#40
0
    def test_ddl_queries_are_closed(self):
        """Regression test for IMPALA-1317

    The shell does not call close() for alter, use and drop queries, leaving them in
    flight. This test issues those queries in interactive mode, and checks the debug
    webpage to confirm that they've been closed.
    TODO: Add every statement type.
    """

        TMP_DB = 'inflight_test_db'
        TMP_TBL = 'tmp_tbl'
        MSG = '%s query should be closed'
        NUM_QUERIES = 'impala-server.num-queries'

        impalad = ImpaladService(socket.getfqdn())
        p = ImpalaShell()
        try:
            start_num_queries = impalad.get_metric_value(NUM_QUERIES)
            p.send_cmd('create database if not exists %s' % TMP_DB)
            p.send_cmd('use %s' % TMP_DB)
            impalad.wait_for_metric_value(NUM_QUERIES, start_num_queries + 2)
            assert impalad.wait_for_num_in_flight_queries(0), MSG % 'use'
            p.send_cmd('create table %s(i int)' % TMP_TBL)
            p.send_cmd('alter table %s add columns (j int)' % TMP_TBL)
            impalad.wait_for_metric_value(NUM_QUERIES, start_num_queries + 4)
            assert impalad.wait_for_num_in_flight_queries(0), MSG % 'alter'
            p.send_cmd('drop table %s' % TMP_TBL)
            impalad.wait_for_metric_value(NUM_QUERIES, start_num_queries + 5)
            assert impalad.wait_for_num_in_flight_queries(0), MSG % 'drop'
        finally:
            run_impala_shell_interactive("drop table if exists %s.%s;" %
                                         (TMP_DB, TMP_TBL))
            run_impala_shell_interactive("drop database if exists foo;")
示例#41
0
 def create_impala_service(cls, host_port=IMPALAD, webserver_port=25000):
     host, port = host_port.split(':')
     return ImpaladService(host,
                           beeswax_port=port,
                           webserver_port=webserver_port)