BlockNotificationHandler.java

1
package org.cardanofoundation.explorer.api.event.blocksync;
2
3
import java.util.function.Consumer;
4
5
import lombok.RequiredArgsConstructor;
6
import lombok.extern.slf4j.Slf4j;
7
8
import org.springframework.context.ApplicationEventPublisher;
9
import org.springframework.stereotype.Component;
10
11
import org.postgresql.PGNotification;
12
13
import org.cardanofoundation.explorer.api.event.websocket.WebSocketEvent;
14
import org.cardanofoundation.explorer.api.event.websocket.WebSocketMessage;
15
import org.cardanofoundation.explorer.api.repository.ledgersync.BlockRepository;
16
import org.cardanofoundation.explorer.api.service.WebSocketService;
17
import org.cardanofoundation.explorer.common.entity.ledgersync.Block;
18
19
@Component
20
@Slf4j
21
@RequiredArgsConstructor
22
public class BlockNotificationHandler implements Consumer<PGNotification> {
23
24
  private final ApplicationEventPublisher applicationEventPublisher;
25
  private final WebSocketService webSocketService;
26
27
  private final BlockRepository blockRepository;
28
29
  @Override
30
  public void accept(PGNotification t) {
31
    log.info(
32
        "Notification received: pid={}, name={}, param={}",
33
        t.getPID(),
34
        t.getName(),
35
        t.getParameter());
36
    String hash = t.getParameter();
37
    Block currentBlock = blockRepository.findCurrentBlockById();
38
39 1 1. accept : negated conditional → NO_COVERAGE
    if (!hash.equals(currentBlock.getHash())) {
40
      return;
41
    }
42
43
    BlockSyncMessage blockSyncMessage =
44
        BlockSyncMessage.builder()
45
            .lastBlockNo(currentBlock.getBlockNo())
46
            .lastBlockHash(currentBlock.getHash())
47 2 1. accept : changed conditional boundary → NO_COVERAGE
2. accept : negated conditional → NO_COVERAGE
            .hasTx(currentBlock.getTxCount() > 0)
48
            .build();
49
50
    WebSocketMessage webSocketMessage = webSocketService.getBatchBlockInfoMessage(blockSyncMessage);
51 1 1. accept : removed call to org/springframework/context/ApplicationEventPublisher::publishEvent → NO_COVERAGE
    applicationEventPublisher.publishEvent(new WebSocketEvent(webSocketMessage) {});
52
  }
53
}

Mutations

39

1.1
Location : accept
Killed by : none
negated conditional → NO_COVERAGE

47

1.1
Location : accept
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : accept
Killed by : none
negated conditional → NO_COVERAGE

51

1.1
Location : accept
Killed by : none
removed call to org/springframework/context/ApplicationEventPublisher::publishEvent → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.14.2