Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SQLLINE-327] !reconnect should respect fastconnect property value #328

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/main/java/sqlline/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/sqlline/DatabaseConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public Connection getConnection() throws SQLException {
}

connect();

sqlLine.setCompletions();
return connection;
}

Expand Down
79 changes: 78 additions & 1 deletion src/test/java/sqlline/CompletionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -149,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 + " "
Expand All @@ -176,6 +177,82 @@ 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 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<String> 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 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<String> tableAndColumns =
getLineReaderCompletedSet(lineReaderCompletion, tableStartNameInput);
assertFalse(tableAndColumns.stream()
.allMatch(t -> t.startsWith(tableStartNameExpected)));

sqlLine.runCommands(new DispatchCallback(),
"!set fastconnect false",
"!reconnect");
os.reset();
final Set<String> 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();
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/sqlline/SqlLineArgsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down