Skip to content

Commit c87f025

Browse files
committed
core: test: Replace use of FileHandle with Inode wherever possible
Now that FileHandle is very much obsolete, use Inode in test code, unless we explicitly test FileHandle-specifics, such as accessing generation, version, magic numbers, etc. Related: #149 Signed-off-by: Christian Kohlschütter <[email protected]>
1 parent 036e23b commit c87f025

File tree

7 files changed

+34
-41
lines changed

7 files changed

+34
-41
lines changed

core/src/test/java/org/dcache/nfs/v3/NfsServerV3READDIRPLUS_3Test.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,14 @@
3333
import org.junit.Test;
3434

3535
public class NfsServerV3READDIRPLUS_3Test {
36-
private FileHandle dirHandle;
3736
private Inode dirInode;
3837
private Stat dirStat;
3938
private VirtualFileSystem vfs;
4039
private NfsServerV3 nfsServer;
4140

4241
@Before
4342
public void setup() throws Exception {
44-
dirHandle = new FileHandle(0, 1, 0, new byte[] {0, 0, 0, 1}); // the dir we want to read
45-
dirInode = dirHandle;
43+
dirInode = new Inode(0, 1, 0, new byte[] {0, 0, 0, 1}); // the dir we want to read;
4644
dirStat = new Stat(); // the stat marking it as a dir
4745
// noinspection OctalInteger
4846
dirStat.setMode(Stat.S_IFDIR | 0755);
@@ -74,7 +72,7 @@ public void testReadDirWithNoResults() throws Exception {
7472

7573
// set up and execute the call
7674
RpcCall call = new RpcCallBuilder().from("1.2.3.4", "someHost.acme.com", 42).nfs3().noAuth().build();
77-
READDIRPLUS3args args = NfsV3Ops.readDirPlus(dirHandle);
75+
READDIRPLUS3args args = NfsV3Ops.readDirPlus(dirInode);
7876
READDIRPLUS3res result = nfsServer.NFSPROC3_READDIRPLUS_3(call, args);
7977

8078
Assert.assertEquals(nfsstat.NFS_OK, result.status);
@@ -96,7 +94,7 @@ public void testReadDirWithTinyLimit() throws Exception {
9694

9795
// set up and execute the 1st call - no cookie, but very tight size limit
9896
RpcCall call = new RpcCallBuilder().from("1.2.3.4", "someHost.acme.com", 42).nfs3().noAuth().build();
99-
READDIRPLUS3args args = NfsV3Ops.readDirPlus(dirHandle, 10); // 10 bytes - not enough for anything
97+
READDIRPLUS3args args = NfsV3Ops.readDirPlus(dirInode, 10); // 10 bytes - not enough for anything
10098
READDIRPLUS3res result = nfsServer.NFSPROC3_READDIRPLUS_3(call, args);
10199

102100
Assert.assertEquals(nfsstat.NFSERR_TOOSMALL, result.status); // error response
@@ -115,7 +113,7 @@ public void testContinueReadingAfterEOF() throws Exception {
115113

116114
// set up and execute the 1st call - no cookie, but very tight size limit
117115
RpcCall call = new RpcCallBuilder().from("1.2.3.4", "someHost.acme.com", 42).nfs3().noAuth().build();
118-
READDIRPLUS3args args = NfsV3Ops.readDirPlus(dirHandle);
116+
READDIRPLUS3args args = NfsV3Ops.readDirPlus(dirInode);
119117
READDIRPLUS3res result = nfsServer.NFSPROC3_READDIRPLUS_3(call, args);
120118

121119
Assert.assertEquals(nfsstat.NFS_OK, result.status); // response ok
@@ -125,7 +123,7 @@ public void testContinueReadingAfterEOF() throws Exception {
125123
// re-read after EOF
126124
long cookie = result.resok.reply.entries.nextentry.cookie.value.value;
127125
cookieVerifier = result.resok.cookieverf.value;
128-
args = NfsV3Ops.readDirPlus(dirHandle, cookie, cookieVerifier);
126+
args = NfsV3Ops.readDirPlus(dirInode, cookie, cookieVerifier);
129127
result = nfsServer.NFSPROC3_READDIRPLUS_3(call, args);
130128

131129
Assert.assertEquals(nfsstat.NFS_OK, result.status); // response ok
@@ -148,7 +146,7 @@ public void testSemiValidVerifier() throws Exception {
148146
long cookie = 1;
149147

150148
RpcCall call = new RpcCallBuilder().from("1.2.3.4", "someHost.acme.com", 42).nfs3().noAuth().build();
151-
READDIRPLUS3args args = NfsV3Ops.readDirPlus(dirHandle, cookie, cookieVerifier);
149+
READDIRPLUS3args args = NfsV3Ops.readDirPlus(dirInode, cookie, cookieVerifier);
152150
READDIRPLUS3res result = nfsServer.NFSPROC3_READDIRPLUS_3(call, args);
153151

154152
Assert.assertEquals(nfsstat.NFS_OK, result.status); // error response
@@ -172,7 +170,7 @@ public void testEofIfLastEntryDoesNotFit() throws Exception {
172170
when(vfs.list(eq(dirInode), any(), anyLong())).thenReturn(new DirectoryStream(cookieVerifier, dirContents));
173171

174172
RpcCall call = new RpcCallBuilder().from("1.2.3.4", "someHost.acme.com", 42).nfs3().noAuth().build();
175-
READDIRPLUS3args args = NfsV3Ops.readDirPlus(dirHandle, 0, cookieVerifier, 3480, 1024); // only 22 entries will
173+
READDIRPLUS3args args = NfsV3Ops.readDirPlus(dirInode, 0, cookieVerifier, 3480, 1024); // only 22 entries will
176174
// fit
177175
READDIRPLUS3res result = nfsServer.NFSPROC3_READDIRPLUS_3(call, args);
178176

core/src/test/java/org/dcache/nfs/v3/NfsServerV3READDIR_3Test.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,14 @@
3434

3535
public class NfsServerV3READDIR_3Test {
3636

37-
private FileHandle dirHandle;
3837
private Inode dirInode;
3938
private Stat dirStat;
4039
private VirtualFileSystem vfs;
4140
private NfsServerV3 nfsServer;
4241

4342
@Before
4443
public void setup() throws Exception {
45-
dirHandle = new FileHandle(0, 1, 0, new byte[] {0, 0, 0, 1}); // the dir we want to read
46-
dirInode = dirHandle;
44+
dirInode = new Inode(0, 1, 0, new byte[] {0, 0, 0, 1}); // the dir we want to read
4745
dirStat = new Stat(); // the stat marking it as a dir
4846
// noinspection OctalInteger
4947
dirStat.setMode(Stat.S_IFDIR | 0755);
@@ -75,7 +73,7 @@ public void testReadDirWithNoResults() throws Exception {
7573

7674
// set up and execute the call
7775
RpcCall call = new RpcCallBuilder().from("1.2.3.4", "someHost.acme.com", 42).nfs3().noAuth().build();
78-
READDIR3args args = NfsV3Ops.readDir(dirHandle);
76+
READDIR3args args = NfsV3Ops.readDir(dirInode);
7977
READDIR3res result = nfsServer.NFSPROC3_READDIR_3(call, args);
8078

8179
Assert.assertEquals(nfsstat.NFS_OK, result.status);
@@ -95,7 +93,7 @@ public void testReadDirWithTinyLimit() throws Exception {
9593

9694
// set up and execute the 1st call - no cookie, but very tight size limit
9795
RpcCall call = new RpcCallBuilder().from("1.2.3.4", "someHost.acme.com", 42).nfs3().noAuth().build();
98-
READDIR3args args = NfsV3Ops.readDir(dirHandle, 10); // 10 bytes - not enough for anything
96+
READDIR3args args = NfsV3Ops.readDir(dirInode, 10); // 10 bytes - not enough for anything
9997
READDIR3res result = nfsServer.NFSPROC3_READDIR_3(call, args);
10098

10199
Assert.assertEquals(nfsstat.NFSERR_TOOSMALL, result.status); // error response
@@ -114,7 +112,7 @@ public void testContinueReadingAfterEOF() throws Exception {
114112

115113
// set up and execute the 1st call - no cookie, but very tight size limit
116114
RpcCall call = new RpcCallBuilder().from("1.2.3.4", "someHost.acme.com", 42).nfs3().noAuth().build();
117-
READDIR3args args = NfsV3Ops.readDir(dirHandle);
115+
READDIR3args args = NfsV3Ops.readDir(dirInode);
118116
READDIR3res result = nfsServer.NFSPROC3_READDIR_3(call, args);
119117

120118
Assert.assertEquals(nfsstat.NFS_OK, result.status); // response ok
@@ -124,7 +122,7 @@ public void testContinueReadingAfterEOF() throws Exception {
124122
// reading after we got EOF
125123
long cookie = result.resok.reply.entries.nextentry.cookie.value.value;
126124
cookieVerifier = result.resok.cookieverf.value;
127-
args = NfsV3Ops.readDir(dirHandle, cookie, cookieVerifier);
125+
args = NfsV3Ops.readDir(dirInode, cookie, cookieVerifier);
128126
result = nfsServer.NFSPROC3_READDIR_3(call, args);
129127

130128
Assert.assertEquals(nfsstat.NFS_OK, result.status); // response ok
@@ -147,7 +145,7 @@ public void testSemiValidVerifier() throws Exception {
147145
long cookie = 1;
148146

149147
RpcCall call = new RpcCallBuilder().from("1.2.3.4", "someHost.acme.com", 42).nfs3().noAuth().build();
150-
READDIR3args args = NfsV3Ops.readDir(dirHandle, cookie, cookieVerifier);
148+
READDIR3args args = NfsV3Ops.readDir(dirInode, cookie, cookieVerifier);
151149
READDIR3res result = nfsServer.NFSPROC3_READDIR_3(call, args);
152150

153151
Assert.assertEquals(nfsstat.NFS_OK, result.status); // error response
@@ -171,7 +169,7 @@ public void testEofIfLastEntryDoesNotFit() throws Exception {
171169
when(vfs.list(eq(dirInode), any(), anyLong())).thenReturn(new DirectoryStream(cookieVerifier, dirContents));
172170

173171
RpcCall call = new RpcCallBuilder().from("1.2.3.4", "someHost.acme.com", 42).nfs3().noAuth().build();
174-
READDIR3args args = NfsV3Ops.readDir(dirHandle, 0, cookieVerifier, 836); // only 22 entries will fit
172+
READDIR3args args = NfsV3Ops.readDir(dirInode, 0, cookieVerifier, 836); // only 22 entries will fit
175173
READDIR3res result = nfsServer.NFSPROC3_READDIR_3(call, args);
176174

177175
int n = 0;

core/src/test/java/org/dcache/nfs/v4/OperationOPENTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void testReturnFhOnOpen() throws Exception {
9090
Inode inode = vfs.create(fsRoot, Stat.Type.REGULAR, "file", new Subject(), 0644);
9191
COMPOUND4res res = execute(context, openArgs);
9292

93-
assertEquals("wrong file handle", inode, new Inode(res.resarray.get(3).opgetfh.resok4.object.value));
93+
assertEquals("wrong file handle", inode, Inode.forNfsHandle(res.resarray.get(3).opgetfh.resok4.object.value));
9494
}
9595

9696
@Test

core/src/test/java/org/dcache/nfs/v4/OperationREADDIRTest.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343

4444
public class OperationREADDIRTest {
4545

46-
private FileHandle dirHandle;
4746
private Inode dirInode;
4847
private Stat dirStat;
4948
private VirtualFileSystem vfs;
@@ -60,8 +59,7 @@ public class OperationREADDIRTest {
6059

6160
@Before
6261
public void setup() throws Exception {
63-
dirHandle = new FileHandle(0, 0, 0, new byte[] {0, 0, 0, 0}); // the dir we want to read
64-
dirInode = dirHandle;
62+
dirInode = new Inode(0, 0, 0, new byte[] {0, 0, 0, 0}); // the dir we want to read;
6563
dirStat = new Stat(); // the stat marking it as a dir
6664
// noinspection OctalInteger
6765
dirStat.setMode(Stat.S_IFDIR | 0755);
@@ -173,8 +171,7 @@ private DirectoryEntry dir(String name) {
173171

174172
int cookie = ino++;
175173

176-
FileHandle handle = new FileHandle(0, 1, 0, Ints.toByteArray(cookie));
177-
Inode inode = handle;
174+
Inode inode = new Inode(0, 1, 0, Ints.toByteArray(cookie));;
178175
Stat stat = new Stat(); // the stat marking it as a dir
179176
// noinspection OctalInteger
180177
stat.setMode(Stat.S_IFDIR | 0755);
@@ -201,8 +198,7 @@ private DirectoryEntry file(String name) {
201198

202199
int cookie = ino++;
203200

204-
FileHandle handle = new FileHandle(0, 1, 0, Ints.toByteArray(cookie));
205-
Inode inode = handle;
201+
Inode inode = new Inode(0, 1, 0, Ints.toByteArray(cookie));
206202
Stat stat = new Stat(); // the stat marking it as a dir
207203
// noinspection OctalInteger
208204
stat.setMode(Stat.S_IFREG | 0644);

core/src/test/java/org/dcache/nfs/vfs/DirectoryStreamTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public void setUp() {
2525
byte[] verifier = verifier4.valueOf(System.currentTimeMillis()).value;
2626

2727
for (int i = 0; i < 10; i++) {
28-
Inode inode = new FileHandle(0, 0, 0, Ints.toByteArray(i));
28+
Inode inode = Inode.forFile(Ints.toByteArray(i));
2929
Stat stat = new Stat();
3030

3131
stat.setMode(Stat.S_IFDIR | 0755);

core/src/test/java/org/dcache/nfs/vfs/FileHandleTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,21 @@ public class FileHandleTest {
3131

3232
@Test(expected = IllegalArgumentException.class)
3333
public void testEmptyHandle() {
34-
new FileHandle(new byte[0]);
34+
Inode.forNfsHandle(new byte[0]);
3535
}
3636

3737
@Test(expected = IllegalArgumentException.class)
3838
public void testBadVersion() {
3939
byte[] bytes = BaseEncoding.base16().lowerCase().decode(
4040
"02caffee00000000ea15b996002e303a494e4f44453a3030303043333732333331373433393234353645423833453434383434453844323844363a30");
41-
new FileHandle(bytes);
41+
Inode.forNfsHandle(bytes);
4242
}
4343

4444
@Test(expected = IllegalArgumentException.class)
4545
public void testBadMagic() {
4646
byte[] bytes = BaseEncoding.base16().lowerCase().decode(
4747
"0100000000000000ea15b996002e303a494e4f44453a3030303043333732333331373433393234353645423833453434383434453844323844363a30");
48-
new FileHandle(bytes);
48+
Inode.forNfsHandle(bytes);
4949
}
5050

5151
@Test
@@ -74,7 +74,7 @@ public void testBuilder() {
7474
fh.toString());
7575
assertArrayEquals(BaseEncoding.base16().lowerCase().decode(
7676
"01caffee00000000ea15b996002e303a494e4f44453a3030303043333732333331373433393234353645423833453434383434453844323844363a30"),
77-
fh.bytes());
77+
fh.toNfsHandle());
7878
}
7979

8080
@Test

core/src/test/java/org/dcache/testutils/NfsV3Ops.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,50 +10,51 @@
1010
import org.dcache.nfs.v3.xdr.uint32;
1111
import org.dcache.nfs.v3.xdr.uint64;
1212
import org.dcache.nfs.vfs.FileHandle;
13+
import org.dcache.nfs.vfs.Inode;
1314

1415
public class NfsV3Ops {
15-
public static READDIR3args readDir(FileHandle requestedDirHandle) {
16+
public static READDIR3args readDir(Inode requestedDirHandle) {
1617
return readDir(requestedDirHandle, 0, new byte[nfs3_prot.NFS3_COOKIEVERFSIZE], Integer.MAX_VALUE);
1718
}
1819

19-
public static READDIR3args readDir(FileHandle requestedDirHandle, int maxResponseSize) {
20+
public static READDIR3args readDir(Inode requestedDirHandle, int maxResponseSize) {
2021
return readDir(requestedDirHandle, 0, new byte[nfs3_prot.NFS3_COOKIEVERFSIZE], maxResponseSize);
2122
}
2223

23-
public static READDIR3args readDir(FileHandle requestedDirHandle, long cookie, byte[] cookieVerifier) {
24+
public static READDIR3args readDir(Inode requestedDirHandle, long cookie, byte[] cookieVerifier) {
2425
return readDir(requestedDirHandle, cookie, cookieVerifier, Integer.MAX_VALUE);
2526
}
2627

27-
public static READDIR3args readDir(FileHandle requestedDirHandle, long cookie, byte[] cookieVerifier,
28+
public static READDIR3args readDir(Inode requestedDirHandle, long cookie, byte[] cookieVerifier,
2829
int maxResponseBytes) {
2930
READDIR3args args = new READDIR3args();
3031
args.dir = new nfs_fh3();
31-
args.dir.data = requestedDirHandle.bytes();
32+
args.dir.data = requestedDirHandle.toNfsHandle();
3233
args.cookie = new cookie3(new uint64(cookie));
3334
args.cookieverf = new cookieverf3(cookieVerifier);
3435
args.count = new count3(new uint32(maxResponseBytes));
3536
return args;
3637
}
3738

38-
public static READDIRPLUS3args readDirPlus(FileHandle requestedDirHandle) {
39+
public static READDIRPLUS3args readDirPlus(Inode requestedDirHandle) {
3940
return readDirPlus(requestedDirHandle, 0, new byte[nfs3_prot.NFS3_COOKIEVERFSIZE], Integer.MAX_VALUE,
4041
Integer.MAX_VALUE);
4142
}
4243

43-
public static READDIRPLUS3args readDirPlus(FileHandle requestedDirHandle, int maxResponseSize) {
44+
public static READDIRPLUS3args readDirPlus(Inode requestedDirHandle, int maxResponseSize) {
4445
return readDirPlus(requestedDirHandle, 0, new byte[nfs3_prot.NFS3_COOKIEVERFSIZE], maxResponseSize,
4546
maxResponseSize);
4647
}
4748

48-
public static READDIRPLUS3args readDirPlus(FileHandle requestedDirHandle, long cookie, byte[] cookieVerifier) {
49+
public static READDIRPLUS3args readDirPlus(Inode requestedDirHandle, long cookie, byte[] cookieVerifier) {
4950
return readDirPlus(requestedDirHandle, cookie, cookieVerifier, Integer.MAX_VALUE, Integer.MAX_VALUE);
5051
}
5152

52-
public static READDIRPLUS3args readDirPlus(FileHandle requestedDirHandle, long cookie, byte[] cookieVerifier,
53+
public static READDIRPLUS3args readDirPlus(Inode requestedDirHandle, long cookie, byte[] cookieVerifier,
5354
int maxResponseBytes, int maxDirectoryListingBytes) {
5455
READDIRPLUS3args args = new READDIRPLUS3args();
5556
args.dir = new nfs_fh3();
56-
args.dir.data = requestedDirHandle.bytes();
57+
args.dir.data = requestedDirHandle.toNfsHandle();
5758
args.cookie = new cookie3(new uint64(cookie));
5859
args.cookieverf = new cookieverf3(cookieVerifier);
5960
args.maxcount = new count3(new uint32(maxResponseBytes));

0 commit comments

Comments
 (0)