19
19
*/
20
20
package org .dcache .nfs .v4 ;
21
21
22
+ import java .net .UnknownHostException ;
22
23
import java .nio .charset .StandardCharsets ;
24
+
25
+ import org .dcache .nfs .ChimeraNFSException ;
23
26
import org .dcache .nfs .status .BadStateidException ;
24
27
import org .dcache .nfs .status .DelayException ;
25
28
import org .dcache .nfs .status .InvalException ;
26
29
import org .dcache .nfs .status .ShareDeniedException ;
27
- import org .dcache . nfs . v4 . xdr . nfs4_prot ;
30
+ import org .hamcrest . Matchers ;
28
31
import org .junit .Before ;
29
32
import org .junit .Test ;
30
33
31
34
import org .dcache .nfs .v4 .xdr .nfs_fh4 ;
32
35
import org .dcache .nfs .vfs .Inode ;
33
36
34
- import static org .junit . Assert .* ;
37
+ import static org .dcache . nfs . v4 . xdr . nfs4_prot . OPEN4_SHARE_ACCESS_WANT_READ_DELEG ;
35
38
import static org .dcache .nfs .v4 .NfsTestUtils .createClient ;
36
39
import static org .dcache .nfs .v4 .NfsTestUtils .generateFileHandle ;
37
40
38
41
import static org .dcache .nfs .v4 .xdr .nfs4_prot .OPEN4_SHARE_ACCESS_READ ;
39
42
import static org .dcache .nfs .v4 .xdr .nfs4_prot .OPEN4_SHARE_ACCESS_WRITE ;
40
43
import static org .dcache .nfs .v4 .xdr .nfs4_prot .OPEN4_SHARE_ACCESS_BOTH ;
41
44
import static org .dcache .nfs .v4 .xdr .nfs4_prot .OPEN4_SHARE_ACCESS_WANT_NO_DELEG ;
45
+ import static org .hamcrest .MatcherAssert .assertThat ;
46
+ import static org .junit .Assert .assertEquals ;
47
+ import static org .junit .Assert .assertFalse ;
48
+ import static org .junit .Assert .assertNotEquals ;
49
+ import static org .junit .Assert .assertTrue ;
50
+ import static org .junit .Assert .fail ;
42
51
import static org .mockito .ArgumentMatchers .any ;
43
52
import static org .mockito .ArgumentMatchers .anyBoolean ;
44
53
import static org .mockito .Mockito .mock ;
@@ -216,7 +225,7 @@ public void shouldGetReadDelegation() throws Exception {
216
225
nfs_fh4 fh = generateFileHandle ();
217
226
Inode inode = Inode .forFile (fh .value );
218
227
219
- var openRecord = tracker .addOpen (client , stateOwner1 , inode , OPEN4_SHARE_ACCESS_READ | nfs4_prot . OPEN4_SHARE_ACCESS_WANT_READ_DELEG , 0 );
228
+ var openRecord = tracker .addOpen (client , stateOwner1 , inode , OPEN4_SHARE_ACCESS_READ | OPEN4_SHARE_ACCESS_WANT_READ_DELEG , 0 );
220
229
assertTrue ("Read delegation not granted" , openRecord .hasDelegation ());
221
230
}
222
231
@@ -248,7 +257,7 @@ public void shouldReCallReadDelegationOnConflict() throws Exception {
248
257
nfs_fh4 fh = generateFileHandle ();
249
258
Inode inode = Inode .forFile (fh .value );
250
259
251
- var openRecord1 = tracker .addOpen (client1 , stateOwner1 , inode , OPEN4_SHARE_ACCESS_READ | nfs4_prot . OPEN4_SHARE_ACCESS_WANT_READ_DELEG , 0 );
260
+ var openRecord1 = tracker .addOpen (client1 , stateOwner1 , inode , OPEN4_SHARE_ACCESS_READ | OPEN4_SHARE_ACCESS_WANT_READ_DELEG , 0 );
252
261
try {
253
262
var openRecord2 = tracker .addOpen (client2 , stateOwner2 , inode , OPEN4_SHARE_ACCESS_WRITE ,
254
263
0 );
@@ -272,8 +281,8 @@ public void shouldAllowMultipleReadDelegation() throws Exception {
272
281
nfs_fh4 fh = generateFileHandle ();
273
282
Inode inode = Inode .forFile (fh .value );
274
283
275
- var openRecord1 = tracker .addOpen (client1 , stateOwner1 , inode , OPEN4_SHARE_ACCESS_READ | nfs4_prot . OPEN4_SHARE_ACCESS_WANT_READ_DELEG , 0 );
276
- var openRecord2 = tracker .addOpen (client2 , stateOwner2 , inode , OPEN4_SHARE_ACCESS_READ | nfs4_prot . OPEN4_SHARE_ACCESS_WANT_READ_DELEG , 0 );
284
+ var openRecord1 = tracker .addOpen (client1 , stateOwner1 , inode , OPEN4_SHARE_ACCESS_READ | OPEN4_SHARE_ACCESS_WANT_READ_DELEG , 0 );
285
+ var openRecord2 = tracker .addOpen (client2 , stateOwner2 , inode , OPEN4_SHARE_ACCESS_READ | OPEN4_SHARE_ACCESS_WANT_READ_DELEG , 0 );
277
286
278
287
assertTrue ("Read delegation not granted" , openRecord2 .hasDelegation ());
279
288
@@ -310,4 +319,49 @@ public void shouldNotIssueReadDelegation() throws Exception {
310
319
var openRecord2 = tracker .addOpen (client , stateOwner , inode , OPEN4_SHARE_ACCESS_READ | OPEN4_SHARE_ACCESS_WANT_NO_DELEG , 0 );
311
320
assertFalse ("Unwanted delegation" , openRecord2 .hasDelegation ());
312
321
}
322
+
323
+
324
+ @ Test
325
+ public void getOpenFiles () throws UnknownHostException , ChimeraNFSException {
326
+
327
+ NFS4Client client1 = createClient (sh );
328
+ NFS4Client client2 = createClient (sh );
329
+ StateOwner stateOwner1 = client1 .getOrCreateOwner ("client1" .getBytes (StandardCharsets .UTF_8 ), new seqid4 (0 ));
330
+ StateOwner stateOwner2 = client2 .getOrCreateOwner ("client2" .getBytes (StandardCharsets .UTF_8 ), new seqid4 (0 ));
331
+
332
+ nfs_fh4 fh = generateFileHandle ();
333
+ Inode inode = Inode .forFile (fh .value );
334
+
335
+ tracker .addOpen (client1 , stateOwner1 , inode , OPEN4_SHARE_ACCESS_READ , 0 );
336
+ tracker .addOpen (client2 , stateOwner2 , inode , OPEN4_SHARE_ACCESS_READ , 0 );
337
+
338
+ var openFiles = tracker .getOpenFiles ();
339
+
340
+ assertEquals ("Number of open files not as expected" , 1 , openFiles .size ());
341
+
342
+ var clients = openFiles .get (inode );
343
+ assertThat ("Expected clients not found" , clients , Matchers .containsInAnyOrder (client1 ,client2 ));
344
+ }
345
+
346
+ @ Test
347
+ public void getDelegations () throws UnknownHostException , ChimeraNFSException {
348
+
349
+ NFS4Client client1 = createClient (sh );
350
+ NFS4Client client2 = createClient (sh );
351
+ StateOwner stateOwner1 = client1 .getOrCreateOwner ("client1" .getBytes (StandardCharsets .UTF_8 ), new seqid4 (0 ));
352
+ StateOwner stateOwner2 = client2 .getOrCreateOwner ("client2" .getBytes (StandardCharsets .UTF_8 ), new seqid4 (0 ));
353
+
354
+ nfs_fh4 fh = generateFileHandle ();
355
+ Inode inode = Inode .forFile (fh .value );
356
+
357
+ tracker .addOpen (client1 , stateOwner1 , inode , OPEN4_SHARE_ACCESS_READ | OPEN4_SHARE_ACCESS_WANT_READ_DELEG , 0 );
358
+ tracker .addOpen (client2 , stateOwner2 , inode , OPEN4_SHARE_ACCESS_READ | OPEN4_SHARE_ACCESS_WANT_READ_DELEG , 0 );
359
+
360
+ var delegations = tracker .getDelegations ();
361
+
362
+ assertEquals ("Number of open files not as expected" , 1 , delegations .size ());
363
+
364
+ var clients = delegations .get (inode );
365
+ assertThat ("Expected clients not found" , clients , Matchers .containsInAnyOrder (client1 ,client2 ));
366
+ }
313
367
}
0 commit comments