use of org.alfresco.service.cmr.search.SearchService in project alfresco-repository by Alfresco.
the class ConcurrentNodeServiceSearchTest method testConcurrent.
public void testConcurrent() throws Exception {
int count = 10;
int repeats = 10;
SearchService searcher = (SearchService) ctx.getBean(ServiceRegistry.SEARCH_SERVICE.getLocalName());
Map<QName, ChildAssociationRef> assocRefs = commitNodeGraph();
Thread runner = null;
for (int i = 0; i < count; i++) {
runner = new Nester("Concurrent-" + i, runner, repeats, searcher);
}
if (runner != null) {
runner.start();
try {
runner.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
assertEquals(2, searcher.selectNodes(rootNodeRef, "/*", null, getNamespacePrefixReolsver(""), false).size());
ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*\"");
// n6 has root aspect - there are three things at the root level in the
// index
assertEquals(3, results.length());
results.close();
}
use of org.alfresco.service.cmr.search.SearchService in project alfresco-repository by Alfresco.
the class FileFolderPerformanceTester method run.
private static void run(final ApplicationContext ctx, String... args) throws Throwable {
ArgumentHelper argHelper = new ArgumentHelper(getUsage(), args);
final int fileCount = argHelper.getIntegerValue("files", true, 1, 10000);
final String folderRefStr = argHelper.getStringValue("folder", false, true);
final int threadCount = argHelper.getIntegerValue("threads", false, 1, 100);
final NodeRef selectedFolderNodeRef = folderRefStr == null ? null : new NodeRef(folderRefStr);
ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
final MutableAuthenticationService authenticationService = serviceRegistry.getAuthenticationService();
final PermissionService permissionService = serviceRegistry.getPermissionService();
final NodeService nodeService = serviceRegistry.getNodeService();
final SearchService searchService = serviceRegistry.getSearchService();
final TransactionService transactionService = serviceRegistry.getTransactionService();
final FileFolderService fileFolderService = serviceRegistry.getFileFolderService();
RunAsWork<String> createUserRunAs = new RunAsWork<String>() {
public String doWork() throws Exception {
String user = GUID.generate();
authenticationService.createAuthentication(user, user.toCharArray());
return user;
}
};
final String user = AuthenticationUtil.runAs(createUserRunAs, AuthenticationUtil.getSystemUserName());
// Create the files
final RetryingTransactionCallback<NodeRef> createCallback = new RetryingTransactionCallback<NodeRef>() {
public NodeRef execute() throws Throwable {
AuthenticationUtil.pushAuthentication();
DictionaryDAO dictionaryDao = (DictionaryDAO) ctx.getBean("dictionaryDAO");
M2Model model = M2Model.createModel("tempModel");
model.createNamespace("test", "t");
model.createNamespace("testx", "");
for (int m = 0; m < 30; m++) {
model.createAspect("t:aspect_" + m);
}
dictionaryDao.putModel(model);
NodeRef folderNodeRef = null;
try {
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
if (selectedFolderNodeRef == null) {
// find the guest folder
StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
ResultSet rs = searchService.query(storeRef, SearchService.LANGUAGE_XPATH, "/app:company_home");
try {
if (rs.length() == 0) {
throw new AlfrescoRuntimeException("Didn't find Company Home");
}
NodeRef companyHomeNodeRef = rs.getNodeRef(0);
folderNodeRef = fileFolderService.create(companyHomeNodeRef, "TOP_FOLDER_" + System.currentTimeMillis(), ContentModel.TYPE_FOLDER).getNodeRef();
System.out.println("Created folder " + folderNodeRef + " with user " + user);
} finally {
rs.close();
}
// Grant permissions
permissionService.setPermission(folderNodeRef, user, PermissionService.ALL_PERMISSIONS, true);
} else {
folderNodeRef = selectedFolderNodeRef;
// Grant permissions
permissionService.setPermission(folderNodeRef, user, PermissionService.ALL_PERMISSIONS, true);
System.out.println("Reusing folder " + folderNodeRef + " with user " + user);
}
} finally {
AuthenticationUtil.popAuthentication();
}
if (selectedFolderNodeRef == null) {
List<String> largeCollection = new ArrayList<String>(1000);
for (int i = 0; i < 50; i++) {
largeCollection.add(String.format("Large-collection-value-%05d", i));
}
// Create the files
for (int i = 0; i < fileCount; i++) {
FileInfo fileInfo = fileFolderService.create(folderNodeRef, String.format("FILE-%4d", i), ContentModel.TYPE_CONTENT);
NodeRef nodeRef = fileInfo.getNodeRef();
nodeService.setProperty(nodeRef, QName.createQName("{test}mv"), (Serializable) largeCollection);
for (int m = 0; m < 30; m++) {
nodeService.addAspect(nodeRef, QName.createQName("{test}aspect_" + m), null);
}
// write the content
ContentWriter writer = fileFolderService.getWriter(nodeRef);
writer.setEncoding("UTF-8");
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
writer.putContent("Some small text data");
}
System.out.println("Created " + fileCount + " files in folder " + folderNodeRef);
}
// Done
return folderNodeRef;
}
};
RunAsWork<NodeRef> createRunAs = new RunAsWork<NodeRef>() {
public NodeRef doWork() throws Exception {
return transactionService.getRetryingTransactionHelper().doInTransaction(createCallback);
}
};
final NodeRef folderNodeRef = AuthenticationUtil.runAs(createRunAs, user);
// Now wait for some input before commencing the read run
System.out.print("Hit any key to commence directory listing ...");
System.in.read();
final RunAsWork<List<FileInfo>> readRunAs = new RunAsWork<List<FileInfo>>() {
public List<FileInfo> doWork() throws Exception {
return fileFolderService.list(folderNodeRef);
}
};
Thread[] threads = new Thread[threadCount];
for (int i = 0; i < threadCount; i++) {
Thread readThread = new Thread("FolderList-" + i) {
int iteration = 0;
public void run() {
while (++iteration <= 2) {
runImpl();
}
}
private void runImpl() {
String threadName = Thread.currentThread().getName();
long start = System.currentTimeMillis();
List<FileInfo> nodeRefs = AuthenticationUtil.runAs(readRunAs, user);
long time = System.currentTimeMillis() - start;
double average = (double) time / (double) (fileCount);
// Make sure that we have the correct number of entries
if (folderRefStr != null && nodeRefs.size() != fileCount) {
System.err.println("WARNING: Thread " + threadName + " got " + nodeRefs.size() + " but expected " + fileCount);
}
System.out.print("\n" + "Thread " + threadName + ": \n" + " Read " + String.format("%4d", fileCount) + " files \n" + " Average: " + String.format("%10.2f", average) + " ms per file \n" + " Average: " + String.format("%10.2f", 1000.0 / average) + " files per second");
}
};
readThread.start();
threads[i] = readThread;
}
for (int i = 0; i < threads.length; i++) {
threads[i].join();
}
}
Aggregations