Skip to content

Commit

Permalink
HDDS-11863. Speed up TestFSORepairTool
Browse files Browse the repository at this point in the history
HDDS-11863. Speed up TestFSORepairTool

Removed another redundant test case
  • Loading branch information
sarvekshayr committed Dec 11, 2024
1 parent ec348a7 commit 99328b6
Showing 1 changed file with 15 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,18 @@ public class TestFSORepairTool {
private static final String DEFAULT_ENCODING = UTF_8.name();
private MiniOzoneCluster cluster;
private FileSystem fs;
private OzoneClient client;
private OzoneConfiguration conf = null;

@BeforeEach
public void init() throws Exception {
// Set configs.
conf = new OzoneConfiguration();

// Build cluster.
cluster = MiniOzoneCluster.newBuilder(conf).build();
cluster = MiniOzoneCluster.newBuilder(conf).build();
cluster.waitForClusterToBeReady();

// Init ofs.
final String rootPath = String.format("%s://%s/", OZONE_OFS_URI_SCHEME, conf.get(OZONE_OM_ADDRESS_KEY));
conf.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, rootPath);
fs = FileSystem.get(conf);
client = OzoneClientFactory.getRpcClient(conf);

System.setOut(new PrintStream(out, false, DEFAULT_ENCODING));
System.setErr(new PrintStream(err, false, DEFAULT_ENCODING));
Expand All @@ -104,69 +99,9 @@ public void reset() throws IOException {
if (cluster != null) {
cluster.shutdown();
}
if (client != null) {
client.close();
}
IOUtils.closeQuietly(fs);
}

@Test
public void testConnectedTreeOneBucket() throws Exception {
CommandLine cmd = new OzoneRepair().getCmd();
String dbPath = new File(OMStorage.getOmDbDir(conf) + "/" + OM_DB_NAME).getPath();

FSORepairTool.Report expectedReport = buildConnectedTree("vol1", "bucket1");
String expectedOutput = serializeReport(expectedReport);

// Test the connected tree in debug mode.
cluster.getOzoneManager().stop();

String[] args = new String[] {"om", "fso-tree", "--db", dbPath};
int exitCode = cmd.execute(args);
assertEquals(0, exitCode);

String cliOutput = out.toString(DEFAULT_ENCODING);
String reportOutput = extractRelevantSection(cliOutput);
Assertions.assertEquals(expectedOutput, reportOutput);

out.reset();
err.reset();

// Running again in repair mode should give same results since the tree is connected.
String[] args1 = new String[] {"om", "fso-tree", "--db", dbPath, "--repair"};
int exitCode1 = cmd.execute(args1);
assertEquals(0, exitCode1);

String cliOutput1 = out.toString(DEFAULT_ENCODING);
String reportOutput1 = extractRelevantSection(cliOutput1);
Assertions.assertEquals(expectedOutput, reportOutput1);

cluster.getOzoneManager().restart();
}

@Test
public void testReportedDataSize() throws Exception {
CommandLine cmd = new OzoneRepair().getCmd();
String dbPath = new File(OMStorage.getOmDbDir(conf) + "/" + OM_DB_NAME).getPath();

FSORepairTool.Report report1 = buildDisconnectedTree("vol1", "bucket1", 10);
FSORepairTool.Report report2 = buildConnectedTree("vol1", "bucket2", 10);
FSORepairTool.Report expectedReport = new FSORepairTool.Report(report1, report2);
String expectedOutput = serializeReport(expectedReport);

cluster.getOzoneManager().stop();

String[] args = new String[] {"om", "fso-tree", "--db", dbPath, "--repair"};
int exitCode = cmd.execute(args);
assertEquals(0, exitCode);

String cliOutput = out.toString(DEFAULT_ENCODING);
String reportOutput = extractRelevantSection(cliOutput);

Assertions.assertEquals(expectedOutput, reportOutput);
cluster.getOzoneManager().restart();
}

/**
* Test to verify how the tool processes the volume and bucket
* filters.
Expand All @@ -176,10 +111,8 @@ public void testVolumeAndBucketFilter() throws Exception {
CommandLine cmd = new OzoneRepair().getCmd();
String dbPath = new File(OMStorage.getOmDbDir(conf) + "/" + OM_DB_NAME).getPath();

FSORepairTool.Report report1 = buildDisconnectedTree("vol1", "bucket1", 10);
FSORepairTool.Report report2 = buildConnectedTree("vol2", "bucket2", 10);
FSORepairTool.Report expectedReport1 = new FSORepairTool.Report(report1);
FSORepairTool.Report expectedReport2 = new FSORepairTool.Report(report2);
FSORepairTool.Report report = buildDisconnectedTree("vol1", "bucket1", 10);
FSORepairTool.Report expectedReport = new FSORepairTool.Report(report);

cluster.getOzoneManager().stop();

Expand All @@ -190,21 +123,21 @@ public void testVolumeAndBucketFilter() throws Exception {

String cliOutput1 = out.toString(DEFAULT_ENCODING);
String reportOutput1 = extractRelevantSection(cliOutput1);
String expectedOutput1 = serializeReport(expectedReport1);
String expectedOutput1 = serializeReport(expectedReport);
Assertions.assertEquals(expectedOutput1, reportOutput1);

out.reset();
err.reset();

// When both volume and bucket filters are passed
String[] args2 = new String[]{"om", "fso-tree", "--db", dbPath, "--volume", "/vol2",
"--bucket", "bucket2"};
String[] args2 = new String[]{"om", "fso-tree", "--db", dbPath, "--volume", "/vol1",
"--bucket", "bucket1"};
int exitCode2 = cmd.execute(args2);
assertEquals(0, exitCode2);

String cliOutput2 = out.toString(DEFAULT_ENCODING);
String reportOutput2 = extractRelevantSection(cliOutput2);
String expectedOutput2 = serializeReport(expectedReport2);
String expectedOutput2 = serializeReport(expectedReport);
Assertions.assertEquals(expectedOutput2, reportOutput2);

out.reset();
Expand All @@ -222,11 +155,11 @@ public void testVolumeAndBucketFilter() throws Exception {
err.reset();

// When a non-existent volume filter is passed
String[] args4 = new String[]{"om", "fso-tree", "--db", dbPath, "--volume", "/vol3"};
String[] args4 = new String[]{"om", "fso-tree", "--db", dbPath, "--volume", "/vol2"};
int exitCode4 = cmd.execute(args4);
assertEquals(0, exitCode4);
String cliOutput4 = out.toString(DEFAULT_ENCODING);
Assertions.assertTrue(cliOutput4.contains("Volume '/vol3' does not exist."));
Assertions.assertTrue(cliOutput4.contains("Volume '/vol2' does not exist."));

out.reset();
err.reset();
Expand All @@ -237,18 +170,17 @@ public void testVolumeAndBucketFilter() throws Exception {
assertEquals(0, exitCode5);
String cliOutput5 = out.toString(DEFAULT_ENCODING);
Assertions.assertTrue(cliOutput5.contains("--bucket flag cannot be used without specifying --volume."));

cluster.getOzoneManager().restart();
}

@Test
public void testMultipleBucketsAndVolumes() throws Exception {
CommandLine cmd = new OzoneRepair().getCmd();
String dbPath = new File(OMStorage.getOmDbDir(conf) + "/" + OM_DB_NAME).getPath();

FSORepairTool.Report report1 = buildConnectedTree("vol1", "bucket1");
FSORepairTool.Report report2 = buildDisconnectedTree("vol2", "bucket2");
FSORepairTool.Report expectedAggregateReport = new FSORepairTool.Report(report1, report2);
FSORepairTool.Report report1 = buildDisconnectedTree("vol1", "bucket1");
FSORepairTool.Report report2 = buildConnectedTree("vol1", "bucket2");
FSORepairTool.Report report3 = buildDisconnectedTree("vol2", "bucket2");
FSORepairTool.Report expectedAggregateReport = new FSORepairTool.Report(report1, report2, report3);
String expectedOutput = serializeReport(expectedAggregateReport);

cluster.getOzoneManager().stop();
Expand All @@ -260,8 +192,6 @@ public void testMultipleBucketsAndVolumes() throws Exception {
String cliOutput = out.toString(DEFAULT_ENCODING);
String reportOutput = extractRelevantSection(cliOutput);
Assertions.assertEquals(expectedOutput, reportOutput);

cluster.getOzoneManager().restart();
}

/**
Expand Down Expand Up @@ -299,8 +229,6 @@ public void testDeleteOverwrite() throws Exception {

String cliOutput = out.toString(DEFAULT_ENCODING);
Assertions.assertTrue(cliOutput.contains("Unreferenced:\n\tDirectories: 1\n\tFiles: 3"));

cluster.getOzoneManager().restart();
}

@Test
Expand Down Expand Up @@ -340,12 +268,11 @@ public void testEmptyFileTrees() throws Exception {
String cliOutput2 = out.toString(DEFAULT_ENCODING);
String reportOutput2 = extractRelevantSection(cliOutput2);
Assertions.assertEquals(expectedOutput, reportOutput2);

cluster.getOzoneManager().restart();
}

@Test
public void testNonFSOBucketsSkipped() throws Exception {
OzoneClient client = OzoneClientFactory.getRpcClient(conf);
ObjectStore store = client.getObjectStore();

// Create legacy and OBS buckets.
Expand Down Expand Up @@ -392,7 +319,7 @@ public void testNonFSOBucketsSkipped() throws Exception {
Assertions.assertTrue(cliOutput.contains("Skipping non-FSO bucket /vol1/obs-bucket"));
Assertions.assertTrue(cliOutput.contains("Skipping non-FSO bucket /vol1/legacy-bucket"));

cluster.getOzoneManager().restart();
client.close();
}

private FSORepairTool.Report buildConnectedTree(String volume, String bucket) throws Exception {
Expand Down

0 comments on commit 99328b6

Please sign in to comment.