mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Merged HEAD-BUG-FIX (5.1/Cloud) to HEAD (5.0/Cloud)
86231: Merged V4.2-BUG-FIX (4.2.4) to HEAD-BUG-FIX (5.0/Cloud) 86156: Merged DEV to V4.2-BUG-FIX (4.2.4) 86145 : MNT-11758 : Starting Alfresco with Centera as the main content store, with content store caching enabled, generates errors - We should recache content if content url was changed after write operation (like centera or xam) - Unit test was added. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@94528 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -273,9 +273,16 @@ public class CachingContentStore implements ContentStore, ApplicationEventPublis
|
|||||||
bsWriter.setLocale(cacheWriter.getLocale());
|
bsWriter.setLocale(cacheWriter.getLocale());
|
||||||
bsWriter.setMimetype(cacheWriter.getMimetype());
|
bsWriter.setMimetype(cacheWriter.getMimetype());
|
||||||
bsWriter.putContent(cacheWriter.getReader());
|
bsWriter.putContent(cacheWriter.getReader());
|
||||||
|
boolean contentUrlChanged = !url.equals(bsWriter.getContentUrl());
|
||||||
|
|
||||||
if (!quota.afterWritingCacheFile(cacheWriter.getSize()))
|
// MNT-11758 fix, re-cache files for which content url has changed after write to backing store (e.g. XAM, Centera)
|
||||||
|
if (!quota.afterWritingCacheFile(cacheWriter.getSize()) || contentUrlChanged)
|
||||||
{
|
{
|
||||||
|
if (contentUrlChanged)
|
||||||
|
{
|
||||||
|
// MNT-11758 fix, cache file with new and correct contentUrl after write operation to backing store completed
|
||||||
|
cache.put(bsWriter.getContentUrl(), cacheWriter.getReader());
|
||||||
|
}
|
||||||
// Quota manager has requested that the new cache file is not kept.
|
// Quota manager has requested that the new cache file is not kept.
|
||||||
cache.deleteFile(url);
|
cache.deleteFile(url);
|
||||||
cache.remove(url);
|
cache.remove(url);
|
||||||
|
@@ -34,6 +34,7 @@ import org.alfresco.repo.content.ContentContext;
|
|||||||
import org.alfresco.repo.content.ContentStore;
|
import org.alfresco.repo.content.ContentStore;
|
||||||
import org.alfresco.repo.content.caching.quota.QuotaManagerStrategy;
|
import org.alfresco.repo.content.caching.quota.QuotaManagerStrategy;
|
||||||
import org.alfresco.repo.content.filestore.FileContentStore;
|
import org.alfresco.repo.content.filestore.FileContentStore;
|
||||||
|
import org.alfresco.service.cmr.repository.ContentReader;
|
||||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||||
import org.alfresco.test_category.OwnJVMTestsCategory;
|
import org.alfresco.test_category.OwnJVMTestsCategory;
|
||||||
import org.alfresco.util.TempFileProvider;
|
import org.alfresco.util.TempFileProvider;
|
||||||
@@ -54,6 +55,7 @@ public class CachingContentStoreSpringTest extends AbstractWritableContentStoreT
|
|||||||
{
|
{
|
||||||
private CachingContentStore store;
|
private CachingContentStore store;
|
||||||
private FileContentStore backingStore;
|
private FileContentStore backingStore;
|
||||||
|
private TestCenteraLikeContentStore centeraLikeBackingStore;
|
||||||
private ContentCacheImpl cache;
|
private ContentCacheImpl cache;
|
||||||
|
|
||||||
|
|
||||||
@@ -194,6 +196,46 @@ public class CachingContentStoreSpringTest extends AbstractWritableContentStoreT
|
|||||||
assertEquals("Cache writer should still return actual size", overLimitSize, writer.getContentData().getSize());
|
assertEquals("Cache writer should still return actual size", overLimitSize, writer.getContentData().getSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* MNT-11758 case test
|
||||||
|
*/
|
||||||
|
public void testBackingStoreBehavesLikeCenteraContentStore()
|
||||||
|
{
|
||||||
|
String content1 = "test content 1";
|
||||||
|
String content2 = "test content 2";
|
||||||
|
|
||||||
|
// create backing store that behaves like centera content store, i.e. contentUrl is known only after content is written
|
||||||
|
centeraLikeBackingStore = new TestCenteraLikeContentStore(ctx,
|
||||||
|
TempFileProvider.getTempDir().getAbsolutePath() +
|
||||||
|
File.separatorChar +
|
||||||
|
getName() + "_centera");
|
||||||
|
|
||||||
|
// create caching content store with centera like backing store
|
||||||
|
store = new CachingContentStore(centeraLikeBackingStore, cache, true);
|
||||||
|
|
||||||
|
ContentWriter writer1 = store.getWriter(new ContentContext(null, null));
|
||||||
|
// for centera like backing content store all writers have the same content url before content was written
|
||||||
|
assertEquals(TestCenteraLikeContentWriter.UNKNOWN_ID, writer1.getContentData().getContentUrl());
|
||||||
|
writer1.putContent(content1);
|
||||||
|
// after content was written into the backing store, content url should change
|
||||||
|
assertNotSame(TestCenteraLikeContentWriter.UNKNOWN_ID, writer1.getContentData().getContentUrl());
|
||||||
|
|
||||||
|
// get another writer
|
||||||
|
ContentWriter writer2 = store.getWriter(new ContentContext(null, null));
|
||||||
|
// for centera like backing content store all writers have the same content url before content was written
|
||||||
|
assertEquals(TestCenteraLikeContentWriter.UNKNOWN_ID, writer2.getContentData().getContentUrl());
|
||||||
|
writer2.putContent(content2);
|
||||||
|
// after content was written into the backing store, content url should change
|
||||||
|
assertNotSame(TestCenteraLikeContentWriter.UNKNOWN_ID, writer2.getContentData().getContentUrl());
|
||||||
|
|
||||||
|
// writers should have different content urls
|
||||||
|
assertNotSame(writer1.getContentData().getContentUrl(), writer2.getContentData().getContentUrl());
|
||||||
|
|
||||||
|
ContentReader reader = store.getReader(writer1.getContentData().getContentUrl());
|
||||||
|
|
||||||
|
assertEquals(content1, reader.getContentString());
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @see org.alfresco.repo.content.AbstractReadOnlyContentStoreTest#getStore()
|
* @see org.alfresco.repo.content.AbstractReadOnlyContentStoreTest#getStore()
|
||||||
*/
|
*/
|
||||||
|
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2014 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.content.caching;
|
||||||
|
|
||||||
|
import org.alfresco.repo.content.filestore.FileContentStore;
|
||||||
|
import org.alfresco.repo.content.filestore.FileContentWriter;
|
||||||
|
import org.alfresco.service.cmr.repository.ContentReader;
|
||||||
|
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test content store that behaves like Centera content store
|
||||||
|
*
|
||||||
|
* @author pavel.yurkevich
|
||||||
|
*/
|
||||||
|
public class TestCenteraLikeContentStore extends FileContentStore
|
||||||
|
{
|
||||||
|
|
||||||
|
public TestCenteraLikeContentStore(ApplicationContext context, String rootDirectoryStr)
|
||||||
|
{
|
||||||
|
super(context, rootDirectoryStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ContentWriter getWriterInternal(ContentReader existingContentReader, String newContentUrl)
|
||||||
|
{
|
||||||
|
FileContentWriter fileContentWriter = (FileContentWriter)super.getWriterInternal(existingContentReader, newContentUrl);
|
||||||
|
|
||||||
|
return new TestCenteraLikeContentWriter(fileContentWriter.getFile(), fileContentWriter.getContentUrl(), existingContentReader);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2014 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.content.caching;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import org.alfresco.repo.content.ContentStore;
|
||||||
|
import org.alfresco.repo.content.filestore.FileContentStore;
|
||||||
|
import org.alfresco.repo.content.filestore.FileContentWriter;
|
||||||
|
import org.alfresco.service.cmr.repository.ContentIOException;
|
||||||
|
import org.alfresco.service.cmr.repository.ContentReader;
|
||||||
|
import org.alfresco.service.cmr.repository.ContentStreamListener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test content writer that changes its content url after content was written (like centera content writer)
|
||||||
|
*
|
||||||
|
* @author pavel.yurkevich
|
||||||
|
*/
|
||||||
|
public class TestCenteraLikeContentWriter extends FileContentWriter implements ContentStreamListener
|
||||||
|
{
|
||||||
|
public static final String UNKNOWN_ID = FileContentStore.STORE_PROTOCOL + ContentStore.PROTOCOL_DELIMITER + "UNKNOWN_ID";
|
||||||
|
|
||||||
|
private String originalContentUrl;
|
||||||
|
|
||||||
|
public TestCenteraLikeContentWriter(File file, String url, ContentReader existingContentReader)
|
||||||
|
{
|
||||||
|
super(file, UNKNOWN_ID, existingContentReader);
|
||||||
|
|
||||||
|
this.originalContentUrl = url;
|
||||||
|
|
||||||
|
this.addListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void contentStreamClosed() throws ContentIOException
|
||||||
|
{
|
||||||
|
setContentUrl(originalContentUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user