From 943ce1647624e63432245e068fd1927cca712b1a Mon Sep 17 00:00:00 2001 From: Mike Drob Date: Mon, 17 Jul 2017 22:57:14 -0500 Subject: [PATCH] HBASE-18393 Fix shell noninteractive launch --- bin/hirb.rb | 9 +++++++ hbase-shell/pom.xml | 7 ++++++ .../org/apache/hadoop/hbase/client/TestShell.java | 29 ++++++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/bin/hirb.rb b/bin/hirb.rb index d0295d638d..841ab54504 100644 --- a/bin/hirb.rb +++ b/bin/hirb.rb @@ -215,6 +215,15 @@ else require "irb/workspace" workspace = IRB::WorkSpace.new(binding()) scanner = RubyLex.new + + # RubyLex claims to take an IO but really wants an InputMethod + module IOExtensions + def encoding + external_encoding + end + end + IO.include IOExtensions + scanner.set_input(STDIN) scanner.each_top_level_statement do |statement, linenum| puts(workspace.evaluate(nil, statement, 'stdin', linenum)) diff --git a/hbase-shell/pom.xml b/hbase-shell/pom.xml index cfe0312bdd..a475bcfbfc 100644 --- a/hbase-shell/pom.xml +++ b/hbase-shell/pom.xml @@ -40,6 +40,13 @@ hbase-webapps/** + + ${project.basedir}/../bin + + hbase + hirb.rb + + diff --git a/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestShell.java b/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestShell.java index 882b811cf5..522fe482d9 100644 --- a/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestShell.java +++ b/hbase-shell/src/test/java/org/apache/hadoop/hbase/client/TestShell.java @@ -18,16 +18,27 @@ */ package org.apache.hadoop.hbase.client; +import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.util.concurrent.TimeUnit; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.hadoop.hbase.testclassification.ClientTests; import org.apache.hadoop.hbase.testclassification.LargeTests; +import org.apache.hadoop.hbase.util.Bytes; import org.jruby.embed.PathType; import org.junit.Test; import org.junit.experimental.categories.Category; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + @Category({ ClientTests.class, LargeTests.class }) public class TestShell extends AbstractTestShell { + private static final Log LOG = LogFactory.getLog(TestShell.class); @Test public void testRunShellTests() throws IOException { @@ -36,4 +47,22 @@ public class TestShell extends AbstractTestShell { jruby.runScriptlet(PathType.ABSOLUTE, "src/test/ruby/tests_runner.rb"); } + @Test + public void testHirbShell() throws IOException, InterruptedException { + // This is a bit fragile, maybe we need to copy files from bin to be local to the module + ProcessBuilder pb = new ProcessBuilder("../bin/hbase", "shell", "-n"); + Process p = pb.start(); + + // Don't have to wait for the thread becuase it will always terminate with the process + new Thread(() -> { + new BufferedReader(new InputStreamReader(p.getInputStream())).lines().forEach(LOG::debug); + }).start(); + + OutputStream stdin = p.getOutputStream(); + stdin.write(Bytes.toBytes("help\n")); + stdin.close(); + + assertTrue("'hbase shell -n' took too long", p.waitFor(60, TimeUnit.SECONDS)); + assertEquals("'hbase shell -n' had non-zero exit", 0, p.exitValue()); + } } -- 2.13.0