|
30 | 30 | import java.nio.charset.StandardCharsets;
|
31 | 31 | import org.dcache.nfs.ChimeraNFSException;
|
32 | 32 | import org.dcache.nfs.status.BadSeqidException;
|
| 33 | +import org.dcache.nfs.status.BadSessionException; |
33 | 34 | import org.dcache.nfs.status.BadStateidException;
|
34 | 35 | import org.dcache.nfs.status.StaleClientidException;
|
35 | 36 | import org.dcache.nfs.v4.xdr.seqid4;
|
36 | 37 |
|
37 | 38 | import static org.dcache.nfs.v4.NfsTestUtils.createClient;
|
38 | 39 | import org.dcache.nfs.v4.xdr.clientid4;
|
| 40 | +import org.dcache.nfs.v4.xdr.sessionid4; |
39 | 41 |
|
40 | 42 | public class NFSv4StateHandlerTest {
|
41 | 43 |
|
@@ -128,4 +130,57 @@ public void testInstanceIdByStateid() throws UnknownHostException, ChimeraNFSExc
|
128 | 130 | }
|
129 | 131 | }
|
130 | 132 |
|
| 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 | + |
131 | 186 | }
|
0 commit comments