use of org.opencastproject.assetmanager.api.query.RichAResult in project opencast by opencast.
the class AbstractAssetManagerSelectTest method testSelectSnapshotByProperty.
@Test
public void testSelectSnapshotByProperty() throws Exception {
final String[] mp = createAndAddMediaPackagesSimple(3, 1, 1);
am.setProperty(p.approved.mk(mp[0], true));
final RichAResult r = enrich(q.select(q.snapshot()).where(q.hasPropertiesOf(p.namespace())).run());
assertEquals("The result set should contain one record", 1, r.getSize());
assertEquals("The result set should contain one snapshot", 1, r.countSnapshots());
assertEquals("The result set should contain media package " + mp[0], mp[0], r.getSnapshots().head2().getMediaPackage().getIdentifier().toString());
}
use of org.opencastproject.assetmanager.api.query.RichAResult in project opencast by opencast.
the class AbstractAssetManagerSelectTest method testManyMediaPackages.
@Ignore
@Test
public void testManyMediaPackages() throws Exception {
final long tStart = System.nanoTime();
final int mpCount = 1000;
final Stream<P2<String, Integer>> inserts = Stream.cont(inc()).take(mpCount).map(new FnX<Integer, P2<String, Integer>>() {
@Override
public P2<String, Integer> applyX(Integer ignore) throws Exception {
final MediaPackage mp = mkMediaPackage(mkCatalog());
final String mpId = mp.getIdentifier().toString();
final int versions = (int) (Math.random() * 10.0 + 1.0);
for (int i = 0; i < Math.random() * 10 + 1; i++) {
am.takeSnapshot(OWNER, mp);
}
// set the legacy ID property
am.setProperty(p.legacyId.mk(mpId, "legacyId=" + mpId));
return Products.E.p2(mp.getIdentifier().toString(), versions);
}
}).eval();
final long tInserted = System.nanoTime();
{
RichAResult r = enrich(q.select(q.snapshot()).where(q.version().isLatest()).run());
assertEquals(mpCount, r.getSize());
assertEquals(mpCount, r.countSnapshots());
}
for (final P2<String, Integer> insert : inserts) {
final RichAResult r = enrich(q.select(p.legacyId.target()).where(q.mediaPackageId(insert.get1()).and(q.version().isLatest())).run());
assertEquals(1, r.getSize());
assertEquals(0, r.countSnapshots());
assertEquals(1, r.countProperties());
assertEquals("legacyId=" + r.getRecords().head().get().getMediaPackageId(), r.getProperties().head().get().getValue().get(Value.STRING));
}
final long tQueried = System.nanoTime();
logger.info("Insertion ms " + ((tInserted - tStart) / 1000000));
logger.info("Queries ms " + ((tQueried - tInserted) / 1000000));
}
use of org.opencastproject.assetmanager.api.query.RichAResult in project opencast by opencast.
the class AbstractAssetManagerSelectTest method testSelectMultiplePropertyNamespaces.
@Test
public void testSelectMultiplePropertyNamespaces() throws Exception {
final MediaPackage mp1 = mkMediaPackage(mkCatalog());
final String mp1Id = mp1.getIdentifier().toString();
am.takeSnapshot(OWNER, mp1);
am.setProperty(p.approved.mk(mp1Id, true));
am.setProperty(p.count.mk(mp1Id, 10L));
am.setProperty(p.start.mk(mp1Id, new Date()));
//
am.setProperty(Property.mk(PropertyId.mk(mp1Id, "org.opencastproject.scheduler", "start"), Value.mk(new Date())));
am.setProperty(Property.mk(PropertyId.mk(mp1Id, "org.opencastproject.scheduler", "end"), Value.mk(new Date())));
//
{
final RichAResult r = enrich(q.select(p.allProperties(), q.propertiesOf("org.opencastproject.scheduler")).run());
assertEquals("One record should be found", 1, r.getSize());
assertEquals("All five properties should be found", 5, r.countProperties());
}
{
final RichAResult r = enrich(q.select(q.propertiesOf(p.namespace())).run());
assertEquals("One record should be found", 1, r.getSize());
assertEquals("No snapshot has been selected", 0, r.countSnapshots());
assertEquals("Three properties should be found", 3, r.countProperties());
}
{
final RichAResult r = enrich(q.select(q.propertiesOf("org.opencastproject.scheduler")).where(q.mediaPackageId(mp1Id)).run());
assertEquals(2, r.countProperties());
}
{
final RichAResult r = enrich(q.select(q.snapshot()).where(p.hasPropertiesOfNamespace()).run());
assertEquals(1, r.getSize());
}
{
final RichAResult r = enrich(q.select(p.allProperties(), q.propertiesOf("org.opencastproject.scheduler")).run());
assertEquals(1, r.getSize());
assertEquals(5, r.countProperties());
}
}
use of org.opencastproject.assetmanager.api.query.RichAResult in project opencast by opencast.
the class AbstractAssetManagerSelectTest method testSelectSnapshotByProperties.
@Test
public void testSelectSnapshotByProperties() throws Exception {
final String[] mp = createAndAddMediaPackagesSimple(3, 1, 1);
am.setProperty(p.approved.mk(mp[0], true));
am.setProperty(p.count.mk(mp[0], 1L));
final RichAResult r = enrich(q.select(q.snapshot()).where(q.hasProperties()).run());
assertEquals("The result set should contain one record", 1, r.getSize());
assertEquals("The result set should contain one snapshot", 1, r.countSnapshots());
assertEquals("The result set should contain media package " + mp[0], mp[0], r.getSnapshots().head2().getMediaPackage().getIdentifier().toString());
}
use of org.opencastproject.assetmanager.api.query.RichAResult in project opencast by opencast.
the class ArchiveToAssetManagerMigrationTest method testMigration.
@Test
@Parameters
public void testMigration(String testData, Stream<String> seriesIds) throws Exception {
// setup database and apply the DDL migration
penv.tx(runStatements("/mysql-reset.sql"));
penv.tx(runStatements("/mysql-archive-schema.sql"));
// insert test data since it makes a difference to migrate a database with or without data
penv.tx(runStatements(testData));
// schema migration pre-processing
penv.tx(runStatements("/mysql-migration-1.sql"));
// data migration
penv.tx(runStatements("/mysql-migration-2.sql"));
// schema migration post-processing and cleanup
penv.tx(runStatements("/mysql-migration-3.sql"));
//
// compare actual and expected DDL
final String showCreateTables = $("oc_assets_snapshot", "oc_assets_asset", "oc_assets_properties", "oc_assets_version_claim", "SEQUENCE").map(Strings.wrap("SHOW CREATE TABLE ", "")).bind(findAll).map(take(1)).mkString(";\n\n").concat(";");
logger.info("+ " + showCreateTables);
assertEquals("Migrated database should be equal to DDL in Ansible playbook", IoSupport.loadFileFromClassPathAsString("/mysql-assetmanager-schema.sql").get().trim(), showCreateTables);
// check sequence table migration
assertTrue("Sequence table should be updated", penv.tx(Queries.sql.findSingle("SELECT * FROM SEQUENCE WHERE SEQ_NAME='seq_oc_assets_asset'")).isSome());
assertTrue("Sequence table should be updated", penv.tx(Queries.sql.findSingle("SELECT * FROM SEQUENCE WHERE SEQ_NAME='seq_oc_assets_snapshot'")).isSome());
//
// if the migration completed successfully the asset manager should be able to run some operations
final AQueryBuilder q = am.createQuery();
{
// run series checks
for (String seriesId : seriesIds) {
final RichAResult r = enrich(q.select(q.snapshot()).where(q.seriesId().eq(seriesId)).run());
assertTrue(r.getSize() > 0);
for (Snapshot e : r.getSnapshots()) {
assertEquals(seriesId, e.getMediaPackage().getSeries());
}
}
}
// add some media packages
final String[] mp = createAndAddMediaPackagesSimple(5, 1, 1);
for (String id : mp) {
am.setProperty(p.agent.mk(id, "agent"));
}
{
final RichAResult r = enrich(q.select(q.snapshot(), q.properties()).run());
assertEquals(59, r.getSize());
assertEquals(59, r.countSnapshots());
assertEquals(5, r.countProperties());
}
}
Aggregations