2323import java .util .ArrayList ;
2424import java .util .Arrays ;
2525import java .io .BufferedInputStream ;
26+ import java .io .Console ;
2627import java .io .File ;
2728import java .io .FileInputStream ;
2829import java .io .FileOutputStream ;
@@ -74,6 +75,9 @@ public class FileUtility
7475 private static final int NUM_DEFAULT_THREADS = 4 ;
7576 static private final int DEFAULT_ACCESS_EXPIRY_SECONDS = 120 ;
7677
78+ static private final int DEFAULT_READ_REQUEST_SIZE = 4096 ;
79+ static private final int DEFAULT_READ_REQUEST_DELAY = 0 ;
80+
7781 private static boolean otelInitialized = false ;
7882
7983 private static class TaskContext
@@ -322,6 +326,28 @@ public JSONArray generateResultsMessage()
322326 }
323327 };
324328
329+ private static String [] getCredentials (CommandLine cmd )
330+ {
331+ Console console = System .console ();
332+
333+ String user = cmd .getOptionValue ("user" );
334+ boolean userIsEmpty = user == null || user .isEmpty ();
335+ if (userIsEmpty )
336+ {
337+ user = new String (console .readLine ("Enter username: " ));
338+ userIsEmpty = user == null || user .isEmpty ();
339+ }
340+
341+ String pass = cmd .getOptionValue ("pass" );
342+ boolean passIsEmpty = pass == null || pass .isEmpty ();
343+ if (!userIsEmpty && passIsEmpty )
344+ {
345+ pass = new String (console .readPassword ("Enter password for " + user + ": " ));
346+ }
347+
348+ return new String [] {user , pass };
349+ }
350+
325351 private static enum FileFormat
326352 {
327353 THOR ,
@@ -548,6 +574,8 @@ private static Options getReadTestOptions()
548574 options .addOption ("pass" , true , "Specifies the password used to connect. Defaults to null." );
549575 options .addOption ("num_threads" , true , "Specifies the number of parallel to use to perform operations." );
550576 options .addOption ("access_expiry_seconds" , true , "Access token expiration seconds." );
577+ options .addOption ("read_request_size" , true , "The size of the read requests in KB sent to the rowservice." );
578+ options .addOption ("read_request_delay" , true , "The delay in MS between read requests sent to the rowservice." );
551579
552580 options .addOption (Option .builder ("file_parts" )
553581 .argName ("_file_parts" )
@@ -801,7 +829,7 @@ public void run()
801829 }
802830 }
803831
804- private static Runnable [] createReadTestTasks (DataPartition [] fileParts , FieldDef recordDef , TaskContext context ) throws Exception
832+ private static Runnable [] createReadTestTasks (DataPartition [] fileParts , FieldDef recordDef , TaskContext context , int readRequestSize , int readRequestDelay ) throws Exception
805833 {
806834 Runnable [] tasks = new Runnable [fileParts .length ];
807835 for (int i = 0 ; i < tasks .length ; i ++)
@@ -818,7 +846,9 @@ public void run()
818846 HpccRemoteFileReader .FileReadContext readContext = new HpccRemoteFileReader .FileReadContext ();
819847 readContext .parentSpan = context .getCurrentOperation ().operationSpan ;
820848 readContext .originalRD = recordDef ;
849+ readContext .readSizeKB = readRequestSize ;
821850 HpccRemoteFileReader <HPCCRecord > fileReader = new HpccRemoteFileReader <HPCCRecord >(readContext , filePart , new HPCCRecordBuilder (recordDef ));
851+ fileReader .getInputStream ().setReadRequestDelay (readRequestDelay );
822852
823853 while (fileReader .hasNext ())
824854 {
@@ -1198,8 +1228,10 @@ private static void performRead(String[] args, TaskContext context)
11981228 }
11991229
12001230 String connString = cmd .getOptionValue ("url" );
1201- String user = cmd .getOptionValue ("user" );
1202- String pass = cmd .getOptionValue ("pass" );
1231+
1232+ String [] creds = getCredentials (cmd );
1233+ String user = creds [0 ];
1234+ String pass = creds [1 ];
12031235
12041236 String outputPath = cmd .getOptionValue ("out" ,"." );
12051237
@@ -1376,8 +1408,10 @@ private static void performReadTest(String[] args, TaskContext context)
13761408 }
13771409
13781410 String connString = cmd .getOptionValue ("url" );
1379- String user = cmd .getOptionValue ("user" );
1380- String pass = cmd .getOptionValue ("pass" );
1411+
1412+ String [] creds = getCredentials (cmd );
1413+ String user = creds [0 ];
1414+ String pass = creds [1 ];
13811415
13821416 String outputPath = cmd .getOptionValue ("out" ,"." );
13831417
@@ -1405,6 +1439,30 @@ private static void performReadTest(String[] args, TaskContext context)
14051439 + numThreadsStr + ", must be an integer. Defaulting to: " + DEFAULT_ACCESS_EXPIRY_SECONDS + "s." );
14061440 }
14071441
1442+ int readRequestSize = DEFAULT_READ_REQUEST_SIZE ;
1443+ String readRequestSizeStr = cmd .getOptionValue ("read_request_size" , "" + readRequestSize );
1444+ try
1445+ {
1446+ readRequestSize = Integer .parseInt (readRequestSizeStr );
1447+ }
1448+ catch (Exception e )
1449+ {
1450+ System .out .println ("Invalid option value for read_request_size: "
1451+ + readRequestSizeStr + ", must be an integer. Defaulting to: " + DEFAULT_READ_REQUEST_SIZE + "KB." );
1452+ }
1453+
1454+ int readRequestDelay = DEFAULT_READ_REQUEST_DELAY ;
1455+ String readRequestDelayStr = cmd .getOptionValue ("read_request_delay" , "" + readRequestDelay );
1456+ try
1457+ {
1458+ readRequestDelay = Integer .parseInt (readRequestDelayStr );
1459+ }
1460+ catch (Exception e )
1461+ {
1462+ System .out .println ("Invalid option value for read_request_delay: "
1463+ + readRequestDelayStr + ", must be an integer. Defaulting to: " + DEFAULT_READ_REQUEST_DELAY + "ms." );
1464+ }
1465+
14081466 String formatStr = cmd .getOptionValue ("format" );
14091467 if (formatStr == null )
14101468 {
@@ -1477,6 +1535,7 @@ private static void performReadTest(String[] args, TaskContext context)
14771535 context .addWarn ("InvalidParams: Skipping invalid file part index: " + filePartsStrs [i ]);
14781536 }
14791537 }
1538+ fileParts = filePartList .toArray (new DataPartition [0 ]);
14801539 }
14811540
14821541 Runnable [] tasks = null ;
@@ -1485,7 +1544,7 @@ private static void performReadTest(String[] args, TaskContext context)
14851544 switch (format )
14861545 {
14871546 case THOR :
1488- tasks = createReadTestTasks (fileParts , recordDef , context );
1547+ tasks = createReadTestTasks (fileParts , recordDef , context , readRequestSize , readRequestDelay );
14891548 break ;
14901549 case PARQUET :
14911550 default :
@@ -1560,8 +1619,9 @@ private static void performCopy(String[] args, TaskContext context)
15601619 + numThreadsStr + ", must be an integer. Defaulting to: " + NUM_DEFAULT_THREADS + " threads." );
15611620 }
15621621
1563- String user = cmd .getOptionValue ("user" );
1564- String pass = cmd .getOptionValue ("pass" );
1622+ String [] creds = getCredentials (cmd );
1623+ String user = creds [0 ];
1624+ String pass = creds [1 ];
15651625
15661626 String destClusterName = cmd .getOptionValue ("dest_cluster" );
15671627
@@ -1741,8 +1801,9 @@ private static void performWrite(String[] args, TaskContext context)
17411801 + numThreadsStr + ", must be an integer. Defaulting to: " + NUM_DEFAULT_THREADS + " threads." );
17421802 }
17431803
1744- String user = cmd .getOptionValue ("user" );
1745- String pass = cmd .getOptionValue ("pass" );
1804+ String [] creds = getCredentials (cmd );
1805+ String user = creds [0 ];
1806+ String pass = creds [1 ];
17461807
17471808 String destClusterName = cmd .getOptionValue ("dest_cluster" );
17481809
0 commit comments