You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2012/08/19 23:47:22 UTC
svn commit: r1374860 [2/2] - in /hbase/trunk/hbase-server/src:
main/java/org/apache/hadoop/hbase/ipc/
main/java/org/apache/hadoop/hbase/monitoring/
main/java/org/apache/hadoop/hbase/protobuf/generated/
main/java/org/apache/hadoop/hbase/regionserver/ ma...
Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java?rev=1374860&r1=1374859&r2=1374860&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java Sun Aug 19 21:47:21 2012
@@ -27,10 +27,13 @@ import java.lang.annotation.RetentionPol
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryUsage;
import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.BindException;
import java.net.InetSocketAddress;
+import java.nio.ByteBuffer;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
@@ -40,11 +43,13 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.SortedSet;
import java.util.Map.Entry;
import java.util.Random;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
+import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -168,6 +173,7 @@ import org.apache.hadoop.hbase.protobuf.
import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.RegionInfo;
import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.RegionSpecifier;
import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.RegionSpecifier.RegionSpecifierType;
+import org.apache.hadoop.hbase.protobuf.generated.RPCProtos.RpcRequestBody;
import org.apache.hadoop.hbase.regionserver.Leases.LeaseStillHeldException;
import org.apache.hadoop.hbase.regionserver.compactions.CompactionProgress;
import org.apache.hadoop.hbase.regionserver.compactions.CompactionRequest;
@@ -224,6 +230,8 @@ import org.apache.hadoop.hbase.RegionSer
import com.google.common.base.Function;
import com.google.protobuf.ByteString;
+import com.google.protobuf.InvalidProtocolBufferException;
+import com.google.protobuf.Message;
import com.google.protobuf.RpcController;
/**
@@ -436,6 +444,11 @@ public class HRegionServer implements C
*/
private final int scannerLeaseTimeoutPeriod;
+ /**
+ * The reference to the QosFunction
+ */
+ private final QosFunction qosFunction;
+
/**
* Starts a HRegionServer at the default location
@@ -513,7 +526,7 @@ public class HRegionServer implements C
this.isa = this.rpcServer.getListenerAddress();
this.rpcServer.setErrorHandler(this);
- this.rpcServer.setQosFunction(new QosFunction());
+ this.rpcServer.setQosFunction((qosFunction = new QosFunction()));
this.startcode = System.currentTimeMillis();
// login the server principal (if using secure Hadoop)
@@ -545,12 +558,61 @@ public class HRegionServer implements C
int priority() default 0;
}
+ QosFunction getQosFunction() {
+ return qosFunction;
+ }
+
+ RegionScanner getScanner(long scannerId) {
+ String scannerIdString = Long.toString(scannerId);
+ return scanners.get(scannerIdString);
+ }
+
/**
* Utility used ensuring higher quality of service for priority rpcs; e.g.
* rpcs to .META. and -ROOT-, etc.
*/
- class QosFunction implements Function<Writable,Integer> {
+ class QosFunction implements Function<RpcRequestBody,Integer> {
private final Map<String, Integer> annotatedQos;
+ //We need to mock the regionserver instance for some unit tests (set via
+ //setRegionServer method.
+ //The field value is initially set to the enclosing instance of HRegionServer.
+ private HRegionServer hRegionServer = HRegionServer.this;
+
+ //The logic for figuring out high priority RPCs is as follows:
+ //1. if the method is annotated with a QosPriority of QOS_HIGH,
+ // that is honored
+ //2. parse out the protobuf message and see if the request is for meta
+ // region, and if so, treat it as a high priority RPC
+ //Some optimizations for (2) are done here -
+ //Clients send the argument classname as part of making the RPC. The server
+ //decides whether to deserialize the proto argument message based on the
+ //pre-established set of argument classes (knownArgumentClasses below).
+ //This prevents the server from having to deserialize all proto argument
+ //messages prematurely.
+ //All the argument classes declare a 'getRegion' method that returns a
+ //RegionSpecifier object. Methods can be invoked on the returned object
+ //to figure out whether it is a meta region or not.
+ @SuppressWarnings("unchecked")
+ private final Class<? extends Message>[] knownArgumentClasses = new Class[]{
+ GetRegionInfoRequest.class,
+ GetStoreFileRequest.class,
+ CloseRegionRequest.class,
+ FlushRegionRequest.class,
+ SplitRegionRequest.class,
+ CompactRegionRequest.class,
+ GetRequest.class,
+ MutateRequest.class,
+ ScanRequest.class,
+ LockRowRequest.class,
+ UnlockRowRequest.class,
+ MultiRequest.class
+ };
+
+ //Some caches for helping performance
+ private final Map<String, Class<? extends Message>> argumentToClassMap =
+ new HashMap<String, Class<? extends Message>>();
+ private final Map<String, Map<Class<? extends Message>, Method>>
+ methodMap = new HashMap<String, Map<Class<? extends Message>, Method>>();
public QosFunction() {
Map<String, Integer> qosMap = new HashMap<String, Integer>();
@@ -562,12 +624,34 @@ public class HRegionServer implements C
}
annotatedQos = qosMap;
+ if (methodMap.get("parseFrom") == null) {
+ methodMap.put("parseFrom",
+ new HashMap<Class<? extends Message>, Method>());
+ }
+ if (methodMap.get("getRegion") == null) {
+ methodMap.put("getRegion",
+ new HashMap<Class<? extends Message>, Method>());
+ }
+ for (Class<? extends Message> cls : knownArgumentClasses) {
+ argumentToClassMap.put(cls.getCanonicalName(), cls);
+ try {
+ methodMap.get("parseFrom").put(cls,
+ cls.getDeclaredMethod("parseFrom",ByteString.class));
+ methodMap.get("getRegion").put(cls, cls.getDeclaredMethod("getRegion"));
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ void setRegionServer(HRegionServer server) {
+ this.hRegionServer = server;
}
public boolean isMetaRegion(byte[] regionName) {
HRegion region;
try {
- region = getRegion(regionName);
+ region = hRegionServer.getRegion(regionName);
} catch (NotServingRegionException ignored) {
return false;
}
@@ -575,62 +659,58 @@ public class HRegionServer implements C
}
@Override
- public Integer apply(Writable from) {
- if (!(from instanceof Invocation)) return NORMAL_QOS;
-
- Invocation inv = (Invocation) from;
- String methodName = inv.getMethodName();
+ public Integer apply(RpcRequestBody from) {
+ String methodName = from.getMethodName();
+ Class<? extends Message> rpcArgClass = null;
+ if (from.hasRequestClassName()) {
+ String cls = from.getRequestClassName();
+ rpcArgClass = argumentToClassMap.get(cls);
+ }
Integer priorityByAnnotation = annotatedQos.get(methodName);
if (priorityByAnnotation != null) {
return priorityByAnnotation;
}
- // scanner methods...
- if (methodName.equals("next") || methodName.equals("close")) {
- // translate!
- Long scannerId;
- try {
- scannerId = (Long) inv.getParameters()[0];
- } catch (ClassCastException ignored) {
- // LOG.debug("Low priority: " + from);
- return NORMAL_QOS; // doh.
- }
- String scannerIdString = Long.toString(scannerId);
- RegionScanner scanner = scanners.get(scannerIdString);
- if (scanner != null && scanner.getRegionInfo().isMetaRegion()) {
- // LOG.debug("High priority scanner request: " + scannerId);
+ if (rpcArgClass == null || from.getRequest().isEmpty()) {
+ return NORMAL_QOS;
+ }
+ Object deserializedRequestObj = null;
+ //check whether the request has reference to Meta region
+ try {
+ Method parseFrom = methodMap.get("parseFrom").get(rpcArgClass);
+ deserializedRequestObj = parseFrom.invoke(null, from.getRequest());
+ Method getRegion = methodMap.get("getRegion").get(rpcArgClass);
+ RegionSpecifier regionSpecifier =
+ (RegionSpecifier)getRegion.invoke(deserializedRequestObj,
+ (Object[])null);
+ HRegion region = hRegionServer.getRegion(regionSpecifier);
+ if (region.getRegionInfo().isMetaRegion()) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("High priority: " + from.toString());
+ }
return HIGH_QOS;
}
- } else if (inv.getParameterClasses().length == 0) {
- // Just let it through. This is getOnlineRegions, etc.
- } else if (inv.getParameterClasses()[0] == byte[].class) {
- // first arg is byte array, so assume this is a regionname:
- if (isMetaRegion((byte[]) inv.getParameters()[0])) {
- // LOG.debug("High priority with method: " + methodName +
- // " and region: "
- // + Bytes.toString((byte[]) inv.getParameters()[0]));
- return HIGH_QOS;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+
+ if (methodName.equals("scan")) { // scanner methods...
+ ScanRequest request = (ScanRequest)deserializedRequestObj;
+ if (!request.hasScannerId()) {
+ return NORMAL_QOS;
}
- } else if (inv.getParameterClasses()[0] == MultiAction.class) {
- MultiAction<?> ma = (MultiAction<?>) inv.getParameters()[0];
- Set<byte[]> regions = ma.getRegions();
- // ok this sucks, but if any single of the actions touches a meta, the
- // whole
- // thing gets pingged high priority. This is a dangerous hack because
- // people
- // can get their multi action tagged high QOS by tossing a Get(.META.)
- // AND this
- // regionserver hosts META/-ROOT-
- for (byte[] region : regions) {
- if (isMetaRegion(region)) {
- // LOG.debug("High priority multi with region: " +
- // Bytes.toString(region));
- return HIGH_QOS; // short circuit for the win.
+ RegionScanner scanner = hRegionServer.getScanner(request.getScannerId());
+ if (scanner != null && scanner.getRegionInfo().isMetaRegion()) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("High priority scanner request: " + request.getScannerId());
}
+ return HIGH_QOS;
}
}
- // LOG.debug("Low priority: " + from.toString());
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Low priority: " + from.toString());
+ }
return NORMAL_QOS;
}
}
Modified: hbase/trunk/hbase-server/src/main/protobuf/RPC.proto
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/protobuf/RPC.proto?rev=1374860&r1=1374859&r2=1374860&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/protobuf/RPC.proto (original)
+++ hbase/trunk/hbase-server/src/main/protobuf/RPC.proto Sun Aug 19 21:47:21 2012
@@ -26,20 +26,21 @@
*
* As part of setting up a connection to a server, the client needs to send
* the ConnectionHeader header. At the data level, this looks like
- * <"hrpc"-bytearray><'5'-byte><length-of-serialized-ConnectionHeader-obj[int32]><ConnectionHeader-object serialized>
+ * <"hrpc"-bytearray><'5'[byte]><length-of-serialized-ConnectionHeader-obj[int32]><ConnectionHeader-object serialized>
*
* For every RPC that the client makes it needs to send the following
* RpcRequestHeader and the RpcRequestBody. At the data level this looks like:
- * <length-of-serialized-RpcRequestHeader + length-of-serialized-RpcRequestBody>
+ * <length-of-serialized-RpcRequestHeader + length-of-varint32-of-serialized-RpcRequestHeader +
+ * length-of-serialized-RpcRequestBody + length-of-varint32-of-serialized-RpcRequestBody>
* <RpcRequestHeader [serialized using Message.writeDelimitedTo]>
- * <RpcRequestBody [serialized using Message.writeTo]>
+ * <RpcRequestBody [serialized using Message.writeDelimitedTo]>
*
* On a success, the server's protobuf response looks like
* <RpcResponseHeader-object [serialized using Message.writeDelimitedTo]>
- * <RpcResponseBody-object [serialized using Message.writeTo]>
+ * <RpcResponseBody-object [serialized using Message.writeDelimitedTo]>
* On a failure, the server's protobuf response looks like
* <RpcResponseHeader-object [serialized using Message.writeDelimitedTo]>
- * <RpcException-object [serialized using Message.writeTo]>
+ * <RpcException-object [serialized using Message.writeDelimitedTo]>
*
* There is one special message that's sent from client to server -
* the Ping message. At the data level, this is just the bytes corresponding
@@ -84,8 +85,16 @@ message RpcRequestBody {
/** protocol version of class declaring the called method */
optional uint64 clientProtocolVersion = 2;
- /** Bytes corresponding to the client protobuf request */
+ /** Bytes corresponding to the client protobuf request. This is the actual
+ * bytes corresponding to the RPC request argument.
+ */
optional bytes request = 3;
+
+ /** Some metainfo about the request. Helps us to treat RPCs with
+ * different priorities. For now this is just the classname of the request
+ * proto object.
+ */
+ optional string requestClassName = 4;
}
/**
@@ -93,7 +102,7 @@ message RpcRequestBody {
*/
message RpcResponseHeader {
/** Echo back the callId the client sent */
- required int32 callId = 1;
+ required uint32 callId = 1;
/** Did the RPC execution encounter an error at the server */
enum Status {
SUCCESS = 0;
@@ -106,7 +115,9 @@ message RpcResponseHeader {
* The RPC response body
*/
message RpcResponseBody {
- /** Optional response bytes */
+ /** Optional response bytes. This is the actual bytes corresponding to the
+ * return value of the invoked RPC.
+ */
optional bytes response = 1;
}
/**
@@ -122,4 +133,4 @@ message RpcException {
/** Exception stack trace from the server side */
optional string stackTrace = 2;
-}
\ No newline at end of file
+}
Modified: hbase/trunk/hbase-server/src/main/resources/hbase-default.xml
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/resources/hbase-default.xml?rev=1374860&r1=1374859&r2=1374860&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/resources/hbase-default.xml (original)
+++ hbase/trunk/hbase-server/src/main/resources/hbase-default.xml Sun Aug 19 21:47:21 2012
@@ -523,7 +523,7 @@
</property>
<property>
<name>hbase.rpc.engine</name>
- <value>org.apache.hadoop.hbase.ipc.WritableRpcEngine</value>
+ <value>org.apache.hadoop.hbase.ipc.ProtobufRpcEngine</value>
<description>Implementation of org.apache.hadoop.hbase.ipc.RpcEngine to be
used for client / server RPC call marshalling.
</description>
Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestDelayedRpc.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestDelayedRpc.java?rev=1374860&r1=1374859&r2=1374860&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestDelayedRpc.java (original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestDelayedRpc.java Sun Aug 19 21:47:21 2012
@@ -34,12 +34,15 @@ import junit.framework.Assert;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.*;
import org.apache.hadoop.hbase.ipc.VersionedProtocol;
+import org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestArg;
+import org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestResponse;
import org.apache.hadoop.hbase.MediumTests;
import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.Logger;
import org.apache.log4j.spi.LoggingEvent;
import org.junit.Test;
import org.junit.experimental.categories.Category;
+import org.mortbay.log.Log;
/**
* Test that delayed RPCs work. Fire up three calls, the first of which should
@@ -163,7 +166,7 @@ public class TestDelayedRpc {
public interface TestRpc extends VersionedProtocol {
public static final long VERSION = 1L;
- int test(boolean delay);
+ TestResponse test(TestArg delay);
}
private static class TestRpcImpl implements TestRpc {
@@ -183,9 +186,12 @@ public class TestDelayedRpc {
}
@Override
- public int test(final boolean delay) {
+ public TestResponse test(final TestArg testArg) {
+ boolean delay = testArg.getDelay();
+ TestResponse.Builder responseBuilder = TestResponse.newBuilder();
if (!delay) {
- return UNDELAYED;
+ responseBuilder.setResponse(UNDELAYED);
+ return responseBuilder.build();
}
final Delayable call = HBaseServer.getCurrentCall();
call.startDelay(delayReturnValue);
@@ -193,7 +199,9 @@ public class TestDelayedRpc {
public void run() {
try {
Thread.sleep(500);
- call.endDelay(delayReturnValue ? DELAYED : null);
+ TestResponse.Builder responseBuilder = TestResponse.newBuilder();
+ call.endDelay(delayReturnValue ?
+ responseBuilder.setResponse(DELAYED).build() : null);
} catch (Exception e) {
e.printStackTrace();
}
@@ -201,7 +209,8 @@ public class TestDelayedRpc {
}.start();
// This value should go back to client only if the response is set
// immediately at delay time.
- return 0xDEADBEEF;
+ responseBuilder.setResponse(0xDEADBEEF);
+ return responseBuilder.build();
}
@Override
@@ -235,7 +244,9 @@ public class TestDelayedRpc {
@Override
public void run() {
try {
- Integer result = new Integer(server.test(delay));
+ Integer result =
+ new Integer(server.test(TestArg.newBuilder()
+ .setDelay(delay).build()).getResponse());
if (results != null) {
synchronized (results) {
results.add(result);
@@ -263,7 +274,7 @@ public class TestDelayedRpc {
int result = 0xDEADBEEF;
try {
- result = client.test(false);
+ result = client.test(TestArg.newBuilder().setDelay(false).build()).getResponse();
} catch (Exception e) {
fail("No exception should have been thrown.");
}
@@ -271,12 +282,13 @@ public class TestDelayedRpc {
boolean caughtException = false;
try {
- result = client.test(true);
+ result = client.test(TestArg.newBuilder().setDelay(true).build()).getResponse();
} catch(Exception e) {
// Exception thrown by server is enclosed in a RemoteException.
- if (e.getCause().getMessage().startsWith(
+ if (e.getCause().getMessage().contains(
"java.lang.Exception: Something went wrong"))
caughtException = true;
+ Log.warn(e);
}
assertTrue(caughtException);
}
@@ -286,9 +298,9 @@ public class TestDelayedRpc {
*/
private static class FaultyTestRpc implements TestRpc {
@Override
- public int test(boolean delay) {
- if (!delay)
- return UNDELAYED;
+ public TestResponse test(TestArg arg) {
+ if (!arg.getDelay())
+ return TestResponse.newBuilder().setResponse(UNDELAYED).build();
Delayable call = HBaseServer.getCurrentCall();
call.startDelay(true);
try {
@@ -297,7 +309,7 @@ public class TestDelayedRpc {
e.printStackTrace();
}
// Client will receive the Exception, not this value.
- return DELAYED;
+ return TestResponse.newBuilder().setResponse(DELAYED).build();
}
@Override
Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestPBOnWritableRpc.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestPBOnWritableRpc.java?rev=1374860&r1=1374859&r2=1374860&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestPBOnWritableRpc.java (original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestPBOnWritableRpc.java Sun Aug 19 21:47:21 2012
@@ -1,135 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.hadoop.hbase.ipc;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotSame;
-
-import java.io.IOException;
-import java.net.InetSocketAddress;
-
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.SmallTests;
-import org.apache.hadoop.io.Text;
-import org.apache.hadoop.io.Writable;
-import org.junit.Test;
-
-import com.google.protobuf.DescriptorProtos;
-import com.google.protobuf.DescriptorProtos.EnumDescriptorProto;
-
-import org.junit.experimental.categories.Category;
-
-/** Unit tests to test PB-based types on WritableRpcEngine. */
-@Category(SmallTests.class)
-public class TestPBOnWritableRpc {
-
- private static Configuration conf = new Configuration();
-
- public interface TestProtocol extends VersionedProtocol {
- public static final long VERSION = 1L;
-
- String echo(String value) throws IOException;
- Writable echo(Writable value) throws IOException;
-
- DescriptorProtos.EnumDescriptorProto exchangeProto(
- DescriptorProtos.EnumDescriptorProto arg);
- }
-
- public static class TestImpl implements TestProtocol {
- public long getProtocolVersion(String protocol, long clientVersion) {
- return TestProtocol.VERSION;
- }
-
- public ProtocolSignature getProtocolSignature(String protocol, long clientVersion,
- int hashcode) {
- return new ProtocolSignature(TestProtocol.VERSION, null);
- }
-
- @Override
- public String echo(String value) throws IOException { return value; }
-
- @Override
- public Writable echo(Writable writable) {
- return writable;
- }
-
- @Override
- public EnumDescriptorProto exchangeProto(EnumDescriptorProto arg) {
- return arg;
- }
- }
-
- @Test(timeout=10000)
- public void testCalls() throws Exception {
- testCallsInternal(conf);
- }
-
- private void testCallsInternal(Configuration conf) throws Exception {
- RpcServer rpcServer = HBaseRPC.getServer(new TestImpl(),
- new Class<?>[] {TestProtocol.class},
- "localhost", // BindAddress is IP we got for this server.
- 9999, // port number
- 2, // number of handlers
- 0, // we dont use high priority handlers in master
- conf.getBoolean("hbase.rpc.verbose", false), conf,
- 0);
- TestProtocol proxy = null;
- try {
- rpcServer.start();
-
- InetSocketAddress isa =
- new InetSocketAddress("localhost", 9999);
- proxy = (TestProtocol) HBaseRPC.waitForProxy(
- TestProtocol.class, TestProtocol.VERSION,
- isa, conf, -1, 8000, 8000);
-
- String stringResult = proxy.echo("foo");
- assertEquals(stringResult, "foo");
-
- stringResult = proxy.echo((String)null);
- assertEquals(stringResult, null);
-
- Text utf8Result = (Text)proxy.echo(new Text("hello world"));
- assertEquals(utf8Result, new Text("hello world"));
-
- utf8Result = (Text)proxy.echo((Text)null);
- assertEquals(utf8Result, null);
-
- // Test protobufs
- EnumDescriptorProto sendProto =
- EnumDescriptorProto.newBuilder().setName("test").build();
- EnumDescriptorProto retProto = proxy.exchangeProto(sendProto);
- assertEquals(sendProto, retProto);
- assertNotSame(sendProto, retProto);
- } finally {
- rpcServer.stop();
- if(proxy != null) {
- HBaseRPC.stopProxy(proxy);
- }
- }
- }
-
- public static void main(String[] args) throws Exception {
- new TestPBOnWritableRpc().testCallsInternal(conf);
- }
-
- @org.junit.Rule
- public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu =
- new org.apache.hadoop.hbase.ResourceCheckerJUnitRule();
-}
Added: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/protobuf/generated/TestDelayedRpcProtos.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/protobuf/generated/TestDelayedRpcProtos.java?rev=1374860&view=auto
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/protobuf/generated/TestDelayedRpcProtos.java (added)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/protobuf/generated/TestDelayedRpcProtos.java Sun Aug 19 21:47:21 2012
@@ -0,0 +1,825 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: test_delayed_rpc.proto
+
+package org.apache.hadoop.hbase.ipc.protobuf.generated;
+
+public final class TestDelayedRpcProtos {
+ private TestDelayedRpcProtos() {}
+ public static void registerAllExtensions(
+ com.google.protobuf.ExtensionRegistry registry) {
+ }
+ public interface TestArgOrBuilder
+ extends com.google.protobuf.MessageOrBuilder {
+
+ // required bool delay = 1;
+ boolean hasDelay();
+ boolean getDelay();
+ }
+ public static final class TestArg extends
+ com.google.protobuf.GeneratedMessage
+ implements TestArgOrBuilder {
+ // Use TestArg.newBuilder() to construct.
+ private TestArg(Builder builder) {
+ super(builder);
+ }
+ private TestArg(boolean noInit) {}
+
+ private static final TestArg defaultInstance;
+ public static TestArg getDefaultInstance() {
+ return defaultInstance;
+ }
+
+ public TestArg getDefaultInstanceForType() {
+ return defaultInstance;
+ }
+
+ public static final com.google.protobuf.Descriptors.Descriptor
+ getDescriptor() {
+ return org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.internal_static_TestArg_descriptor;
+ }
+
+ protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internalGetFieldAccessorTable() {
+ return org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.internal_static_TestArg_fieldAccessorTable;
+ }
+
+ private int bitField0_;
+ // required bool delay = 1;
+ public static final int DELAY_FIELD_NUMBER = 1;
+ private boolean delay_;
+ public boolean hasDelay() {
+ return ((bitField0_ & 0x00000001) == 0x00000001);
+ }
+ public boolean getDelay() {
+ return delay_;
+ }
+
+ private void initFields() {
+ delay_ = false;
+ }
+ private byte memoizedIsInitialized = -1;
+ public final boolean isInitialized() {
+ byte isInitialized = memoizedIsInitialized;
+ if (isInitialized != -1) return isInitialized == 1;
+
+ if (!hasDelay()) {
+ memoizedIsInitialized = 0;
+ return false;
+ }
+ memoizedIsInitialized = 1;
+ return true;
+ }
+
+ public void writeTo(com.google.protobuf.CodedOutputStream output)
+ throws java.io.IOException {
+ getSerializedSize();
+ if (((bitField0_ & 0x00000001) == 0x00000001)) {
+ output.writeBool(1, delay_);
+ }
+ getUnknownFields().writeTo(output);
+ }
+
+ private int memoizedSerializedSize = -1;
+ public int getSerializedSize() {
+ int size = memoizedSerializedSize;
+ if (size != -1) return size;
+
+ size = 0;
+ if (((bitField0_ & 0x00000001) == 0x00000001)) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeBoolSize(1, delay_);
+ }
+ size += getUnknownFields().getSerializedSize();
+ memoizedSerializedSize = size;
+ return size;
+ }
+
+ private static final long serialVersionUID = 0L;
+ @java.lang.Override
+ protected java.lang.Object writeReplace()
+ throws java.io.ObjectStreamException {
+ return super.writeReplace();
+ }
+
+ @java.lang.Override
+ public boolean equals(final java.lang.Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (!(obj instanceof org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestArg)) {
+ return super.equals(obj);
+ }
+ org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestArg other = (org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestArg) obj;
+
+ boolean result = true;
+ result = result && (hasDelay() == other.hasDelay());
+ if (hasDelay()) {
+ result = result && (getDelay()
+ == other.getDelay());
+ }
+ result = result &&
+ getUnknownFields().equals(other.getUnknownFields());
+ return result;
+ }
+
+ @java.lang.Override
+ public int hashCode() {
+ int hash = 41;
+ hash = (19 * hash) + getDescriptorForType().hashCode();
+ if (hasDelay()) {
+ hash = (37 * hash) + DELAY_FIELD_NUMBER;
+ hash = (53 * hash) + hashBoolean(getDelay());
+ }
+ hash = (29 * hash) + getUnknownFields().hashCode();
+ return hash;
+ }
+
+ public static org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestArg parseFrom(
+ com.google.protobuf.ByteString data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data).buildParsed();
+ }
+ public static org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestArg parseFrom(
+ com.google.protobuf.ByteString data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data, extensionRegistry)
+ .buildParsed();
+ }
+ public static org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestArg parseFrom(byte[] data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data).buildParsed();
+ }
+ public static org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestArg parseFrom(
+ byte[] data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data, extensionRegistry)
+ .buildParsed();
+ }
+ public static org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestArg parseFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input).buildParsed();
+ }
+ public static org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestArg parseFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input, extensionRegistry)
+ .buildParsed();
+ }
+ public static org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestArg parseDelimitedFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ Builder builder = newBuilder();
+ if (builder.mergeDelimitedFrom(input)) {
+ return builder.buildParsed();
+ } else {
+ return null;
+ }
+ }
+ public static org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestArg parseDelimitedFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ Builder builder = newBuilder();
+ if (builder.mergeDelimitedFrom(input, extensionRegistry)) {
+ return builder.buildParsed();
+ } else {
+ return null;
+ }
+ }
+ public static org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestArg parseFrom(
+ com.google.protobuf.CodedInputStream input)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input).buildParsed();
+ }
+ public static org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestArg parseFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input, extensionRegistry)
+ .buildParsed();
+ }
+
+ public static Builder newBuilder() { return Builder.create(); }
+ public Builder newBuilderForType() { return newBuilder(); }
+ public static Builder newBuilder(org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestArg prototype) {
+ return newBuilder().mergeFrom(prototype);
+ }
+ public Builder toBuilder() { return newBuilder(this); }
+
+ @java.lang.Override
+ protected Builder newBuilderForType(
+ com.google.protobuf.GeneratedMessage.BuilderParent parent) {
+ Builder builder = new Builder(parent);
+ return builder;
+ }
+ public static final class Builder extends
+ com.google.protobuf.GeneratedMessage.Builder<Builder>
+ implements org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestArgOrBuilder {
+ public static final com.google.protobuf.Descriptors.Descriptor
+ getDescriptor() {
+ return org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.internal_static_TestArg_descriptor;
+ }
+
+ protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internalGetFieldAccessorTable() {
+ return org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.internal_static_TestArg_fieldAccessorTable;
+ }
+
+ // Construct using org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestArg.newBuilder()
+ private Builder() {
+ maybeForceBuilderInitialization();
+ }
+
+ private Builder(BuilderParent parent) {
+ super(parent);
+ maybeForceBuilderInitialization();
+ }
+ private void maybeForceBuilderInitialization() {
+ if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {
+ }
+ }
+ private static Builder create() {
+ return new Builder();
+ }
+
+ public Builder clear() {
+ super.clear();
+ delay_ = false;
+ bitField0_ = (bitField0_ & ~0x00000001);
+ return this;
+ }
+
+ public Builder clone() {
+ return create().mergeFrom(buildPartial());
+ }
+
+ public com.google.protobuf.Descriptors.Descriptor
+ getDescriptorForType() {
+ return org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestArg.getDescriptor();
+ }
+
+ public org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestArg getDefaultInstanceForType() {
+ return org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestArg.getDefaultInstance();
+ }
+
+ public org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestArg build() {
+ org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestArg result = buildPartial();
+ if (!result.isInitialized()) {
+ throw newUninitializedMessageException(result);
+ }
+ return result;
+ }
+
+ private org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestArg buildParsed()
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestArg result = buildPartial();
+ if (!result.isInitialized()) {
+ throw newUninitializedMessageException(
+ result).asInvalidProtocolBufferException();
+ }
+ return result;
+ }
+
+ public org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestArg buildPartial() {
+ org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestArg result = new org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestArg(this);
+ int from_bitField0_ = bitField0_;
+ int to_bitField0_ = 0;
+ if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
+ to_bitField0_ |= 0x00000001;
+ }
+ result.delay_ = delay_;
+ result.bitField0_ = to_bitField0_;
+ onBuilt();
+ return result;
+ }
+
+ public Builder mergeFrom(com.google.protobuf.Message other) {
+ if (other instanceof org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestArg) {
+ return mergeFrom((org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestArg)other);
+ } else {
+ super.mergeFrom(other);
+ return this;
+ }
+ }
+
+ public Builder mergeFrom(org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestArg other) {
+ if (other == org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestArg.getDefaultInstance()) return this;
+ if (other.hasDelay()) {
+ setDelay(other.getDelay());
+ }
+ this.mergeUnknownFields(other.getUnknownFields());
+ return this;
+ }
+
+ public final boolean isInitialized() {
+ if (!hasDelay()) {
+
+ return false;
+ }
+ return true;
+ }
+
+ public Builder mergeFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ com.google.protobuf.UnknownFieldSet.Builder unknownFields =
+ com.google.protobuf.UnknownFieldSet.newBuilder(
+ this.getUnknownFields());
+ while (true) {
+ int tag = input.readTag();
+ switch (tag) {
+ case 0:
+ this.setUnknownFields(unknownFields.build());
+ onChanged();
+ return this;
+ default: {
+ if (!parseUnknownField(input, unknownFields,
+ extensionRegistry, tag)) {
+ this.setUnknownFields(unknownFields.build());
+ onChanged();
+ return this;
+ }
+ break;
+ }
+ case 8: {
+ bitField0_ |= 0x00000001;
+ delay_ = input.readBool();
+ break;
+ }
+ }
+ }
+ }
+
+ private int bitField0_;
+
+ // required bool delay = 1;
+ private boolean delay_ ;
+ public boolean hasDelay() {
+ return ((bitField0_ & 0x00000001) == 0x00000001);
+ }
+ public boolean getDelay() {
+ return delay_;
+ }
+ public Builder setDelay(boolean value) {
+ bitField0_ |= 0x00000001;
+ delay_ = value;
+ onChanged();
+ return this;
+ }
+ public Builder clearDelay() {
+ bitField0_ = (bitField0_ & ~0x00000001);
+ delay_ = false;
+ onChanged();
+ return this;
+ }
+
+ // @@protoc_insertion_point(builder_scope:TestArg)
+ }
+
+ static {
+ defaultInstance = new TestArg(true);
+ defaultInstance.initFields();
+ }
+
+ // @@protoc_insertion_point(class_scope:TestArg)
+ }
+
+ public interface TestResponseOrBuilder
+ extends com.google.protobuf.MessageOrBuilder {
+
+ // required int32 response = 1;
+ boolean hasResponse();
+ int getResponse();
+ }
+ public static final class TestResponse extends
+ com.google.protobuf.GeneratedMessage
+ implements TestResponseOrBuilder {
+ // Use TestResponse.newBuilder() to construct.
+ private TestResponse(Builder builder) {
+ super(builder);
+ }
+ private TestResponse(boolean noInit) {}
+
+ private static final TestResponse defaultInstance;
+ public static TestResponse getDefaultInstance() {
+ return defaultInstance;
+ }
+
+ public TestResponse getDefaultInstanceForType() {
+ return defaultInstance;
+ }
+
+ public static final com.google.protobuf.Descriptors.Descriptor
+ getDescriptor() {
+ return org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.internal_static_TestResponse_descriptor;
+ }
+
+ protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internalGetFieldAccessorTable() {
+ return org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.internal_static_TestResponse_fieldAccessorTable;
+ }
+
+ private int bitField0_;
+ // required int32 response = 1;
+ public static final int RESPONSE_FIELD_NUMBER = 1;
+ private int response_;
+ public boolean hasResponse() {
+ return ((bitField0_ & 0x00000001) == 0x00000001);
+ }
+ public int getResponse() {
+ return response_;
+ }
+
+ private void initFields() {
+ response_ = 0;
+ }
+ private byte memoizedIsInitialized = -1;
+ public final boolean isInitialized() {
+ byte isInitialized = memoizedIsInitialized;
+ if (isInitialized != -1) return isInitialized == 1;
+
+ if (!hasResponse()) {
+ memoizedIsInitialized = 0;
+ return false;
+ }
+ memoizedIsInitialized = 1;
+ return true;
+ }
+
+ public void writeTo(com.google.protobuf.CodedOutputStream output)
+ throws java.io.IOException {
+ getSerializedSize();
+ if (((bitField0_ & 0x00000001) == 0x00000001)) {
+ output.writeInt32(1, response_);
+ }
+ getUnknownFields().writeTo(output);
+ }
+
+ private int memoizedSerializedSize = -1;
+ public int getSerializedSize() {
+ int size = memoizedSerializedSize;
+ if (size != -1) return size;
+
+ size = 0;
+ if (((bitField0_ & 0x00000001) == 0x00000001)) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeInt32Size(1, response_);
+ }
+ size += getUnknownFields().getSerializedSize();
+ memoizedSerializedSize = size;
+ return size;
+ }
+
+ private static final long serialVersionUID = 0L;
+ @java.lang.Override
+ protected java.lang.Object writeReplace()
+ throws java.io.ObjectStreamException {
+ return super.writeReplace();
+ }
+
+ @java.lang.Override
+ public boolean equals(final java.lang.Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (!(obj instanceof org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestResponse)) {
+ return super.equals(obj);
+ }
+ org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestResponse other = (org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestResponse) obj;
+
+ boolean result = true;
+ result = result && (hasResponse() == other.hasResponse());
+ if (hasResponse()) {
+ result = result && (getResponse()
+ == other.getResponse());
+ }
+ result = result &&
+ getUnknownFields().equals(other.getUnknownFields());
+ return result;
+ }
+
+ @java.lang.Override
+ public int hashCode() {
+ int hash = 41;
+ hash = (19 * hash) + getDescriptorForType().hashCode();
+ if (hasResponse()) {
+ hash = (37 * hash) + RESPONSE_FIELD_NUMBER;
+ hash = (53 * hash) + getResponse();
+ }
+ hash = (29 * hash) + getUnknownFields().hashCode();
+ return hash;
+ }
+
+ public static org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestResponse parseFrom(
+ com.google.protobuf.ByteString data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data).buildParsed();
+ }
+ public static org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestResponse parseFrom(
+ com.google.protobuf.ByteString data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data, extensionRegistry)
+ .buildParsed();
+ }
+ public static org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestResponse parseFrom(byte[] data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data).buildParsed();
+ }
+ public static org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestResponse parseFrom(
+ byte[] data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data, extensionRegistry)
+ .buildParsed();
+ }
+ public static org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestResponse parseFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input).buildParsed();
+ }
+ public static org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestResponse parseFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input, extensionRegistry)
+ .buildParsed();
+ }
+ public static org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestResponse parseDelimitedFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ Builder builder = newBuilder();
+ if (builder.mergeDelimitedFrom(input)) {
+ return builder.buildParsed();
+ } else {
+ return null;
+ }
+ }
+ public static org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestResponse parseDelimitedFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ Builder builder = newBuilder();
+ if (builder.mergeDelimitedFrom(input, extensionRegistry)) {
+ return builder.buildParsed();
+ } else {
+ return null;
+ }
+ }
+ public static org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestResponse parseFrom(
+ com.google.protobuf.CodedInputStream input)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input).buildParsed();
+ }
+ public static org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestResponse parseFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input, extensionRegistry)
+ .buildParsed();
+ }
+
+ public static Builder newBuilder() { return Builder.create(); }
+ public Builder newBuilderForType() { return newBuilder(); }
+ public static Builder newBuilder(org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestResponse prototype) {
+ return newBuilder().mergeFrom(prototype);
+ }
+ public Builder toBuilder() { return newBuilder(this); }
+
+ @java.lang.Override
+ protected Builder newBuilderForType(
+ com.google.protobuf.GeneratedMessage.BuilderParent parent) {
+ Builder builder = new Builder(parent);
+ return builder;
+ }
+ public static final class Builder extends
+ com.google.protobuf.GeneratedMessage.Builder<Builder>
+ implements org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestResponseOrBuilder {
+ public static final com.google.protobuf.Descriptors.Descriptor
+ getDescriptor() {
+ return org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.internal_static_TestResponse_descriptor;
+ }
+
+ protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internalGetFieldAccessorTable() {
+ return org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.internal_static_TestResponse_fieldAccessorTable;
+ }
+
+ // Construct using org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestResponse.newBuilder()
+ private Builder() {
+ maybeForceBuilderInitialization();
+ }
+
+ private Builder(BuilderParent parent) {
+ super(parent);
+ maybeForceBuilderInitialization();
+ }
+ private void maybeForceBuilderInitialization() {
+ if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {
+ }
+ }
+ private static Builder create() {
+ return new Builder();
+ }
+
+ public Builder clear() {
+ super.clear();
+ response_ = 0;
+ bitField0_ = (bitField0_ & ~0x00000001);
+ return this;
+ }
+
+ public Builder clone() {
+ return create().mergeFrom(buildPartial());
+ }
+
+ public com.google.protobuf.Descriptors.Descriptor
+ getDescriptorForType() {
+ return org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestResponse.getDescriptor();
+ }
+
+ public org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestResponse getDefaultInstanceForType() {
+ return org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestResponse.getDefaultInstance();
+ }
+
+ public org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestResponse build() {
+ org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestResponse result = buildPartial();
+ if (!result.isInitialized()) {
+ throw newUninitializedMessageException(result);
+ }
+ return result;
+ }
+
+ private org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestResponse buildParsed()
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestResponse result = buildPartial();
+ if (!result.isInitialized()) {
+ throw newUninitializedMessageException(
+ result).asInvalidProtocolBufferException();
+ }
+ return result;
+ }
+
+ public org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestResponse buildPartial() {
+ org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestResponse result = new org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestResponse(this);
+ int from_bitField0_ = bitField0_;
+ int to_bitField0_ = 0;
+ if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
+ to_bitField0_ |= 0x00000001;
+ }
+ result.response_ = response_;
+ result.bitField0_ = to_bitField0_;
+ onBuilt();
+ return result;
+ }
+
+ public Builder mergeFrom(com.google.protobuf.Message other) {
+ if (other instanceof org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestResponse) {
+ return mergeFrom((org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestResponse)other);
+ } else {
+ super.mergeFrom(other);
+ return this;
+ }
+ }
+
+ public Builder mergeFrom(org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestResponse other) {
+ if (other == org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestResponse.getDefaultInstance()) return this;
+ if (other.hasResponse()) {
+ setResponse(other.getResponse());
+ }
+ this.mergeUnknownFields(other.getUnknownFields());
+ return this;
+ }
+
+ public final boolean isInitialized() {
+ if (!hasResponse()) {
+
+ return false;
+ }
+ return true;
+ }
+
+ public Builder mergeFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ com.google.protobuf.UnknownFieldSet.Builder unknownFields =
+ com.google.protobuf.UnknownFieldSet.newBuilder(
+ this.getUnknownFields());
+ while (true) {
+ int tag = input.readTag();
+ switch (tag) {
+ case 0:
+ this.setUnknownFields(unknownFields.build());
+ onChanged();
+ return this;
+ default: {
+ if (!parseUnknownField(input, unknownFields,
+ extensionRegistry, tag)) {
+ this.setUnknownFields(unknownFields.build());
+ onChanged();
+ return this;
+ }
+ break;
+ }
+ case 8: {
+ bitField0_ |= 0x00000001;
+ response_ = input.readInt32();
+ break;
+ }
+ }
+ }
+ }
+
+ private int bitField0_;
+
+ // required int32 response = 1;
+ private int response_ ;
+ public boolean hasResponse() {
+ return ((bitField0_ & 0x00000001) == 0x00000001);
+ }
+ public int getResponse() {
+ return response_;
+ }
+ public Builder setResponse(int value) {
+ bitField0_ |= 0x00000001;
+ response_ = value;
+ onChanged();
+ return this;
+ }
+ public Builder clearResponse() {
+ bitField0_ = (bitField0_ & ~0x00000001);
+ response_ = 0;
+ onChanged();
+ return this;
+ }
+
+ // @@protoc_insertion_point(builder_scope:TestResponse)
+ }
+
+ static {
+ defaultInstance = new TestResponse(true);
+ defaultInstance.initFields();
+ }
+
+ // @@protoc_insertion_point(class_scope:TestResponse)
+ }
+
+ private static com.google.protobuf.Descriptors.Descriptor
+ internal_static_TestArg_descriptor;
+ private static
+ com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internal_static_TestArg_fieldAccessorTable;
+ private static com.google.protobuf.Descriptors.Descriptor
+ internal_static_TestResponse_descriptor;
+ private static
+ com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internal_static_TestResponse_fieldAccessorTable;
+
+ public static com.google.protobuf.Descriptors.FileDescriptor
+ getDescriptor() {
+ return descriptor;
+ }
+ private static com.google.protobuf.Descriptors.FileDescriptor
+ descriptor;
+ static {
+ java.lang.String[] descriptorData = {
+ "\n\026test_delayed_rpc.proto\"\030\n\007TestArg\022\r\n\005d" +
+ "elay\030\001 \002(\010\" \n\014TestResponse\022\020\n\010response\030\001" +
+ " \002(\005BL\n.org.apache.hadoop.hbase.ipc.prot" +
+ "obuf.generatedB\024TestDelayedRpcProtos\210\001\001\240" +
+ "\001\001"
+ };
+ com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
+ new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
+ public com.google.protobuf.ExtensionRegistry assignDescriptors(
+ com.google.protobuf.Descriptors.FileDescriptor root) {
+ descriptor = root;
+ internal_static_TestArg_descriptor =
+ getDescriptor().getMessageTypes().get(0);
+ internal_static_TestArg_fieldAccessorTable = new
+ com.google.protobuf.GeneratedMessage.FieldAccessorTable(
+ internal_static_TestArg_descriptor,
+ new java.lang.String[] { "Delay", },
+ org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestArg.class,
+ org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestArg.Builder.class);
+ internal_static_TestResponse_descriptor =
+ getDescriptor().getMessageTypes().get(1);
+ internal_static_TestResponse_fieldAccessorTable = new
+ com.google.protobuf.GeneratedMessage.FieldAccessorTable(
+ internal_static_TestResponse_descriptor,
+ new java.lang.String[] { "Response", },
+ org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestResponse.class,
+ org.apache.hadoop.hbase.ipc.protobuf.generated.TestDelayedRpcProtos.TestResponse.Builder.class);
+ return null;
+ }
+ };
+ com.google.protobuf.Descriptors.FileDescriptor
+ .internalBuildGeneratedFileFrom(descriptorData,
+ new com.google.protobuf.Descriptors.FileDescriptor[] {
+ }, assigner);
+ }
+
+ // @@protoc_insertion_point(outer_class_scope)
+}
Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestHMasterRPCException.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestHMasterRPCException.java?rev=1374860&r1=1374859&r2=1374860&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestHMasterRPCException.java (original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestHMasterRPCException.java Sun Aug 19 21:47:21 2012
@@ -20,21 +20,23 @@
package org.apache.hadoop.hbase.master;
-import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import java.io.IOException;
import java.net.InetSocketAddress;
+import java.net.SocketTimeoutException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.*;
import org.apache.hadoop.hbase.ipc.HBaseRPC;
import org.apache.hadoop.hbase.MasterMonitorProtocol;
-import org.apache.hadoop.hbase.protobuf.RequestConverter;
-import org.apache.hadoop.ipc.RemoteException;
-import org.apache.hadoop.hbase.ipc.ServerNotRunningYetException;
+import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
+import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.IsMasterRunningRequest;
import org.junit.Test;
import org.junit.experimental.categories.Category;
+import com.google.protobuf.ServiceException;
+
@Category(MediumTests.class)
public class TestHMasterRPCException {
@@ -49,16 +51,32 @@ public class TestHMasterRPCException {
ServerName sm = hm.getServerName();
InetSocketAddress isa = new InetSocketAddress(sm.getHostname(), sm.getPort());
- try {
- MasterMonitorProtocol inf = (MasterMonitorProtocol) HBaseRPC.getProxy(
- MasterMonitorProtocol.class, MasterMonitorProtocol.VERSION, isa, conf, 100);
- fail();
- } catch (ServerNotRunningYetException ex) {
- assertTrue(ex.getMessage().startsWith(
- "org.apache.hadoop.hbase.ipc.ServerNotRunningYetException: Server is not running yet"));
- } catch (Throwable t) {
- fail("Unexpected throwable: " + t);
+ int i = 0;
+ //retry the RPC a few times; we have seen SocketTimeoutExceptions if we
+ //try to connect too soon. Retry on SocketTimeoutException.
+ while (i < 20) {
+ try {
+ MasterMonitorProtocol inf = (MasterMonitorProtocol) HBaseRPC.getProxy(
+ MasterMonitorProtocol.class, MasterMonitorProtocol.VERSION, isa, conf, 100);
+ inf.isMasterRunning(null, IsMasterRunningRequest.getDefaultInstance());
+ fail();
+ } catch (ServiceException ex) {
+ IOException ie = ProtobufUtil.getRemoteException(ex);
+ if (!(ie instanceof SocketTimeoutException)) {
+ if(ie.getMessage().startsWith(
+ "org.apache.hadoop.hbase.ipc.ServerNotRunningYetException: Server is not running yet")) {
+ return;
+ }
+ } else {
+ System.err.println("Got SocketTimeoutException. Will retry. ");
+ }
+ } catch (Throwable t) {
+ fail("Unexpected throwable: " + t);
+ }
+ Thread.sleep(100);
+ i++;
}
+ fail();
}
@org.junit.Rule
Added: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestPriorityRpc.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestPriorityRpc.java?rev=1374860&view=auto
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestPriorityRpc.java (added)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestPriorityRpc.java Sun Aug 19 21:47:21 2012
@@ -0,0 +1,147 @@
+/*
+ * Copyright 2010 The Apache Software Foundation
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hbase.regionserver;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HRegionInfo;
+import org.apache.hadoop.hbase.SmallTests;
+import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.GetOnlineRegionRequest;
+import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.Get;
+import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.GetRequest;
+import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.ScanRequest;
+import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.RegionSpecifier;
+import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.RegionSpecifier.RegionSpecifierType;
+import org.apache.hadoop.hbase.protobuf.generated.RPCProtos.RpcRequestBody;
+import org.apache.hadoop.hbase.regionserver.HRegionServer.QosFunction;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.mockito.Mockito;
+
+import com.google.protobuf.ByteString;
+/**
+ * Tests that verify certain RPCs get a higher QoS.
+ */
+@Category(SmallTests.class)
+public class TestPriorityRpc {
+ static HRegionServer regionServer = null;
+ static QosFunction qosFunction = null;
+ @BeforeClass
+ public static void onetimeSetup() {
+ regionServer =
+ HRegionServer.constructRegionServer(HRegionServer.class, new Configuration());
+ qosFunction = regionServer.getQosFunction();
+ }
+ @Test
+ public void testQosFunctionForMeta() throws IOException {
+ qosFunction = regionServer.getQosFunction();
+ RpcRequestBody.Builder rpcRequestBuilder = RpcRequestBody.newBuilder();
+ //create a rpc request that has references to META region and also
+ //uses one of the known argument classes (known argument classes are
+ //listed in HRegionServer.QosFunction.knownArgumentClasses)
+ rpcRequestBuilder = RpcRequestBody.newBuilder();
+ rpcRequestBuilder.setMethodName("foo");
+
+ GetRequest.Builder getRequestBuilder = GetRequest.newBuilder();
+ RegionSpecifier.Builder regionSpecifierBuilder = RegionSpecifier.newBuilder();
+ regionSpecifierBuilder.setType(RegionSpecifierType.REGION_NAME);
+ ByteString name =
+ ByteString.copyFrom(HRegionInfo.FIRST_META_REGIONINFO.getRegionName());
+ regionSpecifierBuilder.setValue(name);
+ RegionSpecifier regionSpecifier = regionSpecifierBuilder.build();
+ getRequestBuilder.setRegion(regionSpecifier);
+ Get.Builder getBuilder = Get.newBuilder();
+ getBuilder.setRow(ByteString.copyFrom("somerow".getBytes()));
+ getRequestBuilder.setGet(getBuilder.build());
+ rpcRequestBuilder.setRequest(getRequestBuilder.build().toByteString());
+ rpcRequestBuilder.setRequestClassName(GetRequest.class.getCanonicalName());
+ RpcRequestBody rpcRequest = rpcRequestBuilder.build();
+ HRegion mockRegion = Mockito.mock(HRegion.class);
+ HRegionServer mockRS = Mockito.mock(HRegionServer.class);
+ HRegionInfo mockRegionInfo = Mockito.mock(HRegionInfo.class);
+ Mockito.when(mockRS.getRegion((RegionSpecifier)Mockito.any())).thenReturn(mockRegion);
+ Mockito.when(mockRegion.getRegionInfo()).thenReturn(mockRegionInfo);
+ Mockito.when(mockRegionInfo.isMetaRegion()).thenReturn(true);
+ qosFunction.setRegionServer(mockRS);
+ assertTrue (qosFunction.apply(rpcRequest) == HRegionServer.HIGH_QOS);
+ }
+
+ @Test
+ public void testQosFunctionWithoutKnownArgument() throws IOException {
+ //The request is not using any of the
+ //known argument classes (it uses one random request class)
+ //(known argument classes are listed in
+ //HRegionServer.QosFunction.knownArgumentClasses)
+ RpcRequestBody.Builder rpcRequestBuilder = RpcRequestBody.newBuilder();
+ rpcRequestBuilder.setMethodName("foo");
+ rpcRequestBuilder.setRequestClassName(GetOnlineRegionRequest.class.getCanonicalName());
+ RpcRequestBody rpcRequest = rpcRequestBuilder.build();
+ QosFunction qosFunc = regionServer.getQosFunction();
+ assertTrue (qosFunc.apply(rpcRequest) == HRegionServer.NORMAL_QOS);
+ }
+
+ @Test
+ public void testQosFunctionForScanMethod() throws IOException {
+ RpcRequestBody.Builder rpcRequestBuilder = RpcRequestBody.newBuilder();
+ rpcRequestBuilder.setMethodName("scan");
+
+ //build an empty scan request
+ ScanRequest.Builder scanBuilder = ScanRequest.newBuilder();
+ ByteString requestBody = scanBuilder.build().toByteString();
+ rpcRequestBuilder.setRequest(requestBody);
+ RpcRequestBody rpcRequest = rpcRequestBuilder.build();
+ assertTrue (qosFunction.apply(rpcRequest) == HRegionServer.NORMAL_QOS);
+
+ //build a scan request with scannerID
+ scanBuilder = ScanRequest.newBuilder();
+ scanBuilder.setScannerId(12345);
+ requestBody = scanBuilder.build().toByteString();
+ rpcRequestBuilder.setRequest(requestBody);
+ rpcRequestBuilder.setRequestClassName(ScanRequest.class.getCanonicalName());
+ rpcRequest = rpcRequestBuilder.build();
+ //mock out a high priority type handling and see the QoS returned
+ HRegionServer mockRS = Mockito.mock(HRegionServer.class);
+ RegionScanner mockRegionScanner = Mockito.mock(RegionScanner.class);
+ HRegionInfo mockRegionInfo = Mockito.mock(HRegionInfo.class);
+ HRegion mockRegion = Mockito.mock(HRegion.class);
+ Mockito.when(mockRS.getScanner(12345)).thenReturn(mockRegionScanner);
+ Mockito.when(mockRegionScanner.getRegionInfo()).thenReturn(mockRegionInfo);
+ Mockito.when(mockRS.getRegion((RegionSpecifier)Mockito.any())).thenReturn(mockRegion);
+ Mockito.when(mockRegion.getRegionInfo()).thenReturn(mockRegionInfo);
+ Mockito.when(mockRegionInfo.isMetaRegion()).thenReturn(true);
+
+ qosFunction.setRegionServer(mockRS);
+
+ assertTrue (qosFunction.apply(rpcRequest) == HRegionServer.HIGH_QOS);
+
+ //the same as above but with non-meta region
+ Mockito.when(mockRegionInfo.isMetaRegion()).thenReturn(false);
+ assertTrue (qosFunction.apply(rpcRequest) == HRegionServer.NORMAL_QOS);
+ }
+
+ @org.junit.Rule
+ public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu =
+ new org.apache.hadoop.hbase.ResourceCheckerJUnitRule();
+}
\ No newline at end of file
Added: hbase/trunk/hbase-server/src/test/protobuf/test_delayed_rpc.proto
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/protobuf/test_delayed_rpc.proto?rev=1374860&view=auto
==============================================================================
--- hbase/trunk/hbase-server/src/test/protobuf/test_delayed_rpc.proto (added)
+++ hbase/trunk/hbase-server/src/test/protobuf/test_delayed_rpc.proto Sun Aug 19 21:47:21 2012
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+option java_package = "org.apache.hadoop.hbase.ipc.protobuf.generated";
+option java_outer_classname = "TestDelayedRpcProtos";
+option java_generic_services = true;
+option java_generate_equals_and_hash = true;
+
+
+message TestArg {
+ required bool delay = 1;
+}
+
+message TestResponse {
+ required int32 response = 1;
+}