Commit c4aa8713 authored by Kerstin Bach's avatar Kerstin Bach

Added stress test for loading projects

parent 895b9e10
/*
* myCBR License 2.0
*
* Copyright (c) 2009
* Thomas Roth-Berghofer, Armin Stahl & Deutsches Forschungszentrum für Künstliche Intelligenz DFKI GmbH
* Further contributors: myCBR Team (see http://mycbr-project.net/contact.html for further information
* about the myCBR Team).
* All rights reserved.
*
* myCBR is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Since myCBR uses some modules, you should be aware of their licenses for
* which you should have received a copy along with this program, too.
*
* endOfLic */
package test.junittest;
import de.dfki.mycbr.core.DefaultCaseBase;
import de.dfki.mycbr.core.Project;
import de.dfki.mycbr.core.casebase.Instance;
import de.dfki.mycbr.core.model.*;
import de.dfki.mycbr.core.similarity.AmalgamationFct;
import de.dfki.mycbr.core.similarity.IntegerFct;
import de.dfki.mycbr.core.similarity.config.AmalgamationConfig;
import org.junit.Test;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* @author myCBR Team
*
*/
public class StressTestFramework {
public Project prj;
public AmalgamationFct amalgam;
public String initStressTestFramework(int attributes, int cases) throws Exception {
prj = new Project();
String projectName = "Test" + String.valueOf(attributes*cases);
prj.setName(projectName);
Concept mainDesc = prj.createTopConcept("main");
DefaultCaseBase cb = prj.createDefaultCB("casebase");
// creating the specified number of int attributes
for (int attr = 0; attr <= attributes; attr++){
IntegerDesc attDesc = new IntegerDesc(mainDesc, "attr"+String.valueOf(attr), 0, 100);
IntegerFct f = attDesc.addIntegerFct("f" + String.valueOf(attr), true);
f.setSymmetric(true);
f.setFunctionParameterR(0.60);
}
for (int caze = 0; caze <= cases; caze++){
String caseName = "case" + String.valueOf(caze);
// add Case
Instance i = mainDesc.addInstance(caseName);
for (String attName : mainDesc.getAttributeDescs().keySet()){
i.addAttribute(mainDesc.getAttributeDesc(attName), (int) (Math.random()*100));
}
cb.addCase(i);
}
amalgam = mainDesc.addAmalgamationFct(
AmalgamationConfig.EUCLIDEAN, "weightedSum", true);
prj.setPath((System.getProperty("user.dir") + "/src/test/projects/StressTest/tmp/"));
System.out.println("Path: " + prj.getPath());
prj.save();
// project path
return prj.getPath()+projectName+".prj";
}
}
/*
* myCBR License 2.0
*
* Copyright (c) 2009
* Thomas Roth-Berghofer, Armin Stahl & Deutsches Forschungszentrum f&uuml;r K&uuml;nstliche Intelligenz DFKI GmbH
* Further contributors: myCBR Team (see http://mycbr-project.net/contact.html for further information
* about the myCBR Team).
* All rights reserved.
*
* myCBR is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Since myCBR uses some modules, you should be aware of their licenses for
* which you should have received a copy along with this program, too.
*
* endOfLic */
package test.junittest;
import de.dfki.mycbr.core.Project;
import org.junit.Test;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* Runs all jUnit tests
*
* @author myCBR Team
*/
public class StressTests {
// @Test
public void testIncreasingAttributesOnly (){
int cases = 5;
SimpleDateFormat dateFormat = new SimpleDateFormat();
dateFormat.applyPattern("h:mm:ss");
FileWriter fw = null;
try {
fw = new FileWriter(System.getProperty("user.dir") + "/src/test/projects/StressTest/testIncreasingAttributesOnly.csv");
PrintWriter pw = new PrintWriter(fw);
pw.print("noAtts");
pw.print(",");
pw.print("noCases");
pw.print(",");
pw.print("duration");
pw.print("\n");
for (int noAtts = 1 ; noAtts <= 1000 ; noAtts++){
Long duration = loadProject(noAtts,cases);
double dur = ((double) duration) / 1000;
DecimalFormat decFormat = new DecimalFormat("###,###,##0.000");
decFormat.format(dur);
pw.print(noAtts);
pw.print(",");
pw.print(cases);
pw.print(",");
pw.print(dur);
pw.print("\n");
}
pw.flush();
pw.close();
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
@Test
public void testIncreasingCasesOnly (){
int noAtts = 5;
SimpleDateFormat dateFormat = new SimpleDateFormat();
dateFormat.applyPattern("h:mm:ss");
FileWriter fw = null;
try {
fw = new FileWriter(System.getProperty("user.dir") + "/src/test/projects/StressTest/testIncreasingCasesOnly.csv");
PrintWriter pw = new PrintWriter(fw);
pw.print("noAtts");
pw.print(",");
pw.print("noCases");
pw.print(",");
pw.print("duration");
pw.print("\n");
for (int cases = 1 ; cases <= 1000 ; cases++){
Long duration = loadProject(noAtts,cases);
double dur = ((double) duration) / 1000;
DecimalFormat decFormat = new DecimalFormat("###,###,##0.000");
decFormat.format(dur);
pw.print(noAtts);
pw.print(",");
pw.print(cases);
pw.print(",");
pw.print(dur);
pw.print("\n");
}
pw.flush();
pw.close();
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
// Attributes grow exponentially
// @Test
public void testIncreasingCasesAndAttributes (){
int noAtts = 4;
int cases = 50;
SimpleDateFormat dateFormat = new SimpleDateFormat();
dateFormat.applyPattern("h:mm:ss");
FileWriter fw = null;
try {
fw = new FileWriter(System.getProperty("user.dir") + "/src/test/projects/StressTest/testIncreasingCasesAndAttributes.csv");
PrintWriter pw = new PrintWriter(fw);
pw.print("noAtts");
pw.print(",");
pw.print("noCases");
pw.print(",");
pw.print("duration");
pw.print("\n");
do{
Long duration = loadProject(noAtts,cases);
double dur = ((double) duration) / 1000;
DecimalFormat decFormat = new DecimalFormat("###,###,##0.000");
decFormat.format(dur);
pw.print(noAtts);
pw.print(",");
pw.print(cases);
pw.print(",");
pw.print(dur);
pw.print("\n");
noAtts = noAtts + Math.abs(noAtts / 4);
cases = cases + Math.abs(cases/2);;
} while (cases < 20000 && noAtts < 150);
pw.flush();
pw.close();
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
// Attributes grow exponentially
// @Test
public void testIncreasingAttributesAndCases (){
int cases = 4;
int noAtts = 50;
SimpleDateFormat dateFormat = new SimpleDateFormat();
dateFormat.applyPattern("h:mm:ss");
FileWriter fw = null;
try {
fw = new FileWriter(System.getProperty("user.dir") + "/src/test/projects/StressTest/testIncreasingAttributesAndCases.csv");
PrintWriter pw = new PrintWriter(fw);
pw.print("noAtts");
pw.print(",");
pw.print("noCases");
pw.print(",");
pw.print("duration");
pw.print("\n");
do{
Long duration = loadProject(noAtts,cases);
double dur = ((double) duration) / 1000;
DecimalFormat decFormat = new DecimalFormat("###,###,##0.000");
decFormat.format(dur);
pw.print(noAtts);
pw.print(",");
pw.print(cases);
pw.print(",");
pw.print(dur);
pw.print("\n");
cases = cases + Math.abs(cases/4);
noAtts = noAtts + Math.abs(noAtts/2);;
} while (noAtts < 20000 && cases < 150);
pw.flush();
pw.close();
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public long loadProject(int noOfAttributes, int noOfCases) {
long duration = 0L;
try {
StressTestFramework stf = new StressTestFramework();
String projectPath = stf.initStressTestFramework(noOfAttributes, noOfCases);
Date start = new Date();
Project p = new Project(projectPath);
while (p.isImporting()){
Thread.sleep(1);
}
Date end = new Date();
duration = end.getTime() - start.getTime();
} catch (Exception e) {
e.printStackTrace();
}
return duration;
}
}
......@@ -28,19 +28,24 @@
package test.junittest.load;
import de.dfki.mycbr.core.Project;
import junit.framework.TestCase;
import org.junit.Test;
/**
* tests the import functionality of XML files generated by myCBR v2.6.4 to < v3.0
*
* @author myCBR Team
*
*/
public class Test5000 {
public static void main(String args[]) {
public class Test5000 extends TestCase{
@Test
public void load5000() {
try {
new Project("/data/workspace/mycbr/samples/Used Cars (flat)/used_cars_flat5000_CBR_SMF.zip");
Project p = new Project(System.getProperty("user.dir") + "/src/test/projects/StressTest/test30000.prj");
assertTrue(p.hasCB("class") == true);
} catch (Exception e) {
} catch (Exception e) {
e.printStackTrace();
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment