Derek Hulley 29b94cf0d7 Audit and Prop table enhancements
- alf_prop_xxx tables
   - Added alf_prop_root table
   - alf_prop_value_xxx tables enforce uniqueness
   - Better splitting up of Collections and Maps (attempt to use exact storage type)
   - Moved some indexes around to reduce size but maintain index data lookups
   - Allow updates and deletes of properties via alf_prop_root (entry-point table)
 - Audit Application
   - Unique by name
   - Add 'disabled paths' to control audit behaviour (not wired into services)
   - Added concurrency checks for updates to the Audit Application (model change, etc)


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@16217 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
2009-09-11 13:59:45 +00:00

216 lines
8.6 KiB
Java

/*
* Copyright (C) 2005-2009 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.domain.audit;
import java.io.File;
import java.io.Serializable;
import java.net.URL;
import java.util.Collections;
import java.util.Map;
import junit.framework.TestCase;
import org.alfresco.repo.content.transform.AbstractContentTransformerTest;
import org.alfresco.repo.domain.audit.AuditDAO.AuditApplicationInfo;
import org.alfresco.repo.domain.contentdata.ContentDataDAO;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.audit.AuditService.AuditQueryCallback;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.ApplicationContextHelper;
import org.alfresco.util.Pair;
import org.springframework.context.ConfigurableApplicationContext;
/**
* @see ContentDataDAO
*
* @author Derek Hulley
* @since 3.2
*/
public class AuditDAOTest extends TestCase
{
private ConfigurableApplicationContext ctx = (ConfigurableApplicationContext) ApplicationContextHelper.getApplicationContext();
private TransactionService transactionService;
private RetryingTransactionHelper txnHelper;
private AuditDAO auditDAO;
@Override
public void setUp() throws Exception
{
ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
transactionService = serviceRegistry.getTransactionService();
txnHelper = transactionService.getRetryingTransactionHelper();
auditDAO = (AuditDAO) ctx.getBean("auditDAO");
}
public void testAuditModel() throws Exception
{
final File file = AbstractContentTransformerTest.loadQuickTestFile("pdf");
assertNotNull(file);
final URL url = new URL("file:" + file.getAbsolutePath());
RetryingTransactionCallback<Pair<Long, ContentData>> callback = new RetryingTransactionCallback<Pair<Long, ContentData>>()
{
public Pair<Long, ContentData> execute() throws Throwable
{
Pair<Long, ContentData> auditModelPair = auditDAO.getOrCreateAuditModel(url);
return auditModelPair;
}
};
Pair<Long, ContentData> configPair = txnHelper.doInTransaction(callback);
assertNotNull(configPair);
// Now repeat. The results should be exactly the same.
Pair<Long, ContentData> configPairCheck = txnHelper.doInTransaction(callback);
assertNotNull(configPairCheck);
assertEquals(configPair, configPairCheck);
}
public void testAuditApplicatoin() throws Exception
{
final File file = AbstractContentTransformerTest.loadQuickTestFile("pdf");
assertNotNull(file);
final URL url = new URL("file:" + file.getAbsolutePath());
RetryingTransactionCallback<Long> createModelCallback = new RetryingTransactionCallback<Long>()
{
public Long execute() throws Throwable
{
return auditDAO.getOrCreateAuditModel(url).getFirst();
}
};
final Long modelId = txnHelper.doInTransaction(createModelCallback);
final String appName = getName() + "." + System.currentTimeMillis();
final int count = 1000;
RetryingTransactionCallback<Void> createAppCallback = new RetryingTransactionCallback<Void>()
{
public Void execute() throws Throwable
{
for (int i = 0; i < count; i++)
{
AuditApplicationInfo appInfo = auditDAO.getAuditApplication(appName);
if (appInfo == null)
{
appInfo = auditDAO.createAuditApplication(appName, modelId);
}
}
return null;
}
};
long before = System.nanoTime();
txnHelper.doInTransaction(createAppCallback);
long after = System.nanoTime();
System.out.println(
"Time for " + count + " application creations was " +
((double)(after - before)/(10E6)) + "ms");
}
public void testAuditEntry() throws Exception
{
doAuditEntryImpl(1000);
}
/**
* @return Returns the name of the application
*/
private String doAuditEntryImpl(final int count) throws Exception
{
final File file = AbstractContentTransformerTest.loadQuickTestFile("pdf");
assertNotNull(file);
final URL url = new URL("file:" + file.getAbsolutePath());
final String appName = getName() + "." + System.currentTimeMillis();
RetryingTransactionCallback<Long> createAppCallback = new RetryingTransactionCallback<Long>()
{
public Long execute() throws Throwable
{
AuditApplicationInfo appInfo = auditDAO.getAuditApplication(appName);
if (appInfo == null)
{
Long modelId = auditDAO.getOrCreateAuditModel(url).getFirst();
appInfo = auditDAO.createAuditApplication(appName, modelId);
}
return appInfo.getId();
}
};
final Long sessionId = txnHelper.doInTransaction(createAppCallback);
final String username = "alexi";
RetryingTransactionCallback<Void> createEntryCallback = new RetryingTransactionCallback<Void>()
{
public Void execute() throws Throwable
{
for (int i = 0; i < count; i++)
{
Map<String, Serializable> values = Collections.singletonMap("/a/b/c", (Serializable) new Integer(i));
long now = System.currentTimeMillis();
auditDAO.createAuditEntry(sessionId, now, username, values);
}
return null;
}
};
long before = System.nanoTime();
txnHelper.doInTransaction(createEntryCallback);
long after = System.nanoTime();
System.out.println(
"Time for " + count + " entry creations was " +
((double)(after - before)/(10E6)) + "ms");
// Done
return appName;
}
public void testAuditQuery() throws Exception
{
// Some entries
doAuditEntryImpl(1);
// Find everything, bug look for a specific key
final AuditQueryCallback callback = new AuditQueryCallback()
{
public boolean handleAuditEntry(
Long entryId,
String applicationName,
String user,
long time,
Map<String, Serializable> values)
{
System.out.println(values);
return true;
}
};
RetryingTransactionCallback<Void> findCallback = new RetryingTransactionCallback<Void>()
{
public Void execute() throws Throwable
{
auditDAO.findAuditEntries(callback, null, null, null, null, "/a/b/c", null, -1);
return null;
}
};
txnHelper.doInTransaction(findCallback);
}
}