@Test public void testExecuteWithNoActivities() { AddBufferedActivitiesToCache sut = new AddBufferedActivitiesToCache(bulkActivitiesMapper, cache, getIdsOfPeopleFollowingActivityDestinationStreamMapper, updateActorActivityStreamMapper); final List<Long> activityIds = null; final ActivityDTO activity1 = context.mock(ActivityDTO.class); final ActivityDTO activity2 = context.mock(ActivityDTO.class, "a2"); final List<ActivityDTO> activities = new LinkedList<ActivityDTO>(); context.checking(new Expectations() { { allowing(activity1).getId(); will(returnValue(7L)); allowing(activity2).getId(); will(returnValue(8L)); oneOf(cache).setListCAS(CacheKeys.BUFFERED_ACTIVITIES, null); will(returnValue(activityIds)); oneOf(bulkActivitiesMapper).execute(activityIds); will(returnValue(activities)); } }); sut.execute(); context.assertIsSatisfied(); }
public Boolean execute() { List<Long> activityIds = cache.setListCAS(CacheKeys.BUFFERED_ACTIVITIES, null); List<ActivityDTO> activites = bulkActivitiesMapper.execute(activityIds); HashMap<Long, ArrayList<Long>> activitesByFollower = new HashMap<Long, ArrayList<Long>>(); List<Long> allActivityIds = new ArrayList<Long>(); for (ActivityDTO activity : activites) { allActivityIds.add(activity.getId()); List<Long> followers = getIdsOfPeopleFollowingActivityDestinationStreamMapper.execute(activity); for (Long followerId : followers) { if (!activitesByFollower.containsKey(followerId)) { activitesByFollower.put(followerId, new ArrayList<Long>()); } activitesByFollower.get(followerId).add(activity.getId()); } updateActorActivityStreamMapper.execute(activity); } if (!allActivityIds.isEmpty()) { cache.addToTopOfList(CacheKeys.EVERYONE_ACTIVITY_IDS, allActivityIds); } for (Long compositeId : activitesByFollower.keySet()) { ArrayList<Long> ids = activitesByFollower.get(compositeId); cache.addToTopOfList(CacheKeys.ACTIVITIES_BY_FOLLOWING + compositeId, ids); } return true; }
AddBufferedActivitiesToCache extends CachedDomainMapper { public Boolean execute() { List<Long> activityIds = cache.setListCAS(CacheKeys.BUFFERED_ACTIVITIES, null); List<ActivityDTO> activites = bulkActivitiesMapper.execute(activityIds); HashMap<Long, ArrayList<Long>> activitesByFollower = new HashMap<Long, ArrayList<Long>>(); List<Long> allActivityIds = new ArrayList<Long>(); for (ActivityDTO activity : activites) { allActivityIds.add(activity.getId()); List<Long> followers = getIdsOfPeopleFollowingActivityDestinationStreamMapper.execute(activity); for (Long followerId : followers) { if (!activitesByFollower.containsKey(followerId)) { activitesByFollower.put(followerId, new ArrayList<Long>()); } activitesByFollower.get(followerId).add(activity.getId()); } updateActorActivityStreamMapper.execute(activity); } if (!allActivityIds.isEmpty()) { cache.addToTopOfList(CacheKeys.EVERYONE_ACTIVITY_IDS, allActivityIds); } for (Long compositeId : activitesByFollower.keySet()) { ArrayList<Long> ids = activitesByFollower.get(compositeId); cache.addToTopOfList(CacheKeys.ACTIVITIES_BY_FOLLOWING + compositeId, ids); } return true; } }
AddBufferedActivitiesToCache extends CachedDomainMapper { public Boolean execute() { List<Long> activityIds = cache.setListCAS(CacheKeys.BUFFERED_ACTIVITIES, null); List<ActivityDTO> activites = bulkActivitiesMapper.execute(activityIds); HashMap<Long, ArrayList<Long>> activitesByFollower = new HashMap<Long, ArrayList<Long>>(); List<Long> allActivityIds = new ArrayList<Long>(); for (ActivityDTO activity : activites) { allActivityIds.add(activity.getId()); List<Long> followers = getIdsOfPeopleFollowingActivityDestinationStreamMapper.execute(activity); for (Long followerId : followers) { if (!activitesByFollower.containsKey(followerId)) { activitesByFollower.put(followerId, new ArrayList<Long>()); } activitesByFollower.get(followerId).add(activity.getId()); } updateActorActivityStreamMapper.execute(activity); } if (!allActivityIds.isEmpty()) { cache.addToTopOfList(CacheKeys.EVERYONE_ACTIVITY_IDS, allActivityIds); } for (Long compositeId : activitesByFollower.keySet()) { ArrayList<Long> ids = activitesByFollower.get(compositeId); cache.addToTopOfList(CacheKeys.ACTIVITIES_BY_FOLLOWING + compositeId, ids); } return true; } AddBufferedActivitiesToCache(final DomainMapper<List<Long>, List<ActivityDTO>> inBulkActivitiesMapper,
            final Cache inCache,
            final DomainMapper<ActivityDTO, List<Long>> inGetIdsOfPeopleFollowingActivityDestinationStreamMapper,
            final PostActivityUpdateStreamsByActorMapper inUpdateActorActivityStreamMapper); }
AddBufferedActivitiesToCache extends CachedDomainMapper { public Boolean execute() { List<Long> activityIds = cache.setListCAS(CacheKeys.BUFFERED_ACTIVITIES, null); List<ActivityDTO> activites = bulkActivitiesMapper.execute(activityIds); HashMap<Long, ArrayList<Long>> activitesByFollower = new HashMap<Long, ArrayList<Long>>(); List<Long> allActivityIds = new ArrayList<Long>(); for (ActivityDTO activity : activites) { allActivityIds.add(activity.getId()); List<Long> followers = getIdsOfPeopleFollowingActivityDestinationStreamMapper.execute(activity); for (Long followerId : followers) { if (!activitesByFollower.containsKey(followerId)) { activitesByFollower.put(followerId, new ArrayList<Long>()); } activitesByFollower.get(followerId).add(activity.getId()); } updateActorActivityStreamMapper.execute(activity); } if (!allActivityIds.isEmpty()) { cache.addToTopOfList(CacheKeys.EVERYONE_ACTIVITY_IDS, allActivityIds); } for (Long compositeId : activitesByFollower.keySet()) { ArrayList<Long> ids = activitesByFollower.get(compositeId); cache.addToTopOfList(CacheKeys.ACTIVITIES_BY_FOLLOWING + compositeId, ids); } return true; } AddBufferedActivitiesToCache(final DomainMapper<List<Long>, List<ActivityDTO>> inBulkActivitiesMapper,
            final Cache inCache,
            final DomainMapper<ActivityDTO, List<Long>> inGetIdsOfPeopleFollowingActivityDestinationStreamMapper,
            final PostActivityUpdateStreamsByActorMapper inUpdateActorActivityStreamMapper); Boolean execute(); }
AddBufferedActivitiesToCache extends CachedDomainMapper { public Boolean execute() { List<Long> activityIds = cache.setListCAS(CacheKeys.BUFFERED_ACTIVITIES, null); List<ActivityDTO> activites = bulkActivitiesMapper.execute(activityIds); HashMap<Long, ArrayList<Long>> activitesByFollower = new HashMap<Long, ArrayList<Long>>(); List<Long> allActivityIds = new ArrayList<Long>(); for (ActivityDTO activity : activites) { allActivityIds.add(activity.getId()); List<Long> followers = getIdsOfPeopleFollowingActivityDestinationStreamMapper.execute(activity); for (Long followerId : followers) { if (!activitesByFollower.containsKey(followerId)) { activitesByFollower.put(followerId, new ArrayList<Long>()); } activitesByFollower.get(followerId).add(activity.getId()); } updateActorActivityStreamMapper.execute(activity); } if (!allActivityIds.isEmpty()) { cache.addToTopOfList(CacheKeys.EVERYONE_ACTIVITY_IDS, allActivityIds); } for (Long compositeId : activitesByFollower.keySet()) { ArrayList<Long> ids = activitesByFollower.get(compositeId); cache.addToTopOfList(CacheKeys.ACTIVITIES_BY_FOLLOWING + compositeId, ids); } return true; } AddBufferedActivitiesToCache(final DomainMapper<List<Long>, List<ActivityDTO>> inBulkActivitiesMapper,
            final Cache inCache,
            final DomainMapper<ActivityDTO, List<Long>> inGetIdsOfPeopleFollowingActivityDestinationStreamMapper,
            final PostActivityUpdateStreamsByActorMapper inUpdateActorActivityStreamMapper); Boolean execute();  }