def test_shell_prompt(self, vector):
    shell_cmd = get_shell_cmd(vector)
    proc = pexpect.spawn(shell_cmd[0], shell_cmd[1:])
    proc.expect(":{0}] default>".format(get_impalad_port(vector)))
    self._expect_with_cmd(proc, "use foo", vector, (), 'default')
    self._expect_with_cmd(proc, "use functional", vector, (), 'functional')
    self._expect_with_cmd(proc, "use foo", vector, (), 'functional')
    self._expect_with_cmd(proc, 'use `tpch`', vector, (), 'tpch')
    self._expect_with_cmd(proc, 'use ` tpch `', vector, (), 'tpch')

    proc = pexpect.spawn(shell_cmd[0], shell_cmd[1:] + ['-d', 'functional'])
    proc.expect(":{0}] functional>".format(get_impalad_port(vector)))
    self._expect_with_cmd(proc, "use foo", vector, (), 'functional')
    self._expect_with_cmd(proc, "use tpch", vector, (), 'tpch')
    self._expect_with_cmd(proc, "use foo", vector, (), 'tpch')

    proc = pexpect.spawn(shell_cmd[0], shell_cmd[1:] + ['-d', ' functional '])
    proc.expect(":{0}] functional>".format(get_impalad_port(vector)))

    proc = pexpect.spawn(shell_cmd[0], shell_cmd[1:] + ['-d', '` functional `'])
    proc.expect(":{0}] functional>".format(get_impalad_port(vector)))

    # Start an Impala shell with an invalid DB.
    proc = pexpect.spawn(shell_cmd[0], shell_cmd[1:] + ['-d', 'foo'])
    proc.expect(":{0}] default>".format(get_impalad_port(vector)))
    self._expect_with_cmd(proc, "use foo", vector, (), 'default')
    self._expect_with_cmd(proc, "use functional", vector, (), 'functional')
    self._expect_with_cmd(proc, "use foo", vector, (), 'functional')
Example #2
0
    def test_shell_prompt(self, vector):
        shell_cmd = get_shell_cmd(vector)
        proc = pexpect.spawn(shell_cmd[0], shell_cmd[1:])
        proc.expect(":{0}] default>".format(get_impalad_port(vector)))
        self._expect_with_cmd(proc, "use foo", vector, (), 'default')
        self._expect_with_cmd(proc, "use functional", vector, (), 'functional')
        self._expect_with_cmd(proc, "use foo", vector, (), 'functional')
        self._expect_with_cmd(proc, 'use `tpch`', vector, (), 'tpch')
        self._expect_with_cmd(proc, 'use ` tpch `', vector, (), 'tpch')

        proc = pexpect.spawn(shell_cmd[0],
                             shell_cmd[1:] + ['-d', 'functional'])
        proc.expect(":{0}] functional>".format(get_impalad_port(vector)))
        self._expect_with_cmd(proc, "use foo", vector, (), 'functional')
        self._expect_with_cmd(proc, "use tpch", vector, (), 'tpch')
        self._expect_with_cmd(proc, "use foo", vector, (), 'tpch')

        proc = pexpect.spawn(shell_cmd[0],
                             shell_cmd[1:] + ['-d', ' functional '])
        proc.expect(":{0}] functional>".format(get_impalad_port(vector)))

        proc = pexpect.spawn(shell_cmd[0],
                             shell_cmd[1:] + ['-d', '` functional `'])
        proc.expect(":{0}] functional>".format(get_impalad_port(vector)))

        # Start an Impala shell with an invalid DB.
        proc = pexpect.spawn(shell_cmd[0], shell_cmd[1:] + ['-d', 'foo'])
        proc.expect(":{0}] default>".format(get_impalad_port(vector)))
        self._expect_with_cmd(proc, "use foo", vector, (), 'default')
        self._expect_with_cmd(proc, "use functional", vector, (), 'functional')
        self._expect_with_cmd(proc, "use foo", vector, (), 'functional')
        proc.sendeof()
        proc.wait()
Example #3
0
 def test_rerun(self, vector, tmp_history_file):
   """Smoke test for the 'rerun' command"""
   shell_cmd = get_shell_cmd(vector)
   child_proc = pexpect.spawn(shell_cmd[0], shell_cmd[1:])
   child_proc.expect(":{0}] default>".format(get_impalad_port(vector)))
   self._expect_with_cmd(child_proc, "@1", vector, ("Command index out of range"))
   self._expect_with_cmd(child_proc, "rerun -1", vector,
       ("Command index out of range"))
   self._expect_with_cmd(child_proc, "select 'first_command'", vector,
       ("first_command"))
   self._expect_with_cmd(child_proc, "rerun 1", vector, ("first_command"))
   self._expect_with_cmd(child_proc, "@ -1", vector, ("first_command"))
   self._expect_with_cmd(child_proc, "select 'second_command'", vector,
       ("second_command"))
   child_proc.sendline('history;')
   child_proc.expect(":{0}] default>".format(get_impalad_port(vector)))
   assert '[1]: select \'first_command\';' in child_proc.before
   assert '[2]: select \'second_command\';' in child_proc.before
   assert '[3]: history;' in child_proc.before
   # Rerunning command should not add an entry into history.
   assert '[4]' not in child_proc.before
   self._expect_with_cmd(child_proc, "@0", vector, ("Command index out of range"))
   self._expect_with_cmd(child_proc, "rerun   4", vector, ("Command index out of range"))
   self._expect_with_cmd(child_proc, "@-4", vector, ("Command index out of range"))
   self._expect_with_cmd(child_proc, " @ 3 ", vector, ("second_command"))
   self._expect_with_cmd(child_proc, "@-3", vector, ("first_command"))
   self._expect_with_cmd(child_proc, "@", vector,
                         ("Command index to be rerun must be an integer."))
   self._expect_with_cmd(child_proc, "@1foo", vector,
                         ("Command index to be rerun must be an integer."))
   self._expect_with_cmd(child_proc, "@1 2", vector,
                         ("Command index to be rerun must be an integer."))
   self._expect_with_cmd(child_proc, "rerun1", vector, ("Syntax error"))
   child_proc.sendline('quit;')
   child_proc.wait()
 def test_rerun(self, vector, tmp_history_file):
   """Smoke test for the 'rerun' command"""
   shell_cmd = get_shell_cmd(vector)
   child_proc = pexpect.spawn(shell_cmd[0], shell_cmd[1:])
   child_proc.expect(":{0}] default>".format(get_impalad_port(vector)))
   self._expect_with_cmd(child_proc, "@1", vector, ("Command index out of range"))
   self._expect_with_cmd(child_proc, "rerun -1", vector,
       ("Command index out of range"))
   self._expect_with_cmd(child_proc, "select 'first_command'", vector,
       ("first_command"))
   self._expect_with_cmd(child_proc, "rerun 1", vector, ("first_command"))
   self._expect_with_cmd(child_proc, "@ -1", vector, ("first_command"))
   self._expect_with_cmd(child_proc, "select 'second_command'", vector,
       ("second_command"))
   child_proc.sendline('history;')
   child_proc.expect(":{0}] default>".format(get_impalad_port(vector)))
   assert '[1]: select \'first_command\';' in child_proc.before
   assert '[2]: select \'second_command\';' in child_proc.before
   assert '[3]: history;' in child_proc.before
   # Rerunning command should not add an entry into history.
   assert '[4]' not in child_proc.before
   self._expect_with_cmd(child_proc, "@0", vector, ("Command index out of range"))
   self._expect_with_cmd(child_proc, "rerun   4", vector, ("Command index out of range"))
   self._expect_with_cmd(child_proc, "@-4", vector, ("Command index out of range"))
   self._expect_with_cmd(child_proc, " @ 3 ", vector, ("second_command"))
   self._expect_with_cmd(child_proc, "@-3", vector, ("first_command"))
   self._expect_with_cmd(child_proc, "@", vector,
                         ("Command index to be rerun must be an integer."))
   self._expect_with_cmd(child_proc, "@1foo", vector,
                         ("Command index to be rerun must be an integer."))
   self._expect_with_cmd(child_proc, "@1 2", vector,
                         ("Command index to be rerun must be an integer."))
   self._expect_with_cmd(child_proc, "rerun1", vector, ("Syntax error"))
   child_proc.sendline('quit;')
Example #5
0
    def test_reconnect(self, vector):
        """Regression Test for IMPALA-1235

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

            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)))

        finally:
            self.create_impala_clients()
Example #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()

        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)))
Example #7
0
 def test_local_shell_options(self, vector):
     """Test that setting the local shell options works"""
     shell_cmd = get_shell_cmd(vector)
     proc = pexpect.spawn(shell_cmd[0], shell_cmd[1:])
     proc.expect(":{0}] default>".format(get_impalad_port(vector)))
     self._expect_with_cmd(proc, "set", vector,
                           ("LIVE_PROGRESS: False", "LIVE_SUMMARY: False"))
     self._expect_with_cmd(proc, "set live_progress=true", vector)
     self._expect_with_cmd(proc, "set", vector,
                           ("LIVE_PROGRESS: True", "LIVE_SUMMARY: False"))
     self._expect_with_cmd(proc, "set live_summary=1", vector)
     self._expect_with_cmd(proc, "set", vector,
                           ("LIVE_PROGRESS: True", "LIVE_SUMMARY: True"))
     self._expect_with_cmd(proc, "set", vector,
                           ("WRITE_DELIMITED: False", "VERBOSE: True"))
     self._expect_with_cmd(proc, "set", vector,
                           ("DELIMITER: \\t", "OUTPUT_FILE: None"))
     self._expect_with_cmd(proc, "set write_delimited=true", vector)
     self._expect_with_cmd(proc, "set", vector,
                           ("WRITE_DELIMITED: True", "VERBOSE: True"))
     self._expect_with_cmd(proc, "set DELIMITER=,", vector)
     self._expect_with_cmd(proc, "set", vector,
                           ("DELIMITER: ,", "OUTPUT_FILE: None"))
     self._expect_with_cmd(proc, "set output_file=/tmp/clmn.txt", vector)
     self._expect_with_cmd(proc, "set", vector,
                           ("DELIMITER: ,", "OUTPUT_FILE: /tmp/clmn.txt"))
     proc.sendeof()
     proc.wait()
Example #8
0
 def _expect_with_cmd(self, proc, cmd, vector, expectations=(), db="default"):
   """Executes a command on the expect process instance and verifies a set of
   assertions defined by the expectations."""
   proc.sendline(cmd + ";")
   proc.expect(":{0}] {1}>".format(get_impalad_port(vector), db))
   if not expectations: return
   for e in expectations:
     assert e in proc.before
 def _expect_with_cmd(self, proc, cmd, vector, expectations=(), db="default"):
   """Executes a command on the expect process instance and verifies a set of
   assertions defined by the expectations."""
   proc.sendline(cmd + ";")
   proc.expect(":{0}] {1}>".format(get_impalad_port(vector), db))
   if not expectations: return
   for e in expectations:
     assert e in proc.before
  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)))
Example #11
0
 def test_history_file_option(self, vector, tmp_history_file):
   """
   Setting the 'tmp_history_file' fixture above means that the IMPALA_HISTFILE
   environment will be overridden. Here we override that environment by passing
   the --history_file command line option, ensuring that the history ends up
   in the appropriate spot.
   """
   with NamedTemporaryFile() as new_hist:
     shell_cmd = get_shell_cmd(vector) + ["--history_file=%s" % new_hist.name]
     child_proc = pexpect.spawn(shell_cmd[0], shell_cmd[1:])
     child_proc.expect(":{0}] default>".format(get_impalad_port(vector)))
     self._expect_with_cmd(child_proc, "select 'hi'", vector, ('hi'))
     child_proc.sendline('exit;')
     child_proc.expect(pexpect.EOF)
     history_contents = file(new_hist.name).read()
     assert "select 'hi'" in history_contents
 def test_history_file_option(self, vector, tmp_history_file):
   """
   Setting the 'tmp_history_file' fixture above means that the IMPALA_HISTFILE
   environment will be overridden. Here we override that environment by passing
   the --history_file command line option, ensuring that the history ends up
   in the appropriate spot.
   """
   with NamedTemporaryFile() as new_hist:
     shell_cmd = get_shell_cmd(vector) + ["--history_file=%s" % new_hist.name]
     child_proc = pexpect.spawn(shell_cmd[0], shell_cmd[1:])
     child_proc.expect(":{0}] default>".format(get_impalad_port(vector)))
     self._expect_with_cmd(child_proc, "select 'hi'", vector, ('hi'))
     child_proc.sendline('exit;')
     child_proc.expect(pexpect.EOF)
     history_contents = file(new_hist.name).read()
     assert "select 'hi'" in history_contents
 def test_local_shell_options(self, vector):
   """Test that setting the local shell options works"""
   shell_cmd = get_shell_cmd(vector)
   proc = pexpect.spawn(shell_cmd[0], shell_cmd[1:])
   proc.expect(":{0}] default>".format(get_impalad_port(vector)))
   self._expect_with_cmd(proc, "set", vector,
       ("LIVE_PROGRESS: False", "LIVE_SUMMARY: False"))
   self._expect_with_cmd(proc, "set live_progress=true", vector)
   self._expect_with_cmd(proc, "set", vector,
       ("LIVE_PROGRESS: True", "LIVE_SUMMARY: False"))
   self._expect_with_cmd(proc, "set live_summary=1", vector)
   self._expect_with_cmd(proc, "set", vector,
       ("LIVE_PROGRESS: True", "LIVE_SUMMARY: True"))
   self._expect_with_cmd(proc, "set", vector,
       ("WRITE_DELIMITED: False", "VERBOSE: True"))
   self._expect_with_cmd(proc, "set", vector,
       ("DELIMITER: \\t", "OUTPUT_FILE: None"))
   self._expect_with_cmd(proc, "set write_delimited=true", vector)
   self._expect_with_cmd(proc, "set", vector, ("WRITE_DELIMITED: True", "VERBOSE: True"))
   self._expect_with_cmd(proc, "set DELIMITER=,", vector)
   self._expect_with_cmd(proc, "set", vector, ("DELIMITER: ,", "OUTPUT_FILE: None"))
   self._expect_with_cmd(proc, "set output_file=/tmp/clmn.txt", vector)
   self._expect_with_cmd(proc, "set", vector,
       ("DELIMITER: ,", "OUTPUT_FILE: /tmp/clmn.txt"))