Skip to content

Commit

Permalink
test: improve test coverage of NFSv4StateHandler
Browse files Browse the repository at this point in the history
Acked-by: Paul Millar
Target: master
  • Loading branch information
kofemann committed Dec 10, 2018
1 parent 2a43633 commit c4e1219
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions core/src/test/java/org/dcache/nfs/v4/NFSv4StateHandlerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@
import java.nio.charset.StandardCharsets;
import org.dcache.nfs.ChimeraNFSException;
import org.dcache.nfs.status.BadSeqidException;
import org.dcache.nfs.status.BadSessionException;
import org.dcache.nfs.status.BadStateidException;
import org.dcache.nfs.status.StaleClientidException;
import org.dcache.nfs.v4.xdr.seqid4;

import static org.dcache.nfs.v4.NfsTestUtils.createClient;
import org.dcache.nfs.v4.xdr.clientid4;
import org.dcache.nfs.v4.xdr.sessionid4;

public class NFSv4StateHandlerTest {

Expand Down Expand Up @@ -128,4 +130,57 @@ public void testInstanceIdByStateid() throws UnknownHostException, ChimeraNFSExc
}
}

@Test
public void testGetClientByStateid() throws Exception {
NFS4State state = _client.createState(_owner);
stateid4 stateid = state.stateid();
state.confirm();

assertSame(_client, _stateHandler.getClientIdByStateId(stateid));
}

@Test(expected = BadStateidException.class)
public void testGetClientByBadStateid() throws Exception {
stateid4 stateid = new stateid4(new byte[12], 1);

_stateHandler.getClientIdByStateId(stateid);
}

@Test
public void testGetClientBySessionId() throws Exception {
NFSv41Session session = _client.createSession(1, 8192, 8192, 32, 32);

assertSame(_client, _stateHandler.getClient(session.id()));
}

@Test(expected = BadSessionException.class)
public void testGetClientByBadSession() throws Exception {
sessionid4 sesssion = new sessionid4(new byte[12]);

_stateHandler.getClient(sesssion);
}

@Test
public void testGetClients() throws Exception {
assertEquals(1, _stateHandler.getClients().size()); // created in setUp
}

@Test
public void testGetClientsAfterRemove() throws Exception {
// one client created in setUp
_stateHandler.removeClient(_client);
assertEquals(0, _stateHandler.getClients().size());
}

@Test
public void testGetConfirmedClientById() throws Exception {
_client.setConfirmed();
assertSame(_client, _stateHandler.getConfirmedClient(_client.getId()));
}

@Test(expected = StaleClientidException.class)
public void testGetUnconfirmedClientById() throws Exception {
_stateHandler.getConfirmedClient(_client.getId());
}

}

0 comments on commit c4e1219

Please sign in to comment.