Repository: incubator-htrace Updated Branches: refs/heads/master bee26c52c -> a5b7ef771
Add code that was missed in the original commits for HTRACE-213 and HTRACE-210 (cmccabe) Project: http://git-wip-us.apache.org/repos/asf/incubator-htrace/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-htrace/commit/a5b7ef77 Tree: http://git-wip-us.apache.org/repos/asf/incubator-htrace/tree/a5b7ef77 Diff: http://git-wip-us.apache.org/repos/asf/incubator-htrace/diff/a5b7ef77 Branch: refs/heads/master Commit: a5b7ef771fc19ff2d1a5691a5803d641caadf202 Parents: bee26c5 Author: Colin Patrick Mccabe <[email protected]> Authored: Fri Jul 17 13:37:16 2015 -0700 Committer: Colin Patrick Mccabe <[email protected]> Committed: Fri Jul 17 13:42:39 2015 -0700 ---------------------------------------------------------------------- .../src/main/java/org/apache/htrace/Trace.java | 1 + .../java/org/apache/htrace/impl/FakeFlume.java | 110 +++++++++++++++++++ 2 files changed, 111 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/a5b7ef77/htrace-core/src/main/java/org/apache/htrace/Trace.java ---------------------------------------------------------------------- diff --git a/htrace-core/src/main/java/org/apache/htrace/Trace.java b/htrace-core/src/main/java/org/apache/htrace/Trace.java index 5234d95..ef07687 100644 --- a/htrace-core/src/main/java/org/apache/htrace/Trace.java +++ b/htrace-core/src/main/java/org/apache/htrace/Trace.java @@ -19,6 +19,7 @@ package org.apache.htrace; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.htrace.impl.MilliSpan; +import org.apache.htrace.impl.NeverSampler; import org.apache.htrace.wrappers.TraceCallable; import org.apache.htrace.wrappers.TraceRunnable; http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/a5b7ef77/htrace-flume/src/test/java/org/apache/htrace/impl/FakeFlume.java ---------------------------------------------------------------------- diff --git a/htrace-flume/src/test/java/org/apache/htrace/impl/FakeFlume.java b/htrace-flume/src/test/java/org/apache/htrace/impl/FakeFlume.java new file mode 100644 index 0000000..c28f9bd --- /dev/null +++ b/htrace-flume/src/test/java/org/apache/htrace/impl/FakeFlume.java @@ -0,0 +1,110 @@ +/* + * 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.impl; + +import org.apache.avro.AvroRemoteException; +import org.apache.avro.ipc.Server; +import org.apache.flume.api.RpcTestUtils; +import org.apache.flume.source.avro.AvroFlumeEvent; +import org.apache.flume.source.avro.AvroSourceProtocol; +import org.apache.flume.source.avro.Status; +import org.junit.rules.TestRule; +import org.junit.runner.Description; +import org.junit.runners.model.Statement; + +import java.nio.charset.Charset; +import java.util.List; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.BlockingQueue; + +final class FakeFlume implements TestRule { + + private final BlockingQueue<AvroFlumeEvent> receivedEvents = + new ArrayBlockingQueue<AvroFlumeEvent>(1); + + private Server flumeServer; + private AvroSourceProtocol protocol = new AvroSourceProtocol() { + + @Override + public Status append(AvroFlumeEvent event) { + receivedEvents.add(event); + return Status.OK; + } + + @Override + public Status appendBatch(List<AvroFlumeEvent> events) { + receivedEvents.addAll(events); + return Status.OK; + } + }; + + FakeFlume alwaysFail() { + this.protocol = new RpcTestUtils.FailedAvroHandler(); + return this; + } + + FakeFlume alwaysOk() { + this.protocol = new RpcTestUtils.OKAvroHandler(); + return this; + } + + String nextEventBodyAsString() throws InterruptedException { + return new String(receivedEvents.take().getBody().array(), Charset.forName("UTF-8")); + } + + @Override + public Statement apply(final Statement base, Description description) { + return new Statement() { + @Override + public void evaluate() throws Throwable { + start(); + try { + base.evaluate(); + } finally { + stop(); + } + } + }; + } + + private void start() { + flumeServer = RpcTestUtils.startServer(new AvroSourceProtocol(){ + + @Override + public Status append(AvroFlumeEvent event) throws AvroRemoteException { + return protocol.append(event); + } + + @Override + public Status appendBatch(List<AvroFlumeEvent> events) throws AvroRemoteException { + return protocol.appendBatch(events); + } + }); + } + + private void stop() { + if (flumeServer != null) { + RpcTestUtils.stopServer(flumeServer); + flumeServer = null; + } + } + + int getPort() { + return flumeServer.getPort(); + } +}
