Added FTP Upload behaviour.

Added some static buffer sizes
This commit is contained in:
Ziver Koc 2014-08-07 16:20:01 +02:00
parent e066e4431b
commit ffe6425906
6 changed files with 108 additions and 12 deletions

Binary file not shown.

View file

@ -8,8 +8,8 @@ android {
applicationId "com.ericsson.uecontrol"
minSdkVersion 15
targetSdkVersion 19
versionCode 12
versionName "1.0.12"
versionCode 15
versionName "1.0.15"
}
buildTypes {
release {

View file

@ -16,6 +16,7 @@ import java.net.URLConnection;
* Created by ezivkoc on 2014-07-15.
*/
public class UeBehaviourFileDownload extends UeBehaviour {
private static final int BUFFER_SIZE = 512;
private static final Logger log = Logger.getLogger(UeBehaviourFileDownload.class);
@Configurable("File address")
@ -27,7 +28,7 @@ public class UeBehaviourFileDownload extends UeBehaviour {
URL url = new URL(getFileUrl());
log.debug("Downloading file: " + url);
byte[] data = new byte[100];
byte[] data = new byte[BUFFER_SIZE];
URLConnection connection = url.openConnection();
connection.setUseCaches(false);
connection.connect();

View file

@ -0,0 +1,86 @@
package com.ericsson.uecontrol.core.behaviour;
import com.ericsson.uecontrol.core.UeBehaviour;
import com.ericsson.uecontrol.core.util.ThroughputCalculator;
import com.ericsson.uecontrol.gui.util.Configurator.Configurable;
import org.apache.log4j.Logger;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
/**
* This behaviour simulates downloading a file from FTP
*
* Created by ezivkoc on 2014-07-15.
*/
public class UeBehaviourFtpUpload extends UeBehaviour {
private static final int BUFFER_SIZE = 512;
private static final Logger log = Logger.getLogger(UeBehaviourFtpUpload.class);
@Configurable("Host")
private String host;
@Configurable("File Path")
private String filePath;
@Configurable("Username")
private String username;
@Configurable("Password")
private String password;
@Configurable("File Size(Bytes)")
private int size;
@Override
protected void execute() throws IOException {
URL url = new URL(getFileUrl());
log.debug("Uploading file: " + url);
byte[] data = new byte[BUFFER_SIZE];
URLConnection connection = url.openConnection();
connection.connect();
OutputStream out = connection.getOutputStream();
int total = 0;
while(total < size && !stopExecution()){
int writeLength = (total+data.length < size ? data.length : total+data.length-size);
out.write(data, 0, writeLength);
total += writeLength;
super.setHandledOutgoingData(writeLength);
super.setProgress((float)total/size);
}
out.close();
}
protected String getFileUrl() {
String url = "ftp://";
if(username != null && !username.isEmpty()) {
url += username;
if(password !=null && !password.isEmpty())
url += ":"+password;
url += "@";
}
url += host;
if(filePath != null && !filePath.isEmpty()){
if(!filePath.startsWith("/"))
filePath = "/"+filePath;
url += filePath;
}
return url;
}
@Override
public String getName() {
return "FTP Upload";
}
@Override
public String toString() {
return "Will upload a "+ ThroughputCalculator.getByteString(size) +" file.";
}
}

View file

@ -25,8 +25,9 @@ import java.util.regex.Pattern;
* Created by ezivkoc on 2014-07-15.
*/
public class UeBehaviourSurfing extends UeBehaviour {
private static final Logger log = Logger.getLogger(UeBehaviourSurfing.class);
private static final int BUFFER_SIZE = 512;
protected static final int MAX_BUFFER_SIZE = 500000;
private static final Logger log = Logger.getLogger(UeBehaviourSurfing.class);
@Configurable("Web Address")
private String rootUrl = "http://www.ericsson.com";
@ -67,7 +68,7 @@ public class UeBehaviourSurfing extends UeBehaviour {
List<URLContainer> urlList = new ArrayList<URLContainer>();
urlList.add(new URLContainer(new URL(rootUrl), true));
byte[] data = new byte[100];
byte[] data = new byte[BUFFER_SIZE];
IOException retException = null;
long totalRead = 0;

View file

@ -38,16 +38,24 @@ public class ThroughputCalculator {
}
private static final String[] DATA_SIZE = new String[]{"b/s", "kbit/s", "Mbit/s", "Gbit/s", "Tbit/s"};
public static String getBitThroughputString(double bitsPerSec){
int index = 0;
double value = bitsPerSec;
for(; value > 1000 && index < DATA_SIZE.length-1 ;index++) {
value /= 1000;
private static final String[] BIT_DATA_SIZE = new String[]{"b", "kbit", "Mbit", "Gbit", "Tbit"};
public static String getBitThroughputString(double bitsPerSec){
return getSizeString(bitsPerSec, 1000, BIT_DATA_SIZE) +"/s";
}
private static final String[] BYTE_DATA_SIZE = new String[]{"B", "KB", "MB", "GB", "TB"};
public static String getByteString(double value){
return getSizeString(value, 1024, BYTE_DATA_SIZE);
}
private static String getSizeString(double value, int division, String[] sizeList){
int index = 0;
for(; value > division && index < sizeList.length-1 ;index++) {
value /= division;
}
value = (int)(value*10) / 10.0;
return value+" "+DATA_SIZE[index];
return value+" "+ sizeList[index];
}
}