Skip to content

Commit

Permalink
KAFKA-2288; Follow-up to KAFKA-2249 - reduce logging and testing; Rev…
Browse files Browse the repository at this point in the history
…iewd by Jun Rao
  • Loading branch information
gwenshap committed Aug 5, 2015
1 parent 7a666f7 commit 9cefb2a
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 429 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,20 @@ public class AbstractConfig {
private final Map<String, Object> values;

@SuppressWarnings("unchecked")
public AbstractConfig(ConfigDef definition, Map<?, ?> originals) {
public AbstractConfig(ConfigDef definition, Map<?, ?> originals, Boolean doLog) {
/* check that all the keys are really strings */
for (Object key : originals.keySet())
if (!(key instanceof String))
throw new ConfigException(key.toString(), originals.get(key), "Key must be a string.");
this.originals = (Map<String, ?>) originals;
this.values = definition.parse(this.originals);
this.used = Collections.synchronizedSet(new HashSet<String>());
logAll();
if (doLog)
logAll();
}

public AbstractConfig(ConfigDef definition, Map<?, ?> originals) {
this(definition, originals, true);
}

protected Object get(String key) {
Expand Down Expand Up @@ -167,4 +172,18 @@ public <T> List<T> getConfiguredInstances(String key, Class<T> t) {
return objects;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

AbstractConfig that = (AbstractConfig) o;

return originals.equals(that.originals);
}

@Override
public int hashCode() {
return originals.hashCode();
}
}
2 changes: 1 addition & 1 deletion core/src/main/scala/kafka/log/LogConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ object Defaults {
val PreAllocateEnable = kafka.server.Defaults.LogPreAllocateEnable
}

case class LogConfig(props: java.util.Map[_, _]) extends AbstractConfig(LogConfig.configDef, props) {
case class LogConfig(props: java.util.Map[_, _]) extends AbstractConfig(LogConfig.configDef, props, false) {

val segmentSize = getInt(LogConfig.SegmentBytesProp)
val segmentMs = getLong(LogConfig.SegmentMsProp)
Expand Down
22 changes: 0 additions & 22 deletions core/src/test/scala/unit/kafka/log/LogConfigTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,6 @@ class LogConfigTest extends JUnit3Suite {
Assert.assertEquals(LogConfig(), config)
}

@Test
def testFromPropsToProps() {
import scala.util.Random._
val expected = new Properties()
LogConfig.configNames().foreach((name) => {
name match {
case LogConfig.UncleanLeaderElectionEnableProp => expected.setProperty(name, randFrom("true", "false"))
case LogConfig.CompressionTypeProp => expected.setProperty(name, randFrom("producer", "uncompressed", "gzip"))
case LogConfig.CleanupPolicyProp => expected.setProperty(name, randFrom(LogConfig.Compact, LogConfig.Delete))
case LogConfig.MinCleanableDirtyRatioProp => expected.setProperty(name, "%.1f".format(nextDouble * .9 + .1))
case LogConfig.MinInSyncReplicasProp => expected.setProperty(name, (nextInt(Int.MaxValue - 1) + 1).toString)
case LogConfig.RetentionBytesProp => expected.setProperty(name, nextInt().toString)
case LogConfig.RetentionMsProp => expected.setProperty(name, nextLong().toString)
case LogConfig.PreAllocateEnableProp => expected.setProperty(name, randFrom("true", "false"))
case positiveIntProperty => expected.setProperty(name, nextInt(Int.MaxValue).toString)
}
})

val actual = LogConfig(expected).originals
Assert.assertEquals(expected, actual)
}

@Test
def testFromPropsInvalid() {
LogConfig.configNames().foreach((name) => {
Expand Down
Loading

0 comments on commit 9cefb2a

Please sign in to comment.