diff --git a/benchmark/src/main/java/de/tudresden/inf/st/eraser/benchmark/Benchmark.java b/benchmark/src/main/java/de/tudresden/inf/st/eraser/benchmark/Benchmark.java index a22f1b7bb610895afbdfa7f589388129288761a5..a8a9e95b0b173dddef7eb3f1c9cd524525142ecb 100644 --- a/benchmark/src/main/java/de/tudresden/inf/st/eraser/benchmark/Benchmark.java +++ b/benchmark/src/main/java/de/tudresden/inf/st/eraser/benchmark/Benchmark.java @@ -9,6 +9,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.io.File; +import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.Arrays; @@ -69,7 +70,6 @@ public class Benchmark { int i = 0; while ((a_next_record = a_csv_reader.readNext())!= null){ if( i==0 ){ - getCSVHeader(Arrays.copyOf(a_next_record,12),"a"); i++; } @@ -86,11 +86,14 @@ public class Benchmark { setNewValue(values1, PREFERENCE_ITEM_NAME,"preference"); // wait for 1s try{Thread.sleep(TIME_PERIOD);}catch (InterruptedException e){e.printStackTrace();} + logger.warn("checking/comparing the result from web server with the CSV"); HttpResponse response= Request.Get(ACTIVITY_URL).execute().returnResponse(); HttpResponse response1= Request.Get(PREFERENCE_URL).execute().returnResponse(); //check response - checkResult(response, a_next_record); - checkResult(response1, p_next_record); + checkResult(response, a_next_record,null); + checkResult(response1, p_next_record,a_next_record[12]); + logger.warn("checking/comparing finised"); + //logger.info("checking/comparing finished"); break; } } @@ -115,7 +118,7 @@ public class Benchmark { .execute().returnResponse(); String status=httpResponse.getStatusLine().toString(); if(status.contains("200")){ - logger.info("put activity input name: "+name[i]+", value: "+value+"to web server: response 200 ok"); + logger.info("put activity input name: "+ name[i] +", value: "+ value +" to web server: response 200 ok"); }else{ logger.info("can not put activity inputs to rest server"); } @@ -130,8 +133,9 @@ public class Benchmark { HttpResponse httpResponse = Request.Put(uri) .bodyString(values[1], ContentType.TEXT_PLAIN) .execute().returnResponse(); - String put_response=httpResponse.getStatusLine().toString(); - if (put_response.contains("200")){logger.info("put w_brightness to web server: response 200 ok");}else{ + String put_response = httpResponse.getStatusLine().toString(); + if (put_response.contains("200")){logger.info("put preference input name: w_brightness, value : " + + values[1]+" to web server: response 200 ok");} else{ logger.info("can not put w_brightness to rest server"); } }catch (Exception e){ @@ -148,19 +152,18 @@ public class Benchmark { PREFERENCE_ITEM_NAME = a_values; } } - private void checkResult(HttpResponse response,String[] record){ + private void checkResult(HttpResponse response,String[] record, String activity){ int status = response.getStatusLine().getStatusCode(); if(status == 200 && record.length == 13){ logger.info("activity should be (read direct from CSV): " + record[12]); try { - logger.info(EntityUtils.toString(response.getEntity())); + logger.info("get activity from web server: response 200 ok, value is: "+ + EntityUtils.toString(response.getEntity())); }catch (IOException e){ e.printStackTrace(); } - logger.info("get activity from web server: response 200 ok"); - }else if(status ==200 && record.length == 4){ - logger.info("preference should be (read direct from CSV): " + getPreference(record)); + logger.info("preference should be (read direct from CSV): " + comparePreferenceOutput(record,activity)); try { logger.info("get the iris1_item preference from web server: response 200 ok, value is: " + EntityUtils.toString(response.getEntity())); @@ -168,8 +171,7 @@ public class Benchmark { e.printStackTrace(); } - }else if(status != - 200 &&record.length == 13){ + }else if(status != 200 &&record.length == 13){ logger.info("can not get the activity from the web server"); } @@ -180,8 +182,22 @@ public class Benchmark { } } - private String getPreference(String[] record){ - return ""; - + private String comparePreferenceOutput(String[] record, String activity){ + String output = null; + String brightness=record[1]; + File file = new File(p_csv_file_path); + FileReader reader; + CSVReader csv_reader; + try{ + reader = new FileReader(file); + csv_reader=new CSVReader(reader); + String[] next_record; + while ((next_record = csv_reader.readNext())!= null){ + if (next_record[0].equals(activity) && next_record[1].equals(brightness)){ + output = next_record[2]+",100,"+next_record[3]; + } + } + }catch (Exception e){e.printStackTrace();} + return output; } } \ No newline at end of file