Skip to content

Commit 18d8ae1

Browse files
authored
HDDS-13917. Refactor Recon test helper class CommonUtils (#9287)
1 parent b255f11 commit 18d8ae1

9 files changed

Lines changed: 84 additions & 87 deletions

hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/common/CommonUtils.java renamed to hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/api/NSSummaryTests.java

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,34 @@
1515
* limitations under the License.
1616
*/
1717

18-
package org.apache.hadoop.ozone.recon.common;
18+
package org.apache.hadoop.ozone.recon.api;
1919

20+
import static java.util.Collections.singletonList;
2021
import static org.apache.hadoop.ozone.OzoneAcl.AclScope.ACCESS;
22+
import static org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLIdentityType.USER;
23+
import static org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLType.WRITE;
2124
import static org.junit.jupiter.api.Assertions.assertEquals;
2225
import static org.junit.jupiter.api.Assertions.assertNull;
2326

24-
import java.net.InetSocketAddress;
25-
import java.util.ArrayList;
26-
import java.util.Collections;
2727
import javax.ws.rs.core.Response;
2828
import org.apache.hadoop.hdds.protocol.StorageType;
2929
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
30-
import org.apache.hadoop.hdds.scm.ha.SCMNodeDetails;
3130
import org.apache.hadoop.ozone.OzoneAcl;
3231
import org.apache.hadoop.ozone.OzoneConsts;
3332
import org.apache.hadoop.ozone.om.helpers.BucketLayout;
3433
import org.apache.hadoop.ozone.om.helpers.OmPrefixInfo;
35-
import org.apache.hadoop.ozone.recon.api.NSSummaryEndpoint;
3634
import org.apache.hadoop.ozone.recon.api.types.BucketObjectDBInfo;
3735
import org.apache.hadoop.ozone.recon.api.types.EntityType;
3836
import org.apache.hadoop.ozone.recon.api.types.KeyObjectDBInfo;
3937
import org.apache.hadoop.ozone.recon.api.types.NamespaceSummaryResponse;
4038
import org.apache.hadoop.ozone.recon.api.types.ResponseStatus;
4139
import org.apache.hadoop.ozone.recon.api.types.VolumeObjectDBInfo;
4240
import org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager;
43-
import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer;
4441

4542
/**
46-
* This is a utility class for common code for test cases.
43+
* Shared NSSummary test cases.
4744
*/
48-
public class CommonUtils {
45+
public abstract class NSSummaryTests {
4946
private static final String ROOT_PATH = "/";
5047
private static final String VOL_PATH = "/vol";
5148
private static final String BUCKET_ONE_PATH = "/vol/bucket1";
@@ -54,32 +51,17 @@ public class CommonUtils {
5451
private static final String INVALID_PATH = "/vol/path/not/found";
5552
private static final String KEY_PATH = "/vol/bucket2/file4";
5653

57-
private OmPrefixInfo getOmPrefixInfoForTest(
58-
String path,
59-
IAccessAuthorizer.ACLIdentityType identityType,
60-
String identityString,
61-
IAccessAuthorizer.ACLType aclType,
62-
OzoneAcl.AclScope scope) {
63-
return OmPrefixInfo.newBuilder()
64-
.setName(path)
65-
.setAcls(new ArrayList<>(Collections.singletonList(OzoneAcl.of(
66-
identityType, identityString,
67-
scope, aclType))))
68-
.setObjectID(10)
69-
.setUpdateID(100)
70-
.build();
71-
}
72-
73-
public void testNSSummaryBasicInfoRoot(
54+
public static void testNSSummaryBasicInfoRoot(
7455
NSSummaryEndpoint nsSummaryEndpoint,
7556
ReconOMMetadataManager reconOMMetadataManager) throws Exception {
7657
String username = "myuser";
77-
OmPrefixInfo omPrefixInfo = getOmPrefixInfoForTest(ROOT_PATH,
78-
IAccessAuthorizer.ACLIdentityType.USER,
79-
username,
80-
IAccessAuthorizer.ACLType.WRITE,
81-
ACCESS);
82-
omPrefixInfo.getMetadata().put("key", "value");
58+
OmPrefixInfo omPrefixInfo = OmPrefixInfo.newBuilder()
59+
.setName(ROOT_PATH)
60+
.setObjectID(10)
61+
.setUpdateID(100)
62+
.setAcls(singletonList(OzoneAcl.of(USER, username, ACCESS, WRITE)))
63+
.addMetadata("key", "value")
64+
.build();
8365
reconOMMetadataManager.getPrefixTable()
8466
.put(OzoneConsts.OM_KEY_PREFIX, omPrefixInfo);
8567
// Test root basics
@@ -209,12 +191,4 @@ public void testNSSummaryBasicInfoKey(
209191
((KeyObjectDBInfo) keyResObj.getObjectDBInfo()).
210192
getReplicationConfig().getReplicationType());
211193
}
212-
213-
public SCMNodeDetails getReconNodeDetails() {
214-
SCMNodeDetails.Builder builder = new SCMNodeDetails.Builder();
215-
builder.setSCMNodeId("Recon");
216-
builder.setDatanodeProtocolServerAddress(
217-
InetSocketAddress.createUnresolved("127.0.0.1", 9888));
218-
return builder.build();
219-
}
220194
}

hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/api/TestEndpoints.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
import org.apache.hadoop.ozone.recon.api.types.RemoveDataNodesResponseWrapper;
122122
import org.apache.hadoop.ozone.recon.api.types.VolumeObjectDBInfo;
123123
import org.apache.hadoop.ozone.recon.api.types.VolumesResponse;
124-
import org.apache.hadoop.ozone.recon.common.CommonUtils;
124+
import org.apache.hadoop.ozone.recon.common.ReconTestUtils;
125125
import org.apache.hadoop.ozone.recon.persistence.AbstractReconSqlDBTest;
126126
import org.apache.hadoop.ozone.recon.persistence.ContainerHealthSchemaManager;
127127
import org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager;
@@ -196,7 +196,6 @@ public class TestEndpoints extends AbstractReconSqlDBTest {
196196
private ReconUtils reconUtilsMock;
197197
private StorageContainerLocationProtocol mockScmClient;
198198

199-
private CommonUtils commonUtils;
200199
private List<HddsProtos.Node> nodes = getNodeDetails(2);
201200
private Map<String, List<ContainerID>> containerOnDecom = getContainersOnDecomNodes();
202201
private ArrayList<String> metrics = getMetrics();
@@ -266,7 +265,7 @@ private void initializeInjector() throws Exception {
266265
anyString())).thenReturn(temporaryFolder.resolve("reconDbDir").toFile());
267266
when(reconUtilsMock.getReconNodeDetails(
268267
any(OzoneConfiguration.class))).thenReturn(
269-
commonUtils.getReconNodeDetails());
268+
ReconTestUtils.getReconNodeDetails());
270269
ReconTestInjector reconTestInjector =
271270
new ReconTestInjector.Builder(temporaryFolder.toFile())
272271
.withReconSqlDb()
@@ -333,7 +332,6 @@ private void initializeInjector() throws Exception {
333332
public void setUp() throws Exception {
334333
// The following setup runs only once
335334
if (!isSetupDone) {
336-
commonUtils = new CommonUtils();
337335
initializeInjector();
338336
isSetupDone = true;
339337
}

hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/api/TestNSSummaryEndpointWithFSO.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@
7676
import org.apache.hadoop.ozone.recon.api.types.NSSummary;
7777
import org.apache.hadoop.ozone.recon.api.types.QuotaUsageResponse;
7878
import org.apache.hadoop.ozone.recon.api.types.ResponseStatus;
79-
import org.apache.hadoop.ozone.recon.common.CommonUtils;
8079
import org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager;
8180
import org.apache.hadoop.ozone.recon.scm.ReconNodeManager;
8281
import org.apache.hadoop.ozone.recon.scm.ReconStorageContainerManagerFacade;
@@ -124,14 +123,13 @@
124123
* This is a test for the Rest APIs only. We have tested NSSummaryTask before,
125124
* so there is no need to test process() on DB's updates
126125
*/
127-
public class TestNSSummaryEndpointWithFSO {
126+
public class TestNSSummaryEndpointWithFSO extends NSSummaryTests {
128127
@TempDir
129128
private Path temporaryFolder;
130129

131130
private ReconOMMetadataManager reconOMMetadataManager;
132131
private ReconNamespaceSummaryManager reconNamespaceSummaryManager;
133132
private NSSummaryEndpoint nsSummaryEndpoint;
134-
private CommonUtils commonUtils;
135133

136134
private static final String TEST_PATH_UTILITY =
137135
"/vol1/buck1/a/b/c/d/e/file1.txt";
@@ -436,7 +434,6 @@ public void setUp() throws Exception {
436434
new NSSummaryTaskWithFSO(reconNamespaceSummaryManager,
437435
reconOMMetadataManager, 10);
438436
nSSummaryTaskWithFso.reprocessWithFSO(reconOMMetadataManager);
439-
commonUtils = new CommonUtils();
440437
}
441438

442439
@Test
@@ -452,48 +449,48 @@ public void testUtility() {
452449
@Test
453450
public void testGetBasicInfoRoot() throws Exception {
454451
// Test root basics
455-
commonUtils.testNSSummaryBasicInfoRoot(
452+
testNSSummaryBasicInfoRoot(
456453
nsSummaryEndpoint, reconOMMetadataManager);
457454
}
458455

459456
@Test
460457
public void testGetBasicInfoVol() throws Exception {
461458
// Test volume basics
462-
commonUtils.testNSSummaryBasicInfoVolume(nsSummaryEndpoint);
459+
testNSSummaryBasicInfoVolume(nsSummaryEndpoint);
463460
}
464461

465462
@Test
466463
public void testGetBasicInfoBucketOne() throws Exception {
467464
// Test bucket 1's basics
468-
commonUtils.testNSSummaryBasicInfoBucketOne(
465+
testNSSummaryBasicInfoBucketOne(
469466
BucketLayout.FILE_SYSTEM_OPTIMIZED,
470467
nsSummaryEndpoint);
471468
}
472469

473470
@Test
474471
public void testGetBasicInfoBucketTwo() throws Exception {
475472
// Test bucket 2's basics
476-
commonUtils.testNSSummaryBasicInfoBucketTwo(
473+
testNSSummaryBasicInfoBucketTwo(
477474
BucketLayout.FILE_SYSTEM_OPTIMIZED,
478475
nsSummaryEndpoint);
479476
}
480477

481478
@Test
482479
public void testGetBasicInfoDir() throws Exception {
483480
// Test intermediate directory basics
484-
commonUtils.testNSSummaryBasicInfoDir(nsSummaryEndpoint);
481+
testNSSummaryBasicInfoDir(nsSummaryEndpoint);
485482
}
486483

487484
@Test
488485
public void testGetBasicInfoNoPath() throws Exception {
489486
// Test invalid path
490-
commonUtils.testNSSummaryBasicInfoNoPath(nsSummaryEndpoint);
487+
testNSSummaryBasicInfoNoPath(nsSummaryEndpoint);
491488
}
492489

493490
@Test
494491
public void testGetBasicInfoKey() throws Exception {
495492
// Test key
496-
commonUtils.testNSSummaryBasicInfoKey(nsSummaryEndpoint);
493+
testNSSummaryBasicInfoKey(nsSummaryEndpoint);
497494
}
498495

499496
@Test

hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/api/TestNSSummaryEndpointWithLegacy.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@
7777
import org.apache.hadoop.ozone.recon.api.types.FileSizeDistributionResponse;
7878
import org.apache.hadoop.ozone.recon.api.types.QuotaUsageResponse;
7979
import org.apache.hadoop.ozone.recon.api.types.ResponseStatus;
80-
import org.apache.hadoop.ozone.recon.common.CommonUtils;
8180
import org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager;
8281
import org.apache.hadoop.ozone.recon.scm.ReconNodeManager;
8382
import org.apache.hadoop.ozone.recon.scm.ReconStorageContainerManagerFacade;
@@ -125,14 +124,13 @@
125124
* This is a test for the Rest APIs only. We have tested NSSummaryTask before,
126125
* so there is no need to test process() on DB's updates
127126
*/
128-
public class TestNSSummaryEndpointWithLegacy {
127+
public class TestNSSummaryEndpointWithLegacy extends NSSummaryTests {
129128
@TempDir
130129
private Path temporaryFolder;
131130

132131
private ReconNamespaceSummaryManager reconNamespaceSummaryManager;
133132
private ReconOMMetadataManager reconOMMetadataManager;
134133
private NSSummaryEndpoint nsSummaryEndpoint;
135-
private CommonUtils commonUtils;
136134

137135
private static final String TEST_PATH_UTILITY =
138136
"/vol1/buck1/a/b/c/d/e/file1.txt";
@@ -437,7 +435,6 @@ public void setUp() throws Exception {
437435
new NSSummaryTaskWithLegacy(reconNamespaceSummaryManager,
438436
reconOMMetadataManager, conf, 10);
439437
nsSummaryTaskWithLegacy.reprocessWithLegacy(reconOMMetadataManager);
440-
commonUtils = new CommonUtils();
441438
}
442439

443440
@Test
@@ -452,48 +449,48 @@ public void testUtility() {
452449

453450
@Test
454451
public void testGetBasicInfoRoot() throws Exception {
455-
commonUtils.testNSSummaryBasicInfoRoot(
452+
testNSSummaryBasicInfoRoot(
456453
nsSummaryEndpoint, reconOMMetadataManager);
457454
}
458455

459456
@Test
460457
public void testGetBasicInfoVol() throws Exception {
461458
// Test volume basics
462-
commonUtils.testNSSummaryBasicInfoVolume(nsSummaryEndpoint);
459+
testNSSummaryBasicInfoVolume(nsSummaryEndpoint);
463460
}
464461

465462
@Test
466463
public void testGetBasicInfoBucketOne() throws Exception {
467464
// Test bucket 1's basics
468-
commonUtils.testNSSummaryBasicInfoBucketOne(
465+
testNSSummaryBasicInfoBucketOne(
469466
BucketLayout.LEGACY,
470467
nsSummaryEndpoint);
471468
}
472469

473470
@Test
474471
public void testGetBasicInfoBucketTwo() throws Exception {
475472
// Test bucket 2's basics
476-
commonUtils.testNSSummaryBasicInfoBucketTwo(
473+
testNSSummaryBasicInfoBucketTwo(
477474
BucketLayout.LEGACY,
478475
nsSummaryEndpoint);
479476
}
480477

481478
@Test
482479
public void testGetBasicInfoDir() throws Exception {
483480
// Test intermediate directory basics
484-
commonUtils.testNSSummaryBasicInfoDir(nsSummaryEndpoint);
481+
testNSSummaryBasicInfoDir(nsSummaryEndpoint);
485482
}
486483

487484
@Test
488485
public void testGetBasicInfoNoPath() throws Exception {
489486
// Test invalid path
490-
commonUtils.testNSSummaryBasicInfoNoPath(nsSummaryEndpoint);
487+
testNSSummaryBasicInfoNoPath(nsSummaryEndpoint);
491488
}
492489

493490
@Test
494491
public void testGetBasicInfoKey() throws Exception {
495492
// Test key
496-
commonUtils.testNSSummaryBasicInfoKey(nsSummaryEndpoint);
493+
testNSSummaryBasicInfoKey(nsSummaryEndpoint);
497494
}
498495

499496
@Test

hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/api/TestNSSummaryEndpointWithOBSAndLegacy.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@
7676
import org.apache.hadoop.ozone.recon.api.types.QuotaUsageResponse;
7777
import org.apache.hadoop.ozone.recon.api.types.ResponseStatus;
7878
import org.apache.hadoop.ozone.recon.api.types.VolumeObjectDBInfo;
79-
import org.apache.hadoop.ozone.recon.common.CommonUtils;
8079
import org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager;
8180
import org.apache.hadoop.ozone.recon.scm.ReconNodeManager;
8281
import org.apache.hadoop.ozone.recon.scm.ReconStorageContainerManagerFacade;
@@ -122,14 +121,13 @@
122121
* └── bucket4 (Legacy)
123122
* └── KEY_ELEVEN
124123
*/
125-
public class TestNSSummaryEndpointWithOBSAndLegacy {
124+
public class TestNSSummaryEndpointWithOBSAndLegacy extends NSSummaryTests {
126125
@TempDir
127126
private Path temporaryFolder;
128127

129128
private ReconOMMetadataManager reconOMMetadataManager;
130129
private ReconNamespaceSummaryManager reconNamespaceSummaryManager;
131130
private NSSummaryEndpoint nsSummaryEndpoint;
132-
private CommonUtils commonUtils;
133131

134132
private static final String TEST_PATH_UTILITY =
135133
"/vol1/buck1/a/b/c/d/e/file1.txt";
@@ -377,7 +375,6 @@ public void setUp() throws Exception {
377375
new NSSummaryTaskWithLegacy(reconNamespaceSummaryManager,
378376
reconOMMetadataManager, conf, 10);
379377
nsSummaryTaskWithLegacy.reprocessWithLegacy(reconOMMetadataManager);
380-
commonUtils = new CommonUtils();
381378
}
382379

383380
@Test
@@ -528,13 +525,13 @@ public void testGetBasicInfoBucketFour() throws Exception {
528525
@Test
529526
public void testGetBasicInfoNoPath() throws Exception {
530527
// Test invalid path
531-
commonUtils.testNSSummaryBasicInfoNoPath(nsSummaryEndpoint);
528+
testNSSummaryBasicInfoNoPath(nsSummaryEndpoint);
532529
}
533530

534531
@Test
535532
public void testGetBasicInfoKey() throws Exception {
536533
// Test key
537-
commonUtils.testNSSummaryBasicInfoKey(nsSummaryEndpoint);
534+
testNSSummaryBasicInfoKey(nsSummaryEndpoint);
538535
}
539536

540537
@Test

hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/api/TestOpenContainerCount.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
import org.apache.hadoop.ozone.recon.ReconUtils;
7272
import org.apache.hadoop.ozone.recon.api.types.DatanodeMetadata;
7373
import org.apache.hadoop.ozone.recon.api.types.DatanodesResponse;
74-
import org.apache.hadoop.ozone.recon.common.CommonUtils;
74+
import org.apache.hadoop.ozone.recon.common.ReconTestUtils;
7575
import org.apache.hadoop.ozone.recon.persistence.ContainerHealthSchemaManager;
7676
import org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager;
7777
import org.apache.hadoop.ozone.recon.scm.ReconPipelineManager;
@@ -112,7 +112,6 @@ public class TestOpenContainerCount {
112112
private List<Long> containerIDs;
113113

114114
private List<ContainerWithPipeline> cpw;
115-
private CommonUtils commonUtils;
116115

117116
private void initializeInjector() throws Exception {
118117
ReconOMMetadataManager reconOMMetadataManager = getTestReconOmMetadataManager(
@@ -156,7 +155,6 @@ private void initializeInjector() throws Exception {
156155
.thenReturn(containerWithPipeline);
157156
containerIDs.add(i);
158157
cpw.add(containerWithPipeline);
159-
commonUtils = new CommonUtils();
160158
}
161159

162160
// Open 5 containers on pipeline 2
@@ -192,7 +190,7 @@ private void initializeInjector() throws Exception {
192190
anyString())).thenReturn(temporaryFolder.resolve("reconDbDir").toFile());
193191
when(reconUtilsMock.getReconNodeDetails(
194192
any(OzoneConfiguration.class))).thenReturn(
195-
commonUtils.getReconNodeDetails());
193+
ReconTestUtils.getReconNodeDetails());
196194

197195
ReconTestInjector reconTestInjector =
198196
new ReconTestInjector.Builder(temporaryFolder.toFile())

0 commit comments

Comments
 (0)