mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-06-30 18:15:39 +00:00
71594: Merged V4.2-BUG-FIX (4.2.3) to HEAD-BUG-FIX (4.3/Cloud) 70332: Merged V4.1-BUG-FIX (4.1.9) to V4.2-BUG-FIX (4.2.3) 70292: Merged DEV to V4.1-BUG-FIX (4.1.9) 60077: Created branch for MNT-10067 work. 60101: MNT-10067: first commit of a generic SQL script runner. Very rough and ready extraction of SchemaBootstrap SQL script execution functionality. Will serve as the basis for the implementation of MNT-10067. 60147: MNT-10067: added tests for "dialect" placeholder resolution, including overriding of dialects. 60180: MNT-10067: exception thrown when unable to find SQL script to execute 60187: MNT-10067: renamed ScriptExecutor to ScriptExecutorImpl to make way for an interface definition. 60188: MNT-10067: introduced a ScriptExecutor interface. 60189: MNT-10067: renamed ScriptExecutorTest 60190: MNT-10067: added ScriptExecutorImplIntegrationTest to repo test suite. 60194: MNT-10067: a very simple initial implementation of a SQL script runner capable of running multiple scripts in a given directory. 60195: MNT-10067: added integration test for ScriptBundleExecutorImpl. 60196: MNT-10067: moved ScriptBundleExecutorImplTest to correct source tree. 60197: MNT-10067: added ScriptBundleExecutorImplIntegrationTest to repo test suite. 60263: MNT-10067: ScriptBundleExecutor(Impl) now stops executing the main batch of scripts upon failure and runs a post-script. 60459: MNT-10067: minor change to test data to avoid implying that ScriptBundleExecutor.exec(String, String...) has an always-run final script. 60482: MNT-10067: added integration test for ScriptBundleExecutor.execWithPostScript() 60483: MNT-10067: committed missing files from r60482 60488: MNT-10067: set appropriate log levels for log4j 60620: MNT-10067: added alf_props_xxx clean-up script. 60623: MNT-10067: minor tidy up of ScriptExecutorImpl (tidy imports, group fields at top of class) 60625: MNT-10067: further tidy up ScriptExecutorImpl (removed redundant constants, made externally unused public constant private) 60629: MNT-10067: fix tests broken by introduction of scriptExecutor bean in production code. 60662: MNT-10067: added tests to check deletion of doubles, serializables and dates. 61378: MNT-10067 : Cleanup alf_prop_XXX data Added MySQL, Oracle DB, MS SQL Server and IBM DB2 scripts. 63371: MNT-10067: removed the vacuum and analyze statements from the postgresql script. 63372: MNT-10067: replaced begin and commit statements (PostgreSQL script only) with --BEGIN TXN and --END TXN, handled by the script executor. 63568: MNT-10067 : Cleanup alf_prop_XXX data Added start and end transaction marks to the scripts. 64115: MNT-10067: added Quartz job that by default doesn't fire until 2099 and can be manually invoked over JMX. 64223: MNT-10067: improved testing for AuditDAOTest and added PropertyValueDAOTest 64685: MNT-10067: added AttributeServiceTest 65796: MNT-10067 : Cleanup alf_prop_XXX data Implemented a performance test. 65983: MNT-10067 : Cleanup alf_prop_XXX data Reworked the MySQL script. Added time measurements for entry creation. 66116: MNT-10067 : Cleanup alf_prop_XXX data For MySQL: 1) Renamed temp tables. 2) Split the script into execution and cleanup of temp tables parts. 67023: MNT-10067 : Cleanup alf_prop_XXX data Modified MySQL script to skip null values from alf_prop_unique_ctx.prop1_id. 67199: MNT-10067 : Cleanup alf_prop_XXX data Implemented the latest changes of the script for other DB flavors. Removed the MS SQL Server transaction marks. 67763: MNT-10067 : Cleanup alf_prop_XXX data Removed unnecessary temporary index dropping. Added additional cleanup before main script execution. 68710: MNT-10067 : Cleanup alf_prop_XXX data Added batch logging. Moved clearCaches() statement in PropertyValueDAOImpl.cleanupUnusedValues() to finally block. 68711: MNT-10067 : Cleanup alf_prop_XXX data Added batching for MySQL script. 69602: MNT-10067 : Cleanup alf_prop_XXX data Updated scripts for all DB flavors with batching. 69768: MNT-10067 : Cleanup alf_prop_XXX data Fixed failing ScriptBundleExecutorImplIntegrationTest and ScriptExecutorImplIntegrationTest. 70058: Sync with latest changes in V4.1-BUG-FIX. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@74691 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
196 lines
8.0 KiB
Java
196 lines
8.0 KiB
Java
/*
|
|
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
|
*
|
|
* This file is part of Alfresco
|
|
*
|
|
* Alfresco is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* Alfresco 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 Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
package org.alfresco.repo.attributes;
|
|
|
|
import java.io.Serializable;
|
|
import java.util.ArrayList;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
|
|
import junit.framework.TestCase;
|
|
|
|
import org.alfresco.repo.domain.propval.PropValGenerator;
|
|
import org.alfresco.repo.domain.propval.PropertyValueDAO;
|
|
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
|
import org.alfresco.service.cmr.attributes.AttributeService;
|
|
import org.alfresco.service.cmr.attributes.AttributeService.AttributeQueryCallback;
|
|
import org.alfresco.util.ApplicationContextHelper;
|
|
import org.alfresco.util.Pair;
|
|
import org.apache.commons.lang.mutable.MutableInt;
|
|
import org.springframework.context.ApplicationContext;
|
|
|
|
/**
|
|
* {@link AttributeService}
|
|
*
|
|
* @author Derek Hulley
|
|
*/
|
|
public class AttributeServiceTest extends TestCase
|
|
{
|
|
private static final Serializable KEY_A = "a";
|
|
private static final Serializable[] KEY_AAA = new Serializable[] {"a", "a", "a"};
|
|
private static final Serializable[] KEY_AAB = new Serializable[] {"a", "a", "b"};
|
|
private static final Serializable[] KEY_AAC = new Serializable[] {"a", "a", "c"};
|
|
private static final Serializable VALUE_AAA_STRING = "aaa";
|
|
private static final Serializable VALUE_AAB_STRING = "aab";
|
|
private static final Serializable VALUE_AAC_STRING = "aac";
|
|
|
|
private ApplicationContext ctx;
|
|
private AttributeService attributeService;
|
|
private PropertyValueDAO propertyValueDAO;
|
|
|
|
@Override
|
|
protected void setUp() throws Exception
|
|
{
|
|
ctx = ApplicationContextHelper.getApplicationContext();
|
|
attributeService = (AttributeService) ctx.getBean("AttributeService");
|
|
propertyValueDAO = (PropertyValueDAO) ctx.getBean("propertyValueDAO");
|
|
}
|
|
|
|
@Override
|
|
protected void tearDown() throws Exception
|
|
{
|
|
}
|
|
|
|
public void testBasic() throws Exception
|
|
{
|
|
attributeService.removeAttribute(KEY_AAA);
|
|
attributeService.removeAttribute(KEY_AAB);
|
|
attributeService.removeAttribute(KEY_AAC);
|
|
|
|
assertFalse(attributeService.exists(KEY_AAA));
|
|
assertFalse(attributeService.exists(KEY_AAB));
|
|
assertFalse(attributeService.exists(KEY_AAC));
|
|
|
|
attributeService.setAttribute(VALUE_AAA_STRING, KEY_AAA);
|
|
attributeService.setAttribute(VALUE_AAB_STRING, KEY_AAB);
|
|
attributeService.setAttribute(VALUE_AAC_STRING, KEY_AAC);
|
|
|
|
assertTrue(attributeService.exists(KEY_AAA));
|
|
assertTrue(attributeService.exists(KEY_AAB));
|
|
assertTrue(attributeService.exists(KEY_AAC));
|
|
|
|
assertEquals(VALUE_AAA_STRING, attributeService.getAttribute(KEY_AAA));
|
|
assertEquals(VALUE_AAB_STRING, attributeService.getAttribute(KEY_AAB));
|
|
assertEquals(VALUE_AAC_STRING, attributeService.getAttribute(KEY_AAC));
|
|
//
|
|
// attributeService.removeAttribute(KEY_AAA);
|
|
// attributeService.removeAttribute(KEY_AAB);
|
|
// attributeService.removeAttribute(KEY_AAC);
|
|
}
|
|
|
|
/**
|
|
* Checks that {@link AttributeService#getAttributes(AttributeQueryCallback, Serializable...) AttributeService.getAttributes}
|
|
* works. This includes coverage of <a href=https://issues.alfresco.com/jira/browse/MNT-9112>MNT-9112</a>.
|
|
*/
|
|
public void testGetAttributes() throws Exception
|
|
{
|
|
attributeService.setAttribute(VALUE_AAA_STRING, KEY_AAA);
|
|
attributeService.setAttribute(VALUE_AAB_STRING, KEY_AAB);
|
|
attributeService.setAttribute(VALUE_AAC_STRING, KEY_AAC);
|
|
|
|
final List<Serializable> results = new ArrayList<Serializable>();
|
|
final MutableInt counter = new MutableInt();
|
|
final MutableInt max = new MutableInt(3);
|
|
AttributeQueryCallback callback = new AttributeQueryCallback()
|
|
{
|
|
@Override
|
|
public boolean handleAttribute(Long id, Serializable value, Serializable[] keys)
|
|
{
|
|
counter.increment();
|
|
results.add(value);
|
|
if (counter.intValue() == max.intValue())
|
|
{
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
};
|
|
|
|
counter.setValue(0);
|
|
max.setValue(3);
|
|
results.clear();
|
|
attributeService.getAttributes(callback, KEY_A);
|
|
assertEquals(3, results.size());
|
|
assertEquals(3, counter.getValue());
|
|
|
|
counter.setValue(0);
|
|
max.setValue(2);
|
|
results.clear();
|
|
attributeService.getAttributes(callback, KEY_A);
|
|
assertEquals(2, results.size());
|
|
assertEquals(2, counter.getValue());
|
|
}
|
|
|
|
public void testRemoveOrphanedProps()
|
|
{
|
|
final Serializable[] stringKey = new String[] { "z", "q", "string" };
|
|
final Serializable[] doubleKey = new String[] { "z", "q", "double" };
|
|
final Serializable[] dateKey = new String[] { "z", "q", "date" };
|
|
|
|
// Make sure there's nothing left from previous failed test runs etc.
|
|
attributeService.removeAttributes(stringKey);
|
|
attributeService.removeAttributes(doubleKey);
|
|
attributeService.removeAttributes(dateKey);
|
|
|
|
final PropValGenerator valueGen = new PropValGenerator(propertyValueDAO);
|
|
|
|
// Create some values
|
|
final String stringValue = valueGen.createUniqueString();
|
|
attributeService.createAttribute(stringValue, stringKey);
|
|
|
|
final Double doubleValue = valueGen.createUniqueDouble();
|
|
attributeService.createAttribute(doubleValue, doubleKey);
|
|
|
|
final Date dateValue = valueGen.createUniqueDate();
|
|
attributeService.createAttribute(dateValue, dateKey);
|
|
|
|
// Remove the properties, potentially leaving oprhaned prop values.
|
|
attributeService.removeAttributes(stringKey);
|
|
attributeService.removeAttributes(doubleKey);
|
|
attributeService.removeAttributes(dateKey);
|
|
|
|
// Check there are some persisted values to delete, otherwise there is no
|
|
// need to run the cleanup script in the first place.
|
|
assertEquals(stringValue, propertyValueDAO.getPropertyValue(stringValue).getSecond());
|
|
assertEquals(doubleValue, propertyValueDAO.getPropertyValue(doubleValue).getSecond());
|
|
assertEquals(dateValue, propertyValueDAO.getPropertyValue(dateValue).getSecond());
|
|
|
|
// Run the cleanup script - should remove the orphaned values.
|
|
propertyValueDAO.cleanupUnusedValues();
|
|
|
|
// Check that the cleanup script removed the orphaned values.
|
|
assertPropDeleted(propertyValueDAO.getPropertyValue(stringValue));
|
|
assertPropDeleted(propertyValueDAO.getPropertyValue(doubleValue));
|
|
assertPropDeleted(propertyValueDAO.getPropertyValue(dateValue));
|
|
}
|
|
|
|
private void assertPropDeleted(Pair<Long, ?> value)
|
|
{
|
|
if (value != null)
|
|
{
|
|
String msg = String.format("Property value [%s=%s] should have been deleted by cleanup script.",
|
|
value.getSecond().getClass().getSimpleName(), value.getSecond());
|
|
fail(msg);
|
|
}
|
|
}
|
|
}
|