Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 5 commits
  • 21 files changed
  • 0 commit comments
  • 4 contributors
Commits on Aug 07, 2012
@mariusae mariusae [split] GC monitor: be more quiet about missed GCs
Log these at most once every ½ hour.

RB_ID=79217
eb9aca7
Commits on Aug 14, 2012
@aaron-siegel aaron-siegel [split] add a Time.hashCode method
RB_ID=80389
cd1d2b1
Commits on Aug 15, 2012
Sam Ritchie [split] Added ThriftCodec Thrift implementation of the Codec trait.
RB_ID=80610
8cfac96
Commits on Aug 20, 2012
@stuhood stuhood [split] Disable log handler purging: if you encounter unwanted loggin…
…g in tests, use the util-logging API in a base class to mute it.

RB_ID=80726
898fb2b
Commits on Aug 21, 2012
@mariusae mariusae [split] release util 5.3.7
RB_ID=81741
79a117e
View
2 pom.xml
@@ -4,7 +4,7 @@
<groupId>com.twitter</groupId>
<artifactId>util</artifactId>
<packaging>pom</packaging>
- <version>5.3.7-SNAPSHOT</version>
+ <version>5.3.8-SNAPSHOT</version>
<distributionManagement>
<repository>
<id>artifactory-release</id>
View
6 util-benchmark/pom.xml
@@ -4,7 +4,7 @@
<groupId>com.twitter</groupId>
<artifactId>util-benchmark</artifactId>
<packaging>jar</packaging>
- <version>5.3.7-SNAPSHOT</version>
+ <version>5.3.8-SNAPSHOT</version>
<parent>
<groupId>com.twitter</groupId>
<artifactId>scala-parent-292</artifactId>
@@ -25,12 +25,12 @@
<dependency>
<groupId>com.twitter</groupId>
<artifactId>util-core</artifactId>
- <version>5.3.7-SNAPSHOT</version>
+ <version>5.3.8-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.twitter</groupId>
<artifactId>util-jvm</artifactId>
- <version>5.3.7-SNAPSHOT</version>
+ <version>5.3.8-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
View
2 util-class-preloader/pom.xml
@@ -4,7 +4,7 @@
<groupId>com.twitter</groupId>
<artifactId>util-class-preloader</artifactId>
<packaging>jar</packaging>
- <version>5.3.7-SNAPSHOT</version>
+ <version>5.3.8-SNAPSHOT</version>
<parent>
<groupId>com.twitter</groupId>
<artifactId>scala-parent-292</artifactId>
View
4 util-codec/pom.xml
@@ -4,7 +4,7 @@
<groupId>com.twitter</groupId>
<artifactId>util-codec</artifactId>
<packaging>jar</packaging>
- <version>5.3.7-SNAPSHOT</version>
+ <version>5.3.8-SNAPSHOT</version>
<parent>
<groupId>com.twitter</groupId>
<artifactId>scala-parent-292</artifactId>
@@ -25,7 +25,7 @@
<dependency>
<groupId>com.twitter</groupId>
<artifactId>util-core</artifactId>
- <version>5.3.7-SNAPSHOT</version>
+ <version>5.3.8-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
View
4 util-collection/pom.xml
@@ -4,7 +4,7 @@
<groupId>com.twitter</groupId>
<artifactId>util-collection</artifactId>
<packaging>jar</packaging>
- <version>5.3.7-SNAPSHOT</version>
+ <version>5.3.8-SNAPSHOT</version>
<parent>
<groupId>com.twitter</groupId>
<artifactId>scala-parent-292</artifactId>
@@ -30,7 +30,7 @@
<dependency>
<groupId>com.twitter</groupId>
<artifactId>util-core</artifactId>
- <version>5.3.7-SNAPSHOT</version>
+ <version>5.3.8-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
View
2 util-core/pom.xml
@@ -4,7 +4,7 @@
<groupId>com.twitter</groupId>
<artifactId>util-core</artifactId>
<packaging>jar</packaging>
- <version>5.3.7-SNAPSHOT</version>
+ <version>5.3.8-SNAPSHOT</version>
<parent>
<groupId>com.twitter</groupId>
<artifactId>scala-parent-292</artifactId>
View
2 util-core/src/main/scala/com/twitter/util/Time.scala
@@ -239,6 +239,8 @@ class Time private[util] (protected val nanos: Long) extends TimeLike[Time] with
*/
override def toString = Time.defaultFormat.format(this)
+ override def hashCode = nanos.hashCode
+
/**
* Formats this Time according to the given SimpleDateFormat pattern.
*/
View
9 util-core/src/test/scala/com/twitter/util/TimeSpec.scala
@@ -7,6 +7,15 @@ import TimeConversions._
class TimeSpec extends SpecificationWithJUnit {
"Time" should {
+ "work in collections" in {
+ val t0 = Time.fromSeconds(100)
+ val t1 = Time.fromSeconds(100)
+ t0 mustEqual t1
+ t0.hashCode mustEqual t1.hashCode
+ val pairs = List((t0, "foo"), (t1, "bar"))
+ pairs.groupBy { case (time: Time, value: String) => time } mustEqual Map(t0 -> pairs)
+ }
+
"now should be now" in {
(Time.now.inMillis - System.currentTimeMillis).abs must beLessThan(20L)
}
View
4 util-eval/pom.xml
@@ -4,7 +4,7 @@
<groupId>com.twitter</groupId>
<artifactId>util-eval</artifactId>
<packaging>jar</packaging>
- <version>5.3.7-SNAPSHOT</version>
+ <version>5.3.8-SNAPSHOT</version>
<parent>
<groupId>com.twitter</groupId>
<artifactId>scala-parent-292</artifactId>
@@ -26,7 +26,7 @@
<dependency>
<groupId>com.twitter</groupId>
<artifactId>util-core</artifactId>
- <version>5.3.7-SNAPSHOT</version>
+ <version>5.3.8-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
View
4 util-hashing/pom.xml
@@ -4,7 +4,7 @@
<groupId>com.twitter</groupId>
<artifactId>util-hashing</artifactId>
<packaging>jar</packaging>
- <version>5.3.7-SNAPSHOT</version>
+ <version>5.3.8-SNAPSHOT</version>
<parent>
<groupId>com.twitter</groupId>
<artifactId>scala-parent-292</artifactId>
@@ -26,7 +26,7 @@
<dependency>
<groupId>com.twitter</groupId>
<artifactId>util-core</artifactId>
- <version>5.3.7-SNAPSHOT</version>
+ <version>5.3.8-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
View
6 util-jvm/pom.xml
@@ -4,7 +4,7 @@
<groupId>com.twitter</groupId>
<artifactId>util-jvm</artifactId>
<packaging>jar</packaging>
- <version>5.3.7-SNAPSHOT</version>
+ <version>5.3.8-SNAPSHOT</version>
<parent>
<groupId>com.twitter</groupId>
<artifactId>scala-parent-292</artifactId>
@@ -20,13 +20,13 @@
<dependency>
<groupId>com.twitter</groupId>
<artifactId>util-core</artifactId>
- <version>5.3.7-SNAPSHOT</version>
+ <version>5.3.8-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.twitter</groupId>
<artifactId>util-logging</artifactId>
<scope>test</scope>
- <version>5.3.7-SNAPSHOT</version>
+ <version>5.3.8-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
View
11 util-jvm/src/main/scala/com/twitter/jvm/Jvm.scala
@@ -71,7 +71,10 @@ trait Jvm {
*/
def foreachGc(f: Gc => Unit) {
val Period = 1.second
+ val LogPeriod = 30.minutes
val log = Logger.getLogger(getClass.getName)
+ @volatile var missedCollections = 0L
+ @volatile var lastLog = Time.epoch
val lastByName = mutable.HashMap[String, Long]()
def sample() {
@@ -81,8 +84,12 @@ trait Jvm {
lastByName.get(name) match {
case Some(`count`) => // old
case Some(lastCount) =>
- if (lastCount != count-1)
- log.warning("Missed %d collections for %s due to sampling".format(count-1-lastCount, name))
+ missedCollections += count - 1 - lastCount
+ if (missedCollections > 0 && Time.now - lastLog > LogPeriod) {
+ log.warning("Missed %d collections for %s due to sampling".format(missedCollections, name))
+ lastLog = Time.now
+ missedCollections = 0
+ }
f(gc)
case None =>
f(gc)
View
17 util-jvm/src/test/scala/com/twitter/jvm/JvmSpec.scala
@@ -67,7 +67,7 @@ class JvmSpec extends SpecificationWithJUnit with Mockito with TestLogging {
b(3) must be_==(gc1.copy(count=1))
}
- "Complain when sampling rate is too low" in {
+ "Complain when sampling rate is too low, every 30 minutes" in Time.withCurrentTimeFrozen { tc =>
traceLogger(Level.WARNING)
jvm foreachGc { _ => /*ignore*/}
@@ -79,7 +79,20 @@ class JvmSpec extends SpecificationWithJUnit with Mockito with TestLogging {
r.run()
jvm.pushGc(gc.copy(count=2))
r.run()
- mustLog("Missed 1 collections for pcopy due to sampling")
+ logLines() must be_==(Seq("Missed 1 collections for pcopy due to sampling"))
+ jvm.pushGc(gc.copy(count=10))
+ logLines() must be_==(Seq("Missed 1 collections for pcopy due to sampling"))
+ r.run()
+ tc.advance(29.minutes)
+ r.run()
+ logLines() must be_==(Seq("Missed 1 collections for pcopy due to sampling"))
+ tc.advance(2.minutes)
+ jvm.pushGc(gc.copy(count=12))
+ r.run()
+ logLines() must be_==(Seq(
+ "Missed 1 collections for pcopy due to sampling",
+ "Missed 8 collections for pcopy due to sampling"
+ ))
}
}
View
4 util-logging/pom.xml
@@ -4,7 +4,7 @@
<groupId>com.twitter</groupId>
<artifactId>util-logging</artifactId>
<packaging>jar</packaging>
- <version>5.3.7-SNAPSHOT</version>
+ <version>5.3.8-SNAPSHOT</version>
<parent>
<groupId>com.twitter</groupId>
<artifactId>scala-parent-292</artifactId>
@@ -26,7 +26,7 @@
<dependency>
<groupId>com.twitter</groupId>
<artifactId>util-core</artifactId>
- <version>5.3.7-SNAPSHOT</version>
+ <version>5.3.8-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
View
4 util-logging/src/main/scala/com/twitter/logging/Logger.scala
@@ -275,10 +275,6 @@ object Logger extends Iterable[Logger] {
logger
case null =>
val logger = new Logger(name, javalog.Logger.getLogger(name))
- logger.clearHandlers()
- logger.setLevel(null)
- logger.setUseParentHandlers(true)
-
val oldLogger = loggersCache.putIfAbsent(name, logger)
if (oldLogger != null) {
oldLogger
View
5 util-logging/src/main/scala/com/twitter/logging/TestLogging.scala
@@ -65,13 +65,14 @@ trait TestLogging { self: Specification =>
logger.clearHandlers()
logger.addHandler(traceHandler)
}
+
+ def logLines(): Seq[String] = traceHandler.get.split("\n")
/**
* Verify that the logger set up with `traceLogger` has received a log line with the given
* substring somewhere inside it.
*/
def mustLog(substring: String) = {
- val lines = traceHandler.get.split("\n")
- lines.filter { _ contains substring }.size must be_>(0)
+ logLines().filter { _ contains substring }.size must be_>(0)
}
}
View
4 util-reflect/pom.xml
@@ -4,7 +4,7 @@
<groupId>com.twitter</groupId>
<artifactId>util-reflect</artifactId>
<packaging>jar</packaging>
- <version>5.3.7-SNAPSHOT</version>
+ <version>5.3.8-SNAPSHOT</version>
<parent>
<groupId>com.twitter</groupId>
<artifactId>scala-parent-292</artifactId>
@@ -40,7 +40,7 @@
<dependency>
<groupId>com.twitter</groupId>
<artifactId>util-core</artifactId>
- <version>5.3.7-SNAPSHOT</version>
+ <version>5.3.8-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
View
6 util-thrift/pom.xml
@@ -4,7 +4,7 @@
<groupId>com.twitter</groupId>
<artifactId>util-thrift</artifactId>
<packaging>jar</packaging>
- <version>5.3.7-SNAPSHOT</version>
+ <version>5.3.8-SNAPSHOT</version>
<parent>
<groupId>com.twitter</groupId>
<artifactId>scala-parent-292</artifactId>
@@ -41,12 +41,12 @@
<dependency>
<groupId>com.twitter</groupId>
<artifactId>util-codec</artifactId>
- <version>5.3.7-SNAPSHOT</version>
+ <version>5.3.8-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.twitter</groupId>
<artifactId>util-core</artifactId>
- <version>5.3.7-SNAPSHOT</version>
+ <version>5.3.8-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
View
31 util-thrift/src/main/scala/com/twitter/util/ThriftCodec.scala
@@ -0,0 +1,31 @@
+package com.twitter.util
+
+import java.io.{InputStream, ByteArrayInputStream, ByteArrayOutputStream}
+import org.apache.thrift.TBase
+import org.apache.thrift.protocol.{TBinaryProtocol, TCompactProtocol, TProtocolFactory }
+import org.apache.thrift.transport.TIOStreamTransport
+
+object ThriftCodec {
+ def apply[T <: TBase[_,_]: Manifest, P <: TProtocolFactory: Manifest] = new ThriftCodec[T,P]
+}
+
+class ThriftCodec[T <: TBase[_,_]: Manifest, P <: TProtocolFactory:Manifest]
+extends Codec[T, Array[Byte]] with ThriftSerializer {
+
+ protected lazy val prototype: T =
+ manifest[T].erasure.asInstanceOf[Class[T]].newInstance
+
+ override lazy val protocolFactory =
+ manifest[P].erasure.asInstanceOf[Class[P]].newInstance
+
+ override def encode(item: T) = toBytes(item)
+
+ override def decode(bytes: Array[Byte]) = {
+ val obj = prototype.deepCopy
+ fromBytes(obj, bytes)
+ obj.asInstanceOf[T]
+ }
+}
+
+class BinaryThriftCodec[T <: TBase[_,_]: Manifest] extends ThriftCodec[T,TBinaryProtocol.Factory]
+class CompactThriftCodec[T <: TBase[_,_]: Manifest] extends ThriftCodec[T,TCompactProtocol.Factory]
View
14 util-zk-common/pom.xml
@@ -4,7 +4,7 @@
<groupId>com.twitter</groupId>
<artifactId>util-zk-common</artifactId>
<packaging>jar</packaging>
- <version>5.3.7-SNAPSHOT</version>
+ <version>5.3.8-SNAPSHOT</version>
<parent>
<groupId>com.twitter</groupId>
<artifactId>scala-parent-292</artifactId>
@@ -106,32 +106,32 @@
<dependency>
<groupId>com.twitter</groupId>
<artifactId>util-collection</artifactId>
- <version>5.3.7-SNAPSHOT</version>
+ <version>5.3.8-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.twitter</groupId>
<artifactId>util-core</artifactId>
- <version>5.3.7-SNAPSHOT</version>
+ <version>5.3.8-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.twitter</groupId>
<artifactId>util-eval</artifactId>
- <version>5.3.7-SNAPSHOT</version>
+ <version>5.3.8-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.twitter</groupId>
<artifactId>util-hashing</artifactId>
- <version>5.3.7-SNAPSHOT</version>
+ <version>5.3.8-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.twitter</groupId>
<artifactId>util-logging</artifactId>
- <version>5.3.7-SNAPSHOT</version>
+ <version>5.3.8-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.twitter</groupId>
<artifactId>util-zk</artifactId>
- <version>5.3.7-SNAPSHOT</version>
+ <version>5.3.8-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
View
6 util-zk/pom.xml
@@ -4,7 +4,7 @@
<groupId>com.twitter</groupId>
<artifactId>util-zk</artifactId>
<packaging>jar</packaging>
- <version>5.3.7-SNAPSHOT</version>
+ <version>5.3.8-SNAPSHOT</version>
<parent>
<groupId>com.twitter</groupId>
<artifactId>scala-parent-292</artifactId>
@@ -77,12 +77,12 @@
<dependency>
<groupId>com.twitter</groupId>
<artifactId>util-core</artifactId>
- <version>5.3.7-SNAPSHOT</version>
+ <version>5.3.8-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.twitter</groupId>
<artifactId>util-logging</artifactId>
- <version>5.3.7-SNAPSHOT</version>
+ <version>5.3.8-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

No commit comments for this range

Something went wrong with that request. Please try again.