Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
iluwatar#1627 fixing sonar issues
  • Loading branch information
karthikbhat13 committed Jun 16, 2021
commit f712a44c6bda848e511a84b7b2cb3c6224ab7ae3
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static void main(String[] args) {
final List<SquareNumberRequest> requests =
numbers.stream().map(SquareNumberRequest::new).collect(Collectors.toList());

final Consumer consumer = new Consumer(0L);
var consumer = new Consumer(0L);

// Pass the request and the consumer to fanOutFanIn or sometimes referred as Orchestrator
// function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

package com.iluwatar.fanout.fanin;

import java.security.SecureRandom;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

Expand All @@ -42,12 +44,15 @@ public class SquareNumberRequest {
* @param consumer callback class that takes the result after the delay.
* */
public void delayedSquaring(final Consumer consumer) {
long maxTimeOut = 7000L;
long minTimeOut = 5000L;

var minTimeOut = 5000L;

SecureRandom secureRandom = new SecureRandom();
var randomTimeOut = secureRandom.nextInt(2000);

try {
// this will make the thread sleep from 5-7s.
Thread.sleep((long) (Math.random() * (maxTimeOut - minTimeOut) + minTimeOut));
Thread.sleep( minTimeOut + randomTimeOut);
} catch (InterruptedException e) {
LOGGER.error("Exception while sleep ", e);
Thread.currentThread().interrupt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
import java.util.List;
import java.util.stream.Collectors;

public class FanOutFanInTest {
class FanOutFanInTest {

@Test
public void fanOutFanInTest() {
void fanOutFanInTest() {
final List<Long> numbers = Arrays.asList(1L, 3L, 4L, 7L, 8L);

final List<SquareNumberRequest> requests =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class SquareNumberRequestTest {
class SquareNumberRequestTest {

@Test
public void delayedSquaringTest() {
void delayedSquaringTest() {
Consumer consumer = new Consumer(10L);

SquareNumberRequest squareNumberRequest = new SquareNumberRequest(5L);
Expand Down