[Mulgara-svn] r1153 - trunk/src/jar/store-stringpool/java/org/mulgara/store/stringpool

pag at mulgara.org pag at mulgara.org
Sat Aug 23 01:32:19 UTC 2008


Author: pag
Date: 2008-08-22 18:32:19 -0700 (Fri, 22 Aug 2008)
New Revision: 1153

Modified:
   trunk/src/jar/store-stringpool/java/org/mulgara/store/stringpool/StringPoolLoadTest.java
Log:
Removed warnings on generics for collections, and cleaned up formatting

Modified: trunk/src/jar/store-stringpool/java/org/mulgara/store/stringpool/StringPoolLoadTest.java
===================================================================
--- trunk/src/jar/store-stringpool/java/org/mulgara/store/stringpool/StringPoolLoadTest.java	2008-08-23 00:43:11 UTC (rev 1152)
+++ trunk/src/jar/store-stringpool/java/org/mulgara/store/stringpool/StringPoolLoadTest.java	2008-08-23 01:32:19 UTC (rev 1153)
@@ -58,75 +58,44 @@
  * @licence <a href="{@docRoot}/../../LICENCE">Mozilla Public License v1.1</a>
  */
 public class StringPoolLoadTest extends TestCase {
-  /**
-   * Get line separator.
-   */
+  /** Get line separator. */
   private static final String eol = System.getProperty("line.separator");
 
-  /**
-   * Description of the Field
-   *
-   */
-  private static List testEntries;
+  /** List of stored node/string pairs */
+  protected static List<StringPoolTestEntry> testEntries;
 
-  /**
-   * Subclasses must initialize this field.
-   */
+  /** Subclasses must initialize this string pool field. */
   protected XAStringPool stringPool;
 
-  /**
-   * Subclasses must initialize this field.
-   */
+  /** Subclasses must initialize this factory for creating string pool objects. */
   protected SPObjectFactory spoFactory;
 
-  /**
-   * Description of the Field
-   *
-   */
+  /** Reads in test data from file */
   protected BufferedReader reader;
 
-  /**
-   * Description of the Field
-   *
-   */
+  /** maximum number of entries */
   protected int maxSize = 3000000;
 
-  /**
-   * Description of the Field
-   *
-   */
+  /** the number of queries to be made */
   protected int noQueries = 3000;
 
-  /**
-   * Description of the Field
-   *
-   */
+  /** the file containing test data */
   protected String dataFile = "data/testwords.txt.gz";
 
-  /**
-   * Description of the Field
-   *
-   */
+  /** This flag indicates data should be written to the string pool when it is read */
   protected boolean loadData = true;
 
   // these are using for thread testing (testThirdQuery)
 
-  /**
-   * Description of the Field
-   *
-   */
+  /** Query counter */
   private int numberOfQueries = 0;
 
-  /**
-   * Description of the Field
-   *
-   */
+  /** Random number generator */
   private Random random;
 
   /**
-   * CONSTRUCTOR StringPoolLoadTest TO DO
-   *
-   * @param name PARAMETER TO DO
+   * Constructor for the test object.
+   * @param name Name of this test.
    */
   public StringPoolLoadTest(String name) {
     super(name);
@@ -135,196 +104,153 @@
   /**
    * Hook for test runner to obtain an empty test suite from, because this test
    * can't be run (it's abstract). This must be overridden in subclasses.
-   *
    * @return The test suite
    */
   public static Test suite() {
-
     TestSuite suite = new TestSuite();
-
     return suite;
   }
 
+
   /**
    * Default text runner.
-   *
    * @param args The command line arguments
    */
   public static void main(SPString[] args) {
-
     junit.textui.TestRunner.run(suite());
   }
 
+
   /**
    * Reads in all (or a subset determined by maxSize) of the dataset. The total
    * data has approximately 3 million literals.
-   *
-   * @throws Exception EXCEPTION TO DO
    */
   public void testLoadStringPool() throws Exception {
-
     // adjust noQueries if the maxSize is less than it
     noQueries = (maxSize < noQueries) ? maxSize : noQueries;
 
     // create the array of test entries
-    testEntries = new ArrayList();
+    testEntries = new ArrayList<StringPoolTestEntry>();
 
-    String line;
-    line = reader.readLine();
+    String line = reader.readLine();
 
     int count = 1;
-    int entryCount = 0;
     int gapSize = maxSize / noQueries;
 
+    long start = System.currentTimeMillis();
     while ((line != null) && (count < maxSize)) {
-
       SPObject spObject = spoFactory.newSPString(line);
-
-      if (loadData) {
-
-        stringPool.put(count, spObject);
-      }
-
-      if ((count % gapSize) == 0) {
-
-        testEntries.add(new StringPoolTestEntry(count, spObject));
-      }
-
+      if (loadData) stringPool.put(count, spObject);
+      if ((count % gapSize) == 0) testEntries.add(new StringPoolTestEntry(count, spObject));
       line = reader.readLine();
       count++;
     }
+    System.out.println(String.format("Loaded %d statements in %fsec", count, (System.currentTimeMillis() - start) / 1000.0));
   }
 
+
   /**
    * Go through the test entries and find graph node by passing in the SPObject
    * and assert the returned integer equals the original
-   *
-   * @throws Exception EXCEPTION TO DO
    */
   public void testFirstQuery() throws Exception {
 
     for (int i = 0; i < testEntries.size(); i++) {
-
-      StringPoolTestEntry entry =
-        (StringPoolTestEntry) testEntries.get(i);
-
+      StringPoolTestEntry entry = (StringPoolTestEntry) testEntries.get(i);
       long gNode = stringPool.findGNode(entry.spObject);
-
-      assertTrue("StringPool.findGNode returned NONE for gNode/spObject: " +
-        entry.gNode + "/" + entry.spObject, gNode != NodePool.NONE);
-      assertTrue("The graph node found for the SPObject " + entry.spObject +
-        " was incorrect. Expected " + entry.gNode + " but found " + gNode,
-        gNode == entry.gNode);
+      assertTrue("StringPool.findGNode returned NONE for gNode/spObject: " + entry.gNode + "/" + entry.spObject,
+                 gNode != NodePool.NONE);
+      assertTrue("The graph node found for the SPObject " + entry.spObject + " was incorrect. Expected " + entry.gNode + " but found " + gNode,
+                 gNode == entry.gNode);
     }
   }
 
+
   /**
    * Go through the test entries and find string by passing in the node and
    * assert the returned string equals the original
-   *
-   * @throws Exception EXCEPTION TO DO
    */
   public void testSecondQuery() throws Exception {
-
     for (int i = 0; i < testEntries.size(); i++) {
-
-      StringPoolTestEntry entry =
-        (StringPoolTestEntry) testEntries.get(i);
+      StringPoolTestEntry entry = (StringPoolTestEntry)testEntries.get(i);
       SPObject spObject = stringPool.findSPObject(entry.gNode);
-      assertTrue("StringPool.findSPObject returned null for gNode/spObject: " +
-        entry.gNode + "/" + entry.spObject, spObject != null);
-      assertTrue("The SPObject found for the graph node " + entry.gNode +
-        " was incorrect. Expected " + entry.spObject + " but found " +
-        spObject, spObject.equals(entry.spObject));
+
+      assertTrue("StringPool.findSPObject returned null for gNode/spObject: " + entry.gNode + "/" + entry.spObject,
+                 spObject != null);
+      assertTrue("The SPObject found for the graph node " + entry.gNode + " was incorrect. Expected " + entry.spObject + " but found " + spObject,
+                 spObject.equals(entry.spObject));
     }
   }
 
+
   /**
    * This query will test threading capabilities of the string pool.
-   *
-   * @throws Exception EXCEPTION TO DO
    */
   public void testThirdQuery() throws Exception {
-
     int numberOfThreads = 10;
     numberOfQueries = 0;
 
     ThreadGroup testGroup = new ThreadGroup("testThirdQuery");
-
     System.out.print(eol + "Starting StringPoolLoadTest query threads...>");
 
     for (int threadCount = 0; threadCount < numberOfThreads; threadCount++) {
-
-      TestThirdThread thread =
-        new TestThirdThread(testGroup, threadCount, this, testEntries);
+      TestThirdThread thread = new TestThirdThread(testGroup, threadCount, this, testEntries);
       thread.start();
     }
 
-    //Wait for the all the threads to stop.
+    // Wait for the all the threads to stop.
     Thread.sleep(70 * 1000);
 
     System.out.println(eol + "Total number of queries performed in 60 " +
         "seconds with " + numberOfThreads + " threads is :" + numberOfQueries);
   }
 
+
   /**
-   * Adds a feature to the NumberOfQueries attribute of the StringPoolLoadTest
-   * object
-   *
-   * @param numberOfQueries The feature to be added to the NumberOfQueries
-   *      attribute
+   * Adds a feature to the NumberOfQueries attribute of the StringPoolLoadTest object
+   * @param numberOfQueries The feature to be added to the NumberOfQueries attribute
    */
   public void addNumberOfQueries(int numberOfQueries) {
-
     this.numberOfQueries += numberOfQueries;
   }
 
+
   /**
    * get the BufferedReader ready for action
-   *
-   * @throws Exception EXCEPTION TO DO
    */
   protected void setUp() throws Exception {
-
     random = new Random(System.currentTimeMillis());
 
-    GZIPInputStream gzipStream =
-      new GZIPInputStream(new FileInputStream(dataFile));
+    GZIPInputStream gzipStream = new GZIPInputStream(new FileInputStream(dataFile));
     DataInputStream inStream = new DataInputStream(gzipStream);
     reader = new BufferedReader(new InputStreamReader(inStream));
   }
 
+
   /**
    * The teardown method for JUnit
-   *
-   * @throws Exception EXCEPTION TO DO
    */
   protected void tearDown() throws Exception {
-
-    if (stringPool != null) {
-
-      stringPool.close();
-    }
+    if (stringPool != null) stringPool.close();
   }
 
+
   class TestThirdThread extends Thread {
 
     private int numberOfStringPoolQueries = 0;
     private int threadNumber = 0;
-    private boolean stopQueries = false;
     private StringPoolLoadTest parentTest = null;
-    private List entries;
+    private List<StringPoolTestEntry> entries;
 
     /**
-     * CONSTRUCTOR TestThirdThread TO DO
-     *
-     * @param group PARAMETER TO DO
-     * @param threadNumber PARAMETER TO DO
-     * @param parentTest PARAMETER TO DO
-     * @param entries PARAMETER TO DO
+     * Constructs this thread's dta structure.
+     * @param group The group for this thread.
+     * @param threadNumber The id for this thread.
+     * @param parentTest The test object that owns this object.
+     * @param entries The data to query for.
      */
     public TestThirdThread(ThreadGroup group, int threadNumber,
-      StringPoolLoadTest parentTest, List entries) {
+      StringPoolLoadTest parentTest, List<StringPoolTestEntry> entries) {
       super(group, "Thread number :" + String.valueOf(threadNumber));
       this.threadNumber = threadNumber;
       numberOfStringPoolQueries = 0;
@@ -332,11 +258,10 @@
       this.entries = entries;
     }
 
-    public void run() {
 
+    public void run() {
       try {
 
-        Set countSet;
         boolean stopQueries = false;
         int i;
 
@@ -348,79 +273,61 @@
 
           i = Math.abs(random.nextInt()) % testEntries.size();
 
-          StringPoolTestEntry entry =
-            (StringPoolTestEntry) entries.get(i);
+          StringPoolTestEntry entry = entries.get(i);
 
           long gNode = stringPool.findGNode(entry.spObject);
-          assertTrue("StringPool.findGNode returned NONE for gNode/spObject: " +
-            entry.gNode + "/" + entry.spObject, gNode != NodePool.NONE);
-          assertTrue("The graph node found for the SPObject " + entry.spObject +
-            " was incorrect. Expected " + entry.gNode + " but found " + gNode,
-            gNode == entry.gNode);
+          assertTrue("StringPool.findGNode returned NONE for gNode/spObject: " + entry.gNode + "/" + entry.spObject,
+                     gNode != NodePool.NONE);
+          assertTrue("The graph node found for the SPObject " + entry.spObject + " was incorrect. Expected " + entry.gNode + " but found " + gNode,
+                     gNode == entry.gNode);
 
           i = Math.abs(random.nextInt()) % testEntries.size();
 
-          entry = (StringPoolTestEntry) entries.get(i);
+          entry = entries.get(i);
 
           SPObject spObject = stringPool.findSPObject(entry.gNode);
-          assertTrue(
-            "StringPool.findSPObject returned null for node/SPObject: " +
-            entry.gNode + "/" + entry.spObject,
-            spObject != null);
-          assertTrue("The spObject found for the node " + entry.gNode +
-            " was incorrect. Expected " + entry.spObject + " but found " +
-            spObject, spObject.equals(entry.spObject));
+          assertTrue("StringPool.findSPObject returned null for node/SPObject: " + entry.gNode + "/" + entry.spObject,
+                     spObject != null);
+          assertTrue("The spObject found for the node " + entry.gNode + " was incorrect. Expected " + entry.spObject + " but found " + spObject,
+                     spObject.equals(entry.spObject));
 
           numberOfStringPoolQueries++;
 
           if (System.currentTimeMillis() > endTime) {
-
             stopQueries = true;
-
             break;
           }
         }
 
         System.out.print("<..." + String.valueOf(threadNumber));
         parentTest.addNumberOfQueries(numberOfStringPoolQueries);
-      }
-       catch (StringPoolException spe) {
-
+      } catch (StringPoolException spe) {
         System.out.println("string pool exception during multithreading query");
       }
     }
   }
-}
 
-
-// this class is just a structure to store the node/string pair
-
-/**
- * CLASS TO DO
- */
-class StringPoolTestEntry {
-
   /**
-   * Description of the Field
-   *
+   * this class is just a structure to store the node/string pair
    */
-  public int gNode;
+  static protected class StringPoolTestEntry {
 
-  /**
-   * Description of the Field
-   *
-   */
-  public SPObject spObject;
+    /** The node associated with the data. */
+    public int gNode;
 
-  /**
-   * CONSTRUCTOR StringPoolTestEntry TO DO
-   *
-   * @param gNode PARAMETER TO DO
-   * @param spObject PARAMETER TO DO
-   */
-  public StringPoolTestEntry(int gNode, SPObject spObject) {
+    /** The stored data. */
+    public SPObject spObject;
 
-    this.gNode = gNode;
-    this.spObject = spObject;
-  }
+    /**
+     * Constructor.
+     * @param gNode The node for this data
+     * @param spObject The data for this node
+     */
+    public StringPoolTestEntry(int gNode, SPObject spObject) {
+      this.gNode = gNode;
+      this.spObject = spObject;
+    }
 }
+
+
+}




More information about the Mulgara-svn mailing list