chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r929053 - in /incubator/chemistry/trunk/opencmis/opencmis-test/opencmis-test-util/src/main/java/org/apache/opencmis/util/repository: ObjGenApp.java ObjectGenerator.java TimeLogger.java
Date Tue, 30 Mar 2010 09:27:29 GMT
Author: jens
Date: Tue Mar 30 09:27:29 2010
New Revision: 929053

URL: http://svn.apache.org/viewvc?rev=929053&view=rev
Log:
CMIS-183
Add option to cleanup after create
Add option to pass a root folder id used for creation
Add delete timings if cleaned up
Improve output report

Modified:
    incubator/chemistry/trunk/opencmis/opencmis-test/opencmis-test-util/src/main/java/org/apache/opencmis/util/repository/ObjGenApp.java
    incubator/chemistry/trunk/opencmis/opencmis-test/opencmis-test-util/src/main/java/org/apache/opencmis/util/repository/ObjectGenerator.java
    incubator/chemistry/trunk/opencmis/opencmis-test/opencmis-test-util/src/main/java/org/apache/opencmis/util/repository/TimeLogger.java

Modified: incubator/chemistry/trunk/opencmis/opencmis-test/opencmis-test-util/src/main/java/org/apache/opencmis/util/repository/ObjGenApp.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-test/opencmis-test-util/src/main/java/org/apache/opencmis/util/repository/ObjGenApp.java?rev=929053&r1=929052&r2=929053&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-test/opencmis-test-util/src/main/java/org/apache/opencmis/util/repository/ObjGenApp.java
(original)
+++ incubator/chemistry/trunk/opencmis/opencmis-test/opencmis-test-util/src/main/java/org/apache/opencmis/util/repository/ObjGenApp.java
Tue Mar 30 09:27:29 2010
@@ -61,12 +61,16 @@ public class ObjGenApp {
   private final static String FILLER_CONTENT_SIZE = "ContentSizeInKB";
   private final static String COUNT = "Count";
   private final static String BINDING = "Binding";
+  private final static String CLEANUP = "Cleanup";
+  private final static String ROOTFOLDER = "RootFolder";
+  
   private final static String BINDING_ATOM = "AtomPub";
   private final static String BINDING_WS = "WebService";
 
   private CmisProvider fProvider;
   private boolean fUsingAtom; 
   private String fUrlStr;
+  private boolean fDoCleanup;
   
   OptionSpec<String> fCmd;
   OptionSpec<Integer> fDepth;
@@ -78,6 +82,9 @@ public class ObjGenApp {
   OptionSpec<String> fRepoId;
   OptionSpec<Integer> fCount;
   OptionSpec<String> fBinding;
+  OptionSpec<Boolean> fCleanup;
+  OptionSpec<String> fRootFolder;
+  
   
   public static void main(String[] args) {
 
@@ -121,7 +128,11 @@ public class ObjGenApp {
         .describedAs("Repeat a command n times (not yet implemented)");
     fBinding = parser.accepts(BINDING).withOptionalArg().ofType(String.class).defaultsTo(BINDING_ATOM)
       .describedAs("Protocol Binding: " + BINDING_ATOM + " or " + BINDING_WS);
-
+    fCleanup = parser.accepts(CLEANUP).withOptionalArg().ofType(Boolean.class).defaultsTo(false)
+    .describedAs("Clean all created objects at the end");
+    fRootFolder = parser.accepts(ROOTFOLDER).withOptionalArg().ofType(String.class)
+      .describedAs("folder id used as root to create objects (default repository root folder)");
+    
     OptionSet options = parser.parse(args);
 
     if (options.valueOf(fCmd) == null || options.has("?"))
@@ -139,6 +150,8 @@ public class ObjGenApp {
       return;
     }
 
+    fDoCleanup = options.valueOf(fCleanup);
+    
     if (options.valueOf(fCmd).equals("FillRepository")) {
       fillRepository(options);
     } else if (options.valueOf(fCmd).equals("CreateDocument")) {
@@ -189,34 +202,9 @@ public class ObjGenApp {
     }
   }
 
-  private void fillRepository(OptionSet options) {
-    if (fUsingAtom)
-      System.out.println("Connecting to  " + getAtomPubUrl());
-    else
-      System.out.println("Connecting to  " + getWsUrl());
-      
-    System.out.println("Filling repository " + options.valueOf(fRepoId)
-        + " with following arguments:");
-    System.out.println("Documents per folder: " + options.valueOf(fDocsPerFolder));
-    System.out.println("Folder per folder: " + options.valueOf(fFolderPerFolder));
-    System.out.println("Depth: " + options.valueOf(fDepth));
-    System.out.println("Content size: " + options.valueOf(fContentSize));
-    System.out.println("Document Type: " + options.valueOf(fDocType));
-    System.out.println("Folder Type: " + options.valueOf(fFolderType));
-
-    try {
-      fillRepository(options.valueOf(fRepoId), options.valueOf(fDocsPerFolder), options
-          .valueOf(fFolderPerFolder), options.valueOf(fDepth), options.valueOf(fDocType),
options
-          .valueOf(fFolderType), options.valueOf(fContentSize));
-    }
-    catch (Exception e) {
-      System.out.println("Filling repository failed with exception: " + e);
-      e.printStackTrace();
-    }
-  }
 
   private void fillRepository(String repoId, int docsPerFolder, int foldersPerFolders, int
depth,
-      String documentType, String folderType, int contentSizeInKB) {
+      String documentType, String folderType, int contentSizeInKB, String rootFolderId) {
 
     ProviderObjectFactory objectFactory = getObjectFactory();
     NavigationService navSvc = getProvider().getNavigationService();
@@ -232,29 +220,59 @@ public class ObjGenApp {
     gen.setFolderTypeId(folderType);
     // Set contentSize
     gen.setContentSizeInKB(contentSizeInKB);
-    // Simulate a runtime context with configuration parameters
-    // Attach the CallContext to a thread local context that can be accessed from everywhere
+    gen.setCleanUpAfterCreate(fDoCleanup);
 
     // Build the tree
     RepositoryInfoData rep = repSvc.getRepositoryInfo(repoId, null);
-    String rootFolderId = rep.getRootFolderId();
+    if (null == rootFolderId || rootFolderId.length() == 0)
+      rootFolderId = rep.getRootFolderId();
 
     gen.resetCounters();
     gen.createFolderHierachy(depth, foldersPerFolders, rootFolderId);
+    System.out.println();
+    System.out.println("Result:");
     System.out.println("Filling repository succeeded.");
+    System.out.println("Folder used as root for creation (null=rootFolderId): " + rootFolderId);
     System.out.println("Number of documents created: " + gen.getDocumentsInTotal());
     System.out.println("Number of folders created: " + gen.getFoldersInTotal());
     gen.printTimings();
   }
 
+  private void printParameters(OptionSet options) {    
+    if (fUsingAtom)
+      System.out.println("Connecting to  " + getAtomPubUrl());
+    else
+      System.out.println("Connecting to  " + getWsUrl());
+      
+    System.out.println("Repository id is: " + options.valueOf(fRepoId));
+    System.out.println("Content size: " + options.valueOf(fContentSize));
+    System.out.println("Document Type: " + options.valueOf(fDocType));
+    System.out.println("Folder used as root: " + options.valueOf(fRootFolder));
+    System.out.println("Delete all objects after creation: " + fDoCleanup);
+  }
+  
   private void createSingleDocument(OptionSet options) {
-    System.out.println("Connecting to  " + getAtomPubUrl());
-    System.out.println("Creating doc in repository " + options.valueOf(fRepoId));
+    System.out.println();
+    System.out.println("Creating document with parameters:");
+    printParameters(options);
+    createSingleDocument(options.valueOf(fRepoId), options.valueOf(fContentSize), options.valueOf(fRootFolder));
+  }
+  
+  private void fillRepository(OptionSet options) {
+    System.out.println();
+    System.out.println("Creating object tree with folowing parameters: ");
+    System.out.println("Documents per folder: " + options.valueOf(fDocsPerFolder));
+    System.out.println("Folder per folder: " + options.valueOf(fFolderPerFolder));
+    System.out.println("Depth: " + options.valueOf(fDepth));
+    System.out.println("Folder Type: " + options.valueOf(fFolderType));
+    printParameters(options);
 
-    createSingleDocument(options.valueOf(fRepoId), options.valueOf(fContentSize));
+    fillRepository(options.valueOf(fRepoId), options.valueOf(fDocsPerFolder), options
+        .valueOf(fFolderPerFolder), options.valueOf(fDepth), options.valueOf(fDocType), options
+        .valueOf(fFolderType), options.valueOf(fContentSize), options.valueOf(fRootFolder));
   }
 
-  private void createSingleDocument(String repoId, int contentSizeInKB) {
+  private void createSingleDocument(String repoId, int contentSizeInKB, String rootFolderId)
{
 
     ProviderObjectFactory objectFactory = getObjectFactory();
     NavigationService navSvc = getProvider().getNavigationService();
@@ -266,31 +284,37 @@ public class ObjGenApp {
     RepositoryInfoData rep = repSvc.getRepositoryInfo(repoId, null);
     timeLogger.stop();
     timeLogger.printTimes();
-    String rootFolderId = rep.getRootFolderId();
+    if (null == rootFolderId || rootFolderId.length() == 0)
+      rootFolderId = rep.getRootFolderId();
     gen.setContentSizeInKB(contentSizeInKB);
     gen.setUseUuidsForNames(true);
-    gen.createSingleDocument(rootFolderId);
+    gen.setCleanUpAfterCreate(fDoCleanup);
+    String id = gen.createSingleDocument(rootFolderId);
+    System.out.println();
+    System.out.println("Result:");
     System.out.println("Document creation succeeded.");
+    System.out.println("Folder used as root for creation: " + rootFolderId);
+    System.out.println("Id of created document: " + id);
     gen.printTimings();
-
     gen.resetCounters();
   }
 
-  private void callRepoInfo(String repositoryId) {
+  private void callRepoInfo(String repositoryId, int count) {
     RepositoryService repSvc = getProvider().getRepositoryService();
     TimeLogger timeLogger = new TimeLogger("RepoInfoTest");
-    int n = 5;
-    for (int i = 0; i < n; i++) {
+    RepositoryInfoData repoInfo = null;
+    for (int i = 0; i < count; i++) {
       fProvider.clearRepositoryCache(repositoryId);
       timeLogger.start();
-      repSvc.getRepositoryInfo(repositoryId, null);
+      repoInfo = repSvc.getRepositoryInfo(repositoryId, null);
       timeLogger.stop();
     }
+    System.out.println("Root Folder id is: " + (repoInfo==null ? "<unknown>" : repoInfo.getRootFolderId())
);
     timeLogger.printTimes();
   }
 
   private void repositoryInfo(OptionSet options) {
-    callRepoInfo(options.valueOf(fRepoId));
+    callRepoInfo(options.valueOf(fRepoId), options.valueOf(fCount));
   }
 
   private ProviderObjectFactory getObjectFactory() {

Modified: incubator/chemistry/trunk/opencmis/opencmis-test/opencmis-test-util/src/main/java/org/apache/opencmis/util/repository/ObjectGenerator.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-test/opencmis-test-util/src/main/java/org/apache/opencmis/util/repository/ObjectGenerator.java?rev=929053&r1=929052&r2=929053&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-test/opencmis-test-util/src/main/java/org/apache/opencmis/util/repository/ObjectGenerator.java
(original)
+++ incubator/chemistry/trunk/opencmis/opencmis-test/opencmis-test-util/src/main/java/org/apache/opencmis/util/repository/ObjectGenerator.java
Tue Mar 30 09:27:29 2010
@@ -35,6 +35,7 @@ import org.apache.opencmis.commons.Prope
 import org.apache.opencmis.commons.api.ExtensionsData;
 import org.apache.opencmis.commons.enums.BaseObjectTypeIds;
 import org.apache.opencmis.commons.enums.IncludeRelationships;
+import org.apache.opencmis.commons.enums.UnfileObjects;
 import org.apache.opencmis.commons.enums.VersioningState;
 import org.apache.opencmis.commons.impl.dataobjects.ContentStreamDataImpl;
 import org.apache.opencmis.commons.provider.AccessControlList;
@@ -64,8 +65,11 @@ public class ObjectGenerator {
   private String fRepositoryId;
   private TimeLogger fTimeLoggerCreateDoc;
   private TimeLogger fTimeLoggerCreateFolder;
+  private TimeLogger fTimeLoggerDelete;
+  private boolean fCleanup;
+  List<String> fTopLevelDocsCreated; // list of ids created on first level
+  List<String> fTopLevelFoldersCreated; // list of ids created on first level
   
-    
   /**
    * Indicates if / how many documents are created in each folder
    */
@@ -135,6 +139,10 @@ public class ObjectGenerator {
     fUseUuids = false;
     fTimeLoggerCreateDoc = new TimeLogger("createDocument()");
     fTimeLoggerCreateFolder = new TimeLogger("createFolder()");
+    fTimeLoggerDelete = new TimeLogger("Delete");
+    fCleanup = false;
+    fTopLevelDocsCreated = new ArrayList<String>();
+    fTopLevelFoldersCreated = new ArrayList<String>();    
   }
   
   public void setNumberOfDocumentsToCreatePerFolder(int noDocumentsToCreate) {
@@ -161,11 +169,19 @@ public class ObjectGenerator {
     fContentSizeInK = sizeInK;
   }
   
+  public void setCleanUpAfterCreate(boolean doCleanup) {
+    fCleanup = doCleanup;
+  }
+  
   public void createFolderHierachy(int levels, int childrenPerLevel, String rootFolderId)
{
     resetCounters();
     fTimeLoggerCreateDoc.reset();
     fTimeLoggerCreateFolder.reset();
+    fTopLevelFoldersCreated.clear();
+    fTopLevelDocsCreated.clear();
     createFolderHierachy(rootFolderId, 0, levels, childrenPerLevel);
+    if (fCleanup)
+      deleteTree();
   }
   
   public void setUseUuidsForNames(boolean useUuids) {
@@ -252,9 +268,12 @@ public class ObjectGenerator {
     return fDocumentsInTotalCount + fFoldersInTotalCount;
   }
 
-  public void createSingleDocument(String folderId) {
+  public String createSingleDocument(String folderId) {
     fTimeLoggerCreateDoc.reset();
-	  createDocument(folderId, 0, 0);      
+	  String objectId = createDocument(folderId, 0, 0);
+    if (fCleanup)
+      deleteObject(objectId);	  
+    return objectId;
   }
 	  
   public void resetCounters() {
@@ -263,27 +282,34 @@ public class ObjectGenerator {
   
   public void printTimings() {
     fTimeLoggerCreateDoc.printTimes();
-    fTimeLoggerCreateFolder.printTimes();    
+    fTimeLoggerCreateFolder.printTimes();
+    if (fCleanup)
+      fTimeLoggerDelete.printTimes();
   }
   
   public void logTimings() {
     fTimeLoggerCreateDoc.logTimes();
     fTimeLoggerCreateFolder.logTimes();    
+    if (fCleanup)
+      fTimeLoggerDelete.logTimes();
   }
   
   private void createFolderHierachy(String parentId, int level, int levels, int childrenPerLevel)
{
-    
+    String id = null;
+
     if (level>=levels)
       return;
+
     log.debug(" create folder for parent id: " + parentId + ", in level " + level 
          + ", max levels " + levels);
     
     for (int i = 0; i < childrenPerLevel; i++) {
       PropertiesData props = createFolderProperties(i, level);
-      String id = null;
       try {
         fTimeLoggerCreateFolder.start();
         id = fObjSvc.createFolder(fRepositoryId, props, parentId, null, null, null, null);
+        if (level==0)
+          fTopLevelFoldersCreated.add(id);
       } finally {
         fTimeLoggerCreateFolder.stop();
       }
@@ -294,7 +320,9 @@ public class ObjectGenerator {
       }
     }
     for (int j=0; j<fNoDocumentsToCreate; j++) {
-      createDocument(parentId, j, level);
+      id = createDocument(parentId, j, level);
+      if (level==0)
+        fTopLevelDocsCreated.add(id);
     }
   }
 
@@ -325,6 +353,33 @@ public class ObjectGenerator {
     return id;
   }
   
+  private void deleteTree() {
+    
+    // delete all documents from first level
+    for (String id : fTopLevelDocsCreated) {
+      deleteObject(id);
+    }
+    
+    // delete recursively all folders from first level
+    for (String id : fTopLevelFoldersCreated) {
+      try {
+        fTimeLoggerDelete.start();
+        fObjSvc.deleteTree(fRepositoryId, id, true, UnfileObjects.DELETE, true, null);
+      } finally {
+        fTimeLoggerDelete.stop();
+      }    
+    }
+  }
+  
+  private void deleteObject(String objectId) {
+    try {
+      fTimeLoggerDelete.start();
+      fObjSvc.deleteObject(fRepositoryId, objectId, true, null);
+    } finally {
+      fTimeLoggerDelete.stop();
+    }    
+  }
+
   private ContentStreamData createContent() {
     ContentStreamDataImpl content = new ContentStreamDataImpl();
     content.setFilename("data.txt");

Modified: incubator/chemistry/trunk/opencmis/opencmis-test/opencmis-test-util/src/main/java/org/apache/opencmis/util/repository/TimeLogger.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-test/opencmis-test-util/src/main/java/org/apache/opencmis/util/repository/TimeLogger.java?rev=929053&r1=929052&r2=929053&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-test/opencmis-test-util/src/main/java/org/apache/opencmis/util/repository/TimeLogger.java
(original)
+++ incubator/chemistry/trunk/opencmis/opencmis-test/opencmis-test-util/src/main/java/org/apache/opencmis/util/repository/TimeLogger.java
Tue Mar 30 09:27:29 2010
@@ -72,7 +72,7 @@ public class TimeLogger {
     else if (size==1)
       LOG.info("Time elapsed for " + fAction + ": " + getLastTime());
     else {
-      LOG.info("Timings for " + size + " samples: ");
+      LOG.info("Timings for " + size + " samples for action " + fAction + ": ");
       LOG.info("  Average: " + getAverageTime() + "ms");
       LOG.info("  Min    : " + getMinTime() + "ms");
       LOG.info("  Max    : " + getMaxTime() + "ms");
@@ -87,7 +87,7 @@ public class TimeLogger {
     else if (size==1)
       System.out.println("Time elapsed for " + fAction + ": " + getLastTime());
     else {
-      System.out.println("Timings for " + size + " samples: ");
+      System.out.println("Timings for " + size + " samples for action " + fAction + ": ");
       System.out.println("  Average: " + getAverageTime() + "ms");
       System.out.println("  Min    : " + getMinTime() + "ms");
       System.out.println("  Max    : " + getMaxTime() + "ms");



Mime
View raw message