diff --git a/hadoop-ozone/recon/dev-support/findbugsExcludeFile.xml b/hadoop-ozone/recon/dev-support/findbugsExcludeFile.xml index 2fe78fbf2f2a..101c2a716b30 100644 --- a/hadoop-ozone/recon/dev-support/findbugsExcludeFile.xml +++ b/hadoop-ozone/recon/dev-support/findbugsExcludeFile.xml @@ -16,6 +16,7 @@ limitations under the License. --> + @@ -25,34 +26,4 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/TestReconUtils.java b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/TestReconUtils.java index 8b01fa85cb8e..07fea9581900 100644 --- a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/TestReconUtils.java +++ b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/TestReconUtils.java @@ -27,13 +27,9 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import java.io.BufferedWriter; import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.Charset; @@ -56,7 +52,7 @@ * Test Recon Utility methods. */ public class TestReconUtils { - private static PipelineID randomPipelineID = PipelineID.randomId(); + private static final PipelineID RANDOM_PIPELINE_ID = PipelineID.randomId(); @TempDir private Path temporaryFolder; @@ -76,31 +72,18 @@ public void testGetReconDbDir() throws Exception { public void testCreateTarFile(@TempDir File tempSnapshotDir) throws Exception { - FileInputStream fis = null; - FileOutputStream fos = null; File tarFile = null; try { String testDirName = tempSnapshotDir.getPath(); - File file = new File(testDirName + "/temp1.txt"); - OutputStreamWriter writer = new OutputStreamWriter( - new FileOutputStream(file), UTF_8); - writer.write("Test data 1"); - writer.close(); - - file = new File(testDirName + "/temp2.txt"); - writer = new OutputStreamWriter( - new FileOutputStream(file), UTF_8); - writer.write("Test data 2"); - writer.close(); + FileUtils.write(new File(testDirName + "/temp1.txt"), "Test data 1", UTF_8); + FileUtils.write(new File(testDirName + "/temp2.txt"), "Test data 2", UTF_8); tarFile = createTarFile(Paths.get(testDirName)); assertNotNull(tarFile); } finally { - org.apache.hadoop.io.IOUtils.closeStream(fis); - org.apache.hadoop.io.IOUtils.closeStream(fos); FileUtils.deleteDirectory(tempSnapshotDir); FileUtils.deleteQuietly(tarFile); } @@ -113,19 +96,11 @@ public void testUntarCheckpointFile() throws Exception { temporaryFolder.resolve("NewDir")).toFile(); File file1 = Paths.get(newDir.getAbsolutePath(), "file1") .toFile(); - String str = "File1 Contents"; - BufferedWriter writer = new BufferedWriter(new OutputStreamWriter( - new FileOutputStream(file1.getAbsoluteFile()), UTF_8)); - writer.write(str); - writer.close(); + FileUtils.write(file1, "File1 Contents", UTF_8); File file2 = Paths.get(newDir.getAbsolutePath(), "file2") .toFile(); - str = "File2 Contents"; - writer = new BufferedWriter(new OutputStreamWriter( - new FileOutputStream(file2.getAbsoluteFile()), UTF_8)); - writer.write(str); - writer.close(); + FileUtils.write(file2, "File2 Contents", UTF_8); //Create test tar file. File tarFile = createTarFile(newDir.toPath()); @@ -142,25 +117,23 @@ public void testMakeHttpCall() throws Exception { String url = "http://localhost:9874/dbCheckpoint"; File file1 = Paths.get(temporaryFolder.toString(), "file1") .toFile(); - BufferedWriter writer = new BufferedWriter(new OutputStreamWriter( - new FileOutputStream(file1.getAbsoluteFile()), UTF_8)); - writer.write("File 1 Contents"); - writer.close(); - InputStream fileInputStream = new FileInputStream(file1); - - String contents; - URLConnectionFactory connectionFactoryMock = - mock(URLConnectionFactory.class); - HttpURLConnection urlConnectionMock = mock(HttpURLConnection.class); - when(urlConnectionMock.getInputStream()).thenReturn(fileInputStream); - when(connectionFactoryMock.openConnection(any(URL.class), anyBoolean())) - .thenReturn(urlConnectionMock); - try (InputStream inputStream = new ReconUtils() - .makeHttpCall(connectionFactoryMock, url, false).getInputStream()) { - contents = IOUtils.toString(inputStream, Charset.defaultCharset()); + FileUtils.write(file1, "File 1 Contents", UTF_8); + try (InputStream fileInputStream = Files.newInputStream(file1.toPath())) { + + String contents; + URLConnectionFactory connectionFactoryMock = + mock(URLConnectionFactory.class); + HttpURLConnection urlConnectionMock = mock(HttpURLConnection.class); + when(urlConnectionMock.getInputStream()).thenReturn(fileInputStream); + when(connectionFactoryMock.openConnection(any(URL.class), anyBoolean())) + .thenReturn(urlConnectionMock); + try (InputStream inputStream = new ReconUtils() + .makeHttpCall(connectionFactoryMock, url, false).getInputStream()) { + contents = IOUtils.toString(inputStream, Charset.defaultCharset()); + } + + assertEquals("File 1 Contents", contents); } - - assertEquals("File 1 Contents", contents); } @Test @@ -168,28 +141,15 @@ public void testGetLastKnownDB(@TempDir File newDir) throws IOException { File file1 = Paths.get(newDir.getAbsolutePath(), "valid_1") .toFile(); - String str = "File1 Contents"; - BufferedWriter writer = new BufferedWriter(new OutputStreamWriter( - new FileOutputStream(file1.getAbsoluteFile()), UTF_8)); - writer.write(str); - writer.close(); + FileUtils.write(file1, "File1 Contents", UTF_8); File file2 = Paths.get(newDir.getAbsolutePath(), "valid_2") .toFile(); - str = "File2 Contents"; - writer = new BufferedWriter(new OutputStreamWriter( - new FileOutputStream(file2.getAbsoluteFile()), UTF_8)); - writer.write(str); - writer.close(); - + FileUtils.write(file2, "File2 Contents", UTF_8); File file3 = Paths.get(newDir.getAbsolutePath(), "invalid_3") .toFile(); - str = "File3 Contents"; - writer = new BufferedWriter(new OutputStreamWriter( - new FileOutputStream(file3.getAbsoluteFile()), UTF_8)); - writer.write(str); - writer.close(); + FileUtils.write(file3, "File3 Contents", UTF_8); ReconUtils reconUtils = new ReconUtils(); File latestValidFile = reconUtils.getLastKnownDB(newDir, "valid"); @@ -255,7 +215,7 @@ private static ContainerInfo.Builder getDefaultContainerInfoBuilder( public static ContainerInfo getContainer( final HddsProtos.LifeCycleState state) { return getDefaultContainerInfoBuilder(state) - .setPipelineID(randomPipelineID) + .setPipelineID(RANDOM_PIPELINE_ID) .build(); } } diff --git a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/recovery/TestReconOmMetadataManagerImpl.java b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/recovery/TestReconOmMetadataManagerImpl.java index 3f25f7a5b6c4..425e80961bc8 100644 --- a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/recovery/TestReconOmMetadataManagerImpl.java +++ b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/recovery/TestReconOmMetadataManagerImpl.java @@ -62,7 +62,7 @@ public void testStart() throws Exception { File snapshotFile = new File( checkpoint.getCheckpointLocation().getParent() + "/" + "om.snapshot.db_" + System.currentTimeMillis()); - checkpoint.getCheckpointLocation().toFile().renameTo(snapshotFile); + assertTrue(checkpoint.getCheckpointLocation().toFile().renameTo(snapshotFile)); //Create new Recon OM Metadata manager instance. File reconOmDbDir = Files.createDirectory( diff --git a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/spi/impl/TestOzoneManagerServiceProviderImpl.java b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/spi/impl/TestOzoneManagerServiceProviderImpl.java index 3d9e39498e60..3346edb09bf1 100644 --- a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/spi/impl/TestOzoneManagerServiceProviderImpl.java +++ b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/spi/impl/TestOzoneManagerServiceProviderImpl.java @@ -44,15 +44,13 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import java.io.BufferedWriter; import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStreamWriter; import java.net.HttpURLConnection; +import java.nio.file.Files; import java.nio.file.Paths; +import org.apache.commons.io.FileUtils; import org.apache.hadoop.hdds.conf.OzoneConfiguration; import org.apache.hadoop.hdds.utils.db.DBCheckpoint; import org.apache.hadoop.hdds.utils.db.RDBStore; @@ -122,36 +120,37 @@ public void testUpdateReconOmDBWithNewSnapshot( 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); - when(reconUtilsMock.getReconNodeDetails( - any(OzoneConfiguration.class))).thenReturn( - commonUtils.getReconNodeDetails()); - ReconTaskController reconTaskController = getMockTaskController(); + try (InputStream inputStream = Files.newInputStream(tarFile.toPath())) { + ReconUtils reconUtilsMock = getMockReconUtils(); + HttpURLConnection httpURLConnectionMock = mock(HttpURLConnection.class); + when(httpURLConnectionMock.getInputStream()).thenReturn(inputStream); + when(reconUtilsMock.makeHttpCall(any(), anyString(), anyBoolean())) + .thenReturn(httpURLConnectionMock); + when(reconUtilsMock.getReconNodeDetails( + any(OzoneConfiguration.class))).thenReturn( + commonUtils.getReconNodeDetails()); + ReconTaskController reconTaskController = getMockTaskController(); - OzoneManagerServiceProviderImpl ozoneManagerServiceProvider = - new OzoneManagerServiceProviderImpl(configuration, - reconOMMetadataManager, reconTaskController, reconUtilsMock, ozoneManagerProtocol, - reconContext, getMockTaskStatusUpdaterManager()); + OzoneManagerServiceProviderImpl ozoneManagerServiceProvider = + new OzoneManagerServiceProviderImpl(configuration, + reconOMMetadataManager, reconTaskController, reconUtilsMock, ozoneManagerProtocol, + reconContext, getMockTaskStatusUpdaterManager()); - assertNull(reconOMMetadataManager.getKeyTable(getBucketLayout()) - .get("/sampleVol/bucketOne/key_one")); - assertNull(reconOMMetadataManager.getKeyTable(getBucketLayout()) - .get("/sampleVol/bucketOne/key_two")); + assertNull(reconOMMetadataManager.getKeyTable(getBucketLayout()) + .get("/sampleVol/bucketOne/key_one")); + assertNull(reconOMMetadataManager.getKeyTable(getBucketLayout()) + .get("/sampleVol/bucketOne/key_two")); - assertTrue(ozoneManagerServiceProvider.updateReconOmDBWithNewSnapshot()); + assertTrue(ozoneManagerServiceProvider.updateReconOmDBWithNewSnapshot()); - assertNotNull(reconOMMetadataManager.getKeyTable(getBucketLayout()) - .get("/sampleVol/bucketOne/key_one")); - assertNotNull(reconOMMetadataManager.getKeyTable(getBucketLayout()) - .get("/sampleVol/bucketOne/key_two")); + assertNotNull(reconOMMetadataManager.getKeyTable(getBucketLayout()) + .get("/sampleVol/bucketOne/key_one")); + assertNotNull(reconOMMetadataManager.getKeyTable(getBucketLayout()) + .get("/sampleVol/bucketOne/key_two")); - // Verifying if context error GET_OM_DB_SNAPSHOT_FAILED is removed - assertFalse(reconContext.getErrors().contains(ReconContext.ErrorCode.GET_OM_DB_SNAPSHOT_FAILED)); + // Verifying if context error GET_OM_DB_SNAPSHOT_FAILED is removed + assertFalse(reconContext.getErrors().contains(ReconContext.ErrorCode.GET_OM_DB_SNAPSHOT_FAILED)); + } } @Test @@ -199,31 +198,32 @@ public void testUpdateReconOmDBWithNewSnapshotSuccess( 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); - when(reconUtilsMock.getReconNodeDetails(any(OzoneConfiguration.class))) - .thenReturn(commonUtils.getReconNodeDetails()); - ReconTaskController reconTaskController = getMockTaskController(); + try (InputStream inputStream = Files.newInputStream(tarFile.toPath())) { + ReconUtils reconUtilsMock = getMockReconUtils(); + HttpURLConnection httpURLConnectionMock = mock(HttpURLConnection.class); + when(httpURLConnectionMock.getInputStream()).thenReturn(inputStream); + when(reconUtilsMock.makeHttpCall(any(), anyString(), anyBoolean())) + .thenReturn(httpURLConnectionMock); + when(reconUtilsMock.getReconNodeDetails(any(OzoneConfiguration.class))) + .thenReturn(commonUtils.getReconNodeDetails()); + ReconTaskController reconTaskController = getMockTaskController(); - reconContext.updateErrors(ReconContext.ErrorCode.GET_OM_DB_SNAPSHOT_FAILED); + reconContext.updateErrors(ReconContext.ErrorCode.GET_OM_DB_SNAPSHOT_FAILED); - OzoneManagerServiceProviderImpl ozoneManagerServiceProvider = - new OzoneManagerServiceProviderImpl(configuration, - reconOMMetadataManager, reconTaskController, reconUtilsMock, ozoneManagerProtocol, - reconContext, getMockTaskStatusUpdaterManager()); + OzoneManagerServiceProviderImpl ozoneManagerServiceProvider = + new OzoneManagerServiceProviderImpl(configuration, + reconOMMetadataManager, reconTaskController, reconUtilsMock, ozoneManagerProtocol, + reconContext, getMockTaskStatusUpdaterManager()); - assertTrue(reconContext.getErrors().contains(ReconContext.ErrorCode.GET_OM_DB_SNAPSHOT_FAILED)); - assertTrue(ozoneManagerServiceProvider.updateReconOmDBWithNewSnapshot()); - assertFalse(reconContext.getErrors().contains(ReconContext.ErrorCode.GET_OM_DB_SNAPSHOT_FAILED)); + assertTrue(reconContext.getErrors().contains(ReconContext.ErrorCode.GET_OM_DB_SNAPSHOT_FAILED)); + assertTrue(ozoneManagerServiceProvider.updateReconOmDBWithNewSnapshot()); + assertFalse(reconContext.getErrors().contains(ReconContext.ErrorCode.GET_OM_DB_SNAPSHOT_FAILED)); - assertNotNull(reconOMMetadataManager.getKeyTable(getBucketLayout()) - .get("/sampleVol/bucketOne/key_one")); - assertNotNull(reconOMMetadataManager.getKeyTable(getBucketLayout()) - .get("/sampleVol/bucketOne/key_two")); + assertNotNull(reconOMMetadataManager.getKeyTable(getBucketLayout()) + .get("/sampleVol/bucketOne/key_one")); + assertNotNull(reconOMMetadataManager.getKeyTable(getBucketLayout()) + .get("/sampleVol/bucketOne/key_two")); + } } @Test @@ -242,33 +242,35 @@ public void testReconOmDBCloseAndOpenNewSnapshotDb( .getCheckpoint(true); File tarFile1 = createTarFile(checkpoint.getCheckpointLocation()); File tarFile2 = createTarFile(checkpoint.getCheckpointLocation()); - InputStream inputStream1 = new FileInputStream(tarFile1); - InputStream inputStream2 = new FileInputStream(tarFile2); ReconUtils reconUtilsMock = getMockReconUtils(); - HttpURLConnection httpURLConnectionMock1 = mock(HttpURLConnection.class); - when(httpURLConnectionMock1.getInputStream()).thenReturn(inputStream1); - when(reconUtilsMock.makeHttpCall(any(), anyString(), anyBoolean())) - .thenReturn(httpURLConnectionMock1); - when(reconUtilsMock.getReconNodeDetails( - any(OzoneConfiguration.class))).thenReturn( - commonUtils.getReconNodeDetails()); ReconTaskController reconTaskController = getMockTaskController(); + try (InputStream inputStream1 = Files.newInputStream(tarFile1.toPath())) { + HttpURLConnection httpURLConnectionMock1 = mock(HttpURLConnection.class); + when(httpURLConnectionMock1.getInputStream()).thenReturn(inputStream1); + when(reconUtilsMock.makeHttpCall(any(), anyString(), anyBoolean())) + .thenReturn(httpURLConnectionMock1); + when(reconUtilsMock.getReconNodeDetails( + any(OzoneConfiguration.class))).thenReturn( + commonUtils.getReconNodeDetails()); - OzoneManagerServiceProviderImpl ozoneManagerServiceProvider1 = - new OzoneManagerServiceProviderImpl(configuration, - reconOMMetadataManager, reconTaskController, reconUtilsMock, ozoneManagerProtocol, - reconContext, getMockTaskStatusUpdaterManager()); - assertTrue(ozoneManagerServiceProvider1.updateReconOmDBWithNewSnapshot()); + OzoneManagerServiceProviderImpl ozoneManagerServiceProvider1 = + new OzoneManagerServiceProviderImpl(configuration, + reconOMMetadataManager, reconTaskController, reconUtilsMock, ozoneManagerProtocol, + reconContext, getMockTaskStatusUpdaterManager()); + assertTrue(ozoneManagerServiceProvider1.updateReconOmDBWithNewSnapshot()); + } - HttpURLConnection httpURLConnectionMock2 = mock(HttpURLConnection.class); - when(httpURLConnectionMock2.getInputStream()).thenReturn(inputStream2); - when(reconUtilsMock.makeHttpCall(any(), anyString(), anyBoolean())) - .thenReturn(httpURLConnectionMock2); - OzoneManagerServiceProviderImpl ozoneManagerServiceProvider2 = - new OzoneManagerServiceProviderImpl(configuration, - reconOMMetadataManager, reconTaskController, reconUtilsMock, ozoneManagerProtocol, - reconContext, getMockTaskStatusUpdaterManager()); - assertTrue(ozoneManagerServiceProvider2.updateReconOmDBWithNewSnapshot()); + try (InputStream inputStream2 = Files.newInputStream(tarFile2.toPath())) { + HttpURLConnection httpURLConnectionMock2 = mock(HttpURLConnection.class); + when(httpURLConnectionMock2.getInputStream()).thenReturn(inputStream2); + when(reconUtilsMock.makeHttpCall(any(), anyString(), anyBoolean())) + .thenReturn(httpURLConnectionMock2); + OzoneManagerServiceProviderImpl ozoneManagerServiceProvider2 = + new OzoneManagerServiceProviderImpl(configuration, + reconOMMetadataManager, reconTaskController, reconUtilsMock, ozoneManagerProtocol, + reconContext, getMockTaskStatusUpdaterManager()); + assertTrue(ozoneManagerServiceProvider2.updateReconOmDBWithNewSnapshot()); + } } @Test @@ -277,28 +279,19 @@ public void testGetOzoneManagerDBSnapshot(@TempDir File dirReconMetadata) File checkpointDir = Paths.get(dirReconMetadata.getAbsolutePath(), "testGetOzoneManagerDBSnapshot").toFile(); - checkpointDir.mkdir(); + assertTrue(checkpointDir.mkdirs()); File file1 = Paths.get(checkpointDir.getAbsolutePath(), "file1") .toFile(); - String str = "File1 Contents"; - - try (BufferedWriter writer1 = new BufferedWriter(new OutputStreamWriter( - new FileOutputStream(file1), UTF_8))) { - writer1.write(str); - } + FileUtils.write(file1, "File1 Contents", UTF_8); File file2 = Paths.get(checkpointDir.getAbsolutePath(), "file2") .toFile(); - str = "File2 Contents"; - try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter( - new FileOutputStream(file2), UTF_8))) { - writer.write(str); - } + FileUtils.write(file2, "File2 Contents", UTF_8); //Create test tar file. File tarFile = createTarFile(checkpointDir.toPath()); - try (InputStream fileInputStream = new FileInputStream(tarFile)) { + try (InputStream fileInputStream = Files.newInputStream(tarFile.toPath())) { ReconUtils reconUtilsMock = getMockReconUtils(); HttpURLConnection httpURLConnectionMock = mock(HttpURLConnection.class); when(httpURLConnectionMock.getInputStream()).thenReturn(fileInputStream); diff --git a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/tasks/TestNSSummaryTask.java b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/tasks/TestNSSummaryTask.java index 669dc0b388bd..e3241287ea56 100644 --- a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/tasks/TestNSSummaryTask.java +++ b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/tasks/TestNSSummaryTask.java @@ -51,6 +51,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.io.TempDir; /** @@ -59,13 +60,14 @@ * support for OBS buckets. Check that the NSSummary * for the OBS bucket is null. */ -public final class TestNSSummaryTask { +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class TestNSSummaryTask { - private static ReconNamespaceSummaryManager reconNamespaceSummaryManager; - private static OMMetadataManager omMetadataManager; - private static ReconOMMetadataManager reconOMMetadataManager; - private static NSSummaryTask nSSummaryTask; - private static OzoneConfiguration omConfiguration; + private ReconNamespaceSummaryManager reconNamespaceSummaryManager; + private OMMetadataManager omMetadataManager; + private ReconOMMetadataManager reconOMMetadataManager; + private NSSummaryTask nSSummaryTask; + private OzoneConfiguration omConfiguration; // Object names private static final String VOL = "vol"; @@ -99,11 +101,8 @@ public final class TestNSSummaryTask { ReconConstants.MAX_FILE_SIZE_UPPER_BOUND - 100L; private static final long KEY_FIVE_SIZE = 100L; - private TestNSSummaryTask() { - } - @BeforeAll - public static void setUp(@TempDir File tmpDir) throws Exception { + void setUp(@TempDir File tmpDir) throws Exception { initializeNewOmMetadataManager(new File(tmpDir, "om")); OzoneManagerServiceProviderImpl ozoneManagerServiceProvider = getMockOzoneManagerServiceProvider(); @@ -371,7 +370,7 @@ private static OmKeyInfo buildOmKeyInfo(String volume, * * @throws IOException */ - private static void populateOMDB() throws IOException { + private void populateOMDB() throws IOException { // Bucket1 FSO layout writeKeyToOm(reconOMMetadataManager, KEY_ONE, @@ -418,7 +417,7 @@ private static void populateOMDB() throws IOException { * and bucket3 will have OBS layout. * @throws IOException ioEx */ - private static void initializeNewOmMetadataManager( + private void initializeNewOmMetadataManager( File omDbDir) throws IOException { omConfiguration = new OzoneConfiguration(); diff --git a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/tasks/TestNSSummaryTaskWithFSO.java b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/tasks/TestNSSummaryTaskWithFSO.java index 345cb5f525ad..eb38084b4db7 100644 --- a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/tasks/TestNSSummaryTaskWithFSO.java +++ b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/tasks/TestNSSummaryTaskWithFSO.java @@ -51,19 +51,21 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.io.TempDir; /** * Test for NSSummaryTaskWithFSO. */ -public final class TestNSSummaryTaskWithFSO { +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class TestNSSummaryTaskWithFSO { - private static ReconNamespaceSummaryManager reconNamespaceSummaryManager; - private static OMMetadataManager omMetadataManager; - private static ReconOMMetadataManager reconOMMetadataManager; - private static NSSummaryTaskWithFSO nSSummaryTaskWithFso; + private ReconNamespaceSummaryManager reconNamespaceSummaryManager; + private OMMetadataManager omMetadataManager; + private ReconOMMetadataManager reconOMMetadataManager; + private NSSummaryTaskWithFSO nSSummaryTaskWithFso; - private static OzoneConfiguration ozoneConfiguration; + private OzoneConfiguration ozoneConfiguration; // Object names in FSO-enabled format private static final String VOL = "vol"; @@ -112,11 +114,8 @@ public final class TestNSSummaryTaskWithFSO { private static Set bucketTwoAns = new HashSet<>(); private static Set dirOneAns = new HashSet<>(); - private TestNSSummaryTaskWithFSO() { - } - @BeforeAll - public static void setUp(@TempDir File tmpDir) throws Exception { + void setUp(@TempDir File tmpDir) throws Exception { ozoneConfiguration = new OzoneConfiguration(); ozoneConfiguration.setLong(OZONE_RECON_NSSUMMARY_FLUSH_TO_DB_MAX_THRESHOLD, 10); @@ -599,7 +598,7 @@ private static OmDirectoryInfo buildOmDirInfo(String dirName, * * @throws IOException */ - private static void populateOMDB() throws IOException { + private void populateOMDB() throws IOException { writeKeyToOm(reconOMMetadataManager, KEY_ONE, BUCKET_ONE, diff --git a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/tasks/TestNSSummaryTaskWithLegacy.java b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/tasks/TestNSSummaryTaskWithLegacy.java index f07712c32b89..ceb88a36563d 100644 --- a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/tasks/TestNSSummaryTaskWithLegacy.java +++ b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/tasks/TestNSSummaryTaskWithLegacy.java @@ -53,18 +53,20 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.io.TempDir; /** * Test for NSSummaryTaskWithLegacy. */ -public final class TestNSSummaryTaskWithLegacy { +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class TestNSSummaryTaskWithLegacy { - private static ReconNamespaceSummaryManager reconNamespaceSummaryManager; - private static OMMetadataManager omMetadataManager; - private static ReconOMMetadataManager reconOMMetadataManager; - private static NSSummaryTaskWithLegacy nSSummaryTaskWithLegacy; - private static OzoneConfiguration omConfiguration; + private ReconNamespaceSummaryManager reconNamespaceSummaryManager; + private OMMetadataManager omMetadataManager; + private ReconOMMetadataManager reconOMMetadataManager; + private NSSummaryTaskWithLegacy nSSummaryTaskWithLegacy; + private OzoneConfiguration omConfiguration; // Object names private static final String VOL = "vol"; @@ -112,15 +114,12 @@ public final class TestNSSummaryTaskWithLegacy { private static final long KEY_FOUR_SIZE = 2050L; private static final long KEY_FIVE_SIZE = 100L; - private static Set bucketOneAns = new HashSet<>(); - private static Set bucketTwoAns = new HashSet<>(); - private static Set dirOneAns = new HashSet<>(); - - private TestNSSummaryTaskWithLegacy() { - } + private final Set bucketOneAns = new HashSet<>(); + private final Set bucketTwoAns = new HashSet<>(); + private final Set dirOneAns = new HashSet<>(); @BeforeAll - public static void setUp(@TempDir File tmpDir) throws Exception { + void setUp(@TempDir File tmpDir) throws Exception { initializeNewOmMetadataManager(new File(tmpDir, "om")); OzoneManagerServiceProviderImpl ozoneManagerServiceProvider = getMockOzoneManagerServiceProvider(); @@ -599,7 +598,7 @@ private static OmKeyInfo buildOmDirKeyInfo(String volume, * * @throws IOException */ - private static void populateOMDB() throws IOException { + private void populateOMDB() throws IOException { writeKeyToOm(reconOMMetadataManager, KEY_ONE, BUCKET_ONE, @@ -684,7 +683,7 @@ private static void populateOMDB() throws IOException { * buckets. * @throws IOException ioEx */ - private static void initializeNewOmMetadataManager( + private void initializeNewOmMetadataManager( File omDbDir) throws IOException { omConfiguration = new OzoneConfiguration(); diff --git a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/tasks/TestNSSummaryTaskWithLegacyOBSLayout.java b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/tasks/TestNSSummaryTaskWithLegacyOBSLayout.java index 470a09b8d91c..766478b87167 100644 --- a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/tasks/TestNSSummaryTaskWithLegacyOBSLayout.java +++ b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/tasks/TestNSSummaryTaskWithLegacyOBSLayout.java @@ -51,20 +51,22 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.io.TempDir; /** * Test for NSSummaryTaskWithLegacy focusing on the OBS (Object Store) layout. */ -public final class TestNSSummaryTaskWithLegacyOBSLayout { +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class TestNSSummaryTaskWithLegacyOBSLayout { - private static ReconNamespaceSummaryManager reconNamespaceSummaryManager; - private static ReconOMMetadataManager reconOMMetadataManager; - private static OzoneConfiguration ozoneConfiguration; - private static NSSummaryTaskWithLegacy nSSummaryTaskWithLegacy; + private ReconNamespaceSummaryManager reconNamespaceSummaryManager; + private ReconOMMetadataManager reconOMMetadataManager; + private OzoneConfiguration ozoneConfiguration; + private NSSummaryTaskWithLegacy nSSummaryTaskWithLegacy; - private static OMMetadataManager omMetadataManager; - private static OzoneConfiguration omConfiguration; + private OMMetadataManager omMetadataManager; + private OzoneConfiguration omConfiguration; // Object names private static final String VOL = "vol"; @@ -103,11 +105,8 @@ public final class TestNSSummaryTaskWithLegacyOBSLayout { private static final long KEY_SIX_SIZE = 6000L; private static final long KEY_SEVEN_SIZE = 7000L; - private TestNSSummaryTaskWithLegacyOBSLayout() { - } - @BeforeAll - public static void setUp(@TempDir File tmpDir) throws Exception { + void setUp(@TempDir File tmpDir) throws Exception { initializeNewOmMetadataManager(new File(tmpDir, "om")); OzoneManagerServiceProviderImpl ozoneManagerServiceProvider = getMockOzoneManagerServiceProviderWithFSO(); @@ -394,7 +393,7 @@ public void testProcessFileBucketSize() { * * @throws IOException */ - private static void populateOMDB() throws IOException { + private void populateOMDB() throws IOException { writeKeyToOm(reconOMMetadataManager, KEY_ONE, BUCKET_ONE, @@ -459,7 +458,7 @@ private static void populateOMDB() throws IOException { * * @throws IOException ioEx */ - private static void initializeNewOmMetadataManager( + private void initializeNewOmMetadataManager( File omDbDir) throws IOException { omConfiguration = new OzoneConfiguration(); diff --git a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/tasks/TestNSSummaryTaskWithOBS.java b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/tasks/TestNSSummaryTaskWithOBS.java index dce87ac3865a..0db53aee1299 100644 --- a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/tasks/TestNSSummaryTaskWithOBS.java +++ b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/tasks/TestNSSummaryTaskWithOBS.java @@ -28,7 +28,6 @@ import java.io.File; import java.io.IOException; -import java.io.Serializable; import java.util.Arrays; import java.util.Set; import org.apache.hadoop.hdds.client.StandaloneReplicationConfig; @@ -52,17 +51,19 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.io.TempDir; /** * Unit test for NSSummaryTaskWithOBS. */ -public final class TestNSSummaryTaskWithOBS implements Serializable { - private static ReconNamespaceSummaryManager reconNamespaceSummaryManager; - private static OMMetadataManager omMetadataManager; - private static ReconOMMetadataManager reconOMMetadataManager; - private static NSSummaryTaskWithOBS nSSummaryTaskWithOBS; - private static OzoneConfiguration omConfiguration; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class TestNSSummaryTaskWithOBS { + private ReconNamespaceSummaryManager reconNamespaceSummaryManager; + private OMMetadataManager omMetadataManager; + private ReconOMMetadataManager reconOMMetadataManager; + private NSSummaryTaskWithOBS nSSummaryTaskWithOBS; + private OzoneConfiguration omConfiguration; // Object names private static final String VOL = "vol"; @@ -101,11 +102,8 @@ public final class TestNSSummaryTaskWithOBS implements Serializable { private static final long KEY_SIX_SIZE = 6000L; private static final long KEY_SEVEN_SIZE = 7000L; - private TestNSSummaryTaskWithOBS() { - } - @BeforeAll - public static void setUp(@TempDir File tmpDir) throws Exception { + void setUp(@TempDir File tmpDir) throws Exception { initializeNewOmMetadataManager(new File(tmpDir, "om")); OzoneManagerServiceProviderImpl ozoneManagerServiceProvider = getMockOzoneManagerServiceProviderWithFSO(); @@ -137,7 +135,7 @@ public static void setUp(@TempDir File tmpDir) throws Exception { * Nested class for testing NSSummaryTaskWithOBS reprocess. */ @Nested - public class TestReprocess { + class TestReprocess { private NSSummary nsSummaryForBucket1; private NSSummary nsSummaryForBucket2; @@ -389,7 +387,7 @@ public void testProcessFileBucketSize() { * * @throws IOException */ - private static void populateOMDB() throws IOException { + private void populateOMDB() throws IOException { writeKeyToOm(reconOMMetadataManager, KEY_ONE, BUCKET_ONE, @@ -454,7 +452,7 @@ private static void populateOMDB() throws IOException { * * @throws IOException ioEx */ - private static void initializeNewOmMetadataManager( + private void initializeNewOmMetadataManager( File omDbDir) throws IOException { omConfiguration = new OzoneConfiguration();