Changeset 3659


Ignore:
Timestamp:
Aug 13, 2007, 12:55:26 PM (16 years ago)
Author:
Nicklas Nordborg
Message:

References #294: Performance testing

Added framework for testing BASE 2 plug-ins.

Location:
trunk
Files:
10 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/test/net/sf/basedb/test/FileUtil.java

    r2938 r3659  
    4141
    4242  /**
    43     Upload a file to the logged in user's home directory.
     43    Upload a file to the logged in user's home directory, or into the root
     44    directory if the user has no home directory.
    4445  */
    4546  public static File uploadFile(DbControl dc, String filename, String fileTypeId)
     
    5657      file.setFileType(FileType.getById(dc, SystemItems.getId(fileTypeId)));
    5758    }
    58     if (!file.isInDatabase()) dc.saveItem(file);
    59    
    60     file.upload(TestUtil.class.getResourceAsStream(path), false);
     59    if (!file.isInDatabase())
     60    {
     61      dc.saveItem(file);
     62      file.upload(TestUtil.class.getResourceAsStream(path), false);
     63    }
    6164    return file;
    6265  }
  • trunk/src/test/net/sf/basedb/test/PluginUtil.java

    r2938 r3659  
    5757{
    5858
     59  /**
     60    Create a new or load the existing plug-in configuration with a given name. Note!
     61    If the configuration already exists, the parameters are not updated.
     62  */
    5963  public static PluginConfiguration createPluginConfiguration(DbControl dc, String name, String className, Map<String, Object> parameters)
    6064  {
    6165    TestUtil.write("--Creating/loading plugin configuration: " + name + "\n");
    6266   
    63     ItemQuery<PluginConfiguration> query = PluginConfiguration.getQuery();
     67    PluginDefinition definition = PluginDefinition.getByClassName(dc, className);
     68    ItemQuery<PluginConfiguration> query = definition.getPluginConfigurations();
    6469    query.restrict(Restrictions.eq(Hql.property("name"), Expressions.string(name)));
    6570    List<PluginConfiguration> result = query.list(dc);
    6671    if (result.size() > 0) return result.get(0);
    6772   
    68     PluginDefinition definition = PluginDefinition.getByClassName(dc, className);
    6973    PluginConfiguration config = PluginConfiguration.getNew(dc, definition);
    7074    config.setName(name);
     
    98102  /**
    99103    Import reporters.
     104    @param jobName The name of the job
    100105  */
    101   public static void importReporters(PluginConfiguration config, File file)
     106  public static void importReporters(PluginConfiguration config, File file, String jobName)
    102107    throws Exception
    103108  {
     
    109114      config = PluginConfiguration.getById(dc, config.getId());
    110115      Job job = Job.getNew(dc, config.getPluginDefinition(), config);
    111       job.setName("Importing reporters for project A");
     116      job.setName(jobName);
    112117      job.setParameterValue("file", new FileParameterType(), file);
    113118      job.setParameterValue("updateExisting", new BooleanParameterType(), true);
  • trunk/src/test/net/sf/basedb/test/performance/RawDataTest.java

    r2938 r3659  
    2424package net.sf.basedb.test.performance;
    2525
    26 
    27 import java.util.List;
    28 
    2926import net.sf.basedb.core.ArrayDesign;
    3027import net.sf.basedb.core.DbControl;
     28import net.sf.basedb.core.Experiment;
    3129import net.sf.basedb.core.File;
    3230import net.sf.basedb.core.FileParameterType;
    33 import net.sf.basedb.core.FileType;
    3431import net.sf.basedb.core.ItemParameterType;
    35 import net.sf.basedb.core.ItemQuery;
    3632import net.sf.basedb.core.Job;
    3733import net.sf.basedb.core.PluginConfiguration;
     
    3935import net.sf.basedb.core.RawDataTypes;
    4036import net.sf.basedb.core.StringParameterType;
    41 import net.sf.basedb.core.query.Expressions;
    42 import net.sf.basedb.core.query.Hql;
    43 import net.sf.basedb.core.query.Restrictions;
    44 import net.sf.basedb.test.FileUtil;
    45 import net.sf.basedb.test.MouseData;
    4637import net.sf.basedb.test.PluginUtil;
    4738import net.sf.basedb.test.TestUtil;
     39import net.sf.basedb.util.Values;
    4840
    4941/**
    50 
     42  Import raw data.
    5143
    5244  @author nicklas
     
    7062      TestUtil.login(user, password, false);
    7163
    72       // Create importers
    73       dc = TestUtil.getDbControl();
    74       // Importer for reporters
    75       PluginConfiguration reporterImporter = PluginUtil.createPluginConfiguration(dc,
    76         "Reporters for performance test",
    77         "net.sf.basedb.plugins.ReporterFlatFileImporter", MouseData.getReporterParameters());
    78      
    79       // Importer for raw data
    80       PluginConfiguration rawDataImporter = PluginUtil.createPluginConfiguration(dc,
    81         "Raw data for performance test",
    82         "net.sf.basedb.plugins.RawDataFlatFileImporter", MouseData.getGenePixRawDataParameters(false));
    83      
    84       // Importer for features
    85       PluginConfiguration genePixFeatureImporter = PluginUtil.createPluginConfiguration(dc,
    86         "Features from GenePix file",
    87         "net.sf.basedb.plugins.ReporterMapFlatFileImporter", MouseData.getGenePixReporterMapParameters());
    88       dc.commit();
    89      
    90       // Upload files
    91       dc = TestUtil.getDbControl();
    92       File reporters = FileUtil.uploadFile(dc, "plates_and_reporters.mouse.v4.37k.txt", FileType.REPORTER);
    93       File rawData1 = FileUtil.uploadFile(dc, "genepix.mouse.v4.37k.00h.gpr", FileType.RAW_DATA);
    94       File rawData2 = FileUtil.uploadFile(dc, "genepix.mouse.v4.37k.24h.gpr", FileType.RAW_DATA);
    95       dc.commit();
    96      
    97       // Import reporters
    98       PluginUtil.importReporters(reporterImporter, reporters);
    99      
    100       // Create array design
    101       dc = TestUtil.getDbControl();
    102       ArrayDesign design = createArrayDesign(dc, "Array design for performance test");
    103       dc.commit();
    104      
    105       // Import features
    106       if (!design.hasFeatures())
    107       {
    108         importFeatures(genePixFeatureImporter, rawData1, design);
    109       }
    110      
    11164      // Create raw bioassays
    11265      dc = TestUtil.getDbControl();
     66     
     67      // Load prepared items
     68      ArrayDesign design = PrepareTest.getArrayDesign(dc);
     69      Experiment experiment = PrepareTest.getExperiment(dc);
     70      PluginConfiguration rawDataImporter = PrepareTest.getRawDataImporter(dc);
     71      File rawData1 = PrepareTest.getRawDataFile1(dc);
     72      File rawData2 = PrepareTest.getRawDataFile2(dc);
     73     
     74      long startNum = experiment.getRawBioAssays().count(dc);
    11375      RawBioAssay[] rba = new RawBioAssay[numIterations];
    11476      for (int i = 0; i < numIterations; ++i)
    11577      {
    116         rba[i] = createRawBioAssay(dc, "Performance test #" + i, design);
     78        rba[i] = createRawBioAssay(dc, "PerformanceTest #" + (startNum + i), design);
    11779      }
    11880      dc.commit();
    11981     
    12082      // Import raw data
     83      long minTime = Long.MAX_VALUE;
     84      long maxTime = 0;
     85      long totalTime = 0;
    12186      for (int i = 0; i < numIterations; i += 2)
    12287      {
    12388        TestUtil.gc();
    12489        long time = importRawData(rawDataImporter, rawData1, rba[i]) / 1000;
    125         TestUtil.write("Import #" + i + "\t" + time + " s\n");
     90        totalTime += time;
     91        if (time < minTime) minTime = time;
     92        if (time > maxTime) maxTime = time;
     93        TestUtil.write("Import #" + i + "\t" + Values.formatTime(time) + "\n");
     94
    12695        time = importRawData(rawDataImporter, rawData2, rba[i+1]) / 1000;
    127         TestUtil.write("Import #" + (i + 1) + "\t" + time + " s\n");
     96        totalTime += time;
     97        if (time < minTime) minTime = time;
     98        if (time > maxTime) maxTime = time;
     99        TestUtil.write("Import #" + (i + 1) + "\t" + Values.formatTime(time) + " s\n");
    128100      }
     101      TestUtil.write("---------------------------------------------\n");
     102      TestUtil.write("Imported " + numIterations + " raw data sets\n");
     103      TestUtil.write("Max time: " + Values.formatTime(maxTime) + "\n");
     104      TestUtil.write("Min time: " + Values.formatTime(minTime) + "\n");
     105      TestUtil.write("Mean time: " + Values.formatTime(totalTime / numIterations) + "\n");
     106      TestUtil.write("---------------------------------------------\n");
     107     
     108      // Add raw bioassays to experiment
     109      dc = TestUtil.getDbControl();
     110      dc.reattachItem(experiment);
     111      for (int i = 0; i < numIterations; i++)
     112      {
     113        dc.refreshItem(rba[i]);
     114        experiment.addRawBioAssay(rba[i]);
     115      }
     116      dc.commit();
    129117     
    130118      TestUtil.logout();
     
    141129    TestUtil.write("++Leaving raw data test (" + (ok ? "OK" : "FAILED") + ")\n");
    142130    return ok;
    143   }
    144 
    145   /**
    146     Create an array design or load the existing one.
    147   */
    148   public static ArrayDesign createArrayDesign(DbControl dc, String name)
    149   {
    150     TestUtil.write("--Creating/loading array design: " + name + "\n");
    151 
    152     ItemQuery<ArrayDesign> query = ArrayDesign.getQuery();
    153     query.restrict(Restrictions.eq(Hql.property("name"), Expressions.string(name)));
    154     List<ArrayDesign> result = query.list(dc);
    155     if (result.size() > 0) return result.get(0);
    156     ArrayDesign design = ArrayDesign.getNew(dc, false);
    157     design.setName(name);
    158     dc.saveItem(design);
    159     return design;
    160   }
    161 
    162   /**
    163     Import features.
    164   */
    165   public static void importFeatures(PluginConfiguration plugin, File file, ArrayDesign design)
    166     throws Exception
    167   {
    168     TestUtil.write("--Importing features from file: " + file.getName() + "\n");
    169     DbControl dc = TestUtil.getDbControl();
    170     try
    171     {
    172       plugin = PluginConfiguration.getById(dc, plugin.getId());
    173       Job job = Job.getNew(dc, plugin.getPluginDefinition(), plugin);
    174       job.setName("Importing features to array design: " + design.getName());
    175       job.setParameterValue("file", new FileParameterType(), file);
    176       job.setParameterValue("arrayDesign",
    177         new ItemParameterType<ArrayDesign>(ArrayDesign.class, null), design);
    178       job.setParameterValue("missingReporterError", new StringParameterType(), "skip");
    179       dc.saveItem(job);
    180       dc.commit();
    181       PluginUtil.executeJob(job);
    182     }
    183     finally
    184     {
    185       if (dc != null) dc.close();
    186     }
    187131  }
    188132
     
    212156      config = PluginConfiguration.getById(dc, config.getId());
    213157      Job job = Job.getNew(dc, config.getPluginDefinition(), config);
    214       job.setName("Importing data to raw bioassay: " + rba.getName());
     158      job.setName("PerformanceTest: Import data to raw bioassay: " + rba.getName());
     159      job.setSendMessage(false);
     160      job.setRemoveJobWhenFinished(true);
    215161      job.setParameterValue("file", new FileParameterType(), file);
    216162      job.setParameterValue("rawBioAssay",
     
    222168      long time = System.currentTimeMillis();
    223169      PluginUtil.executeJob(job);
    224       return System.currentTimeMillis() - time;
     170      return  System.currentTimeMillis() - time;
    225171    }
    226172    finally
  • trunk/src/test/net/sf/basedb/test/performance/Run.java

    r2938 r3659  
    2424package net.sf.basedb.test.performance;
    2525
     26import java.util.Arrays;
     27import java.util.HashSet;
     28import java.util.Set;
     29
    2630import net.sf.basedb.test.CmdLine;
    2731import net.sf.basedb.test.TestUtil;
     
    4246    CmdLine cmdLine = new CmdLine(args);
    4347
    44     String cmd = cmdLine.getCmd();
    45     boolean all = "all".equals(cmd);
     48    Set<String> cmds = new HashSet<String>(Arrays.asList(args));
     49    boolean all = cmds.contains("all");
    4650   
    4751    String user = cmdLine.getOption("-u", "root");
    4852    String password = cmdLine.getOption("-p", "root");
    49     int numIterations = Values.getInt(cmdLine.getOption("-n"), 100);
     53    int numItems = Values.getInt(cmdLine.getOption("-n"), 4);
    5054
    5155    int tests = 0;
    52     boolean ok = true;
    53     if (ok && (all || "raw".equals(cmd)))
     56    TestUtil.begin(false);
     57    boolean ok = PrepareTest.run(user, password);
     58    if (ok && (all || cmds.contains("raw")))
    5459    {
    55       TestUtil.begin(false);
    56       ok = RawDataTest.run(user, password, numIterations);
     60      ok = RawDataTest.run(user, password, numItems);
     61      tests++;
     62    }
     63    if (ok && (all || cmds.contains("root")))
     64    {
     65      ok = RootTest.run(user, password, numItems);
     66      tests++;
     67    }
     68    if (ok && (all || cmds.contains("filter")))
     69    {
     70      ok = FilterTest.run(user, password);
     71      tests++;
     72    }
     73    if (ok && (all || cmds.contains("lowess")))
     74    {
     75      ok = LowessTest.run(user, password);
     76      tests++;
     77    }
     78    if (ok && cmds.contains("clean"))
     79    {
     80      ok = PrepareTest.cleanUp(user, password);
    5781      tests++;
    5882    }
  • trunk/src/test/net/sf/basedb/test/roles/PowerUserTest.java

    r2981 r3659  
    160160      dc.commit();
    161161     
    162       PluginUtil.importReporters(reporterImporter, reporters);
     162      PluginUtil.importReporters(reporterImporter, reporters, "Importing reporters for project A");
    163163      importPlates(platesImporter, plates, "Plate A", plateType);
    164164     
  • trunk/src/test/set_classpath.bat

    r3510 r3659  
    2727SET CP=%CP%;../../config/local
    2828SET CP=%CP%;../../config/dist
     29SET CP=%CP%;../../config/test
    2930
    3031REM Testdata
  • trunk/src/test/set_classpath.sh

    r3510 r3659  
    2727CP=$CP:../../config/local
    2828CP=$CP:../../config/dist
     29CP=$CP:../../config/test
    2930
    3031# Testdata
Note: See TracChangeset for help on using the changeset viewer.