Skip to content

Commit e2581db

Browse files
committed
refactor unit test.
1 parent 51960ab commit e2581db

File tree

2 files changed

+25
-122
lines changed

2 files changed

+25
-122
lines changed

hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterMountTable.java

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public class TestRouterMountTable {
8686
public static void globalSetUp() throws Exception {
8787
startTime = Time.now();
8888

89-
// Build and start a federated cluster
89+
// Build and start a federated cluster.
9090
cluster = new StateStoreDFSCluster(false, 2);
9191
Configuration conf = new RouterConfigBuilder()
9292
.stateStore()
@@ -99,7 +99,7 @@ public static void globalSetUp() throws Exception {
9999
cluster.startRouters();
100100
cluster.waitClusterUp();
101101

102-
// Get the end points
102+
// Get the end points.
103103
nnContext0 = cluster.getNamenode("ns0", null);
104104
nnContext1 = cluster.getNamenode("ns1", null);
105105
nnFs0 = nnContext0.getFileSystem();
@@ -139,18 +139,18 @@ public void clearMountTable() throws IOException {
139139
@Test
140140
public void testReadOnly() throws Exception {
141141

142-
// Add a read only entry
142+
// Add a read only entry.
143143
MountTable readOnlyEntry = MountTable.newInstance(
144144
"/readonly", Collections.singletonMap("ns0", "/testdir"));
145145
readOnlyEntry.setReadOnly(true);
146146
assertTrue(addMountTable(readOnlyEntry));
147147

148-
// Add a regular entry
148+
// Add a regular entry.
149149
MountTable regularEntry = MountTable.newInstance(
150150
"/regular", Collections.singletonMap("ns0", "/testdir"));
151151
assertTrue(addMountTable(regularEntry));
152152

153-
// Create a folder which should show in all locations
153+
// Create a folder which should show in all locations.
154154
assertTrue(routerFs.mkdirs(new Path("/regular/newdir")));
155155

156156
FileStatus dirStatusNn =
@@ -163,7 +163,7 @@ public void testReadOnly() throws Exception {
163163
routerFs.getFileStatus(new Path("/readonly/newdir"));
164164
assertTrue(dirStatusReadOnly.isDirectory());
165165

166-
// It should fail writing into a read only path
166+
// It should fail writing into a read only path.
167167
try {
168168
routerFs.mkdirs(new Path("/readonly/newdirfail"));
169169
fail("We should not be able to write into a read only mount point");
@@ -188,7 +188,7 @@ private boolean addMountTable(final MountTable entry) throws IOException {
188188
AddMountTableEntryResponse addResponse =
189189
mountTableManager.addMountTableEntry(addRequest);
190190

191-
// Reload the Router cache
191+
// Reload the Router cache.
192192
mountTable.loadCache(true);
193193

194194
return addResponse.getStatus();
@@ -208,7 +208,7 @@ private boolean updateMountTable(final MountTable entry) throws IOException {
208208
UpdateMountTableEntryResponse updateResponse =
209209
mountTableManager.updateMountTableEntry(updateRequest);
210210

211-
// Reload the Router cache
211+
// Reload the Router cache.
212212
mountTable.loadCache(true);
213213

214214
return updateResponse.getStatus();
@@ -220,7 +220,7 @@ private boolean updateMountTable(final MountTable entry) throws IOException {
220220
*/
221221
@Test
222222
public void testMountPointLimit() throws Exception {
223-
// Add mount table entry
223+
// Add mount table entry.
224224
MountTable addEntry = MountTable.newInstance("/testdir-shortlength",
225225
Collections.singletonMap("ns0", "/testdir-shortlength"));
226226
assertTrue(addMountTable(addEntry));
@@ -249,7 +249,7 @@ public void testMountPointLimit() throws Exception {
249249
@Test
250250
public void testListFilesTime() throws Exception {
251251
try {
252-
// Add mount table entry
252+
// Add mount table entry.
253253
MountTable addEntry = MountTable.newInstance("/testdir",
254254
Collections.singletonMap("ns0", "/testdir"));
255255
assertTrue(addMountTable(addEntry));
@@ -266,7 +266,7 @@ public void testListFilesTime() throws Exception {
266266
Collections.singletonMap("ns0", "/test"));
267267
assertTrue(addMountTable(addEntry));
268268

269-
// Create test dir in NN
269+
// Create test dir in NN.
270270
assertTrue(nnFs0.mkdirs(new Path("/newdir")));
271271

272272
Map<String, Long> pathModTime = new TreeMap<>();
@@ -288,12 +288,12 @@ public void testListFilesTime() throws Exception {
288288
for (FileStatus file : iterator) {
289289
pathModTime.put(file.getPath().getName(), file.getModificationTime());
290290
}
291-
// Fetch listing
291+
// Fetch listing.
292292
DirectoryListing listing =
293293
routerProtocol.getListing("/", HdfsFileStatus.EMPTY_NAME, false);
294294
Iterator<String> pathModTimeIterator = pathModTime.keySet().iterator();
295295

296-
// Match date/time for each path returned
296+
// Match date/time for each path returned.
297297
for (HdfsFileStatus f : listing.getPartialListing()) {
298298
String fileName = pathModTimeIterator.next();
299299
String currentFile = f.getFullPath(new Path("/")).getName();
@@ -304,7 +304,7 @@ public void testListFilesTime() throws Exception {
304304
assertTrue(currentTime > startTime);
305305
assertEquals(currentTime, expectedTime);
306306
}
307-
// Verify the total number of results found/matched
307+
// Verify the total number of results found/matched.
308308
assertEquals(pathModTime.size(), listing.getPartialListing().length);
309309
} finally {
310310
nnFs0.delete(new Path("/newdir"), true);
@@ -646,7 +646,7 @@ public void testPathInException() throws Exception {
646646
@Test
647647
public void testGetListingWithTrailingSlash() throws IOException {
648648
try {
649-
// Add mount table entry
649+
// Add mount table entry.
650650
MountTable addEntry = MountTable.newInstance("/testlist",
651651
Collections.singletonMap("ns0", "/testlist"));
652652
assertTrue(addMountTable(addEntry));
@@ -659,11 +659,11 @@ public void testGetListingWithTrailingSlash() throws IOException {
659659

660660
nnFs0.mkdirs(new Path("/testlist/tmp0"));
661661
nnFs1.mkdirs(new Path("/testlist/tmp1"));
662-
// Fetch listing
662+
// Fetch listing.
663663
DirectoryListing list = routerProtocol.getListing(
664664
"/testlist/", HdfsFileStatus.EMPTY_NAME, false);
665665
HdfsFileStatus[] statuses = list.getPartialListing();
666-
// should return tmp0 and tmp1
666+
// Should return tmp0 and tmp1.
667667
assertEquals(2, statuses.length);
668668
} finally {
669669
nnFs0.delete(new Path("/testlist/tmp0"), true);
@@ -674,7 +674,7 @@ public void testGetListingWithTrailingSlash() throws IOException {
674674
@Test
675675
public void testGetFileInfoWithMountPoint() throws IOException {
676676
try {
677-
// Add mount table entry
677+
// Add mount table entry.
678678
MountTable addEntry = MountTable.newInstance("/testgetfileinfo/ns1/dir",
679679
Collections.singletonMap("ns1", "/testgetfileinfo/ns1/dir"));
680680
assertTrue(addMountTable(addEntry));
@@ -740,27 +740,27 @@ public void testRenameMountPoint() throws Exception {
740740
nnFs0.mkdirs(new Path("/testrename1/sub/sub"));
741741
nnFs0.mkdirs(new Path("/testrename2"));
742742

743-
// Success: rename a directory to a mount point
743+
// Success: rename a directory to a mount point.
744744
assertTrue(nnFs0.exists(new Path("/testrename1/sub/sub")));
745745
assertFalse(nnFs0.exists(new Path("/testrename2/sub")));
746746
assertTrue(routerFs.rename(new Path("/testrename1/sub/sub"),
747747
new Path("/testrename2")));
748748
assertFalse(nnFs0.exists(new Path("/testrename1/sub/sub")));
749749
assertTrue(nnFs0.exists(new Path("/testrename2/sub")));
750750

751-
// Fail: the target already exists
751+
// Fail: the target already exists.
752752
nnFs0.mkdirs(new Path("/testrename1/sub/sub"));
753753
assertFalse(routerFs.rename(new Path("/testrename1/sub/sub"),
754754
new Path("/testrename2")));
755755

756-
// Fail: The src is a mount point
756+
// Fail: The src is a mount point.
757757
LambdaTestUtils.intercept(AccessControlException.class,
758758
"The operation is not allowed because the path: "
759759
+ "/testrename1/sub is a mount point",
760760
() -> routerFs.rename(new Path("/testrename1/sub"),
761761
new Path("/testrename2/sub")));
762762

763-
// Fail: There is a mount point under the src
763+
// Fail: There is a mount point under the src.
764764
LambdaTestUtils.intercept(AccessControlException.class,
765765
"The operation is not allowed because there are mount points: "
766766
+ "sub under the path: /testrename1",
@@ -791,7 +791,7 @@ public void testListStatusMountPoint() throws Exception {
791791
@Test
792792
public void testGetEnclosingRoot() throws Exception {
793793

794-
// Add a read only entry
794+
// Add a read only entry.
795795
MountTable readOnlyEntry = MountTable.newInstance(
796796
"/readonly", Collections.singletonMap("ns0", "/testdir"));
797797
readOnlyEntry.setReadOnly(true);
@@ -802,13 +802,13 @@ public void testGetEnclosingRoot() throws Exception {
802802
assertEquals(routerFs.getEnclosingRoot(new Path("/regular")),
803803
routerFs.getEnclosingRoot(routerFs.getEnclosingRoot(new Path("/regular"))));
804804

805-
// Add a regular entry
805+
// Add a regular entry.
806806
MountTable regularEntry = MountTable.newInstance(
807807
"/regular", Collections.singletonMap("ns0", "/testdir"));
808808
assertTrue(addMountTable(regularEntry));
809809
assertEquals(routerFs.getEnclosingRoot(new Path("/regular")), new Path("/regular"));
810810

811-
// path does not need to exist
811+
// Path does not need to exist.
812812
assertEquals(routerFs.getEnclosingRoot(new Path("/regular/pathDNE")), new Path("/regular"));
813813

814814
}

hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/async/TestRouterAsyncMountTable.java

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,17 @@
1818
package org.apache.hadoop.hdfs.server.federation.router.async;
1919

2020
import org.apache.hadoop.conf.Configuration;
21-
import org.apache.hadoop.fs.Path;
2221
import org.apache.hadoop.hdfs.server.federation.RouterConfigBuilder;
2322
import org.apache.hadoop.hdfs.server.federation.StateStoreDFSCluster;
24-
import org.apache.hadoop.hdfs.server.federation.resolver.MountTableManager;
2523
import org.apache.hadoop.hdfs.server.federation.resolver.MountTableResolver;
2624
import org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys;
2725
import org.apache.hadoop.hdfs.server.federation.router.Router;
28-
import org.apache.hadoop.hdfs.server.federation.router.RouterClient;
2926
import org.apache.hadoop.hdfs.server.federation.router.TestRouterMountTable;
30-
import org.apache.hadoop.hdfs.server.federation.store.protocol.AddMountTableEntryRequest;
31-
import org.apache.hadoop.hdfs.server.federation.store.protocol.AddMountTableEntryResponse;
32-
import org.apache.hadoop.hdfs.server.federation.store.protocol.GetMountTableEntriesRequest;
33-
import org.apache.hadoop.hdfs.server.federation.store.protocol.GetMountTableEntriesResponse;
34-
import org.apache.hadoop.hdfs.server.federation.store.protocol.RemoveMountTableEntryRequest;
35-
import org.apache.hadoop.hdfs.server.federation.store.records.MountTable;
36-
import org.apache.hadoop.test.LambdaTestUtils;
3727
import org.apache.hadoop.util.Time;
38-
import org.junit.After;
39-
import org.junit.AfterClass;
4028
import org.junit.BeforeClass;
41-
import org.junit.Test;
4229
import org.slf4j.Logger;
4330
import org.slf4j.LoggerFactory;
4431

45-
import java.io.FileNotFoundException;
46-
import java.io.IOException;
47-
import java.util.Collections;
48-
49-
import static org.junit.Assert.assertEquals;
50-
import static org.junit.Assert.assertTrue;
51-
5232
/**
5333
* Test a router end-to-end including the MountTable using async rpc.
5434
*/
@@ -84,81 +64,4 @@ public static void globalSetUp() throws Exception {
8464
routerProtocol = routerContext.getClient().getNamenode();
8565
mountTable = (MountTableResolver) router.getSubclusterResolver();
8666
}
87-
88-
@AfterClass
89-
public static void tearDown() {
90-
if (cluster != null) {
91-
cluster.stopRouter(routerContext);
92-
cluster.shutdown();
93-
cluster = null;
94-
}
95-
}
96-
97-
@After
98-
public void clearMountTable() throws IOException {
99-
RouterClient client = routerContext.getAdminClient();
100-
MountTableManager mountTableManager = client.getMountTableManager();
101-
GetMountTableEntriesRequest req1 =
102-
GetMountTableEntriesRequest.newInstance("/");
103-
GetMountTableEntriesResponse response =
104-
mountTableManager.getMountTableEntries(req1);
105-
for (MountTable entry : response.getEntries()) {
106-
RemoveMountTableEntryRequest req2 =
107-
RemoveMountTableEntryRequest.newInstance(entry.getSourcePath());
108-
mountTableManager.removeMountTableEntry(req2);
109-
}
110-
mountTable.setDefaultNSEnable(true);
111-
}
112-
113-
/**
114-
* Add a mount table entry to the mount table through the admin API.
115-
* @param entry Mount table entry to add.
116-
* @return If it was succesfully added.
117-
* @throws IOException Problems adding entries.
118-
*/
119-
private boolean addMountTable(final MountTable entry) throws IOException {
120-
RouterClient client = routerContext.getAdminClient();
121-
MountTableManager mountTableManager = client.getMountTableManager();
122-
AddMountTableEntryRequest addRequest =
123-
AddMountTableEntryRequest.newInstance(entry);
124-
AddMountTableEntryResponse addResponse =
125-
mountTableManager.addMountTableEntry(addRequest);
126-
127-
// Reload the Router cache.
128-
mountTable.loadCache(true);
129-
130-
return addResponse.getStatus();
131-
}
132-
133-
@Test
134-
public void testGetEnclosingRoot() throws Exception {
135-
// Add a read only entry.
136-
MountTable readOnlyEntry = MountTable.newInstance(
137-
"/readonly", Collections.singletonMap("ns0", "/testdir"));
138-
readOnlyEntry.setReadOnly(true);
139-
assertTrue(addMountTable(readOnlyEntry));
140-
assertEquals(routerFs.getEnclosingRoot(new Path("/readonly")), new Path("/readonly"));
141-
142-
assertEquals(routerFs.getEnclosingRoot(new Path("/regular")), new Path("/"));
143-
assertEquals(routerFs.getEnclosingRoot(new Path("/regular")),
144-
routerFs.getEnclosingRoot(routerFs.getEnclosingRoot(new Path("/regular"))));
145-
146-
// Add a regular entry.
147-
MountTable regularEntry = MountTable.newInstance(
148-
"/regular", Collections.singletonMap("ns0", "/testdir"));
149-
assertTrue(addMountTable(regularEntry));
150-
assertEquals(routerFs.getEnclosingRoot(new Path("/regular")), new Path("/regular"));
151-
152-
// Path does not need to exist.
153-
assertEquals(routerFs.getEnclosingRoot(new Path("/regular/pathDNE")), new Path("/regular"));
154-
}
155-
156-
@Test
157-
public void testListNonExistPath() throws Exception {
158-
mountTable.setDefaultNSEnable(false);
159-
LambdaTestUtils.intercept(FileNotFoundException.class,
160-
"File /base does not exist.",
161-
"Expect FileNotFoundException.",
162-
() -> routerFs.listStatus(new Path("/base")));
163-
}
16467
}

0 commit comments

Comments
 (0)