package de.qaware.chronix.client;

import de.qaware.chronix.client.benchmark.benchmarkrunner.BenchmarkRunner;
import de.qaware.chronix.database.BenchmarkDataSource;
import de.qaware.chronix.shared.ServerConfig.TSDBInterfaceHandler;

import java.util.LinkedList;
import java.util.List;

/**
 * Created by mcqueen666 on 07.10.16.
 */
public class BenchmarkQueryMeasurement {
    public static void main(String[] args){
        if(args.length < 1) {
            printUsage();
            return;
        }

        String server = args[0];
        List<String> tsdbList = new LinkedList<>();

        TSDBInterfaceHandler tsdbInterfaceHandler = TSDBInterfaceHandler.getInstance();
        // print info for user
        System.out.println("Server: " + server);
        for(int i = 1; i < args.length; i++){
            BenchmarkDataSource<Object> tsdbInterface = tsdbInterfaceHandler.getTSDBInstance(args[i]);
            if(tsdbInterface != null){
                System.out.println("TSDB:   " + args[i]);
                tsdbList.add(args[i]);
            } else {
                System.err.println("No interface found for: " + args[i] + " -> rejected!");
            }
        }

        if(tsdbList.isEmpty()){
            System.err.println("No implemented tsdb interfaces found for your entries -> aborting");
            return;
        }

        BenchmarkRunner benchmarkRunner = BenchmarkRunner.getInstance();
        long startMillis = System.currentTimeMillis();
        benchmarkRunner.doBenchmarkQuery(server, tsdbList);
        long endMillis = System.currentTimeMillis();
        System.out.println("Query test total time: " + (endMillis - startMillis) + "ms");

        System.out.println("\nDownloading benchmark records from server successful: " +  benchmarkRunner.getBenchmarkRecordsFromServer(server));



    }

    public static void printUsage(){
        System.out.println("Benchmark usage: benchmark [server] [tsdbName1] [tsdbName2] ...");
    }
}

@@ -107,131 +107,8 @@
 er;%0A
-import de.qaware.chronix.database.BenchmarkDataSource;%0Aimport de.qaware.chronix.shared.ServerConfig.TSDBInterfaceHandler;%0A%0A
 impo
@@ -120,22 +120,16 @@
 va.util.
-Linked
 List;%0Aim
@@ -143,20 +143,19 @@
 va.util.
-List
+Map
 ;%0A%0A/**%0A 
@@ -305,17 +305,17 @@
 ength %3C 
-1
+2
 ) %7B%0A    
@@ -433,360 +433,115 @@
 List
- = new LinkedList%3C%3E();%0A%0A        TSDBInterfaceHandler tsdbInterfaceHandler = TSDBInterfaceHandler.getInstance();%0A        // print info for user%0A        System.out.println(%22Server: %22 + server);%0A        for(int i = 1; i %3C args.length; i++)%7B%0A            BenchmarkDataSource%3CObject%3E tsdbInterface = tsdbInterfaceHandler.getTSDBInstance(args%5Bi%5D);%0A   
+;%0A%0A        Map%3CString, List%3CString%3E%3E serverTsdbMap = ClientMenu.getConfiguredServerAndTSDBs(args);%0A
         
  if(
@@ -540,40 +540,37 @@
     
- 
 if(
-tsdbInterface != null)%7B%0A    
+serverTsdbMap.isEmpty())%7B%0A
     
@@ -576,35 +576,35 @@
          System.
-out
+err
 .println(%22TSDB: 
@@ -601,66 +601,51 @@
 ln(%22
-TSDB:   %22 + args%5Bi%5D);%0A                tsdbList.add(args%5Bi%5D
+Server: %22 + server + %22 was not configured!%22
 );%0A 
@@ -659,16 +659,15 @@
     
-%7D else %7B
+return;
 %0A   
@@ -667,32 +667,35 @@
 rn;%0A        
+%7D%0A%0A
         
 System.err.p
@@ -686,108 +686,45 @@
     
-System.err.println(%22No interface found for: %22 + args%5Bi%5D + %22 -%3E rejected!%22);%0A            %7D%0A        %7D%0A
+tsdbList = serverTsdbMap.get(server);
 %0A   

use ClientMenu.getConfiguredServerAndTSDBs() to check user entries with server records