Commit 704bc6cd authored by Tigran Mkrtchyan's avatar Tigran Mkrtchyan
Browse files

test: improve layoutcommit test coverage

Acked-by: Paul Millar
Target: master
parent 78c1d752
......@@ -3,6 +3,7 @@ package org.dcache.nfs.v4;
import java.nio.charset.StandardCharsets;
import java.util.OptionalLong;
import org.dcache.nfs.status.BadLayoutException;
import org.dcache.nfs.status.NotSuppException;
import org.dcache.nfs.v4.xdr.nfs_fh4;
import org.dcache.nfs.vfs.Inode;
import org.junit.Before;
......@@ -10,6 +11,7 @@ import org.junit.Test;
import org.dcache.nfs.v4.client.CompoundBuilder;
import org.dcache.nfs.v4.xdr.COMPOUND4args;
import org.dcache.nfs.v4.xdr.COMPOUND4res;
import org.dcache.nfs.v4.xdr.layouttype4;
import org.dcache.nfs.v4.xdr.seqid4;
import org.dcache.nfs.v4.xdr.stateid4;
......@@ -19,7 +21,14 @@ import static org.dcache.nfs.v4.NfsTestUtils.createClient;
import static org.dcache.nfs.v4.NfsTestUtils.execute;
import static org.dcache.nfs.v4.NfsTestUtils.generateRpcCall;
import static org.dcache.nfs.v4.xdr.nfs4_prot.OPEN4_SHARE_ACCESS_READ;
import static org.dcache.nfs.v4.xdr.nfs4_prot.OPEN4_SHARE_ACCESS_WRITE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class OperationLAYOUTCOMMITTest {
......@@ -29,20 +38,25 @@ public class OperationLAYOUTCOMMITTest {
private NFSv4StateHandler sh;
private VirtualFileSystem vfs;
private NFSv41DeviceManager dm;
private NFS4Client client;
private NFSv41Session session;
private StateOwner stateOwner;
@Before
public void setUp() {
public void setUp() throws Exception {
sh = new NFSv4StateHandler();
vfs = mock(VirtualFileSystem.class);
dm = mock(NFSv41DeviceManager.class);
client = createClient(sh);
session = client.createSession(1, 8196, 8192, 128, 16);
stateOwner = client.getOrCreateOwner("client".getBytes(StandardCharsets.UTF_8), new seqid4(0));
}
@Test(expected = BadLayoutException.class)
public void testCommitOnReadLayout() throws Exception {
NFS4Client client = createClient(sh);
NFSv41Session session = client.createSession(1, 8196, 8192, 128, 16);
StateOwner stateOwner = client.getOrCreateOwner("client1".getBytes(StandardCharsets.UTF_8), new seqid4(0));
stateid4 openState = sh.getFileTracker().addOpen(client, stateOwner, inode, OPEN4_SHARE_ACCESS_READ, 0);
......@@ -62,4 +76,82 @@ public class OperationLAYOUTCOMMITTest {
execute(context, layoutCommit);
}
@Test
public void testReturnNewSizeOnFileChange() throws Exception {
when(dm.layoutCommit(any(), any())).thenReturn(OptionalLong.of(100));
StateOwner stateOwner = client.getOrCreateOwner("client1".getBytes(StandardCharsets.UTF_8), new seqid4(0));
stateid4 openState = sh.getFileTracker().addOpen(client, stateOwner, inode, OPEN4_SHARE_ACCESS_WRITE, 0);
COMPOUND4args layoutCommit = new CompoundBuilder()
.withSequence(false, session.id(), 0, 0, 1)
.withPutfh(fh)
.withLayoutcommit(0, 100, true, openState, OptionalLong.of(100), layouttype4.LAYOUT4_FLEX_FILES, new byte[0])
.build();
CompoundContext context = new CompoundContextBuilder()
.withStateHandler(sh)
.withFs(vfs)
.withMinorversion(1)
.withDeviceManager(dm)
.withCall(generateRpcCall())
.build();
COMPOUND4res res = execute(context, layoutCommit);
assertTrue("new size is not set", res.resarray.get(2)
.oplayoutcommit.locr_resok4.locr_newsize.ns_sizechanged);
assertEquals("invalid size returned", 100L, res.resarray.get(2)
.oplayoutcommit.locr_resok4.locr_newsize.ns_size.value);
}
@Test
public void testNoNewSizeOnNoFileChange() throws Exception {
when(dm.layoutCommit(any(), any())).thenReturn(OptionalLong.empty());
StateOwner stateOwner = client.getOrCreateOwner("client1".getBytes(StandardCharsets.UTF_8), new seqid4(0));
stateid4 openState = sh.getFileTracker().addOpen(client, stateOwner, inode, OPEN4_SHARE_ACCESS_WRITE, 0);
COMPOUND4args layoutCommit = new CompoundBuilder()
.withSequence(false, session.id(), 0, 0, 1)
.withPutfh(fh)
.withLayoutcommit(0, 100, true, openState, OptionalLong.of(100), layouttype4.LAYOUT4_FLEX_FILES, new byte[0])
.build();
CompoundContext context = new CompoundContextBuilder()
.withStateHandler(sh)
.withFs(vfs)
.withMinorversion(1)
.withDeviceManager(dm)
.withCall(generateRpcCall())
.build();
COMPOUND4res res = execute(context, layoutCommit);
assertFalse("unexpected new size", res.resarray.get(2)
.oplayoutcommit.locr_resok4.locr_newsize.ns_sizechanged);
}
@Test(expected = NotSuppException.class)
public void testNoPnfsConfigured() throws Exception {
stateid4 openState = sh.getFileTracker().addOpen(client, stateOwner, inode, OPEN4_SHARE_ACCESS_WRITE, 0);
COMPOUND4args layoutCommit = new CompoundBuilder()
.withSequence(false, session.id(), 0, 0, 1)
.withPutfh(fh)
.withLayoutcommit(0, 100, true, openState, OptionalLong.of(100), layouttype4.LAYOUT4_FLEX_FILES, new byte[0])
.build();
CompoundContext context = new CompoundContextBuilder()
.withStateHandler(sh)
.withFs(vfs)
.withMinorversion(1)
.withCall(generateRpcCall())
.build();
execute(context, layoutCommit);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment