Skip to content

Commit

Permalink
review comments changes done.
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishekdahiya-db committed Mar 21, 2023
1 parent b9a31ff commit 3e4b60c
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ public boolean handleException(Response t, int retryCount, Throwable e) {

return false;
}

protected abstract void add(MessageRetry messageRetry);


}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ public class InMemoryMessageRetryHandler extends BasicMessageRetryHandler {

private static final Logger LOG = LoggerFactory.getLogger(InMemoryMessageRetryHandler.class);

Queue<MessageRetry> queue = new ConcurrentLinkedQueue<>();
private Queue<MessageRetry> queue = new ConcurrentLinkedQueue<>();

@Override
public void add(MessageRetry t) {
queue.add(t);
}

@Override
public void clearAll() {
while(queue.poll()!=null);
}

@Override
public Optional<MessageRetry> get() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ public interface MessageRetryHandler {

public Optional<MessageRetry> get();

public void add(MessageRetry messageRetry);

public void clearAll();

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,14 @@ public boolean handleException(Response t, int retryCount, Throwable e) {
return false;
}

@Override
public void add(MessageRetry messageRetry) {
//Do-Nothing
}

@Override
public void clearAll() {
//Do-Nothing
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.finos.springbot.workflow.response.DataResponse;
import org.finos.springbot.workflow.response.Response;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

Expand All @@ -24,43 +23,40 @@ public class InMemoryMessageRetryHandlerTest {
TeamsChannel dummyChat = new TeamsChannel();
Object dummyObject = new Object();

@BeforeEach
public void setUp() {
while(inMemoryMessageRetryHandler.queue.poll()!=null);
LocalDateTime currentTime= LocalDateTime.now();
public void setUp(LocalDateTime retryTime1,LocalDateTime retryTime2) {
inMemoryMessageRetryHandler.clearAll();
Map<String, Object> data1 = new HashMap<>();
data1.put("key1", dummyObject);
Map<String, Object> data2 = new HashMap<>();
data2.put("key2", dummyObject);
Response r1 = new DataResponse(dummyChat, data1, "");
Response r2 = new DataResponse(dummyChat, data2, "");
MessageRetry t1 = new MessageRetry(r1,3,5,currentTime.plusSeconds(5));
MessageRetry t2 = new MessageRetry(r2,3,45,currentTime.plusSeconds(45));
inMemoryMessageRetryHandler.queue.add(t1);
inMemoryMessageRetryHandler.queue.add(t2);
MessageRetry t1 = new MessageRetry(r1,3,45,retryTime1);
MessageRetry t2 = new MessageRetry(r2,3,45,retryTime2);
inMemoryMessageRetryHandler.add(t1);
inMemoryMessageRetryHandler.add(t2);
}
@Test
public void testGet() throws InterruptedException {
public void testFoundMessageForRetry() {
setUp(LocalDateTime.now().minusSeconds(100),LocalDateTime.now().plusSeconds(150));
Map<String, Object> expectedData = new HashMap<>();
expectedData.put("key1", dummyObject);
LocalDateTime futureTime = LocalDateTime.now().plusSeconds(10);
while(LocalDateTime.now().isBefore(futureTime)) {
Thread.sleep(1000);
}
DataResponse actualResponse = (DataResponse) inMemoryMessageRetryHandler.get().get().getResponse();
Assertions.assertTrue(actualResponse.getData().equals(expectedData));
Optional<MessageRetry> actualResult = inMemoryMessageRetryHandler.get();
Assertions.assertFalse(actualResult.isPresent());

}

@Test
public void testGetNoData() throws InterruptedException {
LocalDateTime futureTime = LocalDateTime.now().plusSeconds(1);
while(LocalDateTime.now().isBefore(futureTime)) {
Thread.sleep(1000);
}
public void testNoMessageEligibleForRetry(){
setUp(LocalDateTime.now().plusSeconds(100),LocalDateTime.now().plusSeconds(150));
Optional<MessageRetry> actualResponse = inMemoryMessageRetryHandler.get();
Assertions.assertFalse(actualResponse.isPresent());
}

@Test
public void testNoMessageInQueue() {
inMemoryMessageRetryHandler.clearAll();
Optional<MessageRetry> actualResponse = inMemoryMessageRetryHandler.get();
Assertions.assertFalse(actualResponse.isPresent());

}
}

0 comments on commit 3e4b60c

Please sign in to comment.