diff --git a/htrace-hbase/pom.xml b/htrace-hbase/pom.xml
index f2d0351..ae4a53e 100644
--- a/htrace-hbase/pom.xml
+++ b/htrace-hbase/pom.xml
@@ -31,7 +31,7 @@ language governing permissions and limitations under the License. -->
UTF-8
- 0.99.2
+ 1.1.2
9.2.13.v20150730
true
diff --git a/htrace-hbase/src/main/java/org/apache/htrace/impl/HBaseSpanReceiver.java b/htrace-hbase/src/main/java/org/apache/htrace/impl/HBaseSpanReceiver.java
index aa471ab..11ee578 100644
--- a/htrace-hbase/src/main/java/org/apache/htrace/impl/HBaseSpanReceiver.java
+++ b/htrace-hbase/src/main/java/org/apache/htrace/impl/HBaseSpanReceiver.java
@@ -192,6 +192,7 @@ public class HBaseSpanReceiver extends SpanReceiver {
// Ignored.
}
startClient();
+ /*
if (dequeuedSpans.isEmpty()) {
try {
this.htable.flushCommits();
@@ -201,6 +202,7 @@ public class HBaseSpanReceiver extends SpanReceiver {
}
continue;
}
+ */
try {
for (Span span : dequeuedSpans) {
diff --git a/htrace-hbase/src/test/java/org/apache/htrace/HTraceConfiguration.java b/htrace-hbase/src/test/java/org/apache/htrace/HTraceConfiguration.java
new file mode 100644
index 0000000..f4896e9
--- /dev/null
+++ b/htrace-hbase/src/test/java/org/apache/htrace/HTraceConfiguration.java
@@ -0,0 +1,109 @@
+/*
+ * 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.htrace;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Wrapper which integrating applications should implement in order
+ * to provide tracing configuration.
+ */
+public abstract class HTraceConfiguration {
+
+ private static final Log LOG = LogFactory.getLog(HTraceConfiguration.class);
+
+ private static final Map EMPTY_MAP = new HashMap(1);
+
+ /**
+ * An empty HTrace configuration.
+ */
+ public static final HTraceConfiguration EMPTY = fromMap(EMPTY_MAP);
+
+ /**
+ * Create an HTrace configuration from a map.
+ *
+ * @param conf The map to create the configuration from.
+ * @return The new configuration.
+ */
+ public static HTraceConfiguration fromMap(Map conf) {
+ return new MapConf(conf);
+ }
+
+ static HTraceConfiguration fromKeyValuePairs(String... pairs) {
+ if ((pairs.length % 2) != 0) {
+ throw new RuntimeException("You must specify an equal number of keys " +
+ "and values.");
+ }
+ Map conf = new HashMap();
+ for (int i = 0; i < pairs.length; i+=2) {
+ conf.put(pairs[i], pairs[i + 1]);
+ }
+ return new MapConf(conf);
+ }
+
+ public abstract String get(String key);
+
+ public abstract String get(String key, String defaultValue);
+
+ public boolean getBoolean(String key, boolean defaultValue) {
+ String value = get(key, String.valueOf(defaultValue)).trim().toLowerCase();
+
+ if ("true".equals(value)) {
+ return true;
+ } else if ("false".equals(value)) {
+ return false;
+ }
+
+ LOG.warn("Expected boolean for key [" + key + "] instead got [" + value + "].");
+ return defaultValue;
+ }
+
+ public int getInt(String key, int defaultVal) {
+ String val = get(key);
+ if (val == null || val.trim().isEmpty()) {
+ return defaultVal;
+ }
+ try {
+ return Integer.parseInt(val);
+ } catch (NumberFormatException nfe) {
+ throw new IllegalArgumentException("Bad value for '" + key + "': should be int");
+ }
+ }
+
+ private static class MapConf extends HTraceConfiguration {
+ private final Map conf;
+
+ public MapConf(Map conf) {
+ this.conf = new HashMap(conf);
+ }
+
+ @Override
+ public String get(String key) {
+ return conf.get(key);
+ }
+
+ @Override
+ public String get(String key, String defaultValue) {
+ String value = get(key);
+ return value == null ? defaultValue : value;
+ }
+ }
+}
diff --git a/htrace-hbase/src/test/java/org/apache/htrace/NullScope.java b/htrace-hbase/src/test/java/org/apache/htrace/NullScope.java
new file mode 100644
index 0000000..037a226
--- /dev/null
+++ b/htrace-hbase/src/test/java/org/apache/htrace/NullScope.java
@@ -0,0 +1,35 @@
+/*
+ * 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.htrace;
+
+/**
+ * Stab for unit tests to run MiniHBaseCluster and hbase-client
+ * of hbase-1 which depends on htrace-3.1.0-incubating.
+ */
+public final class NullScope extends TraceScope {
+
+ public static final TraceScope INSTANCE = new NullScope();
+
+ private NullScope() {
+ super(null, null);
+ }
+
+ @Override
+ public String toString() {
+ return "NullScope";
+ }
+}
diff --git a/htrace-hbase/src/test/java/org/apache/htrace/Sampler.java b/htrace-hbase/src/test/java/org/apache/htrace/Sampler.java
new file mode 100644
index 0000000..97adf98
--- /dev/null
+++ b/htrace-hbase/src/test/java/org/apache/htrace/Sampler.java
@@ -0,0 +1,25 @@
+/*
+ * 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.htrace;
+
+/**
+ * Stab for unit tests to run MiniHBaseCluster and hbase-client
+ * of hbase-1 which depends on htrace-3.1.0-incubating.
+ */
+public interface Sampler {
+ public boolean next(T info);
+}
diff --git a/htrace-hbase/src/test/java/org/apache/htrace/Span.java b/htrace-hbase/src/test/java/org/apache/htrace/Span.java
new file mode 100644
index 0000000..52f96bc
--- /dev/null
+++ b/htrace-hbase/src/test/java/org/apache/htrace/Span.java
@@ -0,0 +1,64 @@
+/*
+ * 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.htrace;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Stab for unit tests to run MiniHBaseCluster and hbase-client
+ * of hbase-1 which depends on htrace-3.1.0-incubating.
+ */
+public interface Span {
+ public static final long ROOT_SPAN_ID = 0x74ace;
+
+ void stop();
+
+ long getStartTimeMillis();
+
+ long getStopTimeMillis();
+
+ long getAccumulatedMillis();
+
+ boolean isRunning();
+
+ String getDescription();
+
+ long getSpanId();
+
+ long getTraceId();
+
+ Span child(String description);
+
+ @Override
+ String toString();
+
+ long getParentId();
+
+ void addKVAnnotation(byte[] key, byte[] value);
+
+ void addTimelineAnnotation(String msg);
+
+ Map getKVAnnotations();
+
+ List getTimelineAnnotations();
+
+ String getProcessId();
+
+ String toJson();
+}
diff --git a/htrace-hbase/src/test/java/org/apache/htrace/TimelineAnnotation.java b/htrace-hbase/src/test/java/org/apache/htrace/TimelineAnnotation.java
new file mode 100644
index 0000000..61cd05d
--- /dev/null
+++ b/htrace-hbase/src/test/java/org/apache/htrace/TimelineAnnotation.java
@@ -0,0 +1,44 @@
+/*
+ * 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.htrace;
+
+/**
+ * Stab for unit tests to run MiniHBaseCluster and hbase-client
+ * of hbase-1 which depends on htrace-3.1.0-incubating.
+ */
+public class TimelineAnnotation {
+ private final long time;
+ private final String msg;
+
+ public TimelineAnnotation(long time, String msg) {
+ this.time = time;
+ this.msg = msg;
+ }
+
+ public long getTime() {
+ return time;
+ }
+
+ public String getMessage() {
+ return msg;
+ }
+
+ @Override
+ public String toString() {
+ return "@" + time + ": " + msg;
+ }
+}
diff --git a/htrace-hbase/src/test/java/org/apache/htrace/Trace.java b/htrace-hbase/src/test/java/org/apache/htrace/Trace.java
new file mode 100644
index 0000000..61751db
--- /dev/null
+++ b/htrace-hbase/src/test/java/org/apache/htrace/Trace.java
@@ -0,0 +1,75 @@
+/*
+ * 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.htrace;
+
+/**
+ * Stab for unit tests to run MiniHBaseCluster and hbase-client
+ * of hbase-1 which depends on htrace-3.1.0-incubating.
+ */
+public class Trace {
+ public static TraceScope startSpan(String description) {
+ return NullScope.INSTANCE;
+ }
+
+ public static TraceScope startSpan(String description, Span parent) {
+ return NullScope.INSTANCE;
+ }
+
+ public static TraceScope startSpan(String description, TraceInfo tinfo) {
+ return NullScope.INSTANCE;
+ }
+
+ public static TraceScope startSpan(String description, Sampler s) {
+ return NullScope.INSTANCE;
+ }
+
+ public static TraceScope startSpan(String description, Sampler s, TraceInfo tinfo) {
+ return NullScope.INSTANCE;
+ }
+
+ public static TraceScope startSpan(String description, Sampler s, T info) {
+ return NullScope.INSTANCE;
+ }
+
+ public static TraceScope continueSpan(Span s) {
+ return NullScope.INSTANCE;
+ }
+ public static void setProcessId(String processId) {
+ }
+
+ public static void addKVAnnotation(byte[] key, byte[] value) {
+ }
+
+ public static void addTimelineAnnotation(String msg) {
+ }
+
+ public static boolean isTracing() {
+ return false;
+ }
+
+ public static Span currentSpan() {
+ return null;
+ }
+
+ public static Runnable wrap(Runnable runnable) {
+ return runnable;
+ }
+
+ public static Runnable wrap(String description, Runnable runnable) {
+ return runnable;
+ }
+}
diff --git a/htrace-hbase/src/test/java/org/apache/htrace/TraceInfo.java b/htrace-hbase/src/test/java/org/apache/htrace/TraceInfo.java
new file mode 100644
index 0000000..ebfd9f4
--- /dev/null
+++ b/htrace-hbase/src/test/java/org/apache/htrace/TraceInfo.java
@@ -0,0 +1,41 @@
+/*
+ * 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.htrace;
+
+/**
+ * Stab for unit tests to run MiniHBaseCluster and hbase-client
+ * of hbase-1 which depends on htrace-3.1.0-incubating.
+ */
+public class TraceInfo {
+ public final long traceId;
+ public final long spanId;
+
+ public TraceInfo(long traceId, long spanId) {
+ this.traceId = traceId;
+ this.spanId = spanId;
+ }
+
+ @Override
+ public String toString() {
+ return "TraceInfo(traceId=" + traceId + ", spanId=" + spanId + ")";
+ }
+
+ public static TraceInfo fromSpan(Span s) {
+ if (s == null) return null;
+ return new TraceInfo(s.getTraceId(), s.getSpanId());
+ }
+}
diff --git a/htrace-hbase/src/test/java/org/apache/htrace/TraceScope.java b/htrace-hbase/src/test/java/org/apache/htrace/TraceScope.java
new file mode 100644
index 0000000..bb31070
--- /dev/null
+++ b/htrace-hbase/src/test/java/org/apache/htrace/TraceScope.java
@@ -0,0 +1,61 @@
+/*
+ * 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.htrace;
+
+import java.io.Closeable;
+
+/**
+ * Stab for unit tests to run MiniHBaseCluster and hbase-client
+ * of hbase-1 which depends on htrace-3.1.0-incubating.
+ */
+public class TraceScope implements Closeable {
+
+ private final Span span;
+
+ private final Span savedSpan;
+
+ private boolean detached = false;
+
+ TraceScope(Span span, Span saved) {
+ this.span = span;
+ this.savedSpan = saved;
+ }
+
+ public Span getSpan() {
+ return span;
+ }
+
+ public Span detach() {
+ detached = true;
+ return span;
+ }
+
+ public boolean isDetached() {
+ return detached;
+ }
+
+ @Override
+ public void close() {
+ if (span == null) return;
+
+ if (!detached) {
+ // The span is done
+ span.stop();
+ detach();
+ }
+ }
+}
diff --git a/htrace-hbase/src/test/java/org/apache/htrace/impl/TestHBaseSpanReceiver.java b/htrace-hbase/src/test/java/org/apache/htrace/impl/TestHBaseSpanReceiver.java
index bba19f5..14bea59 100644
--- a/htrace-hbase/src/test/java/org/apache/htrace/impl/TestHBaseSpanReceiver.java
+++ b/htrace-hbase/src/test/java/org/apache/htrace/impl/TestHBaseSpanReceiver.java
@@ -40,6 +40,7 @@ import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.htrace.core.HTraceConfiguration;
+import org.apache.htrace.core.Sampler;
import org.apache.htrace.core.Span;
import org.apache.htrace.core.SpanId;
import org.apache.htrace.core.TimelineAnnotation;
@@ -81,8 +82,7 @@ public class TestHBaseSpanReceiver {
return htable;
}
- // Reenable after fix circular dependency
- @Ignore @Test
+ @Test
public void testHBaseSpanReceiver() {
Table htable = createTable(UTIL);
Configuration conf = UTIL.getConfiguration();
@@ -90,6 +90,8 @@ public class TestHBaseSpanReceiver {
name("testHBaseSpanReceiver").
tracerPool(new TracerPool("testHBaseSpanReceiver")).
conf(HTraceConfiguration.fromKeyValuePairs(
+ Tracer.SPAN_RECEIVER_CLASSES_KEY,
+ HBaseSpanReceiver.class.getName(),
HBaseSpanReceiver.COLLECTOR_QUORUM_KEY,
conf.get(HConstants.ZOOKEEPER_QUORUM),
HBaseSpanReceiver.ZOOKEEPER_CLIENT_PORT_KEY,
@@ -97,6 +99,7 @@ public class TestHBaseSpanReceiver {
HBaseSpanReceiver.ZOOKEEPER_ZNODE_PARENT_KEY,
conf.get(HConstants.ZOOKEEPER_ZNODE_PARENT)
)).build();
+ tracer.addSampler(Sampler.ALWAYS);
TraceCreator tc = new TraceCreator(tracer);
tc.createThreadedTrace();
tc.createSimpleTrace();