@Test public void testGetOperationLimitNullAndMostRecentIdGreaterThanLastId(DbOperationRecordDto dtoFromMemCache) { Long lastId = 1L; when(memcacheService.get(MemcacheKey.DB_OPERATION_COUNTER.getName())).thenReturn(2L); Map<String, Object> mapFromMemCache = Maps.newHashMap(); mapFromMemCache.put("dummyKey", dtoFromMemCache); when(memcacheService.getAll(anyCollection())).thenReturn(mapFromMemCache); List<DbOperationRecordDto> results = operationService.getOperations(lastId, null); verify(memcacheService).getAll(Lists.newArrayList(MemcacheKey.DB_OPERATION_RECORD_PREFIX.getName() + 2)); verify(memcacheService).get(MemcacheKey.DB_OPERATION_COUNTER.getName()); assertEquals(1, results.size()); assertEquals(dtoFromMemCache, results.get(0)); }
public List<DbOperationRecordDto> getOperations(Long lastId, Integer limit) { Long mostRecentId = getMostRecentId(); if (mostRecentId == null) { return null; } long beginId = lastId + 1; long endId = limit != null ? Math.min(lastId + limit, mostRecentId) : mostRecentId; if (beginId > endId) { return null; } Map<String, Object> recordsByKey = memcacheService.getAll(getNewOperationRecordKeys(beginId, endId)); List<DbOperationRecordDto> records = new ArrayList<DbOperationRecordDto>(recordsByKey.size()); for (Object recordObject : recordsByKey.values()) { records.add((DbOperationRecordDto) recordObject); } return records; }
OperationServiceImpl implements OperationService { public List<DbOperationRecordDto> getOperations(Long lastId, Integer limit) { Long mostRecentId = getMostRecentId(); if (mostRecentId == null) { return null; } long beginId = lastId + 1; long endId = limit != null ? Math.min(lastId + limit, mostRecentId) : mostRecentId; if (beginId > endId) { return null; } Map<String, Object> recordsByKey = memcacheService.getAll(getNewOperationRecordKeys(beginId, endId)); List<DbOperationRecordDto> records = new ArrayList<DbOperationRecordDto>(recordsByKey.size()); for (Object recordObject : recordsByKey.values()) { records.add((DbOperationRecordDto) recordObject); } return records; } }
OperationServiceImpl implements OperationService { public List<DbOperationRecordDto> getOperations(Long lastId, Integer limit) { Long mostRecentId = getMostRecentId(); if (mostRecentId == null) { return null; } long beginId = lastId + 1; long endId = limit != null ? Math.min(lastId + limit, mostRecentId) : mostRecentId; if (beginId > endId) { return null; } Map<String, Object> recordsByKey = memcacheService.getAll(getNewOperationRecordKeys(beginId, endId)); List<DbOperationRecordDto> records = new ArrayList<DbOperationRecordDto>(recordsByKey.size()); for (Object recordObject : recordsByKey.values()) { records.add((DbOperationRecordDto) recordObject); } return records; } @Inject  OperationServiceImpl(
            MemcacheService memcacheService); }
OperationServiceImpl implements OperationService { public List<DbOperationRecordDto> getOperations(Long lastId, Integer limit) { Long mostRecentId = getMostRecentId(); if (mostRecentId == null) { return null; } long beginId = lastId + 1; long endId = limit != null ? Math.min(lastId + limit, mostRecentId) : mostRecentId; if (beginId > endId) { return null; } Map<String, Object> recordsByKey = memcacheService.getAll(getNewOperationRecordKeys(beginId, endId)); List<DbOperationRecordDto> records = new ArrayList<DbOperationRecordDto>(recordsByKey.size()); for (Object recordObject : recordsByKey.values()) { records.add((DbOperationRecordDto) recordObject); } return records; } @Inject  OperationServiceImpl(
            MemcacheService memcacheService); @Override Long getMostRecentId(); List<DbOperationRecordDto> getOperations(Long lastId, Integer limit); }
OperationServiceImpl implements OperationService { public List<DbOperationRecordDto> getOperations(Long lastId, Integer limit) { Long mostRecentId = getMostRecentId(); if (mostRecentId == null) { return null; } long beginId = lastId + 1; long endId = limit != null ? Math.min(lastId + limit, mostRecentId) : mostRecentId; if (beginId > endId) { return null; } Map<String, Object> recordsByKey = memcacheService.getAll(getNewOperationRecordKeys(beginId, endId)); List<DbOperationRecordDto> records = new ArrayList<DbOperationRecordDto>(recordsByKey.size()); for (Object recordObject : recordsByKey.values()) { records.add((DbOperationRecordDto) recordObject); } return records; } @Inject  OperationServiceImpl(
            MemcacheService memcacheService); @Override Long getMostRecentId(); List<DbOperationRecordDto> getOperations(Long lastId, Integer limit);  }