Search in sources :

Example 1 with EquivalenceGraphStore

use of org.atlasapi.equivalence.EquivalenceGraphStore in project atlas-deer by atlasapi.

the class CassandraEquivalentContentStoreIT method suite.

public static junit.framework.Test suite() throws Exception {
    TestSuite suite = new TestSuite("CassandraEquivalentContentStoreIT");
    final TestCassandraPersistenceModule module = new TestCassandraPersistenceModule();
    module.startAsync().awaitRunning(1, TimeUnit.MINUTES);
    suite.addTest(EquivalentContentStoreTestSuiteBuilder.using(new EquivalentContentStoreSubjectGenerator() {

        @Override
        public EquivalentContentStore getEquivalentContentStore() {
            return module.equivalentContentStore();
        }

        @Override
        public EquivalenceGraphStore getEquivalenceGraphStore() {
            return module.contentEquivalenceGraphStore();
        }

        @Override
        public ContentStore getContentStore() {
            return module.contentStore();
        }
    }).withTearDown(new Runnable() {

        @Override
        public void run() {
            try {
                module.reset();
            } catch (ConnectionException e) {
                throw new RuntimeException(e);
            }
        }
    }).named("CassandraEquivalentContentStoreIntegrationSuite").createTestSuite());
    return suite;
}
Also used : EquivalenceGraphStore(org.atlasapi.equivalence.EquivalenceGraphStore) TestSuite(junit.framework.TestSuite) TestCassandraPersistenceModule(org.atlasapi.util.TestCassandraPersistenceModule) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException)

Example 2 with EquivalenceGraphStore

use of org.atlasapi.equivalence.EquivalenceGraphStore in project atlas-deer by atlasapi.

the class ChannelIntervalScheduleBootstrapTask method writeEquivalences.

private void writeEquivalences(ImmutableList<ScheduleHierarchy> builtSchedule) {
    if (!equivalenceUpdater.isPresent()) {
        return;
    }
    List<Item> items = builtSchedule.stream().map(ScheduleHierarchy::getItemAndBroadcast).map(ItemAndBroadcast::getItem).collect(Collectors.toList());
    List<Id> ids = items.stream().map(Item::getId).collect(Collectors.toList());
    EquivalenceGraphStore graphStore = equivGraphStore.get();
    EquivalentScheduleWriter updater = equivalenceUpdater.get();
    try {
        Map<Id, Optional<EquivalenceGraph>> graphs = graphStore.resolveIds(items.stream().map(Item::getId).collect(Collectors.toList())).get();
        for (Id id : ids) {
            Optional<EquivalenceGraph> graph = graphs.get(id);
            if (graph.isPresent()) {
                EquivalenceGraphUpdate update = EquivalenceGraphUpdate.builder(graph.get()).build();
                updater.updateEquivalences(update.getAllGraphs());
            } else {
                log.warn("Failed to resolve graph for {}", id);
            }
        }
    } catch (WriteException | InterruptedException | ExecutionException e) {
        log.warn("Failed to update equivs {} {} {}", source, channel, interval);
        throw Throwables.propagate(e);
    }
}
Also used : EquivalenceGraphStore(org.atlasapi.equivalence.EquivalenceGraphStore) WriteException(org.atlasapi.entity.util.WriteException) Optional(com.google.common.base.Optional) ScheduleHierarchy(org.atlasapi.schedule.ScheduleHierarchy) EquivalenceGraphUpdate(org.atlasapi.equivalence.EquivalenceGraphUpdate) EquivalenceGraph(org.atlasapi.equivalence.EquivalenceGraph) Item(org.atlasapi.content.Item) EquivalentScheduleWriter(org.atlasapi.schedule.EquivalentScheduleWriter) Id(org.atlasapi.entity.Id) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

EquivalenceGraphStore (org.atlasapi.equivalence.EquivalenceGraphStore)2 Optional (com.google.common.base.Optional)1 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)1 ExecutionException (java.util.concurrent.ExecutionException)1 TestSuite (junit.framework.TestSuite)1 Item (org.atlasapi.content.Item)1 Id (org.atlasapi.entity.Id)1 WriteException (org.atlasapi.entity.util.WriteException)1 EquivalenceGraph (org.atlasapi.equivalence.EquivalenceGraph)1 EquivalenceGraphUpdate (org.atlasapi.equivalence.EquivalenceGraphUpdate)1 EquivalentScheduleWriter (org.atlasapi.schedule.EquivalentScheduleWriter)1 ScheduleHierarchy (org.atlasapi.schedule.ScheduleHierarchy)1 TestCassandraPersistenceModule (org.atlasapi.util.TestCassandraPersistenceModule)1