From 11d539f5674908a79f30c68ac5389e3b69d2756a Mon Sep 17 00:00:00 2001 From: Scott Carey Date: Sat, 6 Apr 2013 15:58:16 -0700 Subject: [PATCH 1/4] common changes for 2.10 --- core/build.sbt | 8 +++++ .../main/scala-2.8.x/kafka/utils/Annotations.scala | 36 ++++++++++++++++++++ .../main/scala-2.9.x/kafka/utils/Annotations.scala | 38 ++++++++++++++++++++++ .../consumer/ZookeeperConsumerConnector.scala | 2 +- core/src/main/scala/kafka/utils/Annotations.scala | 36 -------------------- .../scala/unit/kafka/metrics/KafkaTimerTest.scala | 4 +++ project/Build.scala | 4 +-- 7 files changed, 89 insertions(+), 39 deletions(-) create mode 100644 core/src/main/scala-2.8.x/kafka/utils/Annotations.scala create mode 100644 core/src/main/scala-2.9.x/kafka/utils/Annotations.scala delete mode 100644 core/src/main/scala/kafka/utils/Annotations.scala diff --git a/core/build.sbt b/core/build.sbt index c54cf44..071fb3e 100644 --- a/core/build.sbt +++ b/core/build.sbt @@ -23,9 +23,17 @@ libraryDependencies ++= Seq( libraryDependencies <<= (scalaVersion, libraryDependencies) { (sv, deps) => deps :+ (sv match { case "2.8.0" => "org.scalatest" % "scalatest" % "1.2" % "test" + case "2.10.1" => "org.scalatest" % "scalatest_2.10.0" % "1.8" % "test" case _ => "org.scalatest" %% "scalatest" % "1.8" % "test" }) } assemblySettings +unmanagedSourceDirectories in Compile <+= (sourceDirectory in Compile, scalaVersion){ (s,v) => + s / ("scala-" + (v match { + case v if v.startsWith("2.8.") => "2.8.x" + case _ => "2.9.x" // also for 2.10 + })) +} + diff --git a/core/src/main/scala-2.8.x/kafka/utils/Annotations.scala b/core/src/main/scala-2.8.x/kafka/utils/Annotations.scala new file mode 100644 index 0000000..28269eb --- /dev/null +++ b/core/src/main/scala-2.8.x/kafka/utils/Annotations.scala @@ -0,0 +1,36 @@ +/** + * 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 kafka.utils + +/* Some helpful annotations */ + +/** + * Indicates that the annotated class is meant to be threadsafe. For an abstract class it is an part of the interface that an implementation + * must respect + */ +class threadsafe extends StaticAnnotation + +/** + * Indicates that the annotated class is not threadsafe + */ +class nonthreadsafe extends StaticAnnotation + +/** + * Indicates that the annotated class is immutable + */ +class immutable extends StaticAnnotation diff --git a/core/src/main/scala-2.9.x/kafka/utils/Annotations.scala b/core/src/main/scala-2.9.x/kafka/utils/Annotations.scala new file mode 100644 index 0000000..1a18226 --- /dev/null +++ b/core/src/main/scala-2.9.x/kafka/utils/Annotations.scala @@ -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 kafka.utils + +import scala.annotation.StaticAnnotation + +/* Some helpful annotations */ + +/** + * Indicates that the annotated class is meant to be threadsafe. For an abstract class it is an part of the interface that an implementation + * must respect + */ +class threadsafe extends StaticAnnotation + +/** + * Indicates that the annotated class is not threadsafe + */ +class nonthreadsafe extends StaticAnnotation + +/** + * Indicates that the annotated class is immutable + */ +class immutable extends StaticAnnotation diff --git a/core/src/main/scala/kafka/consumer/ZookeeperConsumerConnector.scala b/core/src/main/scala/kafka/consumer/ZookeeperConsumerConnector.scala index d952187..3dd154b 100644 --- a/core/src/main/scala/kafka/consumer/ZookeeperConsumerConnector.scala +++ b/core/src/main/scala/kafka/consumer/ZookeeperConsumerConnector.scala @@ -440,7 +440,7 @@ private[kafka] class ZookeeperConsumerConnector(val config: ConsumerConfig, " for topic " + topic + " with consumers: " + curConsumers) for (consumerThreadId <- consumerThreadIdSet) { - val myConsumerPosition = curConsumers.findIndexOf(_ == consumerThreadId) + val myConsumerPosition = curConsumers.indexWhere(_ == consumerThreadId) assert(myConsumerPosition >= 0) val startPart = nPartsPerConsumer*myConsumerPosition + myConsumerPosition.min(nConsumersWithExtraPart) val nParts = nPartsPerConsumer + (if (myConsumerPosition + 1 > nConsumersWithExtraPart) 0 else 1) diff --git a/core/src/main/scala/kafka/utils/Annotations.scala b/core/src/main/scala/kafka/utils/Annotations.scala deleted file mode 100644 index 28269eb..0000000 --- a/core/src/main/scala/kafka/utils/Annotations.scala +++ /dev/null @@ -1,36 +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 kafka.utils - -/* Some helpful annotations */ - -/** - * Indicates that the annotated class is meant to be threadsafe. For an abstract class it is an part of the interface that an implementation - * must respect - */ -class threadsafe extends StaticAnnotation - -/** - * Indicates that the annotated class is not threadsafe - */ -class nonthreadsafe extends StaticAnnotation - -/** - * Indicates that the annotated class is immutable - */ -class immutable extends StaticAnnotation diff --git a/core/src/test/scala/unit/kafka/metrics/KafkaTimerTest.scala b/core/src/test/scala/unit/kafka/metrics/KafkaTimerTest.scala index fe5bc09..3dd83cc 100644 --- a/core/src/test/scala/unit/kafka/metrics/KafkaTimerTest.scala +++ b/core/src/test/scala/unit/kafka/metrics/KafkaTimerTest.scala @@ -38,6 +38,10 @@ class KafkaTimerTest extends JUnit3Suite { assertEquals(1, metric.count()) assertTrue((metric.max() - 1000).abs <= Double.Epsilon) assertTrue((metric.min() - 1000).abs <= Double.Epsilon) + //Epsilon removed in 2.10, Eps added in 2.11. Inline the definition here instead + //See https://issues.scala-lang.org/browse/SI-3791 + assertTrue((metric.max() - 1000).abs <= java.lang.Double.longBitsToDouble(0x3ca0000000000000L)) + assertTrue((metric.min() - 1000).abs <= java.lang.Double.longBitsToDouble(0x3ca0000000000000L)) } private class ManualClock extends Clock { diff --git a/project/Build.scala b/project/Build.scala index f177215..2106be2 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -28,8 +28,8 @@ object KafkaBuild extends Build { val commonSettings = Seq( organization := "org.apache", scalacOptions ++= Seq("-deprecation", "-unchecked", "-g:none"), - crossScalaVersions := Seq("2.8.0","2.8.2", "2.9.1", "2.9.2"), - scalaVersion := "2.8.0", + crossScalaVersions := Seq("2.8.2", "2.9.1", "2.9.2", "2.10.1"), + scalaVersion := "2.8.2", version := "0.8.0-SNAPSHOT", buildNumber := System.getProperty("build.number", ""), version <<= (buildNumber, version) { (build, version) => if (build == "") version else version + "+" + build}, -- 1.8.3.1