Skip to content

Commit 99a0b0f

Browse files
committed
nfs4: add more delegations test
Motivation: Better test coverage. Modification: Test two read delegations from different clients. Acked-by: Paul Millar Target: master
1 parent 533da02 commit 99a0b0f

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

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

+19-3
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,6 @@ public void shouldNotReadDelegation() throws Exception {
239239
public void shouldReCallReadDelegationOnConflict() throws Exception {
240240

241241
NFS4Client client = createClient(sh);
242-
ClientCB mockCallBack = mock(ClientCB.class);
243-
client.setCB(mockCallBack);
244242

245243
StateOwner stateOwner1 = client.getOrCreateOwner("client1".getBytes(StandardCharsets.UTF_8), new seqid4(0));
246244
StateOwner stateOwner2 = client.getOrCreateOwner("client2".getBytes(StandardCharsets.UTF_8), new seqid4(0));
@@ -257,7 +255,25 @@ public void shouldReCallReadDelegationOnConflict() throws Exception {
257255
// expected
258256
}
259257

260-
verify(mockCallBack).cbDelegationRecall(any(), any(), anyBoolean());
258+
verify(client.getCB()).cbDelegationRecall(any(), any(), anyBoolean());
261259
}
262260

261+
@Test
262+
public void shouldAllowMultipleReadDelegation() throws Exception {
263+
264+
NFS4Client client1 = createClient(sh);
265+
NFS4Client client2 = createClient(sh);
266+
267+
StateOwner stateOwner1 = client1.getOrCreateOwner("client1".getBytes(StandardCharsets.UTF_8), new seqid4(0));
268+
StateOwner stateOwner2 = client2.getOrCreateOwner("client2".getBytes(StandardCharsets.UTF_8), new seqid4(0));
269+
270+
nfs_fh4 fh = generateFileHandle();
271+
Inode inode = Inode.forFile(fh.value);
272+
273+
var openRecord1 = tracker.addOpen(client1, stateOwner1, inode, OPEN4_SHARE_ACCESS_READ | nfs4_prot.OPEN4_SHARE_ACCESS_WANT_READ_DELEG, 0);
274+
var openRecord2 = tracker.addOpen(client2, stateOwner2, inode, OPEN4_SHARE_ACCESS_READ | nfs4_prot.OPEN4_SHARE_ACCESS_WANT_READ_DELEG, 0);
275+
276+
assertTrue("Read delegation not granted", openRecord2.hasDelegation());
277+
278+
}
263279
}

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009 - 2020 Deutsches Elektronen-Synchroton,
2+
* Copyright (c) 2009 - 2025 Deutsches Elektronen-Synchroton,
33
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
44
*
55
* This library is free software; you can redistribute it and/or modify
@@ -66,7 +66,12 @@ static NFS4Client createClient(NFSv4StateHandler stateHandler, int minor) throws
6666
byte[] bootTime = new byte[8];
6767
RANDOM.nextBytes(owner);
6868
Bytes.putLong(bootTime, 0, System.currentTimeMillis());
69-
return stateHandler.createClient(address, address, minor, owner, new verifier4(bootTime), null, false);
69+
70+
ClientCB mockCallBack = mock(ClientCB.class);
71+
var client = stateHandler.createClient(address, address, minor, owner, new verifier4(bootTime), null, false);
72+
client.setCB(mockCallBack);
73+
74+
return client;
7075
}
7176

7277
public static COMPOUND4res executeWithStatus(CompoundContext context, COMPOUND4args args, int expectedStatus) throws IOException {

0 commit comments

Comments
 (0)