You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by ph...@apache.org on 2010/08/28 01:33:29 UTC
svn commit: r990299 - in /avro/trunk: ./
lang/java/src/java/org/apache/avro/ipc/trace/
lang/java/src/test/java/org/apache/avro/ipc/trace/
Author: philz
Date: Fri Aug 27 23:33:28 2010
New Revision: 990299
URL: http://svn.apache.org/viewvc?rev=990299&view=rev
Log:
AVRO-636. Expose Singleton Method for TracePlugin.
Added:
avro/trunk/lang/java/src/test/java/org/apache/avro/ipc/trace/SingletonTestingTracePlugin.java
avro/trunk/lang/java/src/test/java/org/apache/avro/ipc/trace/TestTraceConfigurations.java
avro/trunk/lang/java/src/test/java/org/apache/avro/ipc/trace/TestTraceSingletons.java
Modified:
avro/trunk/CHANGES.txt
avro/trunk/lang/java/src/java/org/apache/avro/ipc/trace/TracePlugin.java
avro/trunk/lang/java/src/java/org/apache/avro/ipc/trace/TracePluginConfiguration.java
avro/trunk/lang/java/src/test/java/org/apache/avro/ipc/trace/TestBasicTracing.java
avro/trunk/lang/java/src/test/java/org/apache/avro/ipc/trace/TestEndToEndTracing.java
Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=990299&r1=990298&r2=990299&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Fri Aug 27 23:33:28 2010
@@ -64,6 +64,9 @@ Avro 1.4.0 (unreleased)
IMPROVEMENTS
+ AVRO-636. Expose Singleton Method for TracePlugin. (Patrick Wendell via
+ philz)
+
AVRO-614. Improve Trace frontend UI. (Patrick Wendell via philz)
AVRO-629. Prefer the JSON module of python's stdlib over simplejson.
Modified: avro/trunk/lang/java/src/java/org/apache/avro/ipc/trace/TracePlugin.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/java/org/apache/avro/ipc/trace/TracePlugin.java?rev=990299&r1=990298&r2=990299&view=diff
==============================================================================
--- avro/trunk/lang/java/src/java/org/apache/avro/ipc/trace/TracePlugin.java (original)
+++ avro/trunk/lang/java/src/java/org/apache/avro/ipc/trace/TracePlugin.java Fri Aug 27 23:33:28 2010
@@ -62,6 +62,8 @@ public class TracePlugin extends RPCPlug
final private static Random RANDOM = new Random();
private static final Logger LOG = LoggerFactory.getLogger(TracePlugin.class);
public static enum StorageType { MEMORY, DISK };
+ protected static TracePlugin singleton;
+ protected static TracePluginConfiguration singletonConf;
/*
* This plugin uses three key/value meta-data pairs. The value type for all
@@ -113,7 +115,8 @@ public class TracePlugin extends RPCPlug
private StorageType storageType; // How to store spans
private long maxSpans; // Max number of spans to store
private boolean enabled; // Whether to participate in tracing
-
+ protected TracePluginConfiguration config; // Init options
+
private ThreadLocal<Span> currentSpan; // span in which we are server
private ThreadLocal<Span> childSpan; // span in which we are client
@@ -124,10 +127,38 @@ public class TracePlugin extends RPCPlug
// Client interface
protected Server clientFacingServer;
-
private CharSequence hostname;
+ /**
+ * Get a singleton TracePlugin. This is useful if you want to persist a plugin
+ * across both a { @link Requestor } and { @link Responder }. This must be
+ * prefixed by at least one call of configureSingleton();
+ */
+ public static synchronized TracePlugin getSingleton()
+ throws IOException {
+ if (singletonConf == null) {
+ throw new RuntimeException("Singleton not configured yet.");
+ }
+ singleton = new TracePlugin(singletonConf);
+ return singleton;
+ }
+
+ /**
+ * Configure a singleton instance for this TracePlugin. If a singleton
+ * has already been created according to a different configuration, throw
+ * a RuntimeException.
+ */
+ public static synchronized void configureSingleton(
+ TracePluginConfiguration conf) {
+ if (singleton != null && !(singleton.config.equals(conf))) {
+ throw new RuntimeException("Singleton already in use: " +
+ "can't reconfigure.");
+ }
+ singletonConf = conf;
+ }
+
public TracePlugin(TracePluginConfiguration conf) throws IOException {
+ config = conf;
traceProb = conf.traceProb;
port = conf.port;
clientPort = conf.clientPort;
Modified: avro/trunk/lang/java/src/java/org/apache/avro/ipc/trace/TracePluginConfiguration.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/java/org/apache/avro/ipc/trace/TracePluginConfiguration.java?rev=990299&r1=990298&r2=990299&view=diff
==============================================================================
--- avro/trunk/lang/java/src/java/org/apache/avro/ipc/trace/TracePluginConfiguration.java (original)
+++ avro/trunk/lang/java/src/java/org/apache/avro/ipc/trace/TracePluginConfiguration.java Fri Aug 27 23:33:28 2010
@@ -47,7 +47,7 @@ public class TracePluginConfiguration {
this.traceProb = 0.0;
this.port = DEFAULT_PORT;
this.clientPort = DEFAULT_CLIENT_PORT;
- this.storageType = StorageType.MEMORY;
+ this.storageType = StorageType.DISK;
this.maxSpans = 10000;
this.enabled = true;
this.buffer = true;
@@ -55,4 +55,21 @@ public class TracePluginConfiguration {
this.fileGranularitySeconds = 500;
this.spanStorageDir = "/tmp";
}
+
+ @Override
+ public boolean equals(Object otherObj) {
+ if (!(otherObj instanceof TracePluginConfiguration)) { return false; }
+ TracePluginConfiguration other = (TracePluginConfiguration) otherObj;
+ return (
+ this.traceProb == other.traceProb &&
+ this.port == other.port &&
+ this.clientPort == other.clientPort &&
+ this.storageType == other.storageType &&
+ this.maxSpans == other.maxSpans &&
+ this.enabled == other.enabled &&
+ this.buffer == other.buffer &&
+ this.compressionLevel == other.compressionLevel &&
+ this.fileGranularitySeconds == other.fileGranularitySeconds &&
+ this.spanStorageDir == other.spanStorageDir);
+ }
}
Added: avro/trunk/lang/java/src/test/java/org/apache/avro/ipc/trace/SingletonTestingTracePlugin.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/test/java/org/apache/avro/ipc/trace/SingletonTestingTracePlugin.java?rev=990299&view=auto
==============================================================================
--- avro/trunk/lang/java/src/test/java/org/apache/avro/ipc/trace/SingletonTestingTracePlugin.java (added)
+++ avro/trunk/lang/java/src/test/java/org/apache/avro/ipc/trace/SingletonTestingTracePlugin.java Fri Aug 27 23:33:28 2010
@@ -0,0 +1,38 @@
+/**
+ * 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.avro.ipc.trace;
+
+import java.io.IOException;
+
+public class SingletonTestingTracePlugin extends TracePlugin {
+
+ /**
+ * Lets us clear out the singleton data.
+ */
+ public static void clearSingletonInfo() {
+ singletonConf = null;
+ singleton = null;
+ }
+
+ public SingletonTestingTracePlugin(TracePluginConfiguration conf)
+ throws IOException {
+ super(conf);
+ }
+
+}
Modified: avro/trunk/lang/java/src/test/java/org/apache/avro/ipc/trace/TestBasicTracing.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/test/java/org/apache/avro/ipc/trace/TestBasicTracing.java?rev=990299&r1=990298&r2=990299&view=diff
==============================================================================
--- avro/trunk/lang/java/src/test/java/org/apache/avro/ipc/trace/TestBasicTracing.java (original)
+++ avro/trunk/lang/java/src/test/java/org/apache/avro/ipc/trace/TestBasicTracing.java Fri Aug 27 23:33:28 2010
@@ -36,6 +36,7 @@ import org.apache.avro.ipc.HttpServer;
import org.apache.avro.ipc.HttpTransceiver;
import org.apache.avro.ipc.RPCPlugin;
import org.apache.avro.ipc.Responder;
+import org.apache.avro.ipc.trace.TracePlugin.StorageType;
import org.junit.Test;
public class TestBasicTracing {
@@ -62,6 +63,7 @@ public class TestBasicTracing {
@Test
public void testBasicTrace() throws Exception {
TracePluginConfiguration conf = new TracePluginConfiguration();
+ conf.storageType = StorageType.MEMORY;
conf.port = 51007;
conf.clientPort = 12344;
conf.traceProb = 1.0;
@@ -234,6 +236,7 @@ public class TestBasicTracing {
@Test
public void testRecursingTrace() throws Exception {
TracePluginConfiguration conf = new TracePluginConfiguration();
+ conf.storageType = StorageType.MEMORY;
conf.traceProb = 1.0;
conf.port = 51010;
conf.clientPort = 12346;
@@ -371,6 +374,7 @@ public class TestBasicTracing {
*/
public static void main(String[] args) throws Exception {
TracePluginConfiguration conf = new TracePluginConfiguration();
+ conf.storageType = StorageType.MEMORY;
conf.traceProb = 1.0;
conf.port = 51010;
conf.clientPort = 12346;
Modified: avro/trunk/lang/java/src/test/java/org/apache/avro/ipc/trace/TestEndToEndTracing.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/test/java/org/apache/avro/ipc/trace/TestEndToEndTracing.java?rev=990299&r1=990298&r2=990299&view=diff
==============================================================================
--- avro/trunk/lang/java/src/test/java/org/apache/avro/ipc/trace/TestEndToEndTracing.java (original)
+++ avro/trunk/lang/java/src/test/java/org/apache/avro/ipc/trace/TestEndToEndTracing.java Fri Aug 27 23:33:28 2010
@@ -155,6 +155,7 @@ public class TestEndToEndTracing {
}
public void testTraceAndCollection(TracePluginConfiguration conf) throws Exception {
+ conf.storageType = StorageType.MEMORY;
conf.traceProb = 1.0;
conf.port = 51010;
conf.clientPort = 12346;
Added: avro/trunk/lang/java/src/test/java/org/apache/avro/ipc/trace/TestTraceConfigurations.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/test/java/org/apache/avro/ipc/trace/TestTraceConfigurations.java?rev=990299&view=auto
==============================================================================
--- avro/trunk/lang/java/src/test/java/org/apache/avro/ipc/trace/TestTraceConfigurations.java (added)
+++ avro/trunk/lang/java/src/test/java/org/apache/avro/ipc/trace/TestTraceConfigurations.java Fri Aug 27 23:33:28 2010
@@ -0,0 +1,104 @@
+/**
+ * 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.avro.ipc.trace;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.avro.ipc.trace.TracePlugin.StorageType;
+import org.junit.Test;
+
+public class TestTraceConfigurations {
+
+ @Test
+ public void testTraceEquality() {
+ TracePluginConfiguration conf1 = new TracePluginConfiguration();
+ TracePluginConfiguration conf2 = new TracePluginConfiguration();
+ assertTrue(conf1.equals(conf2));
+ assertEquals(conf1, conf2);
+
+ TracePluginConfiguration conf3 = new TracePluginConfiguration();
+ TracePluginConfiguration conf4 = new TracePluginConfiguration();
+
+ conf3.traceProb = .12345;
+ conf3.port = 333;
+ conf3.clientPort = 444;
+ conf3.storageType = StorageType.DISK;
+ conf3.maxSpans = 10000;
+ conf3.enabled = true;
+ conf3.buffer = true;
+ conf3.compressionLevel = 9;
+ conf3.fileGranularitySeconds = 500;
+ conf3.spanStorageDir = "/tmp";
+
+ conf4.traceProb = .12345;
+ conf4.port = 333;
+ conf4.clientPort = 444;
+ conf4.storageType = StorageType.DISK;
+ conf4.maxSpans = 10000;
+ conf4.enabled = true;
+ conf4.buffer = true;
+ conf4.compressionLevel = 9;
+ conf4.fileGranularitySeconds = 500;
+ conf4.spanStorageDir = "/tmp";
+
+ assertTrue(conf3.equals(conf4));
+ assertEquals(conf3, conf4);
+
+ TracePluginConfiguration conf5 = new TracePluginConfiguration();
+ conf5.traceProb = .4;
+ assertTrue(!conf1.equals(conf5));
+
+ conf5 = new TracePluginConfiguration();
+ conf5.port = 333;
+ assertTrue(!conf1.equals(conf5));
+
+ conf5 = new TracePluginConfiguration();
+ conf5.clientPort = 333;
+ assertTrue(!conf1.equals(conf5));
+
+ conf5 = new TracePluginConfiguration();
+ conf5.storageType = StorageType.MEMORY;
+ assertTrue(!conf1.equals(conf5));
+
+ conf5 = new TracePluginConfiguration();
+ conf5.maxSpans = 4;
+ assertTrue(!conf1.equals(conf5));
+
+ conf5 = new TracePluginConfiguration();
+ conf5.enabled = false;
+ assertTrue(!conf1.equals(conf5));
+
+ conf5 = new TracePluginConfiguration();
+ conf5.buffer = false;
+ assertTrue(!conf1.equals(conf5));
+
+ conf5 = new TracePluginConfiguration();
+ conf5.compressionLevel = 0;
+ assertTrue(!conf1.equals(conf5));
+
+ conf5 = new TracePluginConfiguration();
+ conf5.fileGranularitySeconds = 400;
+ assertTrue(!conf1.equals(conf5));
+
+ conf5 = new TracePluginConfiguration();
+ conf5.spanStorageDir = "/foo";
+ assertTrue(!conf1.equals(conf5));
+ }
+}
Added: avro/trunk/lang/java/src/test/java/org/apache/avro/ipc/trace/TestTraceSingletons.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/test/java/org/apache/avro/ipc/trace/TestTraceSingletons.java?rev=990299&view=auto
==============================================================================
--- avro/trunk/lang/java/src/test/java/org/apache/avro/ipc/trace/TestTraceSingletons.java (added)
+++ avro/trunk/lang/java/src/test/java/org/apache/avro/ipc/trace/TestTraceSingletons.java Fri Aug 27 23:33:28 2010
@@ -0,0 +1,76 @@
+/**
+ * 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.avro.ipc.trace;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+
+import org.junit.Test;
+
+public class TestTraceSingletons {
+
+ @Test
+ public void testNormalConfiguration() throws IOException {
+ TracePluginConfiguration conf = new TracePluginConfiguration();
+ SingletonTestingTracePlugin.configureSingleton(conf);
+ TracePlugin plugin = SingletonTestingTracePlugin.getSingleton();
+ assertEquals(plugin.config, conf);
+ SingletonTestingTracePlugin.clearSingletonInfo();
+ }
+
+ /** Someone tries to re-configure after plugin dispatched. */
+ @Test(expected = RuntimeException.class)
+ public void testInvalidDoubleConfiguration() throws IOException {
+ TracePluginConfiguration conf1 = new TracePluginConfiguration();
+ TracePluginConfiguration conf2 = new TracePluginConfiguration();
+ conf2.clientPort = 3333;
+ SingletonTestingTracePlugin.configureSingleton(conf1);
+ TracePlugin plugin = SingletonTestingTracePlugin.getSingleton();
+ SingletonTestingTracePlugin.configureSingleton(conf2);
+ SingletonTestingTracePlugin.clearSingletonInfo();
+ }
+
+ /**
+ * Someone tries to re-configure after plugin dispatched, but config is
+ * the same.
+ */
+ @Test
+ public void testValidDoubleConfiguration() throws IOException {
+ TracePluginConfiguration conf1 = new TracePluginConfiguration();
+ TracePluginConfiguration conf2 = new TracePluginConfiguration();
+ SingletonTestingTracePlugin.configureSingleton(conf1);
+ TracePlugin plugin = SingletonTestingTracePlugin.getSingleton();
+ try {
+ SingletonTestingTracePlugin.configureSingleton(conf2);
+ }
+ catch (RuntimeException e) {
+ throw new AssertionError("Valid double configuration threw error.");
+ }
+ SingletonTestingTracePlugin.clearSingletonInfo();
+ }
+
+ /**
+ * Someone never configures the singleton, then asks for one.
+ */
+ @Test(expected = RuntimeException.class)
+ public void testNoConfiguration() throws IOException {
+ TracePlugin plugin = SingletonTestingTracePlugin.getSingleton();
+ }
+}