use of org.hadoop.ozone.recon.schema.tables.pojos.ReconTaskStatus in project ozone by apache.
the class TestReconTaskControllerImpl method testBadBehavedTaskIsIgnored.
@Test
public void testBadBehavedTaskIsIgnored() throws Exception {
String taskName = "Dummy_" + System.currentTimeMillis();
DummyReconDBTask dummyReconDBTask = new DummyReconDBTask(taskName, DummyReconDBTask.TaskType.ALWAYS_FAIL);
reconTaskController.registerTask(dummyReconDBTask);
OMUpdateEventBatch omUpdateEventBatchMock = mock(OMUpdateEventBatch.class);
when(omUpdateEventBatchMock.isEmpty()).thenReturn(false);
when(omUpdateEventBatchMock.getLastSequenceNumber()).thenReturn(100L);
OMMetadataManager omMetadataManagerMock = mock(OMMetadataManager.class);
for (int i = 0; i < 2; i++) {
reconTaskController.consumeOMEvents(omUpdateEventBatchMock, omMetadataManagerMock);
assertFalse(reconTaskController.getRegisteredTasks().isEmpty());
assertEquals(dummyReconDBTask, reconTaskController.getRegisteredTasks().get(dummyReconDBTask.getTaskName()));
}
// Should be ignored now.
reconTaskController.consumeOMEvents(omUpdateEventBatchMock, omMetadataManagerMock);
assertTrue(reconTaskController.getRegisteredTasks().isEmpty());
reconTaskStatusDao = getDao(ReconTaskStatusDao.class);
ReconTaskStatus dbRecord = reconTaskStatusDao.findById(taskName);
Assert.assertEquals(taskName, dbRecord.getTaskName());
Assert.assertEquals(Long.valueOf(0L), dbRecord.getLastUpdatedTimestamp());
Assert.assertEquals(Long.valueOf(0L), dbRecord.getLastUpdatedSeqNumber());
}
use of org.hadoop.ozone.recon.schema.tables.pojos.ReconTaskStatus in project ozone by apache.
the class TestReconTaskControllerImpl method testFailedTaskRetryLogic.
@Test
public void testFailedTaskRetryLogic() throws Exception {
String taskName = "Dummy_" + System.currentTimeMillis();
DummyReconDBTask dummyReconDBTask = new DummyReconDBTask(taskName, DummyReconDBTask.TaskType.FAIL_ONCE);
reconTaskController.registerTask(dummyReconDBTask);
long currentTime = System.currentTimeMillis();
OMUpdateEventBatch omUpdateEventBatchMock = mock(OMUpdateEventBatch.class);
when(omUpdateEventBatchMock.isEmpty()).thenReturn(false);
when(omUpdateEventBatchMock.getLastSequenceNumber()).thenReturn(100L);
reconTaskController.consumeOMEvents(omUpdateEventBatchMock, mock(OMMetadataManager.class));
assertFalse(reconTaskController.getRegisteredTasks().isEmpty());
assertEquals(dummyReconDBTask, reconTaskController.getRegisteredTasks().get(dummyReconDBTask.getTaskName()));
reconTaskStatusDao = getDao(ReconTaskStatusDao.class);
ReconTaskStatus dbRecord = reconTaskStatusDao.findById(taskName);
Assert.assertEquals(taskName, dbRecord.getTaskName());
Assert.assertTrue(dbRecord.getLastUpdatedTimestamp() > currentTime);
Assert.assertEquals(Long.valueOf(100L), dbRecord.getLastUpdatedSeqNumber());
}
use of org.hadoop.ozone.recon.schema.tables.pojos.ReconTaskStatus in project ozone by apache.
the class TestReconTaskControllerImpl method testReInitializeTasks.
@Test
public void testReInitializeTasks() throws Exception {
ReconOMMetadataManager omMetadataManagerMock = mock(ReconOMMetadataManager.class);
ReconOmTask reconOmTaskMock = getMockTask("MockTask2");
when(reconOmTaskMock.reprocess(omMetadataManagerMock)).thenReturn(new ImmutablePair<>("MockTask2", true));
when(omMetadataManagerMock.getLastSequenceNumberFromDB()).thenReturn(100L);
long startTime = System.currentTimeMillis();
reconTaskController.registerTask(reconOmTaskMock);
reconTaskController.reInitializeTasks(omMetadataManagerMock);
long endTime = System.currentTimeMillis();
verify(reconOmTaskMock, times(1)).reprocess(omMetadataManagerMock);
verify(omMetadataManagerMock, times(1)).getLastSequenceNumberFromDB();
ReconTaskStatus reconTaskStatus = reconTaskStatusDao.findById("MockTask2");
long taskTimeStamp = reconTaskStatus.getLastUpdatedTimestamp();
long seqNumber = reconTaskStatus.getLastUpdatedSeqNumber();
Assert.assertTrue(startTime <= taskTimeStamp && taskTimeStamp <= endTime);
Assert.assertEquals(seqNumber, omMetadataManagerMock.getLastSequenceNumberFromDB());
}
use of org.hadoop.ozone.recon.schema.tables.pojos.ReconTaskStatus in project ozone by apache.
the class TestReconTaskControllerImpl method testConsumeOMEvents.
@Test
public void testConsumeOMEvents() throws Exception {
ReconOmTask reconOmTaskMock = getMockTask("MockTask");
when(reconOmTaskMock.process(any(OMUpdateEventBatch.class))).thenReturn(new ImmutablePair<>("MockTask", true));
reconTaskController.registerTask(reconOmTaskMock);
OMUpdateEventBatch omUpdateEventBatchMock = mock(OMUpdateEventBatch.class);
when(omUpdateEventBatchMock.getLastSequenceNumber()).thenReturn(100L);
when(omUpdateEventBatchMock.isEmpty()).thenReturn(false);
long startTime = System.currentTimeMillis();
reconTaskController.consumeOMEvents(omUpdateEventBatchMock, mock(OMMetadataManager.class));
verify(reconOmTaskMock, times(1)).process(any());
long endTime = System.currentTimeMillis();
reconTaskStatusDao = getDao(ReconTaskStatusDao.class);
ReconTaskStatus reconTaskStatus = reconTaskStatusDao.findById("MockTask");
long taskTimeStamp = reconTaskStatus.getLastUpdatedTimestamp();
long seqNumber = reconTaskStatus.getLastUpdatedSeqNumber();
Assert.assertTrue(startTime <= taskTimeStamp && taskTimeStamp <= endTime);
Assert.assertEquals(seqNumber, omUpdateEventBatchMock.getLastSequenceNumber());
}
use of org.hadoop.ozone.recon.schema.tables.pojos.ReconTaskStatus in project ozone by apache.
the class ReconTaskControllerImpl method storeLastCompletedTransaction.
/**
* Store the last completed event sequence number and timestamp to the DB
* for that task.
* @param taskName taskname to be updated.
* @param lastSequenceNumber contains the new sequence number.
*/
private void storeLastCompletedTransaction(String taskName, long lastSequenceNumber) {
ReconTaskStatus reconTaskStatusRecord = new ReconTaskStatus(taskName, System.currentTimeMillis(), lastSequenceNumber);
reconTaskStatusDao.update(reconTaskStatusRecord);
}
Aggregations