Skip to content

Commit c4e1219

Browse files
committed
test: improve test coverage of NFSv4StateHandler
Acked-by: Paul Millar Target: master
1 parent 2a43633 commit c4e1219

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@
3030
import java.nio.charset.StandardCharsets;
3131
import org.dcache.nfs.ChimeraNFSException;
3232
import org.dcache.nfs.status.BadSeqidException;
33+
import org.dcache.nfs.status.BadSessionException;
3334
import org.dcache.nfs.status.BadStateidException;
3435
import org.dcache.nfs.status.StaleClientidException;
3536
import org.dcache.nfs.v4.xdr.seqid4;
3637

3738
import static org.dcache.nfs.v4.NfsTestUtils.createClient;
3839
import org.dcache.nfs.v4.xdr.clientid4;
40+
import org.dcache.nfs.v4.xdr.sessionid4;
3941

4042
public class NFSv4StateHandlerTest {
4143

@@ -128,4 +130,57 @@ public void testInstanceIdByStateid() throws UnknownHostException, ChimeraNFSExc
128130
}
129131
}
130132

133+
@Test
134+
public void testGetClientByStateid() throws Exception {
135+
NFS4State state = _client.createState(_owner);
136+
stateid4 stateid = state.stateid();
137+
state.confirm();
138+
139+
assertSame(_client, _stateHandler.getClientIdByStateId(stateid));
140+
}
141+
142+
@Test(expected = BadStateidException.class)
143+
public void testGetClientByBadStateid() throws Exception {
144+
stateid4 stateid = new stateid4(new byte[12], 1);
145+
146+
_stateHandler.getClientIdByStateId(stateid);
147+
}
148+
149+
@Test
150+
public void testGetClientBySessionId() throws Exception {
151+
NFSv41Session session = _client.createSession(1, 8192, 8192, 32, 32);
152+
153+
assertSame(_client, _stateHandler.getClient(session.id()));
154+
}
155+
156+
@Test(expected = BadSessionException.class)
157+
public void testGetClientByBadSession() throws Exception {
158+
sessionid4 sesssion = new sessionid4(new byte[12]);
159+
160+
_stateHandler.getClient(sesssion);
161+
}
162+
163+
@Test
164+
public void testGetClients() throws Exception {
165+
assertEquals(1, _stateHandler.getClients().size()); // created in setUp
166+
}
167+
168+
@Test
169+
public void testGetClientsAfterRemove() throws Exception {
170+
// one client created in setUp
171+
_stateHandler.removeClient(_client);
172+
assertEquals(0, _stateHandler.getClients().size());
173+
}
174+
175+
@Test
176+
public void testGetConfirmedClientById() throws Exception {
177+
_client.setConfirmed();
178+
assertSame(_client, _stateHandler.getConfirmedClient(_client.getId()));
179+
}
180+
181+
@Test(expected = StaleClientidException.class)
182+
public void testGetUnconfirmedClientById() throws Exception {
183+
_stateHandler.getConfirmedClient(_client.getId());
184+
}
185+
131186
}

0 commit comments

Comments
 (0)