beam-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Work logged] (BEAM-4806) Improve BeamSqlLine unit tests
Date Wed, 18 Jul 2018 03:27:00 GMT

     [ https://issues.apache.org/jira/browse/BEAM-4806?focusedWorklogId=124308&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-124308
]

ASF GitHub Bot logged work on BEAM-4806:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 18/Jul/18 03:26
            Start Date: 18/Jul/18 03:26
    Worklog Time Spent: 10m 
      Work Description: akedin commented on a change in pull request #5969: [BEAM-4806] improve
unittest for BeamSqlLine
URL: https://github.com/apache/beam/pull/5969#discussion_r203237624
 
 

 ##########
 File path: sdks/java/extensions/sql/jdbc/src/main/java/org/apache/beam/sdk/extensions/sql/jdbc/BeamSqlLine.java
 ##########
 @@ -53,7 +58,14 @@ public static void main(String[] args) throws IOException {
     if (nickname == null) {
       wrappedArgs.add("-nn").add(NICKNAME);
     }
-    List<String> wrappedArgList = wrappedArgs.build();
-    SqlLine.main(wrappedArgList.toArray(new String[wrappedArgList.size()]));
+
+    return wrappedArgs.build();
+  }
+
+  public static void testMain(String[] args, PrintStream outputStream) throws IOException
{
+    List<String> wrappedArgList = mainUtil(args);
+    SqlLine sqlLine = new SqlLine();
+    sqlLine.setOutputStream(outputStream);
+    sqlLine.begin(wrappedArgList.toArray(new String[wrappedArgList.size()]), null, true);
 
 Review comment:
   You expose 2 independent ways to start `sqlline`.  Breaking `testMain` might not break
`main`,  so there doesn't seem to be a lot of value here. I think it's better to combine the
paths:
   
   * Create a package-private method to create and start `sqlline` instance from args:
   
     ```java
     static Status runSqlLine(
                   String[] rawArgs, 
                   @Nullable InputStream in, 
                   @Nullable OutputStream out, 
                   @Nullable OutputStream err) {
       String[] args = ensureConnectionArgs(rawArgs);
       SqlLine sqlLine = new SqlLine();
       if (out != null) {
         sqlLine.setOutputStream(new PrintStream(out));
       }
       if (err != null) {
         sqlLine.setErrorStream(new PrintStream(err));
       }
   
       return sqlLine.begin(args, in, true);
     }
     ```
   
   * `main` then only calls this method
   
     ```java
     public static void main(String[] args) {
       runSqlLine(args, null, System.out, System.err);
     }
     ```
   
   * .This way you can test exactly same functionality while injecting fakes/mocks, which
is cleaner then creating an unrelated public interface just for testing:
   
      ```java
      String [] EMPTY_ARGS = new String[] {};
      InputStream NULL_INPUT = null;
   
      @Test
      void testRunsMain() {
         OutputStream mainOutput = createOutputStream();
         BeamSqlLine.runSqlLine(EMPTY_ARGS, NULL_INPUT, mainOutput);
      }
     ```

----------------------------------------------------------------
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:
users@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 124308)
    Time Spent: 1h 20m  (was: 1h 10m)

> 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: 1h 20m
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message