1
1
/*
2
- * Copyright (c) 2009 - 2020 Deutsches Elektronen-Synchroton,
2
+ * Copyright (c) 2009 - 2022 Deutsches Elektronen-Synchroton,
3
3
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4
4
*
5
5
* This library is free software; you can redistribute it and/or modify
21
21
22
22
import java .net .UnknownHostException ;
23
23
import java .nio .charset .StandardCharsets ;
24
+ import java .time .Duration ;
25
+ import java .time .temporal .ChronoUnit ;
24
26
import java .util .concurrent .atomic .AtomicBoolean ;
25
27
26
28
import org .dcache .nfs .ChimeraNFSException ;
27
29
import org .dcache .nfs .nfsstat ;
28
30
import org .dcache .nfs .status .SeqMisorderedException ;
31
+ import org .dcache .nfs .util .ManualClock ;
32
+ import org .dcache .nfs .util .NopCacheEventListener ;
29
33
import org .dcache .nfs .v4 .xdr .nfs_argop4 ;
30
34
import org .dcache .nfs .v4 .xdr .nfs_opnum4 ;
31
35
import org .dcache .nfs .v4 .xdr .nfs_resop4 ;
@@ -49,12 +53,20 @@ public class NFS4ClientTest {
49
53
private NFSv4StateHandler stateHandler ;
50
54
private NFS4Client nfsClient ;
51
55
private StateOwner owner ;
56
+ private ManualClock clock ;
52
57
53
58
@ Before
54
59
public void setUp () throws UnknownHostException , ChimeraNFSException {
55
- stateHandler = new NFSv4StateHandler ();
60
+
61
+ clock = new ManualClock ();
62
+ var leaseTime = Duration .ofSeconds (NFSv4Defaults .NFS4_LEASE_TIME );
63
+ var clientStore = new EphemeralClientRecoveryStore ();
64
+ stateHandler = new NFSv4StateHandler (leaseTime , 0 , clientStore ,
65
+ new DefaultClientCache (leaseTime , new NopCacheEventListener <>()), clock );
66
+
56
67
nfsClient = createClient (stateHandler );
57
- owner = nfsClient .getOrCreateOwner ("client test" .getBytes (StandardCharsets .UTF_8 ), new seqid4 (0 ));
68
+ owner = nfsClient .getOrCreateOwner ("client test" .getBytes (StandardCharsets .UTF_8 ),
69
+ new seqid4 (0 ));
58
70
}
59
71
60
72
@ Test
@@ -171,5 +183,23 @@ public void testClientDisposeCleansState() throws ChimeraNFSException {
171
183
assertTrue ("client state is not disposed" , isDisposed .get ());
172
184
assertFalse ("client claims to have a state after dispose" , nfsClient .hasState ());
173
185
}
186
+
187
+ @ Test
188
+ public void testClientValidityBeforeLeaseExpired () throws ChimeraNFSException {
189
+
190
+ assertTrue (nfsClient .isLeaseValid ());
191
+
192
+ clock .advance (stateHandler .getLeaseTime ().minus (1 , ChronoUnit .SECONDS ));
193
+ assertTrue ("Client should be valid before lease have expired." , nfsClient .isLeaseValid ());
194
+ }
195
+
196
+ @ Test
197
+ public void testClientValidityAfterLeaseExpired () throws ChimeraNFSException {
198
+
199
+ assertTrue (nfsClient .isLeaseValid ());
200
+
201
+ clock .advance (stateHandler .getLeaseTime ().plus (1 , ChronoUnit .SECONDS ));
202
+ assertFalse ("Client can be valid with expired lease" , nfsClient .isLeaseValid ());
203
+ }
174
204
}
175
205
0 commit comments