Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Fix test case
  • Loading branch information
fangyiwang committed May 22, 2017
1 parent 4223cbe commit 322119d9884ebf49678c0ed307e946c8c05ebc9e
Showing 2 changed files with 43 additions and 22 deletions.
@@ -19,18 +19,20 @@
public class MetricsCollector
{
private Timer getMetricSnapshotTimer = null;
private long intervalInMin;
private long intervalInMilli;
private String hostname;
private String dirName;

public MetricsCollector (long intervalInMin, String hostname) {
this.intervalInMin = intervalInMin;
public MetricsCollector (long intervalInMilli, String hostname, String dirName) {
this.intervalInMilli = intervalInMilli;
this.hostname = hostname;
this.dirName = dirName;
getMetricSnapshotTimer = new Timer ("GetMetricSnapshot", true);
}

public void start () {
if (getMetricSnapshotTimer != null)
getMetricSnapshotTimer.schedule (new GetMetricSnapshotTimerTask (hostname, intervalInMin), 0, intervalInMin);
getMetricSnapshotTimer.schedule (new GetMetricSnapshotTimerTask (hostname, intervalInMilli, dirName), 0, intervalInMilli);
}

public void cancel ()
@@ -44,16 +46,18 @@ class GetMetricSnapshotTimerTask extends TimerTask
private String hostname = null;
private BufferedWriter bufferedWriter = null;
private long intervalInMilli;
private String dirName;

/**
* Normalize the timestamp in time series data to use seconds
*/
private final static int XSCALE = 1000;

GetMetricSnapshotTimerTask (String hostname, long intervalInMin)
GetMetricSnapshotTimerTask (String hostname, long intervalInMilli, String dirName)
{
this.hostname = hostname;
this.intervalInMilli = intervalInMin * 60 * 1000;
this.intervalInMilli = intervalInMilli;
this.dirName = dirName;
}

public void run ()
@@ -102,7 +106,7 @@ private void getHadoopMetrics(long startTime, long endTime) throws Exception

private void generateCsv (List list, String name, long startTime, BufferedWriter bufferedWriter) throws Exception
{
String fileName = name + "_" + startTime;
String fileName = dirName + "/" + name + "_" + startTime;
PrintWriter writer = new PrintWriter(fileName + ".csv", "UTF-8");
int size = list.size ();
for (int i = 0; i < size; i++) {
@@ -21,11 +21,15 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import junit.framework.TestCase;

import org.apache.hadoop.chukwa.util.ExceptionUtil;


/**
* (1) Run non-stop terasort and teragen
* (2) Collect memory usage metrics from hbase every 5 minutes for 10 hours and write to csv files in /caffe-test/train/data
@@ -40,14 +44,28 @@ public class TestMemoryUsageDetection extends TestCase {
/**
* Run non-stop terasort and teragen to force memory leak
*/
public void setUp() {
new Thread(new Runnable() {
public void setUp() {}

public void tearDown() {}

public void testMemoryDetection () {
String dirName = "/caffe-test/train/data";
Thread teraSortThread = createTeraSortThread ();
ExecutorService executor = Executors.newFixedThreadPool(1);
Future<?> task = executor.submit(teraSortThread);
collectNodeManagerMetrics (dirName);
task.cancel (true);
executor.shutdown ();
caffeTrain (dirName);
}

private Thread createTeraSortThread () {
Thread teraSortThread = new Thread(new Runnable() {
public void run(){
try {
String target = new String("/caffe-test/tera/tera.sh");
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(target);
proc.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String line = "";
while ((line = reader.readLine())!= null) {
@@ -57,30 +75,29 @@ public void run(){
fail(ExceptionUtil.getStackTrace(e));
}
}
}).start();
});
return teraSortThread;
}

public void tearDown() {
}



/**
* Collect memory usage data every 15 min.
* Stop the timer after 10 hours
*/
public void testCollectNodeManagerMetrics() {
int intervalInMin = 15;
long timerElapseTime = 10 * 60 * 60 * 1000;
private void collectNodeManagerMetrics(String dirName) {
int intervalInMilli = 15 * 60 * 1000;
long timerDurationTime = 10 * 60 * 60 * 1000;
String hostname = "";
try {
hostname = InetAddress.getLocalHost().getHostName();
System.out.println (hostname);
} catch (IOException e) {
fail(ExceptionUtil.getStackTrace(e));
}
MetricsCollector collector = new MetricsCollector (intervalInMin, hostname);
MetricsCollector collector = new MetricsCollector (intervalInMilli, hostname, dirName);
collector.start ();
try {
Thread.sleep (timerElapseTime);
Thread.sleep (timerDurationTime);
} catch (InterruptedException e) {
}
collector.cancel ();
@@ -97,9 +114,9 @@ public void testCollectNodeManagerMetrics() {
/**
* Train the images
*/
public void testCaffeTrain () {
private void caffeTrain (String dirName) {
try {
String target = new String("/caffe-test/train/train.sh");
String target = new String(dirName);
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(target);
proc.waitFor();

0 comments on commit 322119d

Please sign in to comment.