Skip to content

Commit

Permalink
test: add OperationLAYOUTCOMMITTest
Browse files Browse the repository at this point in the history
Motivation:
improve test coverage

Modification:
Add OperationLAYOUTCOMMITTest to test leyout commit with read-only open
state.

Result:
better code coverage.

Acked-by: Paul Millar
Target: master
  • Loading branch information
kofemann committed Jul 8, 2019
1 parent 9d9a930 commit c37b716
Showing 1 changed file with 65 additions and 0 deletions.
@@ -0,0 +1,65 @@
package org.dcache.nfs.v4;

import java.nio.charset.StandardCharsets;
import java.util.OptionalLong;
import org.dcache.nfs.status.BadLayoutException;
import org.dcache.nfs.v4.xdr.nfs_fh4;
import org.dcache.nfs.vfs.Inode;
import org.junit.Before;
import org.junit.Test;

import org.dcache.nfs.v4.client.CompoundBuilder;
import org.dcache.nfs.v4.xdr.COMPOUND4args;
import org.dcache.nfs.v4.xdr.layouttype4;
import org.dcache.nfs.v4.xdr.seqid4;
import org.dcache.nfs.v4.xdr.stateid4;
import org.dcache.nfs.vfs.VirtualFileSystem;

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.mockito.Mockito.mock;

public class OperationLAYOUTCOMMITTest {

private final Inode inode = Inode.forFile(new byte[]{1, 2, 3, 4});
private final nfs_fh4 fh = new nfs_fh4(inode.toNfsHandle());

private NFSv4StateHandler sh;
private VirtualFileSystem vfs;
private NFSv41DeviceManager dm;

@Before
public void setUp() {
sh = new NFSv4StateHandler();
vfs = mock(VirtualFileSystem.class);
dm = mock(NFSv41DeviceManager.class);
}

@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);

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();

execute(context, layoutCommit);
}
}

0 comments on commit c37b716

Please sign in to comment.