Skip to content

Commit 4dc4150

Browse files
committed
addtestcase
1 parent 3276544 commit 4dc4150

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/OfflineEditsViewerHelper.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
import java.io.IOException;
2323
import java.util.Iterator;
2424

25+
import org.apache.hadoop.fs.FSDataOutputStream;
26+
import org.apache.hadoop.fs.Path;
27+
import org.apache.hadoop.hdfs.AppendTestUtil;
28+
import org.apache.hadoop.hdfs.protocol.Block;
2529
import org.slf4j.Logger;
2630
import org.slf4j.LoggerFactory;
2731
import org.apache.hadoop.classification.InterfaceAudience;
@@ -132,6 +136,23 @@ private CheckpointSignature runOperations() throws IOException {
132136
DFSTestUtil.runOperations(cluster, dfs, cluster.getConfiguration(0),
133137
dfs.getDefaultBlockSize(), 0);
134138

139+
String client = "client";
140+
String clientMachine = "clientMachine";
141+
String src = "/test/testTruncate";
142+
Path srcPath = new Path(src);
143+
byte[] contents = AppendTestUtil.initBuffer(512);
144+
FSDataOutputStream out = dfs.create(srcPath, true, 4, (short)3,
145+
dfs.getDefaultBlockSize());
146+
out.write(contents, 0, 511);
147+
out.close();
148+
149+
INodesInPath iip = cluster.getNamesystem().getFSDirectory().getINodesInPath(src, FSDirectory.DirOp.WRITE);
150+
cluster.getNamesystem().writeLock();
151+
Block truncateBlock = FSDirTruncateOp.prepareFileForTruncate(cluster.getNamesystem(), iip,
152+
client, clientMachine, 1, null);
153+
cluster.getNamesystem().getEditLog().logTruncate(src, client, clientMachine, truncateBlock.getNumBytes()-1, Time.now(), truncateBlock);
154+
cluster.getNamesystem().writeUnlock();
155+
135156
// OP_ROLLING_UPGRADE_START
136157
cluster.getNamesystem().getEditLog().logStartRollingUpgrade(Time.now());
137158
// OP_ROLLING_UPGRADE_FINALIZE

0 commit comments

Comments
 (0)