Skip to content
Snippets Groups Projects

dev to master

Merged René Schöne requested to merge dev into master
284 files
+ 9133
6046
Compare changes
  • Side-by-side
  • Inline
Files
284
@@ -7,8 +7,11 @@ import org.apache.http.entity.ContentType;
@@ -7,8 +7,11 @@ import org.apache.http.entity.ContentType;
import org.apache.http.util.EntityUtils;
import org.apache.http.util.EntityUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Logger;
 
import java.io.File;
import java.io.File;
 
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileReader;
 
import java.io.IOException;
import java.util.Arrays;
import java.util.Arrays;
public class Benchmark {
public class Benchmark {
@@ -38,24 +41,17 @@ public class Benchmark {
@@ -38,24 +41,17 @@ public class Benchmark {
private static final Logger logger = LogManager.getLogger(Benchmark.class);
private static final Logger logger = LogManager.getLogger(Benchmark.class);
private static final String ERASER_ITEM_URI = "http://localhost:4567/model/items/";
private static final String ERASER_ITEM_URI = "http://localhost:4567/model/items/";
//TODO ITEM_NAME HAS TO BE DISCUSSED
//TODO ITEM_NAME HAS TO BE DISCUSSED
private static final String[] ACTIVITY_ITEM_NAME = {
private String[] ACTIVITY_ITEM_NAME;
"m_accel_x", "m_accel_y", "m_accel_z", "m_rotation_x",
private String[] PREFERENCE_ITEM_NAME;
"m_rotation_y", "m_rotation_z", "w_accel_x", "w_accel_y",
"w_accel_z", "w_rotation_x", "w_rotation_y", "w_rotation_z"};
private static final String[] PREFERENCE_ITEM_NAME = {
"w_brightness"
};
private static boolean flag2 = true;
//csv_type is activity or preference
//csv_type is activity or preference
Benchmark(String a_csv_file_path, String p_csv_file_path) {
Benchmark(String a_csv_file_path, String p_csv_file_path) {
this.a_csv_file_path = a_csv_file_path;
this.a_csv_file_path = a_csv_file_path;
this.p_csv_file_path = p_csv_file_path;
this.p_csv_file_path = p_csv_file_path;
}
}
void start(){
void start(){
 
int TIME_PERIOD = 1000;
String PREFERENCE_URL = "http://localhost:4567/model/items/iris1_item/state";
String PREFERENCE_URL = "http://localhost:4567/model/items/iris1_item/state";
String ACTIVITY_URL = "http://localhost:4567/activity/current";
String ACTIVITY_URL = "http://localhost:4567/activity/current";
int TIME_PERIOD = 5000;
File a_file;
File a_file;
File p_file;
File p_file;
FileReader a_file_reader;
FileReader a_file_reader;
@@ -64,7 +60,6 @@ public class Benchmark {
@@ -64,7 +60,6 @@ public class Benchmark {
CSVReader p_csv_reader;
CSVReader p_csv_reader;
String[] a_next_record;
String[] a_next_record;
String[] p_next_record;
String[] p_next_record;
boolean flag1;
a_file=new File(a_csv_file_path);
a_file=new File(a_csv_file_path);
p_file= new File(p_csv_file_path);
p_file= new File(p_csv_file_path);
try {
try {
@@ -72,41 +67,45 @@ public class Benchmark {
@@ -72,41 +67,45 @@ public class Benchmark {
p_file_reader=new FileReader(p_file);
p_file_reader=new FileReader(p_file);
a_csv_reader = new CSVReader(a_file_reader);
a_csv_reader = new CSVReader(a_file_reader);
p_csv_reader = new CSVReader(p_file_reader);
p_csv_reader = new CSVReader(p_file_reader);
while ((((a_next_record = a_csv_reader.readNext())!= null) && flag2)){
int i = 0;
try{Thread.sleep(TIME_PERIOD);}catch (InterruptedException e){e.printStackTrace();}
while ((a_next_record = a_csv_reader.readNext())!= null){
String[] values = Arrays.copyOf(a_next_record,12);
if( i==0 ){
setNewValue(values, ACTIVITY_ITEM_NAME,"activity");
getCSVHeader(Arrays.copyOf(a_next_record,12),"a");
HttpResponse response= Request.Get(ACTIVITY_URL).execute().returnResponse();
i++;
String status = response.getStatusLine().toString();
if(status.contains("200")){
flag1 = true;
logger.info("activity should be (read direct from CSV): " + a_next_record[12]);
logger.info(EntityUtils.toString(response.getEntity()));
logger.info("get activity from web server: response 200 ok");
}else{
flag1 = false;
flag2 = false;
logger.info("can not get the activity from the web server");
}
}
while((((p_next_record = p_csv_reader.readNext()) != null) && flag1)) {
else{
try{Thread.sleep(TIME_PERIOD);}catch (InterruptedException e){e.printStackTrace();}
String[] values = Arrays.copyOf(a_next_record,12);
String[] values1 = Arrays.copyOf(p_next_record,2);
setNewValue(values, ACTIVITY_ITEM_NAME,"activity");
setNewValue(values1, PREFERENCE_ITEM_NAME,"preference");
int j = 0;
HttpResponse response1= Request.Get(PREFERENCE_URL).execute().returnResponse();
while(((p_next_record = p_csv_reader.readNext()) != null)) {
String status1=response1.getStatusLine().toString();
if( j == 0 ){
if(status1.contains("200")){
getCSVHeader(Arrays.copyOf(p_next_record,2),"p");
flag2 = true;
j++;
logger.info("get the iris1_item preference from web server: response 200 ok, value is: "+EntityUtils.toString(response1.getEntity()));
}else{
}else {flag2 = false;
String[] values1 = Arrays.copyOf(p_next_record,2);
logger.info("can not get the iris1_item from the web server");}
setNewValue(values1, PREFERENCE_ITEM_NAME,"preference");
break;
// 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,null);
 
checkResult(response1, p_next_record,a_next_record[12]);
 
logger.warn("checking/comparing finised");
 
//logger.info("checking/comparing finished");
 
break;
 
}
 
}
}
}
 
}
}
}
}
catch (Exception e){
catch (Exception e){
e.printStackTrace();
e.printStackTrace();
}
}
}
}
 
private void setNewValue(String[] values, String[] name, String file_typ){
private void setNewValue(String[] values, String[] name, String file_typ){
if(file_typ.equals("activity"))
if(file_typ.equals("activity"))
{
{
@@ -119,7 +118,7 @@ public class Benchmark {
@@ -119,7 +118,7 @@ public class Benchmark {
.execute().returnResponse();
.execute().returnResponse();
String status=httpResponse.getStatusLine().toString();
String status=httpResponse.getStatusLine().toString();
if(status.contains("200")){
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{
}else{
logger.info("can not put activity inputs to rest server");
logger.info("can not put activity inputs to rest server");
}
}
@@ -134,13 +133,71 @@ public class Benchmark {
@@ -134,13 +133,71 @@ public class Benchmark {
HttpResponse httpResponse = Request.Put(uri)
HttpResponse httpResponse = Request.Put(uri)
.bodyString(values[1], ContentType.TEXT_PLAIN)
.bodyString(values[1], ContentType.TEXT_PLAIN)
.execute().returnResponse();
.execute().returnResponse();
String put_response=httpResponse.getStatusLine().toString();
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");
logger.info("can not put w_brightness to rest server");
}
}
}catch (Exception e){
}catch (Exception e){
e.printStackTrace();
e.printStackTrace();
}
}
}
}
 
 
}
 
 
private void getCSVHeader(String[] a_values,String csv_typ){
 
if (csv_typ.equals("a")){
 
ACTIVITY_ITEM_NAME = a_values;
 
}else{
 
PREFERENCE_ITEM_NAME = a_values;
 
}
 
}
 
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("get activity from web server: response 200 ok, value is: "+
 
EntityUtils.toString(response.getEntity()));
 
}catch (IOException e){
 
e.printStackTrace();
 
}
 
}else if(status ==200 && record.length == 4){
 
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()));
 
}catch (IOException e){
 
e.printStackTrace();
 
}
 
 
}else if(status != 200 &&record.length == 13){
 
logger.info("can not get the activity from the web server");
 
 
}
 
else if(status != 200 && record.length == 4){
 
logger.info("can not get the iris1_item from the web server");
 
}else {
 
logger.info("unknown check");
 
}
 
}
 
 
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
Loading