Commit 78c1d752 authored by Tigran Mkrtchyan's avatar Tigran Mkrtchyan
Browse files

test: improve open operation test coverage

Acked-by: Paul Millar
Target: master
parent e358afcb
package org.dcache.nfs.v4;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.OptionalLong;
import org.dcache.auth.Subjects;
import org.dcache.nfs.status.BadLayoutException;
import org.dcache.nfs.status.GraceException;
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.COMPOUND4res;
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.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.dcache.nfs.vfs.DirectoryEntry;
import org.dcache.nfs.vfs.DirectoryStream;
import org.dcache.nfs.vfs.DummyVFS;
import org.dcache.nfs.vfs.Stat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class OperationOPENTest {
private NFSv4StateHandler sh;
private VirtualFileSystem vfs;
private Inode fsRoot;
private NFS4Client client;
private NFSv41Session session;
@Before
public void setUp() throws IOException {
sh = new NFSv4StateHandler();
vfs = new DummyVFS();
fsRoot = vfs.getRootInode();
client = createClient(sh);
session = client.createSession(1, 8196, 8192, 128, 16);
}
@Test(expected = GraceException.class)
public void testClientNeedGrace() throws Exception {
COMPOUND4args openArgs = new CompoundBuilder()
.withSequence(false, session.id(), 0, 0, 1)
.withPutfh(new nfs_fh4(fsRoot.toNfsHandle()))
.withOpen("file", 1, client.getId(), OPEN4_SHARE_ACCESS_READ)
.build();
CompoundContext context = new CompoundContextBuilder()
.withStateHandler(sh)
.withFs(vfs)
.withMinorversion(1)
.withCall(generateRpcCall())
.build();
execute(context, openArgs);
}
@Test
public void testReturnFhOnOpen() throws Exception {
client.reclaimComplete();
COMPOUND4args openArgs = new CompoundBuilder()
.withSequence(false, session.id(), 0, 0, 1)
.withPutfh(new nfs_fh4(fsRoot.toNfsHandle()))
.withOpen("file", 1, client.getId(), OPEN4_SHARE_ACCESS_READ)
.withGetfh()
.build();
CompoundContext context = new CompoundContextBuilder()
.withStateHandler(sh)
.withFs(vfs)
.withMinorversion(1)
.withCall(generateRpcCall())
.build();
Inode inode = vfs.create(fsRoot, Stat.Type.REGULAR, "file", Subjects.ROOT, 0644);
COMPOUND4res res = execute(context, openArgs);
assertEquals("wrong file handle", inode, new Inode(res.resarray.get(3).opgetfh.resok4.object.value));
}
@Test
public void testReturnNewFhOnCreate() throws Exception {
client.reclaimComplete();
COMPOUND4args openArgs = new CompoundBuilder()
.withSequence(false, session.id(), 0, 0, 1)
.withPutfh(new nfs_fh4(fsRoot.toNfsHandle()))
.withOpenCreate("file", 1, client.getId(), OPEN4_SHARE_ACCESS_READ)
.withGetfh()
.build();
CompoundContext context = new CompoundContextBuilder()
.withStateHandler(sh)
.withFs(vfs)
.withMinorversion(1)
.withCall(generateRpcCall())
.build();
COMPOUND4res res = execute(context, openArgs);
assertTrue("bad file handle", res.resarray.get(3).opgetfh.resok4.object.value.length > 0);
}
}
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