hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ji...@apache.org
Subject svn commit: r1501851 - in /hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src: main/java/org/apache/hadoop/mount/ main/java/org/apache/hadoop/nfs/nfs3/ main/java/org/apache/hadoop/oncrpc/ main/java/org/apache/hadoop/portmap/ test/java/org/apache/...
Date Wed, 10 Jul 2013 17:01:28 GMT
Author: jing9
Date: Wed Jul 10 17:01:28 2013
New Revision: 1501851

URL: http://svn.apache.org/r1501851
Log:
HDFS-4962. Use enum for nfs constants. Contributed by Tsz Wo (Nicholas) SZE.

Modified:
    hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/mount/MountInterface.java
    hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/mount/MountResponse.java
    hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/Nfs3Constant.java
    hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/RpcAcceptedReply.java
    hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/RpcCall.java
    hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/RpcDeniedReply.java
    hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/RpcMessage.java
    hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/RpcReply.java
    hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/portmap/PortmapInterface.java
    hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/oncrpc/TestRpcAcceptedReply.java
    hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/oncrpc/TestRpcCall.java
    hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/oncrpc/TestRpcDeniedReply.java
    hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/oncrpc/TestRpcMessage.java
    hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/oncrpc/TestRpcReply.java

Modified: hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/mount/MountInterface.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/mount/MountInterface.java?rev=1501851&r1=1501850&r2=1501851&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/mount/MountInterface.java
(original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/mount/MountInterface.java
Wed Jul 10 17:01:28 2013
@@ -26,14 +26,31 @@ import org.apache.hadoop.oncrpc.XDR;
  * requests. See RFC 1094 for more details.
  */
 public interface MountInterface {
-  public static int MNTPROC_NULL = 0;
-  public static int MNTPROC_MNT = 1;
-  public static int MNTPROC_DUMP = 2;
-  public static int MNTPROC_UMNT = 3;
-  public static int MNTPROC_UMNTALL = 4;
-  public static int MNTPROC_EXPORT = 5;
-  public static int MNTPROC_EXPORTALL = 6;
-  public static int MNTPROC_PATHCONF = 7;
+  /** Mount procedures */
+  public static enum MNTPROC {
+    // the order of the values below are significant.
+    NULL,
+    MNT,
+    DUMP,
+    UMNT,
+    UMNTALL,
+    EXPORT,
+    EXPORTALL,
+    PATHCONF;
+
+    /** @return the int value representing the procedure. */
+    public int getValue() {
+      return ordinal();
+    }
+
+    /** @return the procedure corresponding to the value. */
+    public static MNTPROC fromValue(int value) {
+      if (value < 0 || value >= values().length) {
+        return null;
+      }
+      return values()[value];
+    }
+  }
 
   /** MNTPROC_NULL - Do Nothing */
   public XDR nullOp(XDR out, int xid, InetAddress client);

Modified: hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/mount/MountResponse.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/mount/MountResponse.java?rev=1501851&r1=1501850&r2=1501851&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/mount/MountResponse.java
(original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/mount/MountResponse.java
Wed Jul 10 17:01:28 2013
@@ -33,7 +33,7 @@ public class MountResponse {
   private MountResponse() {
   }
   
-  /** Response for RPC call {@link MountInterface#MNTPROC_MNT} */
+  /** Response for RPC call {@link MountInterface.MNTPROC#MNT} */
   public static XDR writeMNTResponse(int status, XDR xdr, int xid,
       byte[] handle) {
     RpcAcceptedReply.voidReply(xdr, xid);
@@ -48,7 +48,7 @@ public class MountResponse {
     return xdr;
   }
 
-  /** Response for RPC call {@link MountInterface#MNTPROC_DUMP} */
+  /** Response for RPC call {@link MountInterface.MNTPROC#DUMP} */
   public static XDR writeMountList(XDR xdr, int xid, List<MountEntry> mounts) {
     RpcAcceptedReply.voidReply(xdr, xid);
     for (MountEntry mountEntry : mounts) {
@@ -60,7 +60,7 @@ public class MountResponse {
     return xdr;
   }
 
-  /** Response for RPC call {@link MountInterface#MNTPROC_EXPORT} */
+  /** Response for RPC call {@link MountInterface.MNTPROC#EXPORT} */
   public static XDR writeExportList(XDR xdr, int xid, List<String> exports) {
     RpcAcceptedReply.voidReply(xdr, xid);
     for (String export : exports) {

Modified: hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/Nfs3Constant.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/Nfs3Constant.java?rev=1501851&r1=1501850&r2=1501851&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/Nfs3Constant.java
(original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/nfs3/Nfs3Constant.java
Wed Jul 10 17:01:28 2013
@@ -17,6 +17,7 @@
  */
 package org.apache.hadoop.nfs.nfs3;
 
+
 /**
  * Some constants for NFSv3
  */
@@ -34,28 +35,58 @@ public class Nfs3Constant {
   public final static int VERSION = 3;
   
   // The procedures
-  public final static int NFSPROC3_NULL = 0;
-  public final static int NFSPROC3_GETATTR = 1;
-  public final static int NFSPROC3_SETATTR = 2;
-  public final static int NFSPROC3_LOOKUP = 3;
-  public final static int NFSPROC3_ACCESS = 4;
-  public final static int NFSPROC3_READLINK = 5;
-  public final static int NFSPROC3_READ = 6;
-  public final static int NFSPROC3_WRITE = 7;
-  public final static int NFSPROC3_CREATE = 8;
-  public final static int NFSPROC3_MKDIR = 9;
-  public final static int NFSPROC3_SYMLINK = 10;
-  public final static int NFSPROC3_MKNOD = 11;
-  public final static int NFSPROC3_REMOVE = 12;
-  public final static int NFSPROC3_RMDIR = 13;
-  public final static int NFSPROC3_RENAME = 14;
-  public final static int NFSPROC3_LINK = 15;
-  public final static int NFSPROC3_READDIR = 16;
-  public final static int NFSPROC3_READDIRPLUS = 17;
-  public final static int NFSPROC3_FSSTAT = 18;
-  public final static int NFSPROC3_FSINFO = 19;
-  public final static int NFSPROC3_PATHCONF = 20;
-  public final static int NFSPROC3_COMMIT = 21;
+  public static enum NFSPROC3 {
+    // the order of the values below are significant.
+    NULL,
+    GETATTR,
+    SETATTR,
+    LOOKUP,
+    ACCESS,
+    READLINK,
+    READ,
+    WRITE,
+    CREATE(false),
+    MKDIR(false),
+    SYMLINK(false),
+    MKNOD(false),
+    REMOVE(false),
+    RMDIR(false),
+    RENAME(false),
+    LINK(false),
+    READDIR,
+    READDIRPLUS,
+    FSSTAT,
+    FSINFO,
+    PATHCONF,
+    COMMIT;
+
+    private final boolean isIdempotent;
+
+    private NFSPROC3(boolean isIdempotent) {
+      this.isIdempotent = isIdempotent;
+    }
+
+    private NFSPROC3() {
+      this(true);
+    }
+
+    public boolean isIdempotent() {
+      return isIdempotent;
+    }
+
+    /** @return the int value representing the procedure. */
+    public int getValue() {
+      return ordinal();
+    }
+
+    /** @return the procedure corresponding to the value. */
+    public static NFSPROC3 fromValue(int value) {
+      if (value < 0 || value >= values().length) {
+        return null;
+      }
+      return values()[value];
+    }
+  }
   
   // The maximum size in bytes of the opaque file handle.
   public final static int NFS3_FHSIZE = 64;
@@ -125,16 +156,13 @@ public class Nfs3Constant {
 
   /** Write call flavors */
   public enum WriteStableHow {
-    UNSTABLE(0), DATA_SYNC(1), FILE_SYNC(2);
-
-    private final int id;
-
-    WriteStableHow(int id) {
-      this.id = id;
-    }
+    // the order of the values below are significant.
+    UNSTABLE,
+    DATA_SYNC,
+    FILE_SYNC;
 
     public int getValue() {
-      return id;
+      return ordinal();
     }
 
     public static WriteStableHow fromValue(int id) {

Modified: hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/RpcAcceptedReply.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/RpcAcceptedReply.java?rev=1501851&r1=1501850&r2=1501851&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/RpcAcceptedReply.java
(original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/RpcAcceptedReply.java
Wed Jul 10 17:01:28 2013
@@ -25,39 +25,34 @@ import org.apache.hadoop.oncrpc.RpcAuthI
  */
 public class RpcAcceptedReply extends RpcReply {
   public enum AcceptState {
-    SUCCESS(0), /* RPC executed successfully */
-    PROG_UNAVAIL(1), /* remote hasn't exported program */
-    PROG_MISMATCH(2), /* remote can't support version # */
-    PROC_UNAVAIL(3), /* program can't support procedure */
-    GARBAGE_ARGS(4), /* procedure can't decode params */
-    SYSTEM_ERR(5); /* e.g. memory allocation failure */
+    // the order of the values below are significant.
+    SUCCESS, /* RPC executed successfully */
+    PROG_UNAVAIL, /* remote hasn't exported program */
+    PROG_MISMATCH, /* remote can't support version # */
+    PROC_UNAVAIL, /* program can't support procedure */
+    GARBAGE_ARGS, /* procedure can't decode params */
+    SYSTEM_ERR; /* e.g. memory allocation failure */
     
-    private final int value;
-
-    AcceptState(int value) {
-      this.value = value;
-    }
-
     public static AcceptState fromValue(int value) {
       return values()[value];
     }
 
     public int getValue() {
-      return value;
+      return ordinal();
     }
   };
 
   private final RpcAuthInfo verifier;
   private final AcceptState acceptState;
 
-  RpcAcceptedReply(int xid, int messageType, ReplyState state,
+  RpcAcceptedReply(int xid, RpcMessage.Type messageType, ReplyState state,
       RpcAuthInfo verifier, AcceptState acceptState) {
     super(xid, messageType, state);
     this.verifier = verifier;
     this.acceptState = acceptState;
   }
 
-  public static RpcAcceptedReply read(int xid, int messageType,
+  public static RpcAcceptedReply read(int xid, RpcMessage.Type messageType,
       ReplyState replyState, XDR xdr) {
     RpcAuthInfo verifier = RpcAuthInfo.read(xdr);
     AcceptState acceptState = AcceptState.fromValue(xdr.readInt());
@@ -79,7 +74,7 @@ public class RpcAcceptedReply extends Rp
   
   public static XDR voidReply(XDR xdr, int xid, AcceptState acceptState) {
     xdr.writeInt(xid);
-    xdr.writeInt(RpcMessage.RPC_REPLY);
+    xdr.writeInt(RpcMessage.Type.RPC_REPLY.getValue());
     xdr.writeInt(ReplyState.MSG_ACCEPTED.getValue());
     xdr.writeInt(AuthFlavor.AUTH_NONE.getValue());
     xdr.writeVariableOpaque(new byte[0]);

Modified: hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/RpcCall.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/RpcCall.java?rev=1501851&r1=1501850&r2=1501851&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/RpcCall.java
(original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/RpcCall.java
Wed Jul 10 17:01:28 2013
@@ -33,7 +33,7 @@ public class RpcCall extends RpcMessage 
   private final RpcAuthInfo credential;
   private final RpcAuthInfo verifier;
 
-  protected RpcCall(int xid, int messageType, int rpcVersion, int program,
+  protected RpcCall(int xid, RpcMessage.Type messageType, int rpcVersion, int program,
       int version, int procedure, RpcAuthInfo credential, RpcAuthInfo verifier) {
     super(xid, messageType);
     this.rpcVersion = rpcVersion;
@@ -56,7 +56,7 @@ public class RpcCall extends RpcMessage 
   }
   
   public void validate() {
-    validateMessageType(RPC_CALL);
+    validateMessageType(RpcMessage.Type.RPC_CALL);
     validateRpcVersion();
     // Validate other members
     // Throw exception if validation fails
@@ -88,7 +88,8 @@ public class RpcCall extends RpcMessage 
   }
   
   public static RpcCall read(XDR xdr) {
-    return new RpcCall(xdr.readInt(), xdr.readInt(), xdr.readInt(), xdr.readInt(),
+    return new RpcCall(xdr.readInt(), RpcMessage.Type.fromValue(xdr.readInt()),
+        xdr.readInt(), xdr.readInt(),
         xdr.readInt(), xdr.readInt(), RpcAuthInfo.read(xdr),
         RpcAuthInfo.read(xdr));
   }
@@ -96,7 +97,7 @@ public class RpcCall extends RpcMessage 
   public static void write(XDR out, int xid, int program, int progVersion,
       int procedure) {
     out.writeInt(xid);
-    out.writeInt(RpcMessage.RPC_CALL);
+    out.writeInt(RpcMessage.Type.RPC_CALL.getValue());
     out.writeInt(2);
     out.writeInt(program);
     out.writeInt(progVersion);
@@ -105,7 +106,7 @@ public class RpcCall extends RpcMessage 
   
   @Override
   public String toString() {
-    return String.format("Xid:%d, messageType:%d, rpcVersion:%d, program:%d,"
+    return String.format("Xid:%d, messageType:%s, rpcVersion:%d, program:%d,"
         + " version:%d, procedure:%d, credential:%s, verifier:%s", xid,
         messageType, rpcVersion, program, version, procedure,
         credential.toString(), verifier.toString());

Modified: hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/RpcDeniedReply.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/RpcDeniedReply.java?rev=1501851&r1=1501850&r2=1501851&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/RpcDeniedReply.java
(original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/RpcDeniedReply.java
Wed Jul 10 17:01:28 2013
@@ -25,16 +25,12 @@ import org.apache.hadoop.oncrpc.RpcAuthI
  */
 public class RpcDeniedReply extends RpcReply {
   public enum RejectState {
-    RPC_MISMATCH(0), AUTH_ERROR(1);
-
-    private final int value;
-
-    RejectState(int value) {
-      this.value = value;
-    }
+    // the order of the values below are significant.
+    RPC_MISMATCH,
+    AUTH_ERROR;
 
     int getValue() {
-      return value;
+      return ordinal();
     }
 
     static RejectState fromValue(int value) {
@@ -44,13 +40,13 @@ public class RpcDeniedReply extends RpcR
 
   private final RejectState rejectState;
 
-  RpcDeniedReply(int xid, int messageType, ReplyState replyState,
+  RpcDeniedReply(int xid, RpcMessage.Type messageType, ReplyState replyState,
       RejectState rejectState) {
     super(xid, messageType, replyState);
     this.rejectState = rejectState;
   }
 
-  public static RpcDeniedReply read(int xid, int messageType,
+  public static RpcDeniedReply read(int xid, RpcMessage.Type messageType,
       ReplyState replyState, XDR xdr) {
     RejectState rejectState = RejectState.fromValue(xdr.readInt());
     return new RpcDeniedReply(xid, messageType, replyState, rejectState);
@@ -70,7 +66,7 @@ public class RpcDeniedReply extends RpcR
   public static XDR voidReply(XDR xdr, int xid, ReplyState msgAccepted,
       RejectState rejectState) {
     xdr.writeInt(xid);
-    xdr.writeInt(RpcMessage.RPC_REPLY);
+    xdr.writeInt(RpcMessage.Type.RPC_REPLY.getValue());
     xdr.writeInt(msgAccepted.getValue());
     xdr.writeInt(AuthFlavor.AUTH_NONE.getValue());
     xdr.writeVariableOpaque(new byte[0]);

Modified: hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/RpcMessage.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/RpcMessage.java?rev=1501851&r1=1501850&r2=1501851&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/RpcMessage.java
(original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/RpcMessage.java
Wed Jul 10 17:01:28 2013
@@ -21,14 +21,29 @@ package org.apache.hadoop.oncrpc;
  * Represent an RPC message as defined in RFC 1831.
  */
 public abstract class RpcMessage {
-  public static final int RPC_CALL = 0;
-  public static final int RPC_REPLY = 1;
+  /** Message type */
+  public static enum Type {
+    // the order of the values below are significant.
+    RPC_CALL,
+    RPC_REPLY;
+    
+    public int getValue() {
+      return ordinal();
+    }
+
+    public static Type fromValue(int value) {
+      if (value < 0 || value >= values().length) {
+        return null;
+      }
+      return values()[value];
+    }
+  }
 
   protected final int xid;
-  protected final int messageType;
+  protected final Type messageType;
   
-  RpcMessage(int xid, int messageType) {
-    if (messageType != RPC_CALL && messageType != RPC_REPLY) {
+  RpcMessage(int xid, Type messageType) {
+    if (messageType != Type.RPC_CALL && messageType != Type.RPC_REPLY) {
       throw new IllegalArgumentException("Invalid message type " + messageType);
     }
     this.xid = xid;
@@ -39,11 +54,11 @@ public abstract class RpcMessage {
     return xid;
   }
 
-  public int getMessageType() {
+  public Type getMessageType() {
     return messageType;
   }
   
-  protected void validateMessageType(int expected) {
+  protected void validateMessageType(Type expected) {
     if (expected != messageType) {
       throw new IllegalArgumentException("Message type is expected to be "
           + expected + " but got " + messageType);

Modified: hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/RpcReply.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/RpcReply.java?rev=1501851&r1=1501850&r2=1501851&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/RpcReply.java
(original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/oncrpc/RpcReply.java
Wed Jul 10 17:01:28 2013
@@ -23,16 +23,12 @@ package org.apache.hadoop.oncrpc;
 public abstract class RpcReply extends RpcMessage {
   /** RPC reply_stat as defined in RFC 1831 */
   public enum ReplyState {
-    MSG_ACCEPTED(0),
-    MSG_DENIED(1);
-    
-    private final int value;
-    ReplyState(int value) {
-      this.value = value;
-    }
+    // the order of the values below are significant.
+    MSG_ACCEPTED,
+    MSG_DENIED;
     
     int getValue() {
-      return value;
+      return ordinal();
     }
     
     public static ReplyState fromValue(int value) {
@@ -42,15 +38,15 @@ public abstract class RpcReply extends R
   
   private final ReplyState state;
   
-  RpcReply(int xid, int messageType, ReplyState state) {
+  RpcReply(int xid, RpcMessage.Type messageType, ReplyState state) {
     super(xid, messageType);
     this.state = state;
-    validateMessageType(RPC_REPLY);
+    validateMessageType(RpcMessage.Type.RPC_REPLY);
   }
 
   public static RpcReply read(XDR xdr) {
     int xid = xdr.readInt();
-    int messageType = xdr.readInt();
+    final Type messageType = Type.fromValue(xdr.readInt());
     ReplyState stat = ReplyState.fromValue(xdr.readInt());
     switch (stat) {
     case MSG_ACCEPTED:

Modified: hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/portmap/PortmapInterface.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/portmap/PortmapInterface.java?rev=1501851&r1=1501850&r2=1501851&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/portmap/PortmapInterface.java
(original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/portmap/PortmapInterface.java
Wed Jul 10 17:01:28 2013
@@ -25,28 +25,23 @@ import org.apache.hadoop.oncrpc.XDR;
  */
 public interface PortmapInterface {
   public enum Procedure {
-    PMAPPROC_NULL(0),
-    PMAPPROC_SET(1),
-    PMAPPROC_UNSET(2),
-    PMAPPROC_GETPORT(3),
-    PMAPPROC_DUMP(4),
-    PMAPPROC_CALLIT(5),
-    PMAPPROC_GETTIME(6),
-    PMAPPROC_UADDR2TADDR(7),
-    PMAPPROC_TADDR2UADDR(8),
-    PMAPPROC_GETVERSADDR(9),
-    PMAPPROC_INDIRECT(10),
-    PMAPPROC_GETADDRLIST(11),
-    PMAPPROC_GETSTAT(12);
-    
-    private final int value;
-    
-    Procedure(int value) {
-      this.value = value;
-    }
+    // the order of the values below are significant.
+    PMAPPROC_NULL,
+    PMAPPROC_SET,
+    PMAPPROC_UNSET,
+    PMAPPROC_GETPORT,
+    PMAPPROC_DUMP,
+    PMAPPROC_CALLIT,
+    PMAPPROC_GETTIME,
+    PMAPPROC_UADDR2TADDR,
+    PMAPPROC_TADDR2UADDR,
+    PMAPPROC_GETVERSADDR,
+    PMAPPROC_INDIRECT,
+    PMAPPROC_GETADDRLIST,
+    PMAPPROC_GETSTAT;
     
     public int getValue() {
-      return value;
+      return ordinal();
     }
     
     public static Procedure fromValue(int value) {

Modified: hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/oncrpc/TestRpcAcceptedReply.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/oncrpc/TestRpcAcceptedReply.java?rev=1501851&r1=1501850&r2=1501851&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/oncrpc/TestRpcAcceptedReply.java
(original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/oncrpc/TestRpcAcceptedReply.java
Wed Jul 10 17:01:28 2013
@@ -46,10 +46,10 @@ public class TestRpcAcceptedReply {
   @Test
   public void testConstructor() {
     RpcAuthInfo verifier = new RpcAuthInfo(AuthFlavor.AUTH_NONE, new byte[0]);
-    RpcAcceptedReply reply = new RpcAcceptedReply(0, RpcMessage.RPC_REPLY,
+    RpcAcceptedReply reply = new RpcAcceptedReply(0, RpcMessage.Type.RPC_REPLY,
         ReplyState.MSG_ACCEPTED, verifier, AcceptState.SUCCESS);
     assertEquals(0, reply.getXid());
-    assertEquals(RpcMessage.RPC_REPLY, reply.getMessageType());
+    assertEquals(RpcMessage.Type.RPC_REPLY, reply.getMessageType());
     assertEquals(ReplyState.MSG_ACCEPTED, reply.getState());
     assertEquals(verifier, reply.getVerifier());
     assertEquals(AcceptState.SUCCESS, reply.getAcceptState());

Modified: hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/oncrpc/TestRpcCall.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/oncrpc/TestRpcCall.java?rev=1501851&r1=1501850&r2=1501851&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/oncrpc/TestRpcCall.java
(original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/oncrpc/TestRpcCall.java
Wed Jul 10 17:01:28 2013
@@ -34,9 +34,10 @@ public class TestRpcCall {
     int program = 2;
     int version = 3;
     int procedure = 4;
-    RpcCall call = new RpcCall(0, RpcMessage.RPC_CALL, rpcVersion, program, version, procedure,
credential, verifier);
+    RpcCall call = new RpcCall(0, RpcMessage.Type.RPC_CALL, rpcVersion, program,
+        version, procedure, credential, verifier);
     assertEquals(0, call.getXid());
-    assertEquals(RpcMessage.RPC_CALL, call.getMessageType());
+    assertEquals(RpcMessage.Type.RPC_CALL, call.getMessageType());
     assertEquals(rpcVersion, call.getRpcVersion());
     assertEquals(program, call.getProgram());
     assertEquals(version, call.getVersion());
@@ -48,12 +49,12 @@ public class TestRpcCall {
   @Test(expected=IllegalArgumentException.class)
   public void testInvalidRpcVersion() {
     int invalidRpcVersion = 3;
-    new RpcCall(0, RpcMessage.RPC_CALL, invalidRpcVersion, 2, 3, 4, null, null);
+    new RpcCall(0, RpcMessage.Type.RPC_CALL, invalidRpcVersion, 2, 3, 4, null, null);
   }
   
   @Test(expected=IllegalArgumentException.class)
   public void testInvalidRpcMessageType() {
-    int invalidMessageType = 3; // Message typ is not RpcMessage.RPC_CALL
+    RpcMessage.Type invalidMessageType = RpcMessage.Type.RPC_REPLY; // Message typ is not
RpcMessage.RPC_CALL
     new RpcCall(0, invalidMessageType, RpcCall.RPC_VERSION, 2, 3, 4, null, null);
   }
 }

Modified: hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/oncrpc/TestRpcDeniedReply.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/oncrpc/TestRpcDeniedReply.java?rev=1501851&r1=1501850&r2=1501851&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/oncrpc/TestRpcDeniedReply.java
(original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/oncrpc/TestRpcDeniedReply.java
Wed Jul 10 17:01:28 2013
@@ -39,12 +39,12 @@ public class TestRpcDeniedReply {
   
   @Test
   public void testConstructor() {
-    RpcDeniedReply reply = new RpcDeniedReply(0, RpcMessage.RPC_REPLY,
+    RpcDeniedReply reply = new RpcDeniedReply(0, RpcMessage.Type.RPC_REPLY,
         ReplyState.MSG_ACCEPTED, RejectState.AUTH_ERROR) {
       // Anonymous class
     };
     Assert.assertEquals(0, reply.getXid());
-    Assert.assertEquals(RpcMessage.RPC_REPLY, reply.getMessageType());
+    Assert.assertEquals(RpcMessage.Type.RPC_REPLY, reply.getMessageType());
     Assert.assertEquals(ReplyState.MSG_ACCEPTED, reply.getState());
     Assert.assertEquals(RejectState.AUTH_ERROR, reply.getRejectState());
   }

Modified: hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/oncrpc/TestRpcMessage.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/oncrpc/TestRpcMessage.java?rev=1501851&r1=1501850&r2=1501851&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/oncrpc/TestRpcMessage.java
(original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/oncrpc/TestRpcMessage.java
Wed Jul 10 17:01:28 2013
@@ -24,34 +24,28 @@ import org.junit.Test;
  * Test for {@link RpcMessage}
  */
 public class TestRpcMessage {
-  private RpcMessage getRpcMessage(int xid, int msgType) {
+  private RpcMessage getRpcMessage(int xid, RpcMessage.Type msgType) {
     return new RpcMessage(xid, msgType) {
       // Anonymous class
     };
   }
   
-  @Test(expected=IllegalArgumentException.class)
-  public void testInvalidMessageType() {
-    int invalidMsgType = 2; // valid values are 0 and 1
-    getRpcMessage(0, invalidMsgType);
-  }
-  
   @Test
   public void testRpcMessage() {
-    RpcMessage msg = getRpcMessage(0, RpcMessage.RPC_CALL);
+    RpcMessage msg = getRpcMessage(0, RpcMessage.Type.RPC_CALL);
     Assert.assertEquals(0, msg.getXid());
-    Assert.assertEquals(RpcMessage.RPC_CALL, msg.getMessageType());
+    Assert.assertEquals(RpcMessage.Type.RPC_CALL, msg.getMessageType());
   }
   
   @Test
   public void testValidateMessage() {
-    RpcMessage msg = getRpcMessage(0, RpcMessage.RPC_CALL);
-    msg.validateMessageType(RpcMessage.RPC_CALL);
+    RpcMessage msg = getRpcMessage(0, RpcMessage.Type.RPC_CALL);
+    msg.validateMessageType(RpcMessage.Type.RPC_CALL);
   }
   
   @Test(expected = IllegalArgumentException.class)
   public void testValidateMessageException() {
-    RpcMessage msg = getRpcMessage(0, RpcMessage.RPC_CALL);
-    msg.validateMessageType(RpcMessage.RPC_REPLY);
+    RpcMessage msg = getRpcMessage(0, RpcMessage.Type.RPC_CALL);
+    msg.validateMessageType(RpcMessage.Type.RPC_REPLY);
   }
 }

Modified: hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/oncrpc/TestRpcReply.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/oncrpc/TestRpcReply.java?rev=1501851&r1=1501850&r2=1501851&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/oncrpc/TestRpcReply.java
(original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/oncrpc/TestRpcReply.java
Wed Jul 10 17:01:28 2013
@@ -39,11 +39,11 @@ public class TestRpcReply {
   
   @Test
   public void testRpcReply() {
-    RpcReply reply = new RpcReply(0, 1, ReplyState.MSG_ACCEPTED) {
+    RpcReply reply = new RpcReply(0, RpcMessage.Type.RPC_REPLY, ReplyState.MSG_ACCEPTED)
{
       // Anonymous class
     };
     Assert.assertEquals(0, reply.getXid());
-    Assert.assertEquals(1, reply.getMessageType());
+    Assert.assertEquals(RpcMessage.Type.RPC_REPLY, reply.getMessageType());
     Assert.assertEquals(ReplyState.MSG_ACCEPTED, reply.getState());
   }
 }



Mime
View raw message