use of org.opencastproject.assetmanager.impl.storage.DeletionSelector in project opencast by opencast.
the class AbstractFileSystemAssetStoreTest method testDeleteNoneVersion.
@Test
public void testDeleteNoneVersion() throws Exception {
DeletionSelector noneVersionSelector = DeletionSelector.deleteAll(ORG_ID, MP_ID);
assertTrue(repo.delete(noneVersionSelector));
assertFalse(sampleElemDir.exists());
File file = new File(PathSupport.concat(new String[] { tmpRoot.toString(), ORG_ID, MP_ID }));
assertFalse(file.exists());
}
use of org.opencastproject.assetmanager.impl.storage.DeletionSelector in project opencast by opencast.
the class AbstractFileSystemAssetStoreTest method testDeleteWithVersion.
@Test
public void testDeleteWithVersion() throws Exception {
DeletionSelector versionSelector = DeletionSelector.delete(ORG_ID, MP_ID, VERSION_2);
assertTrue(repo.delete(versionSelector));
assertFalse(sampleElemDir.exists());
File file = new File(PathSupport.concat(new String[] { tmpRoot.toString(), ORG_ID, MP_ID, VERSION_2.toString() }));
assertFalse(file.exists());
file = new File(PathSupport.concat(new String[] { tmpRoot.toString(), ORG_ID, MP_ID }));
assertFalse(file.exists());
file = new File(PathSupport.concat(new String[] { tmpRoot.toString(), ORG_ID }));
assertTrue(file.exists());
}
use of org.opencastproject.assetmanager.impl.storage.DeletionSelector in project opencast by opencast.
the class AbstractFileSystemAssetStoreTest method testDeleteWrongVersion.
@Test
public void testDeleteWrongVersion() throws Exception {
DeletionSelector versionSelector = DeletionSelector.delete(ORG_ID, MP_ID, VERSION_1);
repo.delete(versionSelector);
assertTrue(sampleElemDir.exists());
}
use of org.opencastproject.assetmanager.impl.storage.DeletionSelector in project opencast by opencast.
the class SchedulerServiceImplTest method mkAssetStore.
AssetStore mkAssetStore() {
return new AssetStore() {
@Override
public Option<Long> getUsedSpace() {
return Option.none();
}
@Override
public Option<Long> getUsableSpace() {
return Option.none();
}
@Override
public Option<Long> getTotalSpace() {
return Option.none();
}
@Override
public void put(StoragePath path, Source source) throws AssetStoreException {
File destFile = new File(baseDir, UrlSupport.concat(path.getMediaPackageId(), path.getMediaPackageElementId(), path.getVersion().toString()));
try {
FileUtils.copyFile(workspace.get(source.getUri()), destFile);
} catch (IOException e) {
throw new RuntimeException(e);
} catch (NotFoundException e) {
throw new RuntimeException(e);
}
}
@Override
public Opt<InputStream> get(StoragePath path) throws AssetStoreException {
File file = new File(baseDir, UrlSupport.concat(path.getMediaPackageId(), path.getMediaPackageElementId(), path.getVersion().toString()));
InputStream inputStream;
try {
inputStream = new ByteArrayInputStream(FileUtils.readFileToByteArray(file));
return Opt.some(inputStream);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public boolean delete(DeletionSelector sel) throws AssetStoreException {
return false;
}
@Override
public boolean copy(StoragePath from, StoragePath to) throws AssetStoreException {
File file = new File(baseDir, UrlSupport.concat(from.getMediaPackageId(), from.getMediaPackageElementId(), from.getVersion().toString()));
File destFile = new File(baseDir, UrlSupport.concat(to.getMediaPackageId(), to.getMediaPackageElementId(), to.getVersion().toString()));
try {
FileUtils.copyFile(file, destFile);
return true;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public boolean contains(StoragePath path) throws AssetStoreException {
return false;
}
};
}
use of org.opencastproject.assetmanager.impl.storage.DeletionSelector in project opencast by opencast.
the class AssetManagerTestBase method mkAssetStore.
/**
* Create a test asset store.
*/
protected AssetStore mkAssetStore() {
return new AssetStore() {
private Set<StoragePath> store = new HashSet<>();
private void logSize() {
logger.debug(format("Store contains %d asset/s", store.size()));
}
@Override
public void put(StoragePath path, Source source) throws AssetStoreException {
store.add(path);
logSize();
}
@Override
public boolean copy(StoragePath from, StoragePath to) throws AssetStoreException {
if (store.contains(from)) {
store.add(to);
logSize();
return true;
} else {
return false;
}
}
@Override
public Opt<InputStream> get(StoragePath path) throws AssetStoreException {
return IoSupport.openClassPathResource("/dublincore-a.xml").toOpt();
}
@Override
public boolean contains(StoragePath path) throws AssetStoreException {
return store.contains(path);
}
@Override
public boolean delete(DeletionSelector sel) throws AssetStoreException {
logger.info("Delete from asset store " + sel);
final Set<StoragePath> newStore = new HashSet<>();
boolean deleted = false;
for (StoragePath s : store) {
if (!(sel.getOrganizationId().equals(s.getOrganizationId()) && sel.getMediaPackageId().equals(s.getMediaPackageId()) && sel.getVersion().map(eq(s.getVersion())).getOr(true))) {
newStore.add(s);
} else {
deleted = true;
}
}
store = newStore;
logSize();
return deleted;
}
@Override
public Option<Long> getTotalSpace() {
return Option.none();
}
@Override
public Option<Long> getUsableSpace() {
return Option.none();
}
@Override
public Option<Long> getUsedSpace() {
return Option.some((long) store.size());
}
};
}
Aggregations