[ https://issues.apache.org/jira/browse/BEAM-4806?focusedWorklogId=124678&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-124678 ]
ASF GitHub Bot logged work on BEAM-4806: ---------------------------------------- Author: ASF GitHub Bot Created on: 18/Jul/18 22:47 Start Date: 18/Jul/18 22:47 Worklog Time Spent: 10m Work Description: amaliujia commented on a change in pull request #5969: [BEAM-4806][SQL] improve unittest for BeamSqlLine URL: https://github.com/apache/beam/pull/5969#discussion_r203554949 ########## File path: sdks/java/extensions/sql/jdbc/src/main/java/org/apache/beam/sdk/extensions/sql/jdbc/BeamSqlLine.java ########## @@ -19,41 +19,57 @@ import static org.apache.beam.sdk.extensions.sql.impl.JdbcDriver.CONNECT_STRING_PREFIX; -import com.google.common.collect.ImmutableList; import java.io.IOException; +import java.io.InputStream; +import java.io.PrintStream; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import javax.annotation.Nullable; import sqlline.SqlLine; +import sqlline.SqlLine.Status; /** {@link BeamSqlLine} provides default arguments to SqlLine. */ public class BeamSqlLine { private static final String NICKNAME = "BeamSQL"; public static void main(String[] args) throws IOException { + runSqlLine(checkConnectionArgs(args), null, null, null); + } + + private static String[] checkConnectionArgs(String[] args) { + List<String> argsList = new ArrayList<String>(Arrays.asList(args)); - // Until we learn otherwise, we expect to add -nn <nickname> -u <url> - @Nullable String databaseUrl = null; - @Nullable String nickname = null; - - // Provide -u and -nn only if they do not exist - for (int i = 0; i < args.length; i++) { - if (args[i].equals("-u")) { - databaseUrl = args[++i]; - } else if (args[i].equals("-nn")) { - nickname = args[++i]; - } + if (!argsList.contains("-nn")) { + argsList.add("-nn"); + argsList.add(NICKNAME); } - ImmutableList.Builder wrappedArgs = ImmutableList.builder().addAll(Arrays.asList(args)); - if (databaseUrl == null) { - wrappedArgs.add("-u").add(CONNECT_STRING_PREFIX); + if (!argsList.contains("-u")) { + argsList.add("-u"); + argsList.add(CONNECT_STRING_PREFIX); } - if (nickname == null) { - wrappedArgs.add("-nn").add(NICKNAME); + + return argsList.toArray(new String[argsList.size()]); + } + + static Status runSqlLine( + String[] args, + InputStream inputStream, + @Nullable PrintStream outputStream, + @Nullable PrintStream errorStream) Review comment: Use `OutputStream` now. This is a good idea to simplify tests. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 124678) Time Spent: 4.5h (was: 4h 20m) > Improve BeamSqlLine unit tests > ------------------------------ > > Key: BEAM-4806 > URL: https://issues.apache.org/jira/browse/BEAM-4806 > Project: Beam > Issue Type: Improvement > Components: dsl-sql > Reporter: Rui Wang > Assignee: Rui Wang > Priority: Major > Time Spent: 4.5h > Remaining Estimate: 0h > -- This message was sent by Atlassian JIRA (v7.6.3#76005)