@Test public void testExecute() { final ArrayList<Long> activityIds = new ArrayList<Long>(); activityIds.add(1L); activityIds.add(2L); final List<String> listsToUpdate = new ArrayList<String>(); listsToUpdate.add(CacheKeys.ACTIVITIES_BY_FOLLOWING + 1L); final List<Long> commentIds = new ArrayList<Long>(); commentIds.add(1L); commentIds.add(2L); final Map<Long, Set<Long>> starredActivityIds = new HashMap<Long, Set<Long>>(); final BulkActivityDeleteResponse deleteResponse = new BulkActivityDeleteResponse(activityIds, commentIds, starredActivityIds); context.checking(new Expectations() { { oneOf(listsMapper).execute(with(any(List.class))); will(returnValue(listsToUpdate)); oneOf(deleteMapper).execute(with(any(List.class))); will(returnValue(deleteResponse)); } }); TaskHandlerActionContext<ActionContext> actionContext = TestContextCreator .createTaskHandlerAsyncContext(activityIds); sut.execute(actionContext); context.assertIsSatisfied(); final List<UserActionRequest> userActionRequests = actionContext.getUserActionRequests(); assertEquals(8, userActionRequests.size()); assertEquals("deleteFromSearchIndexAction", userActionRequests.get(0).getActionKey()); assertEquals("deleteIdsFromLists", userActionRequests.get(1).getActionKey()); assertEquals("deleteCacheKeysAction", userActionRequests.get(2).getActionKey()); assertEquals("deleteCacheKeysAction", userActionRequests.get(3).getActionKey()); assertEquals("deleteCacheKeysAction", userActionRequests.get(4).getActionKey()); assertEquals("deleteCacheKeysAction", userActionRequests.get(5).getActionKey()); }
@SuppressWarnings("unchecked") @Override public Serializable execute(final TaskHandlerActionContext<ActionContext> inActionContext) { List<Long> activityIds = (List<Long>) inActionContext.getActionContext().getParams(); if (log.isTraceEnabled()) { log.trace("Calling DeleteMapper to delete " + activityIds.size() + " activities"); } List<String> keys = listsMapper.execute(activityIds); BulkActivityDeleteResponse response = deleteMapper.execute(activityIds); if (log.isInfoEnabled()) { log.info("Queuing UserActionRequest for removing expired activities from index (num of ids): " + response.getActivityIds().size()); } inActionContext.getUserActionRequests().add( new UserActionRequest("deleteFromSearchIndexAction", null, new DeleteFromSearchIndexRequest( Activity.class, response.getActivityIds()))); if (log.isInfoEnabled()) { log.info("Queuing UserActionRequest for removing expired activity ids from lists cache keys: " + keys); } inActionContext.getUserActionRequests().add( new UserActionRequest("deleteIdsFromLists", null, new DeleteIdsFromListsRequest(keys, response .getActivityIds()))); if (log.isInfoEnabled()) { log.info("Queuing UserActionRequests for removing expired activity ids from cache: " + response.getActivityIds().size()); } generateIndividualDeleteKeyFromCacheTasks(new HashSet<String>(createKeys(CacheKeys.ACTIVITY_BY_ID, response .getActivityIds())), inActionContext); generateIndividualDeleteKeyFromCacheTasks(new HashSet<String>(createKeys(CacheKeys.ACTIVITY_SECURITY_BY_ID, response.getActivityIds())), inActionContext); if (log.isInfoEnabled()) { log.info("Queuing UserActionRequests for removing expired activitys' comment ids from cache: " + response.getCommentIds()); } generateIndividualDeleteKeyFromCacheTasks(new HashSet<String>(createKeys(CacheKeys.COMMENT_BY_ID, response .getCommentIds())), inActionContext); return null; }
DeleteActivitiesByIdsExecution implements TaskHandlerExecutionStrategy<ActionContext> { @SuppressWarnings("unchecked") @Override public Serializable execute(final TaskHandlerActionContext<ActionContext> inActionContext) { List<Long> activityIds = (List<Long>) inActionContext.getActionContext().getParams(); if (log.isTraceEnabled()) { log.trace("Calling DeleteMapper to delete " + activityIds.size() + " activities"); } List<String> keys = listsMapper.execute(activityIds); BulkActivityDeleteResponse response = deleteMapper.execute(activityIds); if (log.isInfoEnabled()) { log.info("Queuing UserActionRequest for removing expired activities from index (num of ids): " + response.getActivityIds().size()); } inActionContext.getUserActionRequests().add( new UserActionRequest("deleteFromSearchIndexAction", null, new DeleteFromSearchIndexRequest( Activity.class, response.getActivityIds()))); if (log.isInfoEnabled()) { log.info("Queuing UserActionRequest for removing expired activity ids from lists cache keys: " + keys); } inActionContext.getUserActionRequests().add( new UserActionRequest("deleteIdsFromLists", null, new DeleteIdsFromListsRequest(keys, response .getActivityIds()))); if (log.isInfoEnabled()) { log.info("Queuing UserActionRequests for removing expired activity ids from cache: " + response.getActivityIds().size()); } generateIndividualDeleteKeyFromCacheTasks(new HashSet<String>(createKeys(CacheKeys.ACTIVITY_BY_ID, response .getActivityIds())), inActionContext); generateIndividualDeleteKeyFromCacheTasks(new HashSet<String>(createKeys(CacheKeys.ACTIVITY_SECURITY_BY_ID, response.getActivityIds())), inActionContext); if (log.isInfoEnabled()) { log.info("Queuing UserActionRequests for removing expired activitys' comment ids from cache: " + response.getCommentIds()); } generateIndividualDeleteKeyFromCacheTasks(new HashSet<String>(createKeys(CacheKeys.COMMENT_BY_ID, response .getCommentIds())), inActionContext); return null; } }
DeleteActivitiesByIdsExecution implements TaskHandlerExecutionStrategy<ActionContext> { @SuppressWarnings("unchecked") @Override public Serializable execute(final TaskHandlerActionContext<ActionContext> inActionContext) { List<Long> activityIds = (List<Long>) inActionContext.getActionContext().getParams(); if (log.isTraceEnabled()) { log.trace("Calling DeleteMapper to delete " + activityIds.size() + " activities"); } List<String> keys = listsMapper.execute(activityIds); BulkActivityDeleteResponse response = deleteMapper.execute(activityIds); if (log.isInfoEnabled()) { log.info("Queuing UserActionRequest for removing expired activities from index (num of ids): " + response.getActivityIds().size()); } inActionContext.getUserActionRequests().add( new UserActionRequest("deleteFromSearchIndexAction", null, new DeleteFromSearchIndexRequest( Activity.class, response.getActivityIds()))); if (log.isInfoEnabled()) { log.info("Queuing UserActionRequest for removing expired activity ids from lists cache keys: " + keys); } inActionContext.getUserActionRequests().add( new UserActionRequest("deleteIdsFromLists", null, new DeleteIdsFromListsRequest(keys, response .getActivityIds()))); if (log.isInfoEnabled()) { log.info("Queuing UserActionRequests for removing expired activity ids from cache: " + response.getActivityIds().size()); } generateIndividualDeleteKeyFromCacheTasks(new HashSet<String>(createKeys(CacheKeys.ACTIVITY_BY_ID, response .getActivityIds())), inActionContext); generateIndividualDeleteKeyFromCacheTasks(new HashSet<String>(createKeys(CacheKeys.ACTIVITY_SECURITY_BY_ID, response.getActivityIds())), inActionContext); if (log.isInfoEnabled()) { log.info("Queuing UserActionRequests for removing expired activitys' comment ids from cache: " + response.getCommentIds()); } generateIndividualDeleteKeyFromCacheTasks(new HashSet<String>(createKeys(CacheKeys.COMMENT_BY_ID, response .getCommentIds())), inActionContext); return null; } DeleteActivitiesByIdsExecution(final GetListsContainingActivities inListsMapper,
            final DeleteActivities inDeleteMapper); }
DeleteActivitiesByIdsExecution implements TaskHandlerExecutionStrategy<ActionContext> { @SuppressWarnings("unchecked") @Override public Serializable execute(final TaskHandlerActionContext<ActionContext> inActionContext) { List<Long> activityIds = (List<Long>) inActionContext.getActionContext().getParams(); if (log.isTraceEnabled()) { log.trace("Calling DeleteMapper to delete " + activityIds.size() + " activities"); } List<String> keys = listsMapper.execute(activityIds); BulkActivityDeleteResponse response = deleteMapper.execute(activityIds); if (log.isInfoEnabled()) { log.info("Queuing UserActionRequest for removing expired activities from index (num of ids): " + response.getActivityIds().size()); } inActionContext.getUserActionRequests().add( new UserActionRequest("deleteFromSearchIndexAction", null, new DeleteFromSearchIndexRequest( Activity.class, response.getActivityIds()))); if (log.isInfoEnabled()) { log.info("Queuing UserActionRequest for removing expired activity ids from lists cache keys: " + keys); } inActionContext.getUserActionRequests().add( new UserActionRequest("deleteIdsFromLists", null, new DeleteIdsFromListsRequest(keys, response .getActivityIds()))); if (log.isInfoEnabled()) { log.info("Queuing UserActionRequests for removing expired activity ids from cache: " + response.getActivityIds().size()); } generateIndividualDeleteKeyFromCacheTasks(new HashSet<String>(createKeys(CacheKeys.ACTIVITY_BY_ID, response .getActivityIds())), inActionContext); generateIndividualDeleteKeyFromCacheTasks(new HashSet<String>(createKeys(CacheKeys.ACTIVITY_SECURITY_BY_ID, response.getActivityIds())), inActionContext); if (log.isInfoEnabled()) { log.info("Queuing UserActionRequests for removing expired activitys' comment ids from cache: " + response.getCommentIds()); } generateIndividualDeleteKeyFromCacheTasks(new HashSet<String>(createKeys(CacheKeys.COMMENT_BY_ID, response .getCommentIds())), inActionContext); return null; } DeleteActivitiesByIdsExecution(final GetListsContainingActivities inListsMapper,
            final DeleteActivities inDeleteMapper); @SuppressWarnings("unchecked") @Override Serializable execute(final TaskHandlerActionContext<ActionContext> inActionContext); }
DeleteActivitiesByIdsExecution implements TaskHandlerExecutionStrategy<ActionContext> { @SuppressWarnings("unchecked") @Override public Serializable execute(final TaskHandlerActionContext<ActionContext> inActionContext) { List<Long> activityIds = (List<Long>) inActionContext.getActionContext().getParams(); if (log.isTraceEnabled()) { log.trace("Calling DeleteMapper to delete " + activityIds.size() + " activities"); } List<String> keys = listsMapper.execute(activityIds); BulkActivityDeleteResponse response = deleteMapper.execute(activityIds); if (log.isInfoEnabled()) { log.info("Queuing UserActionRequest for removing expired activities from index (num of ids): " + response.getActivityIds().size()); } inActionContext.getUserActionRequests().add( new UserActionRequest("deleteFromSearchIndexAction", null, new DeleteFromSearchIndexRequest( Activity.class, response.getActivityIds()))); if (log.isInfoEnabled()) { log.info("Queuing UserActionRequest for removing expired activity ids from lists cache keys: " + keys); } inActionContext.getUserActionRequests().add( new UserActionRequest("deleteIdsFromLists", null, new DeleteIdsFromListsRequest(keys, response .getActivityIds()))); if (log.isInfoEnabled()) { log.info("Queuing UserActionRequests for removing expired activity ids from cache: " + response.getActivityIds().size()); } generateIndividualDeleteKeyFromCacheTasks(new HashSet<String>(createKeys(CacheKeys.ACTIVITY_BY_ID, response .getActivityIds())), inActionContext); generateIndividualDeleteKeyFromCacheTasks(new HashSet<String>(createKeys(CacheKeys.ACTIVITY_SECURITY_BY_ID, response.getActivityIds())), inActionContext); if (log.isInfoEnabled()) { log.info("Queuing UserActionRequests for removing expired activitys' comment ids from cache: " + response.getCommentIds()); } generateIndividualDeleteKeyFromCacheTasks(new HashSet<String>(createKeys(CacheKeys.COMMENT_BY_ID, response .getCommentIds())), inActionContext); return null; } DeleteActivitiesByIdsExecution(final GetListsContainingActivities inListsMapper,
            final DeleteActivities inDeleteMapper); @SuppressWarnings("unchecked") @Override Serializable execute(final TaskHandlerActionContext<ActionContext> inActionContext);  }