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 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)
 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)
示例#4
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)
示例#5
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()
示例#6
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)
示例#7
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 impalad_service.wait_for_num_in_flight_queries(0)
示例#8
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)
    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)
        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
示例#10
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 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
  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_client_protocol_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)))
            proc.sendeof()
            proc.wait()

            # Ensure no sessions or queries are left dangling.
            verifier = MetricVerifier(self.impalad_test_service)
            verifier.verify_metrics_are_zero()
示例#14
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)