From 4dc415002d7088553846237fb90d0aeb257619b2 Mon Sep 17 00:00:00 2001 From: guophilipse Date: Sun, 24 Apr 2022 23:54:52 +0800 Subject: [PATCH] addtestcase --- .../namenode/OfflineEditsViewerHelper.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/OfflineEditsViewerHelper.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/OfflineEditsViewerHelper.java index e7f51ce2e94..124af239ac0 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/OfflineEditsViewerHelper.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/OfflineEditsViewerHelper.java @@ -22,6 +22,10 @@ import java.io.File; import java.io.IOException; import java.util.Iterator; +import org.apache.hadoop.fs.FSDataOutputStream; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hdfs.AppendTestUtil; +import org.apache.hadoop.hdfs.protocol.Block; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.hadoop.classification.InterfaceAudience; @@ -132,6 +136,23 @@ public class OfflineEditsViewerHelper { DFSTestUtil.runOperations(cluster, dfs, cluster.getConfiguration(0), dfs.getDefaultBlockSize(), 0); + String client = "client"; + String clientMachine = "clientMachine"; + String src = "/test/testTruncate"; + Path srcPath = new Path(src); + byte[] contents = AppendTestUtil.initBuffer(512); + FSDataOutputStream out = dfs.create(srcPath, true, 4, (short)3, + dfs.getDefaultBlockSize()); + out.write(contents, 0, 511); + out.close(); + + INodesInPath iip = cluster.getNamesystem().getFSDirectory().getINodesInPath(src, FSDirectory.DirOp.WRITE); + cluster.getNamesystem().writeLock(); + Block truncateBlock = FSDirTruncateOp.prepareFileForTruncate(cluster.getNamesystem(), iip, + client, clientMachine, 1, null); + cluster.getNamesystem().getEditLog().logTruncate(src, client, clientMachine, truncateBlock.getNumBytes()-1, Time.now(), truncateBlock); + cluster.getNamesystem().writeUnlock(); + // OP_ROLLING_UPGRADE_START cluster.getNamesystem().getEditLog().logStartRollingUpgrade(Time.now()); // OP_ROLLING_UPGRADE_FINALIZE