use of org.apache.hadoop.ozone.recon.tasks.ReconTaskController in project ozone by apache.
the class MockOzoneServiceProvider method testUpdateReconOmDBWithNewSnapshot.
@Test
public void testUpdateReconOmDBWithNewSnapshot() throws Exception {
OMMetadataManager omMetadataManager = initializeNewOmMetadataManager(temporaryFolder.newFolder());
ReconOMMetadataManager reconOMMetadataManager = getTestReconOmMetadataManager(omMetadataManager, temporaryFolder.newFolder());
writeDataToOm(omMetadataManager, "key_one");
writeDataToOm(omMetadataManager, "key_two");
DBCheckpoint checkpoint = omMetadataManager.getStore().getCheckpoint(true);
File tarFile = createTarFile(checkpoint.getCheckpointLocation());
InputStream inputStream = new FileInputStream(tarFile);
ReconUtils reconUtilsMock = getMockReconUtils();
HttpURLConnection httpURLConnectionMock = mock(HttpURLConnection.class);
when(httpURLConnectionMock.getInputStream()).thenReturn(inputStream);
when(reconUtilsMock.makeHttpCall(any(), anyString(), anyBoolean())).thenReturn(httpURLConnectionMock);
ReconTaskController reconTaskController = getMockTaskController();
OzoneManagerServiceProviderImpl ozoneManagerServiceProvider = new OzoneManagerServiceProviderImpl(configuration, reconOMMetadataManager, reconTaskController, reconUtilsMock, ozoneManagerProtocol);
Assert.assertNull(reconOMMetadataManager.getKeyTable(getBucketLayout()).get("/sampleVol/bucketOne/key_one"));
Assert.assertNull(reconOMMetadataManager.getKeyTable(getBucketLayout()).get("/sampleVol/bucketOne/key_two"));
assertTrue(ozoneManagerServiceProvider.updateReconOmDBWithNewSnapshot());
assertNotNull(reconOMMetadataManager.getKeyTable(getBucketLayout()).get("/sampleVol/bucketOne/key_one"));
assertNotNull(reconOMMetadataManager.getKeyTable(getBucketLayout()).get("/sampleVol/bucketOne/key_two"));
}
use of org.apache.hadoop.ozone.recon.tasks.ReconTaskController in project ozone by apache.
the class MockOzoneServiceProvider method testSyncDataFromOMFullSnapshot.
@Test
public void testSyncDataFromOMFullSnapshot() throws Exception {
// Empty OM DB to start with.
ReconOMMetadataManager omMetadataManager = getTestReconOmMetadataManager(initializeEmptyOmMetadataManager(temporaryFolder.newFolder()), temporaryFolder.newFolder());
ReconTaskStatusDao reconTaskStatusDaoMock = mock(ReconTaskStatusDao.class);
doNothing().when(reconTaskStatusDaoMock).update(any(ReconTaskStatus.class));
ReconTaskController reconTaskControllerMock = getMockTaskController();
when(reconTaskControllerMock.getReconTaskStatusDao()).thenReturn(reconTaskStatusDaoMock);
doNothing().when(reconTaskControllerMock).reInitializeTasks(omMetadataManager);
OzoneManagerServiceProviderImpl ozoneManagerServiceProvider = new MockOzoneServiceProvider(configuration, omMetadataManager, reconTaskControllerMock, new ReconUtils(), ozoneManagerProtocol);
OzoneManagerSyncMetrics metrics = ozoneManagerServiceProvider.getMetrics();
assertEquals(0, metrics.getNumSnapshotRequests().value());
// Should trigger full snapshot request.
ozoneManagerServiceProvider.syncDataFromOM();
ArgumentCaptor<ReconTaskStatus> captor = ArgumentCaptor.forClass(ReconTaskStatus.class);
verify(reconTaskStatusDaoMock, times(1)).update(captor.capture());
assertTrue(captor.getValue().getTaskName().equals(OmSnapshotRequest.name()));
verify(reconTaskControllerMock, times(1)).reInitializeTasks(omMetadataManager);
assertEquals(1, metrics.getNumSnapshotRequests().value());
}
use of org.apache.hadoop.ozone.recon.tasks.ReconTaskController in project ozone by apache.
the class MockOzoneServiceProvider method testGetOzoneManagerDBSnapshot.
@Test
public void testGetOzoneManagerDBSnapshot() throws Exception {
File reconOmSnapshotDbDir = temporaryFolder.newFolder();
File checkpointDir = Paths.get(reconOmSnapshotDbDir.getAbsolutePath(), "testGetOzoneManagerDBSnapshot").toFile();
checkpointDir.mkdir();
File file1 = Paths.get(checkpointDir.getAbsolutePath(), "file1").toFile();
String str = "File1 Contents";
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file1), UTF_8));
writer.write(str);
} finally {
if (writer != null) {
writer.close();
}
}
File file2 = Paths.get(checkpointDir.getAbsolutePath(), "file2").toFile();
str = "File2 Contents";
try {
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file2), UTF_8));
writer.write(str);
} finally {
writer.close();
}
// Create test tar file.
File tarFile = createTarFile(checkpointDir.toPath());
InputStream fileInputStream = new FileInputStream(tarFile);
ReconUtils reconUtilsMock = getMockReconUtils();
HttpURLConnection httpURLConnectionMock = mock(HttpURLConnection.class);
when(httpURLConnectionMock.getInputStream()).thenReturn(fileInputStream);
when(reconUtilsMock.makeHttpCall(any(), anyString(), anyBoolean())).thenReturn(httpURLConnectionMock);
ReconOMMetadataManager reconOMMetadataManager = mock(ReconOMMetadataManager.class);
ReconTaskController reconTaskController = getMockTaskController();
OzoneManagerServiceProviderImpl ozoneManagerServiceProvider = new OzoneManagerServiceProviderImpl(configuration, reconOMMetadataManager, reconTaskController, reconUtilsMock, ozoneManagerProtocol);
DBCheckpoint checkpoint = ozoneManagerServiceProvider.getOzoneManagerDBSnapshot();
assertNotNull(checkpoint);
assertTrue(checkpoint.getCheckpointLocation().toFile().isDirectory());
assertTrue(checkpoint.getCheckpointLocation().toFile().listFiles().length == 2);
}
use of org.apache.hadoop.ozone.recon.tasks.ReconTaskController in project ozone by apache.
the class MockOzoneServiceProvider method testSyncDataFromOMDeltaUpdates.
@Test
public void testSyncDataFromOMDeltaUpdates() throws Exception {
// Non-Empty OM DB to start with.
ReconOMMetadataManager omMetadataManager = getTestReconOmMetadataManager(initializeNewOmMetadataManager(temporaryFolder.newFolder()), temporaryFolder.newFolder());
ReconTaskStatusDao reconTaskStatusDaoMock = mock(ReconTaskStatusDao.class);
doNothing().when(reconTaskStatusDaoMock).update(any(ReconTaskStatus.class));
ReconTaskController reconTaskControllerMock = getMockTaskController();
when(reconTaskControllerMock.getReconTaskStatusDao()).thenReturn(reconTaskStatusDaoMock);
doNothing().when(reconTaskControllerMock).consumeOMEvents(any(OMUpdateEventBatch.class), any(OMMetadataManager.class));
OzoneManagerServiceProviderImpl ozoneManagerServiceProvider = new OzoneManagerServiceProviderImpl(configuration, omMetadataManager, reconTaskControllerMock, new ReconUtils(), ozoneManagerProtocol);
OzoneManagerSyncMetrics metrics = ozoneManagerServiceProvider.getMetrics();
// Should trigger delta updates.
ozoneManagerServiceProvider.syncDataFromOM();
ArgumentCaptor<ReconTaskStatus> captor = ArgumentCaptor.forClass(ReconTaskStatus.class);
verify(reconTaskStatusDaoMock, times(1)).update(captor.capture());
assertTrue(captor.getValue().getTaskName().equals(OmDeltaRequest.name()));
verify(reconTaskControllerMock, times(1)).consumeOMEvents(any(OMUpdateEventBatch.class), any(OMMetadataManager.class));
assertEquals(0, metrics.getNumSnapshotRequests().value());
}
Aggregations