use of com.hubspot.singularity.data.history.RequestHistoryHelper in project Singularity by HubSpot.
the class BlendedHistoryTest method testBlendedRequestHistory.
// DESCENDING
@Test
public void testBlendedRequestHistory() {
HistoryManager hm = mock(HistoryManager.class);
String rid = "rid";
request = new SingularityRequestBuilder(rid, RequestType.WORKER).build();
RequestHistoryHelper rhh = new RequestHistoryHelper(requestManager, hm);
mockRequestHistory(hm, Collections.<SingularityRequestHistory>emptyList());
Assert.assertTrue(rhh.getBlendedHistory(rid, 0, 100).isEmpty());
Assert.assertTrue(!rhh.getFirstHistory(rid).isPresent());
Assert.assertTrue(!rhh.getLastHistory(rid).isPresent());
mockRequestHistory(hm, Arrays.asList(makeHistory(52, RequestHistoryType.EXITED_COOLDOWN), makeHistory(51, RequestHistoryType.ENTERED_COOLDOWN), makeHistory(50, RequestHistoryType.CREATED)));
List<SingularityRequestHistory> history = rhh.getBlendedHistory(rid, 0, 5);
Assert.assertTrue(history.size() == 3);
saveHistory(100, RequestHistoryType.DELETED);
saveHistory(120, RequestHistoryType.CREATED);
history = rhh.getBlendedHistory(rid, 0, 5);
Assert.assertTrue(history.size() == 5);
Assert.assertTrue(history.get(0).getCreatedAt() == 120);
Assert.assertTrue(history.get(4).getCreatedAt() == 50);
history = rhh.getBlendedHistory(rid, 1, 5);
Assert.assertTrue(history.size() == 4);
Assert.assertTrue(history.get(0).getCreatedAt() == 100);
Assert.assertTrue(history.get(3).getCreatedAt() == 50);
history = rhh.getBlendedHistory(rid, 2, 5);
Assert.assertTrue(history.size() == 3);
Assert.assertTrue(history.get(0).getCreatedAt() == 52);
Assert.assertTrue(history.get(2).getCreatedAt() == 50);
mockRequestHistory(hm, Collections.<SingularityRequestHistory>emptyList());
history = rhh.getBlendedHistory(rid, 3, 5);
Assert.assertTrue(history.isEmpty());
history = rhh.getBlendedHistory(rid, 1, 5);
Assert.assertTrue(history.size() == 1);
Assert.assertTrue(history.get(0).getCreatedAt() == 100);
Assert.assertTrue(rhh.getFirstHistory(rid).get().getCreatedAt() == 100);
Assert.assertTrue(rhh.getLastHistory(rid).get().getCreatedAt() == 120);
mockRequestHistory(hm, Arrays.asList(makeHistory(1, RequestHistoryType.EXITED_COOLDOWN)));
Assert.assertTrue(rhh.getFirstHistory(rid).get().getCreatedAt() == 1);
Assert.assertTrue(rhh.getLastHistory(rid).get().getCreatedAt() == 120);
}
Aggregations