Make KafkaLookupExtractorFactoryTest fast (#4466)

* Make KafkaLookupExtractorFactoryTest fast

* Use list

* Use Bytes
This commit is contained in:
Jihoon Son 2017-06-27 00:15:28 +09:00 committed by Roman Leventov
parent 0f99467cfb
commit 5fec619284
1 changed files with 11 additions and 15 deletions

View File

@ -26,6 +26,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.primitives.Bytes;
import io.druid.jackson.DefaultObjectMapper; import io.druid.jackson.DefaultObjectMapper;
import io.druid.java.util.common.StringUtils; import io.druid.java.util.common.StringUtils;
import io.druid.server.lookup.namespace.cache.CacheHandler; import io.druid.server.lookup.namespace.cache.CacheHandler;
@ -47,11 +48,12 @@ import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunner;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
@ -129,18 +131,15 @@ public class KafkaLookupExtractorFactoryTest
TOPIC, TOPIC,
DEFAULT_PROPERTIES DEFAULT_PROPERTIES
); );
factory.getMapRef().set(ImmutableMap.<String, String>of()); factory.getMapRef().set(ImmutableMap.of());
final AtomicLong events = factory.getDoubleEventCount(); final AtomicLong events = factory.getDoubleEventCount();
final LookupExtractor extractor = factory.get(); final LookupExtractor extractor = factory.get();
final List<byte[]> byteArrays = new ArrayList<>(n); final Set<List<Byte>> byteArrays = new HashSet<>(n);
for (int i = 0; i < n; ++i) { for (int i = 0; i < n; ++i) {
final byte[] myKey = extractor.getCacheKey(); final List<Byte> myKey = Bytes.asList(extractor.getCacheKey());
// Not terribly efficient.. but who cares Assert.assertFalse(byteArrays.contains(myKey));
for (byte[] byteArray : byteArrays) {
Assert.assertFalse(Arrays.equals(byteArray, myKey));
}
byteArrays.add(myKey); byteArrays.add(myKey);
events.incrementAndGet(); events.incrementAndGet();
} }
@ -156,17 +155,14 @@ public class KafkaLookupExtractorFactoryTest
TOPIC, TOPIC,
DEFAULT_PROPERTIES DEFAULT_PROPERTIES
); );
factory.getMapRef().set(ImmutableMap.<String, String>of()); factory.getMapRef().set(ImmutableMap.of());
final AtomicLong events = factory.getDoubleEventCount(); final AtomicLong events = factory.getDoubleEventCount();
final List<byte[]> byteArrays = new ArrayList<>(n); final Set<List<Byte>> byteArrays = new HashSet<>(n);
for (int i = 0; i < n; ++i) { for (int i = 0; i < n; ++i) {
final LookupExtractor extractor = factory.get(); final LookupExtractor extractor = factory.get();
final byte[] myKey = extractor.getCacheKey(); final List<Byte> myKey = Bytes.asList(extractor.getCacheKey());
// Not terribly efficient.. but who cares Assert.assertFalse(byteArrays.contains(myKey));
for (byte[] byteArray : byteArrays) {
Assert.assertFalse(Arrays.equals(byteArray, myKey));
}
byteArrays.add(myKey); byteArrays.add(myKey);
events.incrementAndGet(); events.incrementAndGet();
} }