@Test public void testHandleSubscriptions() throws Exception { pool.cancelTimer(); Field f = FeedView.class.getDeclaredField("feedPool"); f.setAccessible(true); FeedRenderingPool rp = (FeedRenderingPool) f.get(fv1); rp.cancelTimer(); final String feedId = "f1"; FeedView fv2 = Mockito.mock(FeedView.class); FeedProvider fp2 = Mockito.mock(FeedProvider.class); Mockito.when(fp2.getSubscriptionId()).thenReturn(feedId); Mockito.when(fp2.toString()).thenReturn("fp2 : " + feedId); Mockito.when(fp2.getTimeService()).thenReturn(timeService); Mockito.when(fv2.getVisibleFeedProviders()).thenReturn(Collections.singleton(fp2)); feedId1.set(feedId); Assert.assertEquals(fv1.getVisibleFeedProviders().iterator().next().getSubscriptionId(), feedId); Assert.assertEquals(fv1.getVisibleFeedProviders().iterator().next().getSubscriptionId().compareTo(fv2.getVisibleFeedProviders().iterator().next().getSubscriptionId()),0); pool.addFeedView(fv1); pool.handleSubscriptions(); Mockito.verify(manager).subscribe(feedId); pool.handleSubscriptions(); Mockito.verify(manager).subscribe(feedId); pool.addFeedView(fv2); pool.handleSubscriptions(); Mockito.verify(manager,Mockito.times(1)).subscribe(feedId); pool.removeFeedView(fv1); pool.removeFeedView(fv2); pool.handleSubscriptions(); Mockito.verify(manager).unsubscribe(feedId); }
void handleSubscriptions() { Set<FeedProvider> requiredSubscriptions = buildRequiredSubscriptions(); List<FeedProvider> newSubscriptions = new ArrayList<FeedProvider>(); List<FeedProvider> removedSubscriptions = new ArrayList<FeedProvider>(); Set<FeedProvider> set = new TreeSet<FeedProvider>(FEED_COMPARATOR); set.addAll(requiredSubscriptions); ComponentModelUtil.computeAsymmetricSetDifferences( requiredSubscriptions, activeSubscriptions, newSubscriptions, removedSubscriptions,set); if (exceededMaxSubscriptions(requiredSubscriptions, newSubscriptions)) return; SubscriptionManager manager = getSubscriptionManager(); if (manager != null) { for (FeedProvider feed:removedSubscriptions) { LOGGER.debug("removing subscription for {0}", feed.getSubscriptionId()); manager.unsubscribe(feed.getSubscriptionId()); activeFeeds.remove(feed); } List<String> newlyAddedSubscriptionIds = new ArrayList<String> (newSubscriptions.size()); for (FeedProvider feed:newSubscriptions) { LOGGER.debug("adding subscription for {0}", feed.getSubscriptionId()); newlyAddedSubscriptionIds.add(feed.getSubscriptionId()); activeFeeds.put(feed, feed.getTimeService().getCurrentTime()); } assert newlyAddedSubscriptionIds.size() == newSubscriptions.size(); if (!newlyAddedSubscriptionIds.isEmpty()) { manager.subscribe(newlyAddedSubscriptionIds.toArray(new String[newlyAddedSubscriptionIds.size()])); } activeSubscriptions = requiredSubscriptions; } else { LOGGER.warn("subscription manager not available, subscriptions not updated"); } }
FeedRenderingPool { void handleSubscriptions() { Set<FeedProvider> requiredSubscriptions = buildRequiredSubscriptions(); List<FeedProvider> newSubscriptions = new ArrayList<FeedProvider>(); List<FeedProvider> removedSubscriptions = new ArrayList<FeedProvider>(); Set<FeedProvider> set = new TreeSet<FeedProvider>(FEED_COMPARATOR); set.addAll(requiredSubscriptions); ComponentModelUtil.computeAsymmetricSetDifferences( requiredSubscriptions, activeSubscriptions, newSubscriptions, removedSubscriptions,set); if (exceededMaxSubscriptions(requiredSubscriptions, newSubscriptions)) return; SubscriptionManager manager = getSubscriptionManager(); if (manager != null) { for (FeedProvider feed:removedSubscriptions) { LOGGER.debug("removing subscription for {0}", feed.getSubscriptionId()); manager.unsubscribe(feed.getSubscriptionId()); activeFeeds.remove(feed); } List<String> newlyAddedSubscriptionIds = new ArrayList<String> (newSubscriptions.size()); for (FeedProvider feed:newSubscriptions) { LOGGER.debug("adding subscription for {0}", feed.getSubscriptionId()); newlyAddedSubscriptionIds.add(feed.getSubscriptionId()); activeFeeds.put(feed, feed.getTimeService().getCurrentTime()); } assert newlyAddedSubscriptionIds.size() == newSubscriptions.size(); if (!newlyAddedSubscriptionIds.isEmpty()) { manager.subscribe(newlyAddedSubscriptionIds.toArray(new String[newlyAddedSubscriptionIds.size()])); } activeSubscriptions = requiredSubscriptions; } else { LOGGER.warn("subscription manager not available, subscriptions not updated"); } } }
FeedRenderingPool { void handleSubscriptions() { Set<FeedProvider> requiredSubscriptions = buildRequiredSubscriptions(); List<FeedProvider> newSubscriptions = new ArrayList<FeedProvider>(); List<FeedProvider> removedSubscriptions = new ArrayList<FeedProvider>(); Set<FeedProvider> set = new TreeSet<FeedProvider>(FEED_COMPARATOR); set.addAll(requiredSubscriptions); ComponentModelUtil.computeAsymmetricSetDifferences( requiredSubscriptions, activeSubscriptions, newSubscriptions, removedSubscriptions,set); if (exceededMaxSubscriptions(requiredSubscriptions, newSubscriptions)) return; SubscriptionManager manager = getSubscriptionManager(); if (manager != null) { for (FeedProvider feed:removedSubscriptions) { LOGGER.debug("removing subscription for {0}", feed.getSubscriptionId()); manager.unsubscribe(feed.getSubscriptionId()); activeFeeds.remove(feed); } List<String> newlyAddedSubscriptionIds = new ArrayList<String> (newSubscriptions.size()); for (FeedProvider feed:newSubscriptions) { LOGGER.debug("adding subscription for {0}", feed.getSubscriptionId()); newlyAddedSubscriptionIds.add(feed.getSubscriptionId()); activeFeeds.put(feed, feed.getTimeService().getCurrentTime()); } assert newlyAddedSubscriptionIds.size() == newSubscriptions.size(); if (!newlyAddedSubscriptionIds.isEmpty()) { manager.subscribe(newlyAddedSubscriptionIds.toArray(new String[newlyAddedSubscriptionIds.size()])); } activeSubscriptions = requiredSubscriptions; } else { LOGGER.warn("subscription manager not available, subscriptions not updated"); } } FeedRenderingPool(int paintRateInterval); }
FeedRenderingPool { void handleSubscriptions() { Set<FeedProvider> requiredSubscriptions = buildRequiredSubscriptions(); List<FeedProvider> newSubscriptions = new ArrayList<FeedProvider>(); List<FeedProvider> removedSubscriptions = new ArrayList<FeedProvider>(); Set<FeedProvider> set = new TreeSet<FeedProvider>(FEED_COMPARATOR); set.addAll(requiredSubscriptions); ComponentModelUtil.computeAsymmetricSetDifferences( requiredSubscriptions, activeSubscriptions, newSubscriptions, removedSubscriptions,set); if (exceededMaxSubscriptions(requiredSubscriptions, newSubscriptions)) return; SubscriptionManager manager = getSubscriptionManager(); if (manager != null) { for (FeedProvider feed:removedSubscriptions) { LOGGER.debug("removing subscription for {0}", feed.getSubscriptionId()); manager.unsubscribe(feed.getSubscriptionId()); activeFeeds.remove(feed); } List<String> newlyAddedSubscriptionIds = new ArrayList<String> (newSubscriptions.size()); for (FeedProvider feed:newSubscriptions) { LOGGER.debug("adding subscription for {0}", feed.getSubscriptionId()); newlyAddedSubscriptionIds.add(feed.getSubscriptionId()); activeFeeds.put(feed, feed.getTimeService().getCurrentTime()); } assert newlyAddedSubscriptionIds.size() == newSubscriptions.size(); if (!newlyAddedSubscriptionIds.isEmpty()) { manager.subscribe(newlyAddedSubscriptionIds.toArray(new String[newlyAddedSubscriptionIds.size()])); } activeSubscriptions = requiredSubscriptions; } else { LOGGER.warn("subscription manager not available, subscriptions not updated"); } } FeedRenderingPool(int paintRateInterval); void addFeedView(FeedView manifestation); void removeFeedView(FeedView manifestation); SynchronizationControl synchronizeTime(final long syncTime); }
FeedRenderingPool { void handleSubscriptions() { Set<FeedProvider> requiredSubscriptions = buildRequiredSubscriptions(); List<FeedProvider> newSubscriptions = new ArrayList<FeedProvider>(); List<FeedProvider> removedSubscriptions = new ArrayList<FeedProvider>(); Set<FeedProvider> set = new TreeSet<FeedProvider>(FEED_COMPARATOR); set.addAll(requiredSubscriptions); ComponentModelUtil.computeAsymmetricSetDifferences( requiredSubscriptions, activeSubscriptions, newSubscriptions, removedSubscriptions,set); if (exceededMaxSubscriptions(requiredSubscriptions, newSubscriptions)) return; SubscriptionManager manager = getSubscriptionManager(); if (manager != null) { for (FeedProvider feed:removedSubscriptions) { LOGGER.debug("removing subscription for {0}", feed.getSubscriptionId()); manager.unsubscribe(feed.getSubscriptionId()); activeFeeds.remove(feed); } List<String> newlyAddedSubscriptionIds = new ArrayList<String> (newSubscriptions.size()); for (FeedProvider feed:newSubscriptions) { LOGGER.debug("adding subscription for {0}", feed.getSubscriptionId()); newlyAddedSubscriptionIds.add(feed.getSubscriptionId()); activeFeeds.put(feed, feed.getTimeService().getCurrentTime()); } assert newlyAddedSubscriptionIds.size() == newSubscriptions.size(); if (!newlyAddedSubscriptionIds.isEmpty()) { manager.subscribe(newlyAddedSubscriptionIds.toArray(new String[newlyAddedSubscriptionIds.size()])); } activeSubscriptions = requiredSubscriptions; } else { LOGGER.warn("subscription manager not available, subscriptions not updated"); } } FeedRenderingPool(int paintRateInterval); void addFeedView(FeedView manifestation); void removeFeedView(FeedView manifestation); SynchronizationControl synchronizeTime(final long syncTime);  }