Skip to content
Snippets Groups Projects
Commit 30d19e5c authored by BBQ's avatar BBQ
Browse files

add preference checking for benchmark

parent 9274f92d
No related branches found
No related tags found
1 merge request!19dev to master
......@@ -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;
}
}
......@@ -131,7 +134,8 @@ public class Benchmark {
.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{
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment