Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dev-support/pmd/pmd-ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<rule ref="category/java/bestpractices.xml/UnusedPrivateMethod"/>
<rule ref="category/java/bestpractices.xml/UnusedPrivateField"/>
<rule ref="category/java/bestpractices.xml/UseCollectionIsEmpty" />
<rule ref="category/java/bestpractices.xml/SimplifiableTestAssertion" />
Comment on lines 32 to +34
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep these ordered when adding the next rule.


<rule ref="category/java/performance.xml/AvoidFileStream"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLIdentityType.GROUP;
import static org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLIdentityType.USER;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand Down Expand Up @@ -54,7 +55,7 @@ public class TestOzoneAclUtil {
@Test
public void testAddAcl() throws IOException {
List<OzoneAcl> currentAcls = getDefaultAcls();
assertTrue(!currentAcls.isEmpty());
assertFalse(currentAcls.isEmpty());

// Add new permission to existing acl entry.
OzoneAcl oldAcl = currentAcls.get(0);
Expand Down Expand Up @@ -86,7 +87,7 @@ public void testRemoveAcl() {
removeAndVerifyAcl(currentAcls, USER1, false, 0);

currentAcls = getDefaultAcls();
assertTrue(!currentAcls.isEmpty());
assertFalse(currentAcls.isEmpty());

// Add new permission to existing acl entru.
OzoneAcl oldAcl = currentAcls.get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.hadoop.ozone.security;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand All @@ -38,7 +39,7 @@ public void testKeyGenerationWithDefaults() throws Exception {
.equalsIgnoreCase(OzoneConsts.GDPR_ALGORITHM_NAME));

gkey.acceptKeyDetails(
(k, v) -> assertTrue(!v.isEmpty()));
(k, v) -> assertFalse(v.isEmpty()));
}

@Test
Expand All @@ -51,7 +52,7 @@ public void testKeyGenerationWithValidInput() throws Exception {
.equalsIgnoreCase(OzoneConsts.GDPR_ALGORITHM_NAME));

gkey.acceptKeyDetails(
(k, v) -> assertTrue(!v.isEmpty()));
(k, v) -> assertFalse(v.isEmpty()));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ public void testDeleteWithMultiLevelsBlockDoubleBuffer() throws Exception {
assertTableRowCount(deletedDirTable, 0);
assertTableRowCount(keyTable, 0);
assertTrue(volume.getBucket(bucketName).getUsedNamespace() >= 0);
assertTrue(volume.getBucket(bucketName).getUsedBytes() == 0);
assertEquals(0, volume.getBucket(bucketName).getUsedBytes());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1340,13 +1340,13 @@ public void testNormalKeyOverwriteHSyncKey() throws Exception {

// hsync call for overwritten hsync key, should fail
OMException omException = assertThrows(OMException.class, () -> outputStream1.hsync());
assertTrue(omException.getResult() == OMException.ResultCodes.KEY_NOT_FOUND);
assertEquals(OMException.ResultCodes.KEY_NOT_FOUND, omException.getResult());
assertTrue(omException.getMessage().contains("already deleted/overwritten"));

// allocate new block for overwritten hsync key, should fail
IOException ioException = assertThrows(IOException.class, () -> outputStream1.write(newData));
assertTrue(ioException.getCause() instanceof OMException);
assertTrue(((OMException)ioException.getCause()).getResult() == OMException.ResultCodes.KEY_NOT_FOUND);
assertEquals(OMException.ResultCodes.KEY_NOT_FOUND, ((OMException)ioException.getCause()).getResult());
assertTrue(ioException.getMessage().contains("already deleted/overwritten"));

// recover key will success since key is already committed by outputStream2
Expand Down Expand Up @@ -1508,7 +1508,7 @@ public void testHSyncKeyOverwriteHSyncKey() throws Exception {

// close first hsync key should fail
OMException omException = assertThrows(OMException.class, () -> outputStream1.close());
assertTrue(omException.getResult() == OMException.ResultCodes.KEY_NOT_FOUND);
assertEquals(OMException.ResultCodes.KEY_NOT_FOUND, omException.getResult());
assertTrue(omException.getMessage().contains("already deleted/overwritten"));

// hsync/close second hsync key should success
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -953,9 +953,9 @@ public void testAclDeDuplication()
assertEquals(3, bucketAcls.size());
assertTrue(bucketAcls.contains(currentUserAcl));
assertTrue(bucketAcls.contains(currentUserPrimaryGroupAcl));
assertTrue(bucketAcls.get(2).getName().equals(userAcl1.getName()));
assertTrue(bucketAcls.get(2).getAclList().equals(userAcl1.getAclList()));
assertTrue(bucketAcls.get(2).getAclScope().equals(ACCESS));
assertEquals(userAcl1.getName(), bucketAcls.get(2).getName());
assertEquals(userAcl1.getAclList(), bucketAcls.get(2).getAclList());
assertEquals(ACCESS, bucketAcls.get(2).getAclScope());

// link bucket
OzoneAcl userAcl2 = new OzoneAcl(USER, "test-link", DEFAULT, READ);
Expand All @@ -971,9 +971,9 @@ public void testAclDeDuplication()
assertTrue(linkBucketAcls.contains(currentUserPrimaryGroupAcl));
assertTrue(linkBucketAcls.contains(userAcl2));
assertTrue(linkBucketAcls.contains(OzoneAcl.LINK_BUCKET_DEFAULT_ACL));
assertTrue(linkBucketAcls.get(4).getName().equals(userAcl1.getName()));
assertTrue(linkBucketAcls.get(4).getAclList().equals(userAcl1.getAclList()));
assertTrue(linkBucketAcls.get(4).getAclScope().equals(ACCESS));
assertEquals(userAcl1.getName(), linkBucketAcls.get(4).getName());
assertEquals(userAcl1.getAclList(), linkBucketAcls.get(4).getAclList());
assertEquals(ACCESS, linkBucketAcls.get(4).getAclScope());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ public void testDeleteNonEmptyContainerOnDirEmptyCheckTrue()
contains("Files still part of the container on delete"),
500,
5 * 2000);
assertTrue(!isContainerDeleted(hddsDatanodeService, containerId.getId()));

assertFalse(isContainerDeleted(hddsDatanodeService, containerId.getId()));
assertThat(beforeDeleteFailedCount).isLessThan(metrics.getContainerDeleteFailedNonEmpty());
// Send the delete command. It should pass with force flag.
// Deleting a non-empty container should pass on the DN when the force flag
Expand Down Expand Up @@ -439,8 +440,8 @@ public void testDeleteNonEmptyContainerBlockTable()
contains("the container is not empty with blockCount"),
500,
5 * 2000);
assertTrue(!isContainerDeleted(hddsDatanodeService,
containerId.getId()));

assertFalse(isContainerDeleted(hddsDatanodeService, containerId.getId()));
assertThat(containerDeleteFailedNonEmptyBlockDB)
.isLessThan(metrics.getContainerDeleteFailedNonEmpty());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_HEARTBEAT_PROCESS_INTERVAL;
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_STALENODE_INTERVAL;
import static org.apache.hadoop.ozone.container.common.statemachine.DatanodeConfiguration.CONTAINER_SCHEMA_V3_ENABLED;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

Expand Down Expand Up @@ -173,15 +174,11 @@ public void testFinalizeBlock(boolean enableSchemaV3) throws Exception {
ContainerProtos.ContainerCommandResponseProto response =
xceiverClient.sendCommand(request);

assertTrue(response.getFinalizeBlock()
.getBlockData().getBlockID().getLocalID()
== omKeyLocationInfoGroupList.get(0)
.getLocationList().get(0).getLocalID());
assertEquals(response.getFinalizeBlock().getBlockData().getBlockID().getLocalID(),
omKeyLocationInfoGroupList.get(0).getLocationList().get(0).getLocalID());

assertTrue(((KeyValueContainerData)getContainerfromDN(
cluster.getHddsDatanodes().get(0),
containerId.getId()).getContainerData())
.getFinalizedBlockSet().size() == 1);
assertEquals(1, ((KeyValueContainerData)getContainerfromDN(cluster.getHddsDatanodes().get(0),
containerId.getId()).getContainerData()).getFinalizedBlockSet().size());

testRejectPutAndWriteChunkAfterFinalizeBlock(containerId, pipeline, xceiverClient, omKeyLocationInfoGroupList);
testFinalizeBlockReloadAfterDNRestart(containerId);
Expand All @@ -196,10 +193,8 @@ private void testFinalizeBlockReloadAfterDNRestart(ContainerID containerId) {
}

// After restart DN, finalizeBlock should be loaded into memory
assertTrue(((KeyValueContainerData)
getContainerfromDN(cluster.getHddsDatanodes().get(0),
containerId.getId()).getContainerData())
.getFinalizedBlockSet().size() == 1);
assertEquals(1, ((KeyValueContainerData)getContainerfromDN(cluster.getHddsDatanodes().get(0),
containerId.getId()).getContainerData()).getFinalizedBlockSet().size());
}

private void testFinalizeBlockClearAfterCloseContainer(ContainerID containerId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ void testLinkBucketRemoveBucketAcl() throws Exception {
OzoneObj srcObj = buildBucketObj(srcBucket);
// As by default create will add some default acls in RpcClient.
List<OzoneAcl> acls = getObjectStore().getAcl(linkObj);
assertTrue(!acls.isEmpty());
assertFalse(acls.isEmpty());
// Remove an existing acl.
boolean removeAcl = getObjectStore().removeAcl(linkObj, acls.get(0));
assertTrue(removeAcl);
Expand All @@ -759,7 +759,7 @@ void testLinkBucketRemoveBucketAcl() throws Exception {
OzoneObj srcObj2 = buildBucketObj(srcBucket2);
// As by default create will add some default acls in RpcClient.
List<OzoneAcl> acls2 = getObjectStore().getAcl(srcObj2);
assertTrue(!acls2.isEmpty());
assertFalse(acls2.isEmpty());
// Remove an existing acl.
boolean removeAcl2 = getObjectStore().removeAcl(srcObj2, acls.get(0));
assertTrue(removeAcl2);
Expand Down Expand Up @@ -994,7 +994,7 @@ private void testSetAcl(String remoteUserName, OzoneObj ozoneObj,
OzoneObj.ResourceType.PREFIX.name())) {
List<OzoneAcl> acls = objectStore.getAcl(ozoneObj);

assertTrue(!acls.isEmpty());
assertFalse(acls.isEmpty());
}

OzoneAcl modifiedUserAcl = new OzoneAcl(USER, remoteUserName,
Expand Down Expand Up @@ -1051,7 +1051,7 @@ private void testRemoveAcl(String remoteUserName, OzoneObj ozoneObj,
}
acls = objectStore.getAcl(ozoneObj);

assertTrue(!acls.isEmpty());
assertFalse(acls.isEmpty());

// Remove an existing acl.
boolean removeAcl = objectStore.removeAcl(ozoneObj, acls.get(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.VOLUME_NOT_FOUND;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand Down Expand Up @@ -613,7 +614,7 @@ public void testListOpenFiles(BucketLayout bucketLayout) throws Exception {
bucketLayout, 100, dbPrefix, false, dbPrefix);

assertEquals(numOpenKeys, res.getTotalOpenKeyCount());
assertEquals(false, res.hasMore());
assertFalse(res.hasMore());
List<OpenKeySession> keySessionList = res.getOpenKeys();
assertEquals(numOpenKeys, keySessionList.size());
// Verify that every single open key shows up in the result, and in order
Expand All @@ -632,7 +633,7 @@ public void testListOpenFiles(BucketLayout bucketLayout) throws Exception {
// total open key count should still be 3
assertEquals(numOpenKeys, res.getTotalOpenKeyCount());
// hasMore should have been set
assertEquals(true, res.hasMore());
assertTrue(res.hasMore());
keySessionList = res.getOpenKeys();
assertEquals(numExpectedKeys, keySessionList.size());
for (int i = 0; i < numExpectedKeys; i++) {
Expand All @@ -648,7 +649,7 @@ public void testListOpenFiles(BucketLayout bucketLayout) throws Exception {
numExpectedKeys = numOpenKeys - pageSize;
// total open key count should still be 3
assertEquals(numOpenKeys, res.getTotalOpenKeyCount());
assertEquals(false, res.hasMore());
assertFalse(res.hasMore());
keySessionList = res.getOpenKeys();
assertEquals(numExpectedKeys, keySessionList.size());
for (int i = 0; i < numExpectedKeys; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.apache.hadoop.ozone.recon.ReconConstants.CONTAINER_COUNT;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.anyInt;
Expand Down Expand Up @@ -168,8 +169,8 @@ public void testNegativeSizeRecordNotInsertedButLogged() {
status, (long) 123456, unhealthyContainerStateStatsMap);

// Assert that none of the records are for negative.
records.forEach(record -> assertFalse(record.getContainerState()
.equals(UnHealthyContainerStates.NEGATIVE_SIZE.toString())));
records.forEach(record -> assertNotEquals(
UnHealthyContainerStates.NEGATIVE_SIZE.toString(), record.getContainerState()));


// Assert that the NEGATIVE_SIZE state is logged
Expand Down