Skip to content

Commit

Permalink
Merge pull request #99 from Friendly-neighborhood-development/benchma…
Browse files Browse the repository at this point in the history
…rking

Benchmarked annotation deployed
  • Loading branch information
SergeyPodgorny authored Dec 15, 2023
2 parents 27dbd2b + 1a11bb8 commit c5a993b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.fnd.games_store.games.annotations;


import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Benchmarked {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.fnd.games_store.games.aspects;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import java.time.Duration;
import java.time.Instant;

@Component
@Aspect
@Slf4j
public class Benchmarking {


@Around("@annotation(com.fnd.games_store.games.annotations.Benchmarked)")
public Object performTImeMeasure(ProceedingJoinPoint joinPoint) throws Throwable {

Instant startTime = Instant.now();

Object proceed = joinPoint.proceed();

Instant endTime = Instant.now();

log.info(Duration.between(endTime,startTime).toString());

return proceed;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.fnd.games_store.games.service.implementation;

import com.fnd.games_store.games.annotations.Benchmarked;
import com.fnd.games_store.games.dto.game.GameResponseDTO;
import com.fnd.games_store.games.exceptions.GameNotFoundException;
import com.fnd.games_store.games.repository.GameRepository;
Expand Down Expand Up @@ -32,6 +33,7 @@ public SpecificGameListServiceImpl(GameRepository repository) {
isolation = Isolation.REPEATABLE_READ,
timeout = 5,
readOnly = true)
@Benchmarked
@Override
public List<GameResponseDTO> getSpecifiedGameList(Integer page, Integer pageSize, Sort sortBy) {
return repository.findAll(PageRequest.of(page,pageSize, sortBy)).stream().map(GameResponseDTO::new).collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.fnd.games_store.games.service.implementation;

import com.fnd.games_store.games.annotations.Benchmarked;
import com.fnd.games_store.games.dto.game.GameResponseDTO;
import com.fnd.games_store.games.exceptions.GameNotFoundException;
import com.fnd.games_store.games.repository.GameRepository;
Expand Down Expand Up @@ -27,6 +28,7 @@ public SpecificGameServiceImpl(GameRepository repository) {
timeout = 5,
readOnly = true,
rollbackFor = GameNotFoundException.class)
@Benchmarked
@Override
public GameResponseDTO getGameByName(String name) {
return new GameResponseDTO(repository.getGameByName(name).orElseThrow(GameNotFoundException::new));
Expand Down

0 comments on commit c5a993b

Please sign in to comment.