Commit c262e047 authored by Kerstin Bach's avatar Kerstin Bach

Merge branch 'feature-test-loading-tax' into 'mycbr-3.0.1'

Feature Test Loading Tax

Added Performance Testing for Taxonomies

* Extended test harness including symbolic value ranges
* Added test that measures loading times for projects with taxonomies
parents d0af4ea7 c50b0f0d
......@@ -3,8 +3,8 @@
*
* 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).
* 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
......@@ -23,18 +23,23 @@
*
* 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 com.sun.deploy.util.ArrayUtil;
import de.dfki.mycbr.core.DefaultCaseBase;
import de.dfki.mycbr.core.Project;
import de.dfki.mycbr.core.casebase.Instance;
import de.dfki.mycbr.core.casebase.SymbolAttribute;
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.Similarity;
import de.dfki.mycbr.core.similarity.TaxonomyFct;
import de.dfki.mycbr.core.similarity.config.AmalgamationConfig;
import de.dfki.mycbr.core.similarity.config.TaxonomyConfig;
import org.junit.Test;
import java.text.ParseException;
......@@ -43,7 +48,7 @@ import java.util.*;
/**
* @author myCBR Team
*
*
*/
public class StressTestFramework {
......@@ -87,4 +92,71 @@ public class StressTestFramework {
// project path
return prj.getPath()+projectName+".prj";
}
public String initSymbolTestFramework(int attributes, int cases, int values, int sValues) throws Exception {
prj = new Project();
String projectName = "TestSymbol" + String.valueOf(attributes*values);
prj.setName(projectName);
Concept mainDesc = prj.createTopConcept("main");
DefaultCaseBase cb = prj.createDefaultCB("casebase");
HashSet<String> baseValues = new HashSet<>();
for (int i=0; i<=values; i++) {
baseValues.add("value-" + i);
}
HashSet<String> subValues = new HashSet<>();
for (int i=0; i<=sValues; i++) {
subValues.add("subvalue-" + i);
}
// contains all values
HashSet<String> valuesSet = new HashSet<String>();
valuesSet.addAll(baseValues);
valuesSet.addAll(subValues);
amalgam = mainDesc.addAmalgamationFct(AmalgamationConfig.EUCLIDEAN, "weightedSum", true);
// creating the specified number of int attributes
for (int attr = 0; attr <= attributes; attr++){
SymbolDesc valueDesc = new SymbolDesc(mainDesc, "valueDesc"+attr, valuesSet);
// creates taxonomy will all values
TaxonomyFct taxonomyFct = valueDesc.addTaxonomyFct("taxonomy"+attr, true);
for (int iColor = 0; iColor <= baseValues.size(); iColor++){
SymbolAttribute symbolAttribute = (SymbolAttribute) valueDesc.getSymbolAttributes().toArray()[iColor];
for (int iSubColor = 0; iSubColor <= subValues.size(); iSubColor++){
SymbolAttribute subsymbolAttribute = (SymbolAttribute) valueDesc.getSymbolAttributes().toArray()[iSubColor];
taxonomyFct.setNodeSimilarity(valueDesc, Similarity.get(0.5));
taxonomyFct.setParent(subsymbolAttribute, symbolAttribute);
taxonomyFct.setNodeSimilarity(symbolAttribute, Similarity.get(0.75));
}
}
taxonomyFct.setQueryConfig(TaxonomyConfig.INNER_NODES_ANY);
amalgam.setActiveFct(valueDesc, taxonomyFct);
}
// 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);
// }
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";
}
}
......@@ -29,26 +29,42 @@
package test.junittest;
import de.dfki.mycbr.core.Project;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* Runs all jUnit tests
* Runs Project Loading Stress Tests
*
* @author myCBR Team
*/
public class StressTestsLoading {
@After
public void removeTmp(){
try {
File directory = new File(System.getProperty("user.dir") + "/src/test/projects/StressTest/tmp");
File[] files = directory.listFiles();
for (File file : files) {
file.delete();
}
} catch (Exception e) {
e.printStackTrace();
}
}
// @Test
@Test
public void testIncreasingAttributesOnly (){
int cases = 5;
int maxAttributes = 100;
SimpleDateFormat dateFormat = new SimpleDateFormat();
dateFormat.applyPattern("h:mm:ss");
......@@ -65,7 +81,7 @@ public class StressTestsLoading {
pw.print("duration");
pw.print("\n");
for (int noAtts = 1 ; noAtts <= 1000 ; noAtts++){
for (int noAtts = 1 ; noAtts <= maxAttributes ; noAtts++){
Long duration = loadProject(noAtts,cases);
double dur = ((double) duration) / 1000;
......@@ -89,6 +105,7 @@ public class StressTestsLoading {
@Test
public void testIncreasingCasesOnly (){
int noAtts = 5;
int maxCases = 100;
SimpleDateFormat dateFormat = new SimpleDateFormat();
dateFormat.applyPattern("h:mm:ss");
......@@ -105,7 +122,7 @@ public class StressTestsLoading {
pw.print("duration");
pw.print("\n");
for (int cases = 1 ; cases <= 1000 ; cases++){
for (int cases = 1 ; cases <= maxCases ; cases++){
Long duration = loadProject(noAtts,cases);
double dur = ((double) duration) / 1000;
......@@ -121,16 +138,20 @@ public class StressTestsLoading {
pw.flush();
pw.close();
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
// Attributes grow exponentially
// @Test
@Test
public void testIncreasingCasesAndAttributes (){
int noAtts = 4;
int cases = 50;
int maxAtts = 50;
int maxCases = 200;
SimpleDateFormat dateFormat = new SimpleDateFormat();
dateFormat.applyPattern("h:mm:ss");
......@@ -161,7 +182,7 @@ public class StressTestsLoading {
pw.print("\n");
noAtts = noAtts + Math.abs(noAtts / 4);
cases = cases + Math.abs(cases/2);;
} while (cases < 20000 && noAtts < 150);
} while (cases < maxCases && noAtts < maxAtts);
pw.flush();
pw.close();
fw.close();
......@@ -171,10 +192,12 @@ public class StressTestsLoading {
}
// Attributes grow exponentially
// @Test
@Test
public void testIncreasingAttributesAndCases (){
int cases = 4;
int noAtts = 50;
int maxAtts = 200;
int maxCases = 50;
SimpleDateFormat dateFormat = new SimpleDateFormat();
dateFormat.applyPattern("h:mm:ss");
......@@ -205,7 +228,66 @@ public class StressTestsLoading {
pw.print("\n");
cases = cases + Math.abs(cases/4);
noAtts = noAtts + Math.abs(noAtts/2);;
} while (noAtts < 20000 && cases < 150);
} while (noAtts < maxAtts && cases < maxCases);
pw.flush();
pw.close();
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
// Attributes grow exponentially
@Test
public void testSymbolsIncreasingAttributesAndCases (){
int cases = 0;
int noAtts = 4;
int values = 10;
int subValues = 10;
int maxValues = 15;
int maxSubValues = 15;
int maxAtts = 100;
int maxCases = 0;
SimpleDateFormat dateFormat = new SimpleDateFormat();
dateFormat.applyPattern("h:mm:ss");
FileWriter fw = null;
try {
fw = new FileWriter(System.getProperty("user.dir") + "/src/test/projects/StressTest/testSymbolsIncreasingAttributesAndCases.csv");
PrintWriter pw = new PrintWriter(fw);
pw.print("noAtts");
pw.print(",");
pw.print("noCases");
pw.print(",");
pw.print("noValues");
pw.print(",");
pw.print("noSubValues");
pw.print(",");
pw.print("duration");
pw.print("\n");
do{
Long duration = loadSymbolsInProject(noAtts, cases, values, subValues);
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(values);
pw.print(",");
pw.print(subValues);
pw.print(",");
pw.print(dur);
pw.print("\n");
values++;
subValues++;
noAtts++;
} while (noAtts < maxAtts && values < maxValues && subValues < maxSubValues);
pw.flush();
pw.close();
fw.close();
......@@ -235,4 +317,25 @@ public class StressTestsLoading {
}
public long loadSymbolsInProject(int attributes, int cases, int values, int subValues) {
long duration = 0L;
try {
StressTestFramework stf = new StressTestFramework();
String projectPath = stf.initSymbolTestFramework(attributes, cases, values, subValues);
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;
}
}
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