From 833cf8fde970d0f1a94e33b728f4cbf0046a8ac0 Mon Sep 17 00:00:00 2001 From: snuyanzin Date: Sat, 13 Jul 2019 22:39:47 +0200 Subject: [PATCH 1/3] Fix tests on Windows --- src/test/java/sqlline/SqlLineArgsTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/sqlline/SqlLineArgsTest.java b/src/test/java/sqlline/SqlLineArgsTest.java index a0970ae4..096e46ad 100644 --- a/src/test/java/sqlline/SqlLineArgsTest.java +++ b/src/test/java/sqlline/SqlLineArgsTest.java @@ -780,7 +780,7 @@ public void testRecordHome() { */ @Test public void testRecordFilenameWithSpace() { - final String fileNameWithSpaces = "sqlline' file\" with\\ spaces"; + final String fileNameWithSpaces = "sqlline' file with spaces"; File file = createTempFile(fileNameWithSpaces, ".log"); final SqlLine sqlLine = new SqlLine(); final String script = "!set incremental true\n" @@ -2603,7 +2603,7 @@ void setNickname(String nickname) { }; final SqlLine sqlLine = new SqlLine(); ByteArrayOutputStream os = new ByteArrayOutputStream(); - final String filename = "file' with\\\" spaces"; + final String filename = "file' with spaces"; String[] connectionArgs = new String[] { "-u", ConnectionSpec.H2.url, "-n", ConnectionSpec.H2.username, From 0f9069c3164287d25e21a1554ee5ab1e28326c9d Mon Sep 17 00:00:00 2001 From: snuyanzin Date: Thu, 18 Jul 2019 18:20:54 +0200 Subject: [PATCH 2/3] [SQLLINE-327] !reconnect should respect fastconnect property value --- src/main/java/sqlline/Commands.java | 1 - src/main/java/sqlline/DatabaseConnection.java | 2 +- src/test/java/sqlline/CompletionTest.java | 80 +++++++++++++++++++ 3 files changed, 81 insertions(+), 2 deletions(-) diff --git a/src/main/java/sqlline/Commands.java b/src/main/java/sqlline/Commands.java index ff64795d..c17447e8 100644 --- a/src/main/java/sqlline/Commands.java +++ b/src/main/java/sqlline/Commands.java @@ -1324,7 +1324,6 @@ public void connect(Properties props, DispatchCallback callback) { try { sqlLine.getDatabaseConnections().setConnection(connection); sqlLine.getDatabaseConnection().getConnection(); - sqlLine.setCompletions(); callback.setToSuccess(); } catch (Exception e) { connection.close(); diff --git a/src/main/java/sqlline/DatabaseConnection.java b/src/main/java/sqlline/DatabaseConnection.java index 1a2ffaf5..6edbcfe4 100644 --- a/src/main/java/sqlline/DatabaseConnection.java +++ b/src/main/java/sqlline/DatabaseConnection.java @@ -180,7 +180,7 @@ public Connection getConnection() throws SQLException { } connect(); - + sqlLine.setCompletions(); return connection; } diff --git a/src/test/java/sqlline/CompletionTest.java b/src/test/java/sqlline/CompletionTest.java index 29d67cb4..60925e9e 100644 --- a/src/test/java/sqlline/CompletionTest.java +++ b/src/test/java/sqlline/CompletionTest.java @@ -37,6 +37,8 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Test cases for Completions. @@ -176,6 +178,84 @@ public void testSqlCompletions() { } } + @Test + public void testSqlCompletionsWithoutFastConnect() { + try { + SqlLine sqlLine = new SqlLine(); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + SqlLine.Status status = + begin(sqlLine, os, false, "-e", "!set maxwidth 80"); + assertEquals(status, SqlLine.Status.OK); + sqlLine.runCommands(new DispatchCallback(), + "!set maxwidth 80", + "!set fastconnect false", + "!connect " + + SqlLineArgsTest.ConnectionSpec.H2.url + " " + + SqlLineArgsTest.ConnectionSpec.H2.username + " " + + "\"\""); + os.reset(); + + LineReader lineReader = sqlLine.getLineReader(); + + LineReaderCompletionImpl lineReaderCompletion = + new LineReaderCompletionImpl(lineReader.getTerminal()); + lineReaderCompletion.setCompleter(new SqlLineCompleter(sqlLine)); + final String tableStartName = "FUNCTION_ALIASE"; + final String tableStartNameExpected = "FUNCTION_ALIASES"; + final Set tableAndColumns = + getLineReaderCompletedSet(lineReaderCompletion, tableStartName); + assertFalse(tableAndColumns.isEmpty()); + assertTrue(tableAndColumns.stream() + .allMatch(t -> t.startsWith(tableStartNameExpected))); + } catch (Exception e) { + // fail + throw new RuntimeException(e); + } + } + + @Test + public void testSqlCompletionsWithAndWithoutFastConnect() { + try { + SqlLine sqlLine = new SqlLine(); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + SqlLine.Status status = + begin(sqlLine, os, false, "-e", "!set maxwidth 80"); + assertEquals(status, SqlLine.Status.OK); + sqlLine.runCommands(new DispatchCallback(), + "!set maxwidth 80", + "!set fastconnect true", + "!connect " + + SqlLineArgsTest.ConnectionSpec.H2.url + " " + + SqlLineArgsTest.ConnectionSpec.H2.username + " " + + "\"\""); + os.reset(); + + LineReader lineReader = sqlLine.getLineReader(); + + LineReaderCompletionImpl lineReaderCompletion = + new LineReaderCompletionImpl(lineReader.getTerminal()); + lineReaderCompletion.setCompleter(new SqlLineCompleter(sqlLine)); + final String tableStartNameInput = "FUNCTION_ALIASE"; + final String tableStartNameExpected = "FUNCTION_ALIASES"; + final Set tableAndColumns = + getLineReaderCompletedSet(lineReaderCompletion, tableStartNameInput); + assertFalse(tableAndColumns.stream() + .allMatch(t -> t.startsWith(tableStartNameExpected))); + + sqlLine.runCommands(new DispatchCallback(), + "!set fastconnect false", + "!reconnect"); + os.reset(); + final Set tableAndColumnsAfterReconnect = + getLineReaderCompletedSet(lineReaderCompletion, tableStartNameInput); + assertTrue(tableAndColumnsAfterReconnect.stream() + .allMatch(t -> t.startsWith(tableStartNameExpected))); + } catch (Exception e) { + // fail + throw new RuntimeException(e); + } + } + private LineReaderCompletionImpl getDummyLineReader() { try { TerminalBuilder terminalBuilder = TerminalBuilder.builder(); From 9795b147b4fe5027aa71f1955fe7f35232d2e073 Mon Sep 17 00:00:00 2001 From: snuyanzin Date: Thu, 18 Jul 2019 20:29:34 +0200 Subject: [PATCH 3/3] [SQLLINE-327] remove duplicate width setting --- src/test/java/sqlline/CompletionTest.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/test/java/sqlline/CompletionTest.java b/src/test/java/sqlline/CompletionTest.java index 60925e9e..c7d99767 100644 --- a/src/test/java/sqlline/CompletionTest.java +++ b/src/test/java/sqlline/CompletionTest.java @@ -151,7 +151,6 @@ public void testSqlCompletions() { begin(sqlLine, os, false, "-e", "!set maxwidth 80"); assertEquals(status, SqlLine.Status.OK); sqlLine.runCommands(new DispatchCallback(), - "!set maxwidth 80", "!connect " + SqlLineArgsTest.ConnectionSpec.H2.url + " " + SqlLineArgsTest.ConnectionSpec.H2.username + " " @@ -187,7 +186,6 @@ public void testSqlCompletionsWithoutFastConnect() { begin(sqlLine, os, false, "-e", "!set maxwidth 80"); assertEquals(status, SqlLine.Status.OK); sqlLine.runCommands(new DispatchCallback(), - "!set maxwidth 80", "!set fastconnect false", "!connect " + SqlLineArgsTest.ConnectionSpec.H2.url + " " @@ -222,7 +220,6 @@ public void testSqlCompletionsWithAndWithoutFastConnect() { begin(sqlLine, os, false, "-e", "!set maxwidth 80"); assertEquals(status, SqlLine.Status.OK); sqlLine.runCommands(new DispatchCallback(), - "!set maxwidth 80", "!set fastconnect true", "!connect " + SqlLineArgsTest.ConnectionSpec.H2.url + " "