Search in sources :

Example 11 with WRITE3Response

use of org.apache.hadoop.nfs.nfs3.response.WRITE3Response in project hadoop by apache.

the class TestRpcProgramNfs3 method testWrite.

@Test(timeout = 60000)
public void testWrite() throws Exception {
    HdfsFileStatus status = nn.getRpcServer().getFileInfo("/tmp/bar");
    long dirId = status.getFileId();
    FileHandle handle = new FileHandle(dirId);
    byte[] buffer = new byte[10];
    for (int i = 0; i < 10; i++) {
        buffer[i] = (byte) i;
    }
    WRITE3Request writeReq = new WRITE3Request(handle, 0, 10, WriteStableHow.DATA_SYNC, ByteBuffer.wrap(buffer));
    XDR xdr_req = new XDR();
    writeReq.serialize(xdr_req);
    // Attempt by an unpriviledged user should fail.
    WRITE3Response response1 = nfsd.write(xdr_req.asReadOnlyWrap(), null, 1, securityHandlerUnpriviledged, new InetSocketAddress("localhost", 1234));
    assertEquals("Incorrect return code:", Nfs3Status.NFS3ERR_ACCES, response1.getStatus());
    // Attempt by a priviledged user should pass.
    WRITE3Response response2 = nfsd.write(xdr_req.asReadOnlyWrap(), null, 1, securityHandler, new InetSocketAddress("localhost", 1234));
    assertEquals("Incorrect response:", null, response2);
}
Also used : FileHandle(org.apache.hadoop.nfs.nfs3.FileHandle) InetSocketAddress(java.net.InetSocketAddress) HdfsFileStatus(org.apache.hadoop.hdfs.protocol.HdfsFileStatus) XDR(org.apache.hadoop.oncrpc.XDR) WRITE3Request(org.apache.hadoop.nfs.nfs3.request.WRITE3Request) WRITE3Response(org.apache.hadoop.nfs.nfs3.response.WRITE3Response) Test(org.junit.Test)

Aggregations

WRITE3Response (org.apache.hadoop.nfs.nfs3.response.WRITE3Response)10 XDR (org.apache.hadoop.oncrpc.XDR)8 WccData (org.apache.hadoop.nfs.nfs3.response.WccData)7 VerifierNone (org.apache.hadoop.oncrpc.security.VerifierNone)6 IOException (java.io.IOException)5 FileHandle (org.apache.hadoop.nfs.nfs3.FileHandle)5 WriteStableHow (org.apache.hadoop.nfs.nfs3.Nfs3Constant.WriteStableHow)5 WccAttr (org.apache.hadoop.nfs.nfs3.response.WccAttr)4 Nfs3FileAttributes (org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes)3 WRITE3Request (org.apache.hadoop.nfs.nfs3.request.WRITE3Request)3 InetSocketAddress (java.net.InetSocketAddress)2 HdfsFileStatus (org.apache.hadoop.hdfs.protocol.HdfsFileStatus)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 File (java.io.File)1 RandomAccessFile (java.io.RandomAccessFile)1 ClosedChannelException (java.nio.channels.ClosedChannelException)1 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)1 Path (org.apache.hadoop.fs.Path)1 DFSClient (org.apache.hadoop.hdfs.DFSClient)1 HdfsDataOutputStream (org.apache.hadoop.hdfs.client.HdfsDataOutputStream)1