mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-01 14:41:46 +00:00
ACS-1582 : Storage classes - java api (#467)
* ACS-1582 : Storage classes - java api - added ContentContext updates - added StorageClasses related exception
This commit is contained in:
committed by
Andrea Ligios
parent
9e7c3f3502
commit
0b840643f9
@@ -26,6 +26,7 @@
|
|||||||
package org.alfresco.repo.content;
|
package org.alfresco.repo.content;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.alfresco.service.cmr.repository.ContentReader;
|
import org.alfresco.service.cmr.repository.ContentReader;
|
||||||
|
|
||||||
@@ -49,6 +50,7 @@ public class ContentContext implements Serializable
|
|||||||
|
|
||||||
private ContentReader existingContentReader;
|
private ContentReader existingContentReader;
|
||||||
private String contentUrl;
|
private String contentUrl;
|
||||||
|
private Set<String> storageClasses;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct the instance with the content URL.
|
* Construct the instance with the content URL.
|
||||||
@@ -89,4 +91,21 @@ public class ContentContext implements Serializable
|
|||||||
return contentUrl;
|
return contentUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Returns the storage classes for the content- may be <tt>null</tt>
|
||||||
|
*/
|
||||||
|
public Set<String> getStorageClasses()
|
||||||
|
{
|
||||||
|
return storageClasses;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the storage classes for the content- may be <tt>null</tt>
|
||||||
|
*
|
||||||
|
* @param storageClasses
|
||||||
|
*/
|
||||||
|
public void setStorageClasses(Set<String> storageClasses)
|
||||||
|
{
|
||||||
|
this.storageClasses = storageClasses;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -25,6 +25,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.repo.content;
|
package org.alfresco.repo.content;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.alfresco.api.AlfrescoPublicApi;
|
import org.alfresco.api.AlfrescoPublicApi;
|
||||||
import org.alfresco.service.cmr.repository.ContentAccessor;
|
import org.alfresco.service.cmr.repository.ContentAccessor;
|
||||||
import org.alfresco.service.cmr.repository.ContentIOException;
|
import org.alfresco.service.cmr.repository.ContentIOException;
|
||||||
@@ -33,8 +38,6 @@ import org.alfresco.service.cmr.repository.ContentStreamListener;
|
|||||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||||
import org.alfresco.service.cmr.repository.DirectAccessUrl;
|
import org.alfresco.service.cmr.repository.DirectAccessUrl;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides low-level retrieval of content
|
* Provides low-level retrieval of content
|
||||||
* {@link org.alfresco.service.cmr.repository.ContentReader readers} and
|
* {@link org.alfresco.service.cmr.repository.ContentReader readers} and
|
||||||
@@ -89,6 +92,16 @@ public interface ContentStore
|
|||||||
*/
|
*/
|
||||||
public static final String PROTOCOL_DELIMITER = "://";
|
public static final String PROTOCOL_DELIMITER = "://";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The 'default' storage class
|
||||||
|
*
|
||||||
|
* A content is considered to have a default storage class if:
|
||||||
|
* the value is a Set.of("default")
|
||||||
|
* the value is an empty set
|
||||||
|
* the value is null
|
||||||
|
*/
|
||||||
|
public static final String DEFAULT_SC = "default";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the content URL format is supported by the store.
|
* Check if the content URL format is supported by the store.
|
||||||
*
|
*
|
||||||
@@ -263,4 +276,64 @@ public interface ContentStore
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether or not the current {@link ContentStore} supports the provided {@link Set} storage classes
|
||||||
|
*
|
||||||
|
* @param storageClasses The storage classes that will be checked whether or not are supported
|
||||||
|
* @return true if the storage classes are supported, false otherwise.
|
||||||
|
*/
|
||||||
|
default boolean isStorageClassesSupported(Set<String> storageClasses)
|
||||||
|
{
|
||||||
|
return storageClasses == null ||
|
||||||
|
storageClasses.isEmpty() ||
|
||||||
|
(1 == storageClasses.size() && storageClasses.contains(DEFAULT_SC));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Returns the complete {@link Set} of supported storage classes by this {@link ContentStore}
|
||||||
|
*/
|
||||||
|
default Set<String> getSupportedStorageClasses()
|
||||||
|
{
|
||||||
|
return Set.of(DEFAULT_SC);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the storage class for content
|
||||||
|
*
|
||||||
|
* @param contentUrl The URL of the content that will have its storage classes updated
|
||||||
|
* @param storageClasses The new storage classes
|
||||||
|
* @param parameters extra parameters
|
||||||
|
*/
|
||||||
|
default void updateStorageClasses(String contentUrl, Set<String> storageClasses, Map<String, Object> parameters)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param contentUrl the URL of the content for which the storage classes are to be requested
|
||||||
|
* @return Returns the current storage classes for the content found at the contentUrl
|
||||||
|
*/
|
||||||
|
default Set<String> findStorageClasses(String contentUrl)
|
||||||
|
{
|
||||||
|
return Collections.emptySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Returns the complete collection of allowed storage classes transitions.
|
||||||
|
* The key represents the source storage classes while the value (as a {@link Set}) represents all the possible target storage classes.
|
||||||
|
*/
|
||||||
|
default Map<Set<String>, Set<Set<String>>> getStorageClassesTransitions()
|
||||||
|
{
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param contentUrl the URL of the content for which the storage classes transitions are to be requested
|
||||||
|
* @return Returns the complete collection of allowed storage classes transitions for the content found at content URL
|
||||||
|
*/
|
||||||
|
default Map<Set<String>, Set<Set<String>>> findStorageClassesTransitions(String contentUrl)
|
||||||
|
{
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* #%L
|
||||||
|
* Alfresco Data model classes
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
||||||
|
* %%
|
||||||
|
* This file is part of the Alfresco software.
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
package org.alfresco.repo.content;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thrown when an operation regarding the storage classes of the content failed to execute.
|
||||||
|
*
|
||||||
|
* @author Lucian Tuca
|
||||||
|
*/
|
||||||
|
public class UnsupportedStorageClassException extends AlfrescoRuntimeException
|
||||||
|
{
|
||||||
|
private final ContentStore contentStore;
|
||||||
|
private final Set<String> storageClasses;
|
||||||
|
|
||||||
|
public UnsupportedStorageClassException(ContentStore contentStore, Set<String> storageClasses, String msg)
|
||||||
|
{
|
||||||
|
super(msg);
|
||||||
|
this.contentStore = contentStore;
|
||||||
|
this.storageClasses = storageClasses;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContentStore getContentStore()
|
||||||
|
{
|
||||||
|
return contentStore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<String> getStorageClasses()
|
||||||
|
{
|
||||||
|
return storageClasses;
|
||||||
|
}
|
||||||
|
}
|
@@ -25,7 +25,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.repo.content;
|
package org.alfresco.repo.content;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||||
import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
|
import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
|
||||||
import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
|
import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
|
||||||
@@ -416,4 +418,35 @@ public abstract class AbstractRoutingContentStore implements ContentStore
|
|||||||
}
|
}
|
||||||
return deleted;
|
return deleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isStorageClassesSupported(Set<String> storageClasses)
|
||||||
|
{
|
||||||
|
boolean supported = false;
|
||||||
|
for (ContentStore store : getAllStores())
|
||||||
|
{
|
||||||
|
if (store.isStorageClassesSupported(storageClasses))
|
||||||
|
{
|
||||||
|
supported = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Done
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug("The storage classes " + storageClasses + (supported ? "are" : "are not") + " supported by at least one store.");
|
||||||
|
}
|
||||||
|
return supported;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<String> getSupportedStorageClasses()
|
||||||
|
{
|
||||||
|
Set<String> supportedStorageClasses = new HashSet<>();
|
||||||
|
for (ContentStore store : getAllStores())
|
||||||
|
{
|
||||||
|
supportedStorageClasses.addAll(store.getSupportedStorageClasses());
|
||||||
|
}
|
||||||
|
return supportedStorageClasses;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -26,6 +26,7 @@
|
|||||||
package org.alfresco.repo.content.caching;
|
package org.alfresco.repo.content.caching;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||||
import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
|
import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
|
||||||
import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
|
import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
|
||||||
@@ -487,4 +488,16 @@ public class CachingContentStore implements ContentStore, ApplicationEventPublis
|
|||||||
{
|
{
|
||||||
return backingStore.getDirectAccessUrl(contentUrl, expiresAt);
|
return backingStore.getDirectAccessUrl(contentUrl, expiresAt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isStorageClassesSupported(Set<String> storageClasses)
|
||||||
|
{
|
||||||
|
return backingStore.isStorageClassesSupported(storageClasses);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<String> getSupportedStorageClasses()
|
||||||
|
{
|
||||||
|
return backingStore.getSupportedStorageClasses();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -27,6 +27,7 @@ package org.alfresco.repo.content.replication;
|
|||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.locks.Lock;
|
import java.util.concurrent.locks.Lock;
|
||||||
import java.util.concurrent.locks.ReadWriteLock;
|
import java.util.concurrent.locks.ReadWriteLock;
|
||||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||||
@@ -375,4 +376,36 @@ public class AggregatingContentStore extends AbstractContentStore
|
|||||||
readLock.unlock();
|
readLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isStorageClassesSupported(Set<String> storageClasses)
|
||||||
|
{
|
||||||
|
// Check the primary store
|
||||||
|
boolean isStorageClassesSupported = primaryStore.isStorageClassesSupported(storageClasses);
|
||||||
|
|
||||||
|
if (!isStorageClassesSupported)
|
||||||
|
{
|
||||||
|
// Storage class is not supported by the primary store so we have to check the
|
||||||
|
// other stores
|
||||||
|
for (ContentStore store : secondaryStores)
|
||||||
|
{
|
||||||
|
isStorageClassesSupported = store.isDirectAccessSupported();
|
||||||
|
|
||||||
|
if (isStorageClassesSupported)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return isStorageClassesSupported;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<String> getSupportedStorageClasses()
|
||||||
|
{
|
||||||
|
// We only need to provide info about the primary store,
|
||||||
|
// because the aggregating CS only allows to be written in the primary
|
||||||
|
return primaryStore.getSupportedStorageClasses();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -30,6 +30,7 @@ import java.util.Collections;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||||
import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
|
import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
|
||||||
import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
|
import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
|
||||||
@@ -271,5 +272,17 @@ public abstract class AbstractTenantRoutingContentStore extends AbstractRoutingC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isStorageClassesSupported(Set<String> storageClasses)
|
||||||
|
{
|
||||||
|
return getTenantContentStore().isStorageClassesSupported(storageClasses);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<String> getSupportedStorageClasses()
|
||||||
|
{
|
||||||
|
return getTenantContentStore().getSupportedStorageClasses();
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract ContentStore initContentStore(ApplicationContext ctx, String contentRoot);
|
protected abstract ContentStore initContentStore(ApplicationContext ctx, String contentRoot);
|
||||||
}
|
}
|
||||||
|
@@ -25,13 +25,16 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.service.cmr.repository;
|
package org.alfresco.service.cmr.repository;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.alfresco.api.AlfrescoPublicApi;
|
import org.alfresco.api.AlfrescoPublicApi;
|
||||||
import org.alfresco.service.Auditable;
|
import org.alfresco.service.Auditable;
|
||||||
import org.alfresco.service.cmr.dictionary.InvalidTypeException;
|
import org.alfresco.service.cmr.dictionary.InvalidTypeException;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides methods for accessing and transforming content.
|
* Provides methods for accessing and transforming content.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -170,4 +173,62 @@ public interface ContentService
|
|||||||
*/
|
*/
|
||||||
@Auditable(parameters = {"nodeRef", "expiresAt"})
|
@Auditable(parameters = {"nodeRef", "expiresAt"})
|
||||||
public DirectAccessUrl getDirectAccessUrl(NodeRef nodeRef, Date expiresAt);
|
public DirectAccessUrl getDirectAccessUrl(NodeRef nodeRef, Date expiresAt);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether or not the current {@link ContentService} supports the provided {@link Set} storage classes
|
||||||
|
*
|
||||||
|
* @param storageClasses The storage classes that will be checked whether or not are supported
|
||||||
|
* @return true if the storage classes are supported, false otherwise.
|
||||||
|
*/
|
||||||
|
default boolean isStorageClassesSupported(Set<String> storageClasses)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Returns the complete {@link Set} of supported storage classes by this {@link ContentService}
|
||||||
|
*/
|
||||||
|
default Set<String> getSupportedStorageClasses()
|
||||||
|
{
|
||||||
|
return Collections.emptySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the storage class for a {@link NodeRef}
|
||||||
|
*
|
||||||
|
* @param nodeRef The ref of the node that will have its storage classes updated
|
||||||
|
* @param storageClasses The new storage classes
|
||||||
|
* @param parameters extra parameters
|
||||||
|
*/
|
||||||
|
default void updateStorageClasses(NodeRef nodeRef, Set<String> storageClasses, Map<String, Object> parameters)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param nodeRef the {@link NodeRef} for which the storage classes are to be requested
|
||||||
|
* @return Returns the current storage classes for the given {@link NodeRef}
|
||||||
|
*/
|
||||||
|
default Set<String> findStorageClasses(NodeRef nodeRef)
|
||||||
|
{
|
||||||
|
return Collections.emptySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Returns the complete collection of allowed storage classes transitions.
|
||||||
|
* The key represents the source storage classes while the value (as a {@link Set}) represents all the possible target storage classes.
|
||||||
|
*/
|
||||||
|
default Map<Set<String>, Set<Set<String>>> getStorageClassesTransitions()
|
||||||
|
{
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param nodeRef the {@link NodeRef} for which the storage classes transitions are to be requested
|
||||||
|
* @return Returns the complete collection of allowed storage classes transitions for the content found at content URL
|
||||||
|
*/
|
||||||
|
default Map<Set<String>, Set<Set<String>>> findStorageClassesTransitions(NodeRef nodeRef)
|
||||||
|
{
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -25,6 +25,12 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.repo.content;
|
package org.alfresco.repo.content;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -42,12 +48,6 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.experimental.categories.Category;
|
import org.junit.experimental.categories.Category;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensures that the routing of URLs based on context is working. A combination
|
* Ensures that the routing of URLs based on context is working. A combination
|
||||||
* of fully featured and incompletely featured stores is used to ensure that
|
* of fully featured and incompletely featured stores is used to ensure that
|
||||||
@@ -157,6 +157,12 @@ public class RoutingContentStoreTest extends AbstractWritableContentStoreTest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsStorageClassesSupported()
|
||||||
|
{
|
||||||
|
assertTrue(routingStore.isStorageClassesSupported(null));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A test routing store that directs content writes to a randomly-chosen store.
|
* A test routing store that directs content writes to a randomly-chosen store.
|
||||||
* Matching of content URLs back to the stores is handled by the base class.
|
* Matching of content URLs back to the stores is handled by the base class.
|
||||||
|
@@ -30,21 +30,24 @@ import static org.junit.Assert.assertEquals;
|
|||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.Assert.assertSame;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.anyLong;
|
import static org.mockito.ArgumentMatchers.anyLong;
|
||||||
|
import static org.mockito.ArgumentMatchers.anySet;
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Mockito.atLeastOnce;
|
import static org.mockito.Mockito.atLeastOnce;
|
||||||
import static org.mockito.Mockito.doThrow;
|
import static org.mockito.Mockito.doThrow;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.only;
|
import static org.mockito.Mockito.only;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.alfresco.repo.content.ContentContext;
|
import org.alfresco.repo.content.ContentContext;
|
||||||
import org.alfresco.repo.content.ContentStore;
|
import org.alfresco.repo.content.ContentStore;
|
||||||
@@ -520,4 +523,22 @@ public class CachingContentStoreTest
|
|||||||
when(backingStore.getDirectAccessUrl(anyString(), any())).thenReturn(new DirectAccessUrl());
|
when(backingStore.getDirectAccessUrl(anyString(), any())).thenReturn(new DirectAccessUrl());
|
||||||
cachingStore.getDirectAccessUrl("url", null);
|
cachingStore.getDirectAccessUrl("url", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBackingStoreIsCalledForSupportedStorageClasses()
|
||||||
|
{
|
||||||
|
when(backingStore.isStorageClassesSupported(anySet())).thenReturn(true);
|
||||||
|
|
||||||
|
final Set<String> storageClasses = Set.of("a-certain-storage-class");
|
||||||
|
assertTrue(cachingStore.isStorageClassesSupported(storageClasses));
|
||||||
|
verify(backingStore, times(1)).isStorageClassesSupported(storageClasses);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBackingStoreIsCalledForGetSupportedStorageClasses()
|
||||||
|
{
|
||||||
|
when(backingStore.getSupportedStorageClasses()).thenReturn(Collections.emptySet());
|
||||||
|
assertTrue(cachingStore.getSupportedStorageClasses().isEmpty());
|
||||||
|
verify(backingStore, times(1)).getSupportedStorageClasses();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -25,9 +25,16 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.repo.content.filestore;
|
package org.alfresco.repo.content.filestore;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.alfresco.repo.content.AbstractWritableContentStoreTest;
|
import org.alfresco.repo.content.AbstractWritableContentStoreTest;
|
||||||
import org.alfresco.repo.content.ContentContext;
|
import org.alfresco.repo.content.ContentContext;
|
||||||
@@ -46,12 +53,6 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.experimental.categories.Category;
|
import org.junit.experimental.categories.Category;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests read and write functionality for the store.
|
* Tests read and write functionality for the store.
|
||||||
*
|
*
|
||||||
@@ -348,6 +349,18 @@ public class FileContentStoreTest extends AbstractWritableContentStoreTest
|
|||||||
assertEquals(1024L, reader.getContentString().getBytes("UTF-8").length);
|
assertEquals(1024L, reader.getContentString().getBytes("UTF-8").length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSupportsDefaultStorageClass()
|
||||||
|
{
|
||||||
|
assertTrue(store.isStorageClassesSupported(Set.of(ContentStore.DEFAULT_SC)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDoesNotSupportUnknownStorageClass()
|
||||||
|
{
|
||||||
|
assertFalse(store.isStorageClassesSupported(Set.of("unknown")));
|
||||||
|
}
|
||||||
|
|
||||||
private void assertDirExists(File root, String dir)
|
private void assertDirExists(File root, String dir)
|
||||||
{
|
{
|
||||||
assertTrue("Directory [" + dir + "] should exist", new File(root, dir).exists());
|
assertTrue("Directory [" + dir + "] should exist", new File(root, dir).exists());
|
||||||
|
@@ -25,9 +25,24 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.repo.content.replication;
|
package org.alfresco.repo.content.replication;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.alfresco.repo.content.AbstractWritableContentStoreTest;
|
import org.alfresco.repo.content.AbstractWritableContentStoreTest;
|
||||||
import org.alfresco.repo.content.ContentContext;
|
import org.alfresco.repo.content.ContentContext;
|
||||||
@@ -49,18 +64,6 @@ import org.mockito.Mock;
|
|||||||
import org.mockito.junit.MockitoJUnit;
|
import org.mockito.junit.MockitoJUnit;
|
||||||
import org.mockito.junit.MockitoRule;
|
import org.mockito.junit.MockitoRule;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
import static org.junit.Assert.assertNull;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests read and write functionality for the aggregating store.
|
* Tests read and write functionality for the aggregating store.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -309,4 +312,51 @@ public class AggregatingContentStoreTest extends AbstractWritableContentStoreTes
|
|||||||
directAccessUrl = aggStore.getDirectAccessUrl("urlSecSupported", null);
|
directAccessUrl = aggStore.getDirectAccessUrl("urlSecSupported", null);
|
||||||
assertNotNull(directAccessUrl);
|
assertNotNull(directAccessUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsStorageClassesSupported()
|
||||||
|
{
|
||||||
|
Set<String> sc = Set.of("a-certain-storage-class");
|
||||||
|
// Create the aggregating store
|
||||||
|
AggregatingContentStore aggStore = new AggregatingContentStore();
|
||||||
|
aggStore.setPrimaryStore(primaryStoreMock);
|
||||||
|
aggStore.setSecondaryStores(List.of(secondaryStoreMock));
|
||||||
|
|
||||||
|
// SC supported by the primary store
|
||||||
|
when(primaryStoreMock.isStorageClassesSupported(sc)).thenReturn(true);
|
||||||
|
assertTrue(aggStore.isStorageClassesSupported(sc));
|
||||||
|
verify(primaryStoreMock, times(1)).isStorageClassesSupported(sc);
|
||||||
|
verify(secondaryStoreMock, never()).isStorageClassesSupported(sc);
|
||||||
|
|
||||||
|
// SC supported by the secondary store
|
||||||
|
when(primaryStoreMock.isStorageClassesSupported(sc)).thenReturn(false);
|
||||||
|
when(secondaryStoreMock.isStorageClassesSupported(sc)).thenReturn(true);
|
||||||
|
assertTrue(aggStore.isStorageClassesSupported(sc));
|
||||||
|
verify(primaryStoreMock, times(1)).isStorageClassesSupported(sc);
|
||||||
|
verify(secondaryStoreMock, times(1)).isStorageClassesSupported(sc);
|
||||||
|
|
||||||
|
// SC not supported by the stores
|
||||||
|
when(primaryStoreMock.isStorageClassesSupported(sc)).thenReturn(false);
|
||||||
|
when(secondaryStoreMock.isStorageClassesSupported(sc)).thenReturn(false);
|
||||||
|
assertFalse(aggStore.isStorageClassesSupported(sc));
|
||||||
|
verify(primaryStoreMock, times(1)).isStorageClassesSupported(sc);
|
||||||
|
verify(secondaryStoreMock, times(1)).isStorageClassesSupported(sc);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetSupportedStorageClasses()
|
||||||
|
{
|
||||||
|
Set<String> sc = Collections.emptySet();
|
||||||
|
// Create the aggregating store
|
||||||
|
AggregatingContentStore aggStore = new AggregatingContentStore();
|
||||||
|
aggStore.setPrimaryStore(primaryStoreMock);
|
||||||
|
aggStore.setSecondaryStores(List.of(secondaryStoreMock));
|
||||||
|
|
||||||
|
when(primaryStoreMock.getSupportedStorageClasses()).thenReturn(sc);
|
||||||
|
|
||||||
|
final Set<String> supportedStorageClasses = aggStore.getSupportedStorageClasses();
|
||||||
|
assertTrue(supportedStorageClasses.isEmpty());
|
||||||
|
verify(primaryStoreMock, times(1)).getSupportedStorageClasses();
|
||||||
|
verify(secondaryStoreMock, times(0)).getSupportedStorageClasses();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user