HDFS-17539. Make TestFileChecksum fields static (#6853)

This commit is contained in:
Felix Nguyen 2024-06-11 15:26:21 +08:00 committed by GitHub
parent 2e1deee87a
commit 776c0a3ab9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -30,9 +30,7 @@
import org.apache.hadoop.hdfs.server.datanode.DataNode; import org.apache.hadoop.hdfs.server.datanode.DataNode;
import org.apache.hadoop.hdfs.server.datanode.DataNodeFaultInjector; import org.apache.hadoop.hdfs.server.datanode.DataNodeFaultInjector;
import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.test.GenericTestUtils;
import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
@ -60,34 +58,34 @@
public class TestFileChecksum { public class TestFileChecksum {
private static final Logger LOG = LoggerFactory private static final Logger LOG = LoggerFactory
.getLogger(TestFileChecksum.class); .getLogger(TestFileChecksum.class);
private final ErasureCodingPolicy ecPolicy = private static final ErasureCodingPolicy ecPolicy =
StripedFileTestUtil.getDefaultECPolicy(); StripedFileTestUtil.getDefaultECPolicy();
private int dataBlocks = ecPolicy.getNumDataUnits(); private static final int dataBlocks = ecPolicy.getNumDataUnits();
private int parityBlocks = ecPolicy.getNumParityUnits(); private static final int parityBlocks = ecPolicy.getNumParityUnits();
private MiniDFSCluster cluster; private static MiniDFSCluster cluster;
private DistributedFileSystem fs; private static DistributedFileSystem fs;
private Configuration conf; private static Configuration conf;
private DFSClient client; private static DFSClient client;
private int cellSize = ecPolicy.getCellSize(); private static final int cellSize = ecPolicy.getCellSize();
private int stripesPerBlock = 6; private static final int stripesPerBlock = 6;
private int blockSize = cellSize * stripesPerBlock; private static final int blockSize = cellSize * stripesPerBlock;
private int numBlockGroups = 10; private static final int numBlockGroups = 10;
private int stripSize = cellSize * dataBlocks; private static final int stripSize = cellSize * dataBlocks;
private int blockGroupSize = stripesPerBlock * stripSize; private static final int blockGroupSize = stripesPerBlock * stripSize;
private int fileSize = numBlockGroups * blockGroupSize; private static final int fileSize = numBlockGroups * blockGroupSize;
private int bytesPerCRC; private static int bytesPerCRC;
private String ecDir = "/striped"; private static final String ecDir = "/striped";
private String stripedFile1 = ecDir + "/stripedFileChecksum1"; private static final String stripedFile1 = ecDir + "/stripedFileChecksum1";
private String stripedFile2 = ecDir + "/stripedFileChecksum2"; private static final String stripedFile2 = ecDir + "/stripedFileChecksum2";
private String replicatedFile = "/replicatedFileChecksum"; private static final String replicatedFile = "/replicatedFileChecksum";
private String checksumCombineMode; private static String checksumCombineMode;
public TestFileChecksum(String checksumCombineMode) { public TestFileChecksum(String mode) {
this.checksumCombineMode = checksumCombineMode; checksumCombineMode = mode;
} }
@Parameterized.Parameters @Parameterized.Parameters
@ -100,8 +98,9 @@ public static Object[] getParameters() {
@Rule @Rule
public ExpectedException exception = ExpectedException.none(); public ExpectedException exception = ExpectedException.none();
@Before @Parameterized.BeforeParam
public void setup() throws IOException { public static void setup(String mode) throws IOException {
checksumCombineMode = mode;
int numDNs = dataBlocks + parityBlocks + 2; int numDNs = dataBlocks + parityBlocks + 2;
conf = new Configuration(); conf = new Configuration();
conf.setLong(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, blockSize); conf.setLong(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, blockSize);
@ -124,8 +123,8 @@ public void setup() throws IOException {
GenericTestUtils.setLogLevel(FileChecksumHelper.LOG, Level.DEBUG); GenericTestUtils.setLogLevel(FileChecksumHelper.LOG, Level.DEBUG);
} }
@After @Parameterized.AfterParam
public void tearDown() { public static void tearDown() {
if (cluster != null) { if (cluster != null) {
cluster.shutdown(); cluster.shutdown();
cluster = null; cluster = null;