diff --git a/codestyle/checkstyle-suppressions.xml b/codestyle/checkstyle-suppressions.xml
index 0c8300aedc6..15604f37a47 100644
--- a/codestyle/checkstyle-suppressions.xml
+++ b/codestyle/checkstyle-suppressions.xml
@@ -29,9 +29,6 @@
-
-
-
diff --git a/core/src/test/java/org/apache/druid/collections/BlockingPoolTest.java b/core/src/test/java/org/apache/druid/collections/BlockingPoolTest.java
index 19a21f2c089..19d6a496301 100644
--- a/core/src/test/java/org/apache/druid/collections/BlockingPoolTest.java
+++ b/core/src/test/java/org/apache/druid/collections/BlockingPoolTest.java
@@ -22,6 +22,7 @@ package org.apache.druid.collections;
import com.google.common.base.Suppliers;
import org.apache.druid.java.util.common.concurrent.Execs;
import org.junit.After;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -34,11 +35,6 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
public class BlockingPoolTest
{
private ExecutorService service;
@@ -85,10 +81,10 @@ public class BlockingPoolTest
public void testTake()
{
final ReferenceCountingResourceHolder holder = pool.take(100);
- assertNotNull(holder);
- assertEquals(9, pool.getPoolSize());
+ Assert.assertNotNull(holder);
+ Assert.assertEquals(9, pool.getPoolSize());
holder.close();
- assertEquals(10, pool.getPoolSize());
+ Assert.assertEquals(10, pool.getPoolSize());
}
@Test(timeout = 60_000L)
@@ -96,7 +92,7 @@ public class BlockingPoolTest
{
final List> batchHolder = pool.takeBatch(10, 100L);
final ReferenceCountingResourceHolder holder = pool.take(100);
- assertNull(holder);
+ Assert.assertNull(holder);
batchHolder.forEach(ReferenceCountingResourceHolder::close);
}
@@ -104,20 +100,20 @@ public class BlockingPoolTest
public void testTakeBatch()
{
final List> holder = pool.takeBatch(6, 100L);
- assertNotNull(holder);
- assertEquals(6, holder.size());
- assertEquals(4, pool.getPoolSize());
+ Assert.assertNotNull(holder);
+ Assert.assertEquals(6, holder.size());
+ Assert.assertEquals(4, pool.getPoolSize());
holder.forEach(ReferenceCountingResourceHolder::close);
- assertEquals(10, pool.getPoolSize());
+ Assert.assertEquals(10, pool.getPoolSize());
}
@Test(timeout = 60_000L)
public void testWaitAndTakeBatch() throws InterruptedException, ExecutionException
{
List> batchHolder = pool.takeBatch(10, 10);
- assertNotNull(batchHolder);
- assertEquals(10, batchHolder.size());
- assertEquals(0, pool.getPoolSize());
+ Assert.assertNotNull(batchHolder);
+ Assert.assertEquals(10, batchHolder.size());
+ Assert.assertEquals(0, pool.getPoolSize());
final Future>> future = service.submit(
() -> pool.takeBatch(8, 100)
@@ -126,19 +122,19 @@ public class BlockingPoolTest
batchHolder.forEach(ReferenceCountingResourceHolder::close);
batchHolder = future.get();
- assertNotNull(batchHolder);
- assertEquals(8, batchHolder.size());
- assertEquals(2, pool.getPoolSize());
+ Assert.assertNotNull(batchHolder);
+ Assert.assertEquals(8, batchHolder.size());
+ Assert.assertEquals(2, pool.getPoolSize());
batchHolder.forEach(ReferenceCountingResourceHolder::close);
- assertEquals(10, pool.getPoolSize());
+ Assert.assertEquals(10, pool.getPoolSize());
}
@Test(timeout = 60_000L)
public void testTakeBatchTooManyObjects()
{
final List> holder = pool.takeBatch(100, 100L);
- assertTrue(holder.isEmpty());
+ Assert.assertTrue(holder.isEmpty());
}
@Test(timeout = 60_000L)
@@ -148,39 +144,29 @@ public class BlockingPoolTest
final int limit2 = pool.maxSize() - limit1 + 1;
final Future>> f1 = service.submit(
- new Callable>>()
- {
- @Override
- public List> call()
- {
- List> result = new ArrayList<>();
- for (int i = 0; i < limit1; i++) {
- result.add(pool.take(10));
- }
- return result;
+ () -> {
+ List> result = new ArrayList<>();
+ for (int i = 0; i < limit1; i++) {
+ result.add(pool.take(10));
}
+ return result;
}
);
final Future>> f2 = service.submit(
- new Callable>>()
- {
- @Override
- public List> call()
- {
- List> result = new ArrayList<>();
- for (int i = 0; i < limit2; i++) {
- result.add(pool.take(10));
- }
- return result;
+ () -> {
+ List> result = new ArrayList<>();
+ for (int i = 0; i < limit2; i++) {
+ result.add(pool.take(10));
}
+ return result;
}
);
final List> r1 = f1.get();
final List> r2 = f2.get();
- assertEquals(0, pool.getPoolSize());
- assertTrue(r1.contains(null) || r2.contains(null));
+ Assert.assertEquals(0, pool.getPoolSize());
+ Assert.assertTrue(r1.contains(null) || r2.contains(null));
int nonNullCount = 0;
for (ReferenceCountingResourceHolder holder : r1) {
@@ -194,29 +180,19 @@ public class BlockingPoolTest
nonNullCount++;
}
}
- assertEquals(pool.maxSize(), nonNullCount);
+ Assert.assertEquals(pool.maxSize(), nonNullCount);
- final Future future1 = service.submit(new Runnable()
- {
- @Override
- public void run()
- {
- for (ReferenceCountingResourceHolder holder : r1) {
- if (holder != null) {
- holder.close();
- }
+ final Future future1 = service.submit(() -> {
+ for (ReferenceCountingResourceHolder holder : r1) {
+ if (holder != null) {
+ holder.close();
}
}
});
- final Future future2 = service.submit(new Runnable()
- {
- @Override
- public void run()
- {
- for (ReferenceCountingResourceHolder holder : r2) {
- if (holder != null) {
- holder.close();
- }
+ final Future future2 = service.submit(() -> {
+ for (ReferenceCountingResourceHolder holder : r2) {
+ if (holder != null) {
+ holder.close();
}
}
});
@@ -224,7 +200,7 @@ public class BlockingPoolTest
future1.get();
future2.get();
- assertEquals(pool.maxSize(), pool.getPoolSize());
+ Assert.assertEquals(pool.maxSize(), pool.getPoolSize());
}
@Test(timeout = 60_000L)
@@ -243,18 +219,18 @@ public class BlockingPoolTest
final List> r2 = f2.get();
if (r1 != null) {
- assertTrue(r2.isEmpty());
- assertEquals(pool.maxSize() - batch1, pool.getPoolSize());
- assertEquals(batch1, r1.size());
+ Assert.assertTrue(r2.isEmpty());
+ Assert.assertEquals(pool.maxSize() - batch1, pool.getPoolSize());
+ Assert.assertEquals(batch1, r1.size());
r1.forEach(ReferenceCountingResourceHolder::close);
} else {
- assertNotNull(r2);
- assertEquals(pool.maxSize() - batch2, pool.getPoolSize());
- assertEquals(batch2, r2.size());
+ Assert.assertNotNull(r2);
+ Assert.assertEquals(pool.maxSize() - batch2, pool.getPoolSize());
+ Assert.assertEquals(batch2, r2.size());
r2.forEach(ReferenceCountingResourceHolder::close);
}
- assertEquals(pool.maxSize(), pool.getPoolSize());
+ Assert.assertEquals(pool.maxSize(), pool.getPoolSize());
}
@Test(timeout = 60_000L)
@@ -272,35 +248,22 @@ public class BlockingPoolTest
final List> r1 = f1.get();
final List> r2 = f2.get();
- assertNotNull(r1);
- assertNotNull(r2);
- assertEquals(batch1, r1.size());
- assertEquals(batch2, r2.size());
- assertEquals(0, pool.getPoolSize());
+ Assert.assertNotNull(r1);
+ Assert.assertNotNull(r2);
+ Assert.assertEquals(batch1, r1.size());
+ Assert.assertEquals(batch2, r2.size());
+ Assert.assertEquals(0, pool.getPoolSize());
- final Future future1 = service.submit(new Runnable()
- {
- @Override
- public void run()
- {
- r1.forEach(ReferenceCountingResourceHolder::close);
- }
- });
- final Future future2 = service.submit(new Runnable()
- {
- @Override
- public void run()
- {
- r2.forEach(ReferenceCountingResourceHolder::close);
- }
- });
+ final Future future1 = service.submit(() -> r1.forEach(ReferenceCountingResourceHolder::close));
+ final Future future2 = service.submit(() -> r2.forEach(ReferenceCountingResourceHolder::close));
future1.get();
future2.get();
- assertEquals(pool.maxSize(), pool.getPoolSize());
+ Assert.assertEquals(pool.maxSize(), pool.getPoolSize());
}
+ @SuppressWarnings("CatchMayIgnoreException")
@Test(timeout = 60_000L)
public void testConcurrentTakeBatchClose() throws ExecutionException, InterruptedException
{
@@ -309,28 +272,23 @@ public class BlockingPoolTest
final Callable>> c2 = () -> pool.takeBatch(10, 100);
final Future>> f2 = service.submit(c2);
- final Future f1 = service.submit(new Runnable()
- {
- @Override
- public void run()
- {
- try {
- Thread.sleep(50);
- }
- catch (InterruptedException e) {
- // ignore
- }
- r1.forEach(ReferenceCountingResourceHolder::close);
+ final Future f1 = service.submit(() -> {
+ try {
+ Thread.sleep(50);
}
+ catch (InterruptedException e) {
+ // ignore
+ }
+ r1.forEach(ReferenceCountingResourceHolder::close);
});
final List> r2 = f2.get();
f1.get();
- assertNotNull(r2);
- assertEquals(10, r2.size());
- assertEquals(0, pool.getPoolSize());
+ Assert.assertNotNull(r2);
+ Assert.assertEquals(10, r2.size());
+ Assert.assertEquals(0, pool.getPoolSize());
r2.forEach(ReferenceCountingResourceHolder::close);
- assertEquals(pool.maxSize(), pool.getPoolSize());
+ Assert.assertEquals(pool.maxSize(), pool.getPoolSize());
}
}
diff --git a/core/src/test/java/org/apache/druid/java/util/emitter/core/ParametrizedUriEmitterTest.java b/core/src/test/java/org/apache/druid/java/util/emitter/core/ParametrizedUriEmitterTest.java
index 40f79dd167b..db6660fb8f9 100644
--- a/core/src/test/java/org/apache/druid/java/util/emitter/core/ParametrizedUriEmitterTest.java
+++ b/core/src/test/java/org/apache/druid/java/util/emitter/core/ParametrizedUriEmitterTest.java
@@ -40,9 +40,6 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
-import static org.apache.druid.java.util.emitter.core.EmitterTest.okResponse;
-import static org.junit.Assert.assertEquals;
-
public class ParametrizedUriEmitterTest
{
private static final ObjectMapper jsonMapper = new ObjectMapper();
@@ -71,7 +68,7 @@ public class ParametrizedUriEmitterTest
props.setProperty("org.apache.druid.java.util.emitter.recipientBaseUrlPattern", uriPattern);
lifecycle = new Lifecycle();
Emitter emitter = Emitters.create(props, httpClient, lifecycle);
- assertEquals(ParametrizedUriEmitter.class, emitter.getClass());
+ Assert.assertEquals(ParametrizedUriEmitter.class, emitter.getClass());
lifecycle.start();
return emitter;
}
@@ -107,7 +104,7 @@ public class ParametrizedUriEmitterTest
StandardCharsets.UTF_8.decode(request.getByteBufferData().slice()).toString()
);
- return GoHandlers.immediateFuture(okResponse());
+ return GoHandlers.immediateFuture(EmitterTest.okResponse());
}
}.times(1)
);
@@ -140,7 +137,7 @@ public class ParametrizedUriEmitterTest
request.getUrl(),
StandardCharsets.UTF_8.decode(request.getByteBufferData().slice()).toString()
);
- return GoHandlers.immediateFuture(okResponse());
+ return GoHandlers.immediateFuture(EmitterTest.okResponse());
}
}.times(2)
);
@@ -152,7 +149,8 @@ public class ParametrizedUriEmitterTest
Assert.assertTrue(httpClient.succeeded());
Map expected = ImmutableMap.of(
"http://example.com/test1", StringUtils.format("[%s]\n", jsonMapper.writeValueAsString(events.get(0))),
- "http://example.com/test2", StringUtils.format("[%s]\n", jsonMapper.writeValueAsString(events.get(1))));
+ "http://example.com/test2", StringUtils.format("[%s]\n", jsonMapper.writeValueAsString(events.get(1)))
+ );
Assert.assertEquals(expected, results);
}
@@ -181,7 +179,7 @@ public class ParametrizedUriEmitterTest
StandardCharsets.UTF_8.decode(request.getByteBufferData().slice()).toString()
);
- return GoHandlers.immediateFuture(okResponse());
+ return GoHandlers.immediateFuture(EmitterTest.okResponse());
}
}.times(1)
);
@@ -209,7 +207,9 @@ public class ParametrizedUriEmitterTest
Assert.assertEquals(
e.getMessage(),
StringUtils.format(
- "ParametrizedUriExtractor with pattern http://example.com/{keyNotSetInEvents} requires keyNotSetInEvents to be set in event, but found %s", event.toMap())
+ "ParametrizedUriExtractor with pattern http://example.com/{keyNotSetInEvents} requires keyNotSetInEvents to be set in event, but found %s",
+ event.toMap()
+ )
);
}
}
diff --git a/core/src/test/java/org/apache/druid/timeline/partition/IntegerPartitionChunkTest.java b/core/src/test/java/org/apache/druid/timeline/partition/IntegerPartitionChunkTest.java
index 71806bb9c80..36b3915f9de 100644
--- a/core/src/test/java/org/apache/druid/timeline/partition/IntegerPartitionChunkTest.java
+++ b/core/src/test/java/org/apache/druid/timeline/partition/IntegerPartitionChunkTest.java
@@ -22,61 +22,83 @@ package org.apache.druid.timeline.partition;
import org.junit.Assert;
import org.junit.Test;
-import static org.apache.druid.timeline.partition.IntegerPartitionChunk.make;
-
-/**
- */
public class IntegerPartitionChunkTest
{
@Test
public void testAbuts()
{
- IntegerPartitionChunk lhs = make(null, 10, 0, 1);
+ IntegerPartitionChunk lhs = IntegerPartitionChunk.make(null, 10, 0, 1);
- Assert.assertTrue(lhs.abuts(make(10, null, 1, 2)));
- Assert.assertFalse(lhs.abuts(make(11, null, 2, 3)));
- Assert.assertFalse(lhs.abuts(make(null, null, 3, 4)));
+ Assert.assertTrue(lhs.abuts(IntegerPartitionChunk.make(10, null, 1, 2)));
+ Assert.assertFalse(lhs.abuts(IntegerPartitionChunk.make(11, null, 2, 3)));
+ Assert.assertFalse(lhs.abuts(IntegerPartitionChunk.make(null, null, 3, 4)));
- Assert.assertFalse(make(null, null, 0, 1).abuts(make(null, null, 1, 2)));
+ Assert.assertFalse(IntegerPartitionChunk.make(null, null, 0, 1)
+ .abuts(IntegerPartitionChunk.make(null, null, 1, 2)));
}
@Test
public void testIsStart()
{
- Assert.assertTrue(make(null, 10, 0, 1).isStart());
- Assert.assertFalse(make(10, null, 0, 1).isStart());
- Assert.assertFalse(make(10, 11, 0, 1).isStart());
- Assert.assertTrue(make(null, null, 0, 1).isStart());
+ Assert.assertTrue(IntegerPartitionChunk.make(null, 10, 0, 1).isStart());
+ Assert.assertFalse(IntegerPartitionChunk.make(10, null, 0, 1).isStart());
+ Assert.assertFalse(IntegerPartitionChunk.make(10, 11, 0, 1).isStart());
+ Assert.assertTrue(IntegerPartitionChunk.make(null, null, 0, 1).isStart());
}
@Test
public void testIsEnd()
{
- Assert.assertFalse(make(null, 10, 0, 1).isEnd());
- Assert.assertTrue(make(10, null, 0, 1).isEnd());
- Assert.assertFalse(make(10, 11, 0, 1).isEnd());
- Assert.assertTrue(make(null, null, 0, 1).isEnd());
+ Assert.assertFalse(IntegerPartitionChunk.make(null, 10, 0, 1).isEnd());
+ Assert.assertTrue(IntegerPartitionChunk.make(10, null, 0, 1).isEnd());
+ Assert.assertFalse(IntegerPartitionChunk.make(10, 11, 0, 1).isEnd());
+ Assert.assertTrue(IntegerPartitionChunk.make(null, null, 0, 1).isEnd());
}
@Test
public void testCompareTo()
{
- Assert.assertEquals(0, make(null, null, 0, 1).compareTo(make(null, null, 0, 1)));
- Assert.assertEquals(0, make(10, null, 0, 1).compareTo(make(10, null, 0, 2)));
- Assert.assertEquals(0, make(null, 10, 0, 1).compareTo(make(null, 10, 0, 2)));
- Assert.assertEquals(0, make(10, 11, 0, 1).compareTo(make(10, 11, 0, 2)));
- Assert.assertEquals(-1, make(null, 10, 0, 1).compareTo(make(10, null, 1, 2)));
- Assert.assertEquals(-1, make(11, 20, 0, 1).compareTo(make(20, 33, 1, 1)));
- Assert.assertEquals(1, make(20, 33, 1, 1).compareTo(make(11, 20, 0, 1)));
- Assert.assertEquals(1, make(10, null, 1, 1).compareTo(make(null, 10, 0, 1)));
+ //noinspection EqualsWithItself (the intention of this first test is specifically to call compareTo with itself)
+ Assert.assertEquals(
+ 0,
+ IntegerPartitionChunk.make(null, null, 0, 1).compareTo(IntegerPartitionChunk.make(null, null, 0, 1))
+ );
+ Assert.assertEquals(
+ 0,
+ IntegerPartitionChunk.make(10, null, 0, 1).compareTo(IntegerPartitionChunk.make(10, null, 0, 2))
+ );
+ Assert.assertEquals(
+ 0,
+ IntegerPartitionChunk.make(null, 10, 0, 1).compareTo(IntegerPartitionChunk.make(null, 10, 0, 2))
+ );
+ Assert.assertEquals(
+ 0,
+ IntegerPartitionChunk.make(10, 11, 0, 1).compareTo(IntegerPartitionChunk.make(10, 11, 0, 2))
+ );
+ Assert.assertEquals(
+ -1,
+ IntegerPartitionChunk.make(null, 10, 0, 1).compareTo(IntegerPartitionChunk.make(10, null, 1, 2))
+ );
+ Assert.assertEquals(
+ -1,
+ IntegerPartitionChunk.make(11, 20, 0, 1).compareTo(IntegerPartitionChunk.make(20, 33, 1, 1))
+ );
+ Assert.assertEquals(
+ 1,
+ IntegerPartitionChunk.make(20, 33, 1, 1).compareTo(IntegerPartitionChunk.make(11, 20, 0, 1))
+ );
+ Assert.assertEquals(
+ 1,
+ IntegerPartitionChunk.make(10, null, 1, 1).compareTo(IntegerPartitionChunk.make(null, 10, 0, 1))
+ );
}
@Test
public void testEquals()
{
- Assert.assertEquals(make(null, null, 0, 1), make(null, null, 0, 1));
- Assert.assertEquals(make(null, 10, 0, 1), make(null, 10, 0, 1));
- Assert.assertEquals(make(10, null, 0, 1), make(10, null, 0, 1));
- Assert.assertEquals(make(10, 11, 0, 1), make(10, 11, 0, 1));
+ Assert.assertEquals(IntegerPartitionChunk.make(null, null, 0, 1), IntegerPartitionChunk.make(null, null, 0, 1));
+ Assert.assertEquals(IntegerPartitionChunk.make(null, 10, 0, 1), IntegerPartitionChunk.make(null, 10, 0, 1));
+ Assert.assertEquals(IntegerPartitionChunk.make(10, null, 0, 1), IntegerPartitionChunk.make(10, null, 0, 1));
+ Assert.assertEquals(IntegerPartitionChunk.make(10, 11, 0, 1), IntegerPartitionChunk.make(10, 11, 0, 1));
}
}
diff --git a/core/src/test/java/org/apache/druid/timeline/partition/StringPartitionChunkTest.java b/core/src/test/java/org/apache/druid/timeline/partition/StringPartitionChunkTest.java
index c178f4c4e32..e3f98462903 100644
--- a/core/src/test/java/org/apache/druid/timeline/partition/StringPartitionChunkTest.java
+++ b/core/src/test/java/org/apache/druid/timeline/partition/StringPartitionChunkTest.java
@@ -22,61 +22,89 @@ package org.apache.druid.timeline.partition;
import org.junit.Assert;
import org.junit.Test;
-import static org.apache.druid.timeline.partition.StringPartitionChunk.make;
-
-/**
- */
public class StringPartitionChunkTest
{
@Test
public void testAbuts()
{
- StringPartitionChunk lhs = make(null, "10", 0, 1);
+ StringPartitionChunk lhs = StringPartitionChunk.make(null, "10", 0, 1);
- Assert.assertTrue(lhs.abuts(make("10", null, 1, 2)));
- Assert.assertFalse(lhs.abuts(make("11", null, 2, 3)));
- Assert.assertFalse(lhs.abuts(make(null, null, 3, 4)));
+ Assert.assertTrue(lhs.abuts(StringPartitionChunk.make("10", null, 1, 2)));
+ Assert.assertFalse(lhs.abuts(StringPartitionChunk.make("11", null, 2, 3)));
+ Assert.assertFalse(lhs.abuts(StringPartitionChunk.make(null, null, 3, 4)));
- Assert.assertFalse(make(null, null, 0, 1).abuts(make(null, null, 1, 2)));
+ Assert.assertFalse(StringPartitionChunk.make(null, null, 0, 1).abuts(StringPartitionChunk.make(null, null, 1, 2)));
}
@Test
public void testIsStart()
{
- Assert.assertTrue(make(null, "10", 0, 1).isStart());
- Assert.assertFalse(make("10", null, 0, 1).isStart());
- Assert.assertFalse(make("10", "11", 0, 1).isStart());
- Assert.assertTrue(make(null, null, 0, 1).isStart());
+ Assert.assertTrue(StringPartitionChunk.make(null, "10", 0, 1).isStart());
+ Assert.assertFalse(StringPartitionChunk.make("10", null, 0, 1).isStart());
+ Assert.assertFalse(StringPartitionChunk.make("10", "11", 0, 1).isStart());
+ Assert.assertTrue(StringPartitionChunk.make(null, null, 0, 1).isStart());
}
@Test
public void testIsEnd()
{
- Assert.assertFalse(make(null, "10", 0, 1).isEnd());
- Assert.assertTrue(make("10", null, 0, 1).isEnd());
- Assert.assertFalse(make("10", "11", 0, 1).isEnd());
- Assert.assertTrue(make(null, null, 0, 1).isEnd());
+ Assert.assertFalse(StringPartitionChunk.make(null, "10", 0, 1).isEnd());
+ Assert.assertTrue(StringPartitionChunk.make("10", null, 0, 1).isEnd());
+ Assert.assertFalse(StringPartitionChunk.make("10", "11", 0, 1).isEnd());
+ Assert.assertTrue(StringPartitionChunk.make(null, null, 0, 1).isEnd());
}
@Test
public void testCompareTo()
{
- Assert.assertEquals(0, make(null, null, 0, 1).compareTo(make(null, null, 0, 2)));
- Assert.assertEquals(0, make("10", null, 0, 1).compareTo(make("10", null, 0, 2)));
- Assert.assertEquals(0, make(null, "10", 1, 1).compareTo(make(null, "10", 1, 2)));
- Assert.assertEquals(0, make("10", "11", 1, 1).compareTo(make("10", "11", 1, 2)));
- Assert.assertEquals(-1, make(null, "10", 0, 1).compareTo(make("10", null, 1, 2)));
- Assert.assertEquals(-1, make("11", "20", 0, 1).compareTo(make("20", "33", 1, 1)));
- Assert.assertEquals(1, make("20", "33", 1, 1).compareTo(make("11", "20", 0, 1)));
- Assert.assertEquals(1, make("10", null, 1, 1).compareTo(make(null, "10", 0, 1)));
+ Assert.assertEquals(
+ 0,
+ StringPartitionChunk.make(null, null, 0, 1)
+ .compareTo(StringPartitionChunk.make(null, null, 0, 2))
+ );
+ Assert.assertEquals(
+ 0,
+ StringPartitionChunk.make("10", null, 0, 1)
+ .compareTo(StringPartitionChunk.make("10", null, 0, 2))
+ );
+ Assert.assertEquals(
+ 0,
+ StringPartitionChunk.make(null, "10", 1, 1)
+ .compareTo(StringPartitionChunk.make(null, "10", 1, 2))
+ );
+ Assert.assertEquals(
+ 0,
+ StringPartitionChunk.make("10", "11", 1, 1)
+ .compareTo(StringPartitionChunk.make("10", "11", 1, 2))
+ );
+ Assert.assertEquals(
+ -1,
+ StringPartitionChunk.make(null, "10", 0, 1)
+ .compareTo(StringPartitionChunk.make("10", null, 1, 2))
+ );
+ Assert.assertEquals(
+ -1,
+ StringPartitionChunk.make("11", "20", 0, 1)
+ .compareTo(StringPartitionChunk.make("20", "33", 1, 1))
+ );
+ Assert.assertEquals(
+ 1,
+ StringPartitionChunk.make("20", "33", 1, 1)
+ .compareTo(StringPartitionChunk.make("11", "20", 0, 1))
+ );
+ Assert.assertEquals(
+ 1,
+ StringPartitionChunk.make("10", null, 1, 1)
+ .compareTo(StringPartitionChunk.make(null, "10", 0, 1))
+ );
}
@Test
public void testEquals()
{
- Assert.assertEquals(make(null, null, 0, 1), make(null, null, 0, 1));
- Assert.assertEquals(make(null, "10", 0, 1), make(null, "10", 0, 1));
- Assert.assertEquals(make("10", null, 0, 1), make("10", null, 0, 1));
- Assert.assertEquals(make("10", "11", 0, 1), make("10", "11", 0, 1));
+ Assert.assertEquals(StringPartitionChunk.make(null, null, 0, 1), StringPartitionChunk.make(null, null, 0, 1));
+ Assert.assertEquals(StringPartitionChunk.make(null, "10", 0, 1), StringPartitionChunk.make(null, "10", 0, 1));
+ Assert.assertEquals(StringPartitionChunk.make("10", null, 0, 1), StringPartitionChunk.make("10", null, 0, 1));
+ Assert.assertEquals(StringPartitionChunk.make("10", "11", 0, 1), StringPartitionChunk.make("10", "11", 0, 1));
}
}
diff --git a/extensions-contrib/azure-extensions/src/test/java/org/apache/druid/storage/azure/AzureByteSourceTest.java b/extensions-contrib/azure-extensions/src/test/java/org/apache/druid/storage/azure/AzureByteSourceTest.java
index 539d567944b..2947a7dedfa 100644
--- a/extensions-contrib/azure-extensions/src/test/java/org/apache/druid/storage/azure/AzureByteSourceTest.java
+++ b/extensions-contrib/azure-extensions/src/test/java/org/apache/druid/storage/azure/AzureByteSourceTest.java
@@ -20,6 +20,7 @@
package org.apache.druid.storage.azure;
import com.microsoft.azure.storage.StorageException;
+import org.easymock.EasyMock;
import org.easymock.EasyMockSupport;
import org.junit.Test;
@@ -27,8 +28,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
-import static org.easymock.EasyMock.expect;
-
public class AzureByteSourceTest extends EasyMockSupport
{
@@ -40,7 +39,7 @@ public class AzureByteSourceTest extends EasyMockSupport
AzureStorage azureStorage = createMock(AzureStorage.class);
InputStream stream = createMock(InputStream.class);
- expect(azureStorage.getBlobInputStream(containerName, blobPath)).andReturn(stream);
+ EasyMock.expect(azureStorage.getBlobInputStream(containerName, blobPath)).andReturn(stream);
replayAll();
@@ -58,7 +57,7 @@ public class AzureByteSourceTest extends EasyMockSupport
final String blobPath = "/path/to/file";
AzureStorage azureStorage = createMock(AzureStorage.class);
- expect(azureStorage.getBlobInputStream(containerName, blobPath)).andThrow(
+ EasyMock.expect(azureStorage.getBlobInputStream(containerName, blobPath)).andThrow(
new StorageException(
"",
"",
diff --git a/extensions-contrib/azure-extensions/src/test/java/org/apache/druid/storage/azure/AzureDataSegmentKillerTest.java b/extensions-contrib/azure-extensions/src/test/java/org/apache/druid/storage/azure/AzureDataSegmentKillerTest.java
index 9657836d57e..827d5538396 100644
--- a/extensions-contrib/azure-extensions/src/test/java/org/apache/druid/storage/azure/AzureDataSegmentKillerTest.java
+++ b/extensions-contrib/azure-extensions/src/test/java/org/apache/druid/storage/azure/AzureDataSegmentKillerTest.java
@@ -25,6 +25,7 @@ import org.apache.druid.java.util.common.Intervals;
import org.apache.druid.segment.loading.SegmentLoadingException;
import org.apache.druid.timeline.DataSegment;
import org.apache.druid.timeline.partition.NoneShardSpec;
+import org.easymock.EasyMock;
import org.easymock.EasyMockSupport;
import org.junit.Before;
import org.junit.Test;
@@ -34,19 +35,16 @@ import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
-import static org.easymock.EasyMock.expect;
-
public class AzureDataSegmentKillerTest extends EasyMockSupport
{
+ private static final String CONTAINER_NAME = "container";
+ private static final String BLOB_PATH = "test/2015-04-12T00:00:00.000Z_2015-04-13T00:00:00.000Z/1/0/index.zip";
- private static final String containerName = "container";
- private static final String blobPath = "test/2015-04-12T00:00:00.000Z_2015-04-13T00:00:00.000Z/1/0/index.zip";
-
- private static final DataSegment dataSegment = new DataSegment(
+ private static final DataSegment DATA_SEGMENT = new DataSegment(
"test",
Intervals.of("2015-04-12/2015-04-13"),
"1",
- ImmutableMap.of("containerName", containerName, "blobPath", blobPath),
+ ImmutableMap.of("containerName", CONTAINER_NAME, "blobPath", BLOB_PATH),
null,
null,
NoneShardSpec.instance(),
@@ -67,15 +65,15 @@ public class AzureDataSegmentKillerTest extends EasyMockSupport
{
List deletedFiles = new ArrayList<>();
- final String dirPath = Paths.get(blobPath).getParent().toString();
+ final String dirPath = Paths.get(BLOB_PATH).getParent().toString();
- expect(azureStorage.emptyCloudBlobDirectory(containerName, dirPath)).andReturn(deletedFiles);
+ EasyMock.expect(azureStorage.emptyCloudBlobDirectory(CONTAINER_NAME, dirPath)).andReturn(deletedFiles);
replayAll();
AzureDataSegmentKiller killer = new AzureDataSegmentKiller(azureStorage);
- killer.kill(dataSegment);
+ killer.kill(DATA_SEGMENT);
verifyAll();
}
@@ -84,9 +82,9 @@ public class AzureDataSegmentKillerTest extends EasyMockSupport
public void killWithErrorTest() throws SegmentLoadingException, URISyntaxException, StorageException
{
- String dirPath = Paths.get(blobPath).getParent().toString();
+ String dirPath = Paths.get(BLOB_PATH).getParent().toString();
- expect(azureStorage.emptyCloudBlobDirectory(containerName, dirPath)).andThrow(
+ EasyMock.expect(azureStorage.emptyCloudBlobDirectory(CONTAINER_NAME, dirPath)).andThrow(
new StorageException(
"",
"",
@@ -100,7 +98,7 @@ public class AzureDataSegmentKillerTest extends EasyMockSupport
AzureDataSegmentKiller killer = new AzureDataSegmentKiller(azureStorage);
- killer.kill(dataSegment);
+ killer.kill(DATA_SEGMENT);
verifyAll();
}
diff --git a/extensions-contrib/azure-extensions/src/test/java/org/apache/druid/storage/azure/AzureDataSegmentPullerTest.java b/extensions-contrib/azure-extensions/src/test/java/org/apache/druid/storage/azure/AzureDataSegmentPullerTest.java
index 5b52dca3c80..8884754a425 100644
--- a/extensions-contrib/azure-extensions/src/test/java/org/apache/druid/storage/azure/AzureDataSegmentPullerTest.java
+++ b/extensions-contrib/azure-extensions/src/test/java/org/apache/druid/storage/azure/AzureDataSegmentPullerTest.java
@@ -22,7 +22,9 @@ package org.apache.druid.storage.azure;
import com.microsoft.azure.storage.StorageException;
import org.apache.druid.java.util.common.FileUtils;
import org.apache.druid.segment.loading.SegmentLoadingException;
+import org.easymock.EasyMock;
import org.easymock.EasyMockSupport;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -33,11 +35,6 @@ import java.io.InputStream;
import java.net.URISyntaxException;
import java.nio.file.Files;
-import static org.easymock.EasyMock.expect;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
public class AzureDataSegmentPullerTest extends EasyMockSupport
{
@@ -61,7 +58,7 @@ public class AzureDataSegmentPullerTest extends EasyMockSupport
try {
final InputStream zipStream = new FileInputStream(pulledFile);
- expect(azureStorage.getBlobInputStream(containerName, blobPath)).andReturn(zipStream);
+ EasyMock.expect(azureStorage.getBlobInputStream(containerName, blobPath)).andReturn(zipStream);
replayAll();
@@ -70,9 +67,9 @@ public class AzureDataSegmentPullerTest extends EasyMockSupport
FileUtils.FileCopyResult result = puller.getSegmentFiles(containerName, blobPath, toDir);
File expected = new File(toDir, SEGMENT_FILE_NAME);
- assertEquals(value.length(), result.size());
- assertTrue(expected.exists());
- assertEquals(value.length(), expected.length());
+ Assert.assertEquals(value.length(), result.size());
+ Assert.assertTrue(expected.exists());
+ Assert.assertEquals(value.length(), expected.length());
verifyAll();
}
@@ -89,7 +86,7 @@ public class AzureDataSegmentPullerTest extends EasyMockSupport
final File outDir = Files.createTempDirectory("druid").toFile();
try {
- expect(azureStorage.getBlobInputStream(containerName, blobPath)).andThrow(
+ EasyMock.expect(azureStorage.getBlobInputStream(containerName, blobPath)).andThrow(
new URISyntaxException(
"error",
"error",
@@ -103,13 +100,12 @@ public class AzureDataSegmentPullerTest extends EasyMockSupport
puller.getSegmentFiles(containerName, blobPath, outDir);
- assertFalse(outDir.exists());
+ Assert.assertFalse(outDir.exists());
verifyAll();
}
finally {
org.apache.commons.io.FileUtils.deleteDirectory(outDir);
}
-
}
}
diff --git a/extensions-contrib/azure-extensions/src/test/java/org/apache/druid/storage/azure/AzureDataSegmentPusherTest.java b/extensions-contrib/azure-extensions/src/test/java/org/apache/druid/storage/azure/AzureDataSegmentPusherTest.java
index 8a75adfee49..caa01e41ae1 100644
--- a/extensions-contrib/azure-extensions/src/test/java/org/apache/druid/storage/azure/AzureDataSegmentPusherTest.java
+++ b/extensions-contrib/azure-extensions/src/test/java/org/apache/druid/storage/azure/AzureDataSegmentPusherTest.java
@@ -29,6 +29,7 @@ import org.apache.druid.java.util.common.MapUtils;
import org.apache.druid.java.util.common.StringUtils;
import org.apache.druid.timeline.DataSegment;
import org.apache.druid.timeline.partition.NoneShardSpec;
+import org.easymock.EasyMock;
import org.easymock.EasyMockSupport;
import org.junit.Assert;
import org.junit.Before;
@@ -44,9 +45,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;
-import static org.easymock.EasyMock.expectLastCall;
-import static org.junit.Assert.assertEquals;
-
public class AzureDataSegmentPusherTest extends EasyMockSupport
{
@Rule
@@ -134,7 +132,7 @@ public class AzureDataSegmentPusherTest extends EasyMockSupport
final String storageDir = pusher.getStorageDir(dataSegment, false);
final String azurePath = pusher.getAzurePath(dataSegment, false);
- assertEquals(
+ Assert.assertEquals(
StringUtils.format("%s/%s", storageDir, AzureStorageDruidModule.INDEX_ZIP_FILE_NAME),
azurePath
);
@@ -149,7 +147,7 @@ public class AzureDataSegmentPusherTest extends EasyMockSupport
final String azurePath = pusher.getAzurePath(dataSegment, false);
azureStorage.uploadBlob(compressedSegmentData, containerName, azurePath);
- expectLastCall();
+ EasyMock.expectLastCall();
replayAll();
@@ -161,11 +159,11 @@ public class AzureDataSegmentPusherTest extends EasyMockSupport
azurePath
);
- assertEquals(compressedSegmentData.length(), pushedDataSegment.getSize());
- assertEquals(binaryVersion, (int) pushedDataSegment.getBinaryVersion());
+ Assert.assertEquals(compressedSegmentData.length(), pushedDataSegment.getSize());
+ Assert.assertEquals(binaryVersion, (int) pushedDataSegment.getBinaryVersion());
Map loadSpec = pushedDataSegment.getLoadSpec();
- assertEquals(AzureStorageDruidModule.SCHEME, MapUtils.getString(loadSpec, "type"));
- assertEquals(azurePath, MapUtils.getString(loadSpec, "blobPath"));
+ Assert.assertEquals(AzureStorageDruidModule.SCHEME, MapUtils.getString(loadSpec, "type"));
+ Assert.assertEquals(azurePath, MapUtils.getString(loadSpec, "blobPath"));
verifyAll();
}
diff --git a/extensions-contrib/azure-extensions/src/test/java/org/apache/druid/storage/azure/AzureTaskLogsTest.java b/extensions-contrib/azure-extensions/src/test/java/org/apache/druid/storage/azure/AzureTaskLogsTest.java
index ce134e9c2ec..0255923c7e6 100644
--- a/extensions-contrib/azure-extensions/src/test/java/org/apache/druid/storage/azure/AzureTaskLogsTest.java
+++ b/extensions-contrib/azure-extensions/src/test/java/org/apache/druid/storage/azure/AzureTaskLogsTest.java
@@ -25,6 +25,7 @@ import com.google.common.io.Files;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.druid.java.util.common.StringUtils;
+import org.easymock.EasyMock;
import org.easymock.EasyMockSupport;
import org.junit.Assert;
import org.junit.Before;
@@ -35,9 +36,6 @@ import java.io.File;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.expectLastCall;
-
public class AzureTaskLogsTest extends EasyMockSupport
{
@@ -66,7 +64,7 @@ public class AzureTaskLogsTest extends EasyMockSupport
final File logFile = new File(tmpDir, "log");
azureStorage.uploadBlob(logFile, container, prefix + "/" + taskid + "/log");
- expectLastCall();
+ EasyMock.expectLastCall();
replayAll();
@@ -85,9 +83,9 @@ public class AzureTaskLogsTest extends EasyMockSupport
final String testLog = "hello this is a log";
final String blobPath = prefix + "/" + taskid + "/log";
- expect(azureStorage.getBlobExists(container, blobPath)).andReturn(true);
- expect(azureStorage.getBlobLength(container, blobPath)).andReturn((long) testLog.length());
- expect(azureStorage.getBlobInputStream(container, blobPath)).andReturn(
+ EasyMock.expect(azureStorage.getBlobExists(container, blobPath)).andReturn(true);
+ EasyMock.expect(azureStorage.getBlobLength(container, blobPath)).andReturn((long) testLog.length());
+ EasyMock.expect(azureStorage.getBlobInputStream(container, blobPath)).andReturn(
new ByteArrayInputStream(testLog.getBytes(StandardCharsets.UTF_8)));
@@ -108,9 +106,9 @@ public class AzureTaskLogsTest extends EasyMockSupport
final String testLog = "hello this is a log";
final String blobPath = prefix + "/" + taskid + "/log";
- expect(azureStorage.getBlobExists(container, blobPath)).andReturn(true);
- expect(azureStorage.getBlobLength(container, blobPath)).andReturn((long) testLog.length());
- expect(azureStorage.getBlobInputStream(container, blobPath)).andReturn(
+ EasyMock.expect(azureStorage.getBlobExists(container, blobPath)).andReturn(true);
+ EasyMock.expect(azureStorage.getBlobLength(container, blobPath)).andReturn((long) testLog.length());
+ EasyMock.expect(azureStorage.getBlobInputStream(container, blobPath)).andReturn(
new ByteArrayInputStream(testLog.getBytes(StandardCharsets.UTF_8)));
@@ -131,9 +129,9 @@ public class AzureTaskLogsTest extends EasyMockSupport
final String testLog = "hello this is a log";
final String blobPath = prefix + "/" + taskid + "/log";
- expect(azureStorage.getBlobExists(container, blobPath)).andReturn(true);
- expect(azureStorage.getBlobLength(container, blobPath)).andReturn((long) testLog.length());
- expect(azureStorage.getBlobInputStream(container, blobPath)).andReturn(
+ EasyMock.expect(azureStorage.getBlobExists(container, blobPath)).andReturn(true);
+ EasyMock.expect(azureStorage.getBlobLength(container, blobPath)).andReturn((long) testLog.length());
+ EasyMock.expect(azureStorage.getBlobInputStream(container, blobPath)).andReturn(
new ByteArrayInputStream(StringUtils.toUtf8(testLog)));
diff --git a/extensions-contrib/cloudfiles-extensions/src/test/java/org/apache/druid/storage/cloudfiles/CloudFilesByteSourceTest.java b/extensions-contrib/cloudfiles-extensions/src/test/java/org/apache/druid/storage/cloudfiles/CloudFilesByteSourceTest.java
index dd8b7800b33..6a07063c722 100644
--- a/extensions-contrib/cloudfiles-extensions/src/test/java/org/apache/druid/storage/cloudfiles/CloudFilesByteSourceTest.java
+++ b/extensions-contrib/cloudfiles-extensions/src/test/java/org/apache/druid/storage/cloudfiles/CloudFilesByteSourceTest.java
@@ -19,19 +19,17 @@
package org.apache.druid.storage.cloudfiles;
+import org.easymock.EasyMock;
import org.easymock.EasyMockSupport;
import org.jclouds.io.Payload;
+import org.junit.Assert;
import org.junit.Test;
import java.io.IOException;
import java.io.InputStream;
-import static org.easymock.EasyMock.expect;
-import static org.junit.Assert.assertEquals;
-
public class CloudFilesByteSourceTest extends EasyMockSupport
{
-
@Test
public void openStreamTest() throws IOException
{
@@ -42,15 +40,15 @@ public class CloudFilesByteSourceTest extends EasyMockSupport
Payload payload = createMock(Payload.class);
InputStream stream = createMock(InputStream.class);
- expect(objectApi.get(path, 0)).andReturn(cloudFilesObject);
- expect(cloudFilesObject.getPayload()).andReturn(payload);
- expect(payload.openStream()).andReturn(stream);
+ EasyMock.expect(objectApi.get(path, 0)).andReturn(cloudFilesObject);
+ EasyMock.expect(cloudFilesObject.getPayload()).andReturn(payload);
+ EasyMock.expect(payload.openStream()).andReturn(stream);
payload.close();
replayAll();
CloudFilesByteSource byteSource = new CloudFilesByteSource(objectApi, path);
- assertEquals(stream, byteSource.openStream());
+ Assert.assertEquals(stream, byteSource.openStream());
byteSource.closeStream();
verifyAll();
@@ -66,9 +64,9 @@ public class CloudFilesByteSourceTest extends EasyMockSupport
Payload payload = createMock(Payload.class);
InputStream stream = createMock(InputStream.class);
- expect(objectApi.get(path, 0)).andReturn(cloudFilesObject);
- expect(cloudFilesObject.getPayload()).andReturn(payload);
- expect(payload.openStream()).andThrow(new IOException()).andReturn(stream);
+ EasyMock.expect(objectApi.get(path, 0)).andReturn(cloudFilesObject);
+ EasyMock.expect(cloudFilesObject.getPayload()).andReturn(payload);
+ EasyMock.expect(payload.openStream()).andThrow(new IOException()).andReturn(stream);
payload.close();
replayAll();
@@ -78,13 +76,12 @@ public class CloudFilesByteSourceTest extends EasyMockSupport
byteSource.openStream();
}
catch (Exception e) {
- assertEquals("Recoverable exception", e.getMessage());
+ Assert.assertEquals("Recoverable exception", e.getMessage());
}
- assertEquals(stream, byteSource.openStream());
+ Assert.assertEquals(stream, byteSource.openStream());
byteSource.closeStream();
verifyAll();
}
-
}
diff --git a/extensions-contrib/cloudfiles-extensions/src/test/java/org/apache/druid/storage/cloudfiles/CloudFilesObjectApiProxyTest.java b/extensions-contrib/cloudfiles-extensions/src/test/java/org/apache/druid/storage/cloudfiles/CloudFilesObjectApiProxyTest.java
index 9d7036b5972..eb3b61c2149 100644
--- a/extensions-contrib/cloudfiles-extensions/src/test/java/org/apache/druid/storage/cloudfiles/CloudFilesObjectApiProxyTest.java
+++ b/extensions-contrib/cloudfiles-extensions/src/test/java/org/apache/druid/storage/cloudfiles/CloudFilesObjectApiProxyTest.java
@@ -19,19 +19,17 @@
package org.apache.druid.storage.cloudfiles;
+import org.easymock.EasyMock;
import org.easymock.EasyMockSupport;
import org.jclouds.io.Payload;
import org.jclouds.openstack.swift.v1.domain.SwiftObject;
import org.jclouds.openstack.swift.v1.features.ObjectApi;
import org.jclouds.rackspace.cloudfiles.v1.CloudFilesApi;
+import org.junit.Assert;
import org.junit.Test;
-import static org.easymock.EasyMock.expect;
-import static org.junit.Assert.assertEquals;
-
public class CloudFilesObjectApiProxyTest extends EasyMockSupport
{
-
@Test
public void getTest()
{
@@ -44,21 +42,20 @@ public class CloudFilesObjectApiProxyTest extends EasyMockSupport
SwiftObject swiftObject = createMock(SwiftObject.class);
Payload payload = createMock(Payload.class);
- expect(cloudFilesApi.getObjectApi(region, container)).andReturn(objectApi);
- expect(objectApi.get(path)).andReturn(swiftObject);
- expect(swiftObject.getPayload()).andReturn(payload);
+ EasyMock.expect(cloudFilesApi.getObjectApi(region, container)).andReturn(objectApi);
+ EasyMock.expect(objectApi.get(path)).andReturn(swiftObject);
+ EasyMock.expect(swiftObject.getPayload()).andReturn(payload);
replayAll();
CloudFilesObjectApiProxy cfoApiProxy = new CloudFilesObjectApiProxy(cloudFilesApi, region, container);
CloudFilesObject cloudFilesObject = cfoApiProxy.get(path, 0);
- assertEquals(cloudFilesObject.getPayload(), payload);
- assertEquals(cloudFilesObject.getRegion(), region);
- assertEquals(cloudFilesObject.getContainer(), container);
- assertEquals(cloudFilesObject.getPath(), path);
+ Assert.assertEquals(cloudFilesObject.getPayload(), payload);
+ Assert.assertEquals(cloudFilesObject.getRegion(), region);
+ Assert.assertEquals(cloudFilesObject.getContainer(), container);
+ Assert.assertEquals(cloudFilesObject.getPath(), path);
verifyAll();
}
-
}
diff --git a/extensions-contrib/influx-extensions/src/test/java/org/apache/druid/data/input/influx/InfluxParserTest.java b/extensions-contrib/influx-extensions/src/test/java/org/apache/druid/data/input/influx/InfluxParserTest.java
index b14b8bd5909..49307f91e0a 100644
--- a/extensions-contrib/influx-extensions/src/test/java/org/apache/druid/data/input/influx/InfluxParserTest.java
+++ b/extensions-contrib/influx-extensions/src/test/java/org/apache/druid/data/input/influx/InfluxParserTest.java
@@ -26,6 +26,8 @@ import junitparams.Parameters;
import org.apache.druid.java.util.common.Pair;
import org.apache.druid.java.util.common.parsers.ParseException;
import org.apache.druid.java.util.common.parsers.Parser;
+import org.hamcrest.MatcherAssert;
+import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -33,15 +35,14 @@ import org.junit.runner.RunWith;
import java.util.HashMap;
import java.util.Map;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.isA;
-
@RunWith(JUnitParamsRunner.class)
public class InfluxParserTest
{
+ @SuppressWarnings("unused")
private String name;
+ @SuppressWarnings("unused")
private String input;
+ @SuppressWarnings("unused")
private Map expected;
private static Object[] testCase(String name, String input, Parsed expected)
@@ -49,7 +50,6 @@ public class InfluxParserTest
return Lists.newArrayList(name, input, expected).toArray();
}
-
public Object[] testData()
{
return Lists.newArrayList(
@@ -142,14 +142,20 @@ public class InfluxParserTest
{
Parser parser = new InfluxParser(null);
Map parsed = parser.parseToMap(input);
- assertThat("correct measurement name", parsed.get("measurement"), equalTo(expected.measurement));
- assertThat("correct timestamp", parsed.get(InfluxParser.TIMESTAMP_KEY), equalTo(expected.timestamp));
- expected.kv.forEach((k, v) -> {
- assertThat("correct field " + k, parsed.get(k), equalTo(v));
- });
+ MatcherAssert.assertThat(
+ "correct measurement name",
+ parsed.get("measurement"),
+ Matchers.equalTo(expected.measurement)
+ );
+ MatcherAssert.assertThat(
+ "correct timestamp",
+ parsed.get(InfluxParser.TIMESTAMP_KEY),
+ Matchers.equalTo(expected.timestamp)
+ );
+ expected.kv.forEach((k, v) -> MatcherAssert.assertThat("correct field " + k, parsed.get(k), Matchers.equalTo(v)));
parsed.remove("measurement");
parsed.remove(InfluxParser.TIMESTAMP_KEY);
- assertThat("No extra keys in parsed data", parsed.keySet(), equalTo(expected.kv.keySet()));
+ MatcherAssert.assertThat("No extra keys in parsed data", parsed.keySet(), Matchers.equalTo(expected.kv.keySet()));
}
@Test
@@ -158,7 +164,7 @@ public class InfluxParserTest
Parser parser = new InfluxParser(Sets.newHashSet("cpu"));
String input = "cpu,host=foo.bar.baz,region=us-east,application=echo pct_idle=99.3,pct_user=88.8,m1_load=2 1465839830100400200";
Map parsed = parser.parseToMap(input);
- assertThat(parsed.get("measurement"), equalTo("cpu"));
+ MatcherAssert.assertThat(parsed.get("measurement"), Matchers.equalTo("cpu"));
}
@Test
@@ -170,7 +176,7 @@ public class InfluxParserTest
parser.parseToMap(input);
}
catch (ParseException t) {
- assertThat(t, isA(ParseException.class));
+ MatcherAssert.assertThat(t, Matchers.isA(ParseException.class));
return;
}
@@ -192,10 +198,10 @@ public class InfluxParserTest
{
Parser parser = new InfluxParser(null);
try {
- Map res = parser.parseToMap(testCase.rhs);
+ parser.parseToMap(testCase.rhs);
}
catch (ParseException t) {
- assertThat(t, isA(ParseException.class));
+ MatcherAssert.assertThat(t, Matchers.isA(ParseException.class));
return;
}
@@ -206,9 +212,9 @@ public class InfluxParserTest
{
private String measurement;
private Long timestamp;
- private Map kv = new HashMap<>();
+ private final Map kv = new HashMap<>();
- public static Parsed row(String measurement, Long timestamp)
+ static Parsed row(String measurement, Long timestamp)
{
Parsed e = new Parsed();
e.measurement = measurement;
@@ -216,7 +222,7 @@ public class InfluxParserTest
return e;
}
- public Parsed with(String k, Object v)
+ Parsed with(String k, Object v)
{
kv.put(k, v);
return this;
diff --git a/extensions-contrib/materialized-view-maintenance/src/test/java/org/apache/druid/indexing/materializedview/MaterializedViewSupervisorSpecTest.java b/extensions-contrib/materialized-view-maintenance/src/test/java/org/apache/druid/indexing/materializedview/MaterializedViewSupervisorSpecTest.java
index 46728e2418c..e19cb784ac7 100644
--- a/extensions-contrib/materialized-view-maintenance/src/test/java/org/apache/druid/indexing/materializedview/MaterializedViewSupervisorSpecTest.java
+++ b/extensions-contrib/materialized-view-maintenance/src/test/java/org/apache/druid/indexing/materializedview/MaterializedViewSupervisorSpecTest.java
@@ -41,6 +41,7 @@ import org.apache.druid.segment.TestHelper;
import org.apache.druid.segment.realtime.firehose.ChatHandlerProvider;
import org.apache.druid.segment.realtime.firehose.NoopChatHandlerProvider;
import org.apache.druid.server.security.AuthorizerMapper;
+import org.easymock.EasyMock;
import org.hamcrest.CoreMatchers;
import org.junit.Assert;
import org.junit.Before;
@@ -50,15 +51,13 @@ import org.junit.rules.ExpectedException;
import java.io.IOException;
-import static org.easymock.EasyMock.createMock;
-
-public class MaterializedViewSupervisorSpecTest
+public class MaterializedViewSupervisorSpecTest
{
@Rule
public ExpectedException expectedException = ExpectedException.none();
- private ObjectMapper objectMapper = TestHelper.makeJsonMapper();
-
+ private final ObjectMapper objectMapper = TestHelper.makeJsonMapper();
+
@Before
public void setup()
{
@@ -73,53 +72,53 @@ public class MaterializedViewSupervisorSpecTest
.addValue(SQLMetadataSegmentManager.class, null)
.addValue(IndexerMetadataStorageCoordinator.class, null)
.addValue(MaterializedViewTaskConfig.class, new MaterializedViewTaskConfig())
- .addValue(AuthorizerMapper.class, createMock(AuthorizerMapper.class))
+ .addValue(AuthorizerMapper.class, EasyMock.createMock(AuthorizerMapper.class))
.addValue(ChatHandlerProvider.class, new NoopChatHandlerProvider())
.addValue(SupervisorStateManagerConfig.class, new SupervisorStateManagerConfig())
);
}
@Test
- public void testSupervisorSerialization() throws IOException
+ public void testSupervisorSerialization() throws IOException
{
String supervisorStr = "{\n" +
- " \"type\" : \"derivativeDataSource\",\n" +
- " \"baseDataSource\": \"wikiticker\",\n" +
- " \"dimensionsSpec\":{\n" +
- " \"dimensions\" : [\n" +
- " \"isUnpatrolled\",\n" +
- " \"metroCode\",\n" +
- " \"namespace\",\n" +
- " \"page\",\n" +
- " \"regionIsoCode\",\n" +
- " \"regionName\",\n" +
- " \"user\"\n" +
- " ]\n" +
- " },\n" +
- " \"metricsSpec\" : [\n" +
- " {\n" +
- " \"name\" : \"count\",\n" +
- " \"type\" : \"count\"\n" +
- " },\n" +
- " {\n" +
- " \"name\" : \"added\",\n" +
- " \"type\" : \"longSum\",\n" +
- " \"fieldName\" : \"added\"\n" +
- " }\n" +
- " ],\n" +
- " \"tuningConfig\": {\n" +
- " \"type\" : \"hadoop\"\n" +
- " }\n" +
- "}";
+ " \"type\" : \"derivativeDataSource\",\n" +
+ " \"baseDataSource\": \"wikiticker\",\n" +
+ " \"dimensionsSpec\":{\n" +
+ " \"dimensions\" : [\n" +
+ " \"isUnpatrolled\",\n" +
+ " \"metroCode\",\n" +
+ " \"namespace\",\n" +
+ " \"page\",\n" +
+ " \"regionIsoCode\",\n" +
+ " \"regionName\",\n" +
+ " \"user\"\n" +
+ " ]\n" +
+ " },\n" +
+ " \"metricsSpec\" : [\n" +
+ " {\n" +
+ " \"name\" : \"count\",\n" +
+ " \"type\" : \"count\"\n" +
+ " },\n" +
+ " {\n" +
+ " \"name\" : \"added\",\n" +
+ " \"type\" : \"longSum\",\n" +
+ " \"fieldName\" : \"added\"\n" +
+ " }\n" +
+ " ],\n" +
+ " \"tuningConfig\": {\n" +
+ " \"type\" : \"hadoop\"\n" +
+ " }\n" +
+ "}";
MaterializedViewSupervisorSpec expected = new MaterializedViewSupervisorSpec(
"wikiticker",
new DimensionsSpec(
Lists.newArrayList(
new StringDimensionSchema("isUnpatrolled"),
- new StringDimensionSchema("metroCode"),
- new StringDimensionSchema("namespace"),
- new StringDimensionSchema("page"),
- new StringDimensionSchema("regionIsoCode"),
+ new StringDimensionSchema("metroCode"),
+ new StringDimensionSchema("namespace"),
+ new StringDimensionSchema("page"),
+ new StringDimensionSchema("regionIsoCode"),
new StringDimensionSchema("regionName"),
new StringDimensionSchema("user")
),
@@ -144,7 +143,7 @@ public class MaterializedViewSupervisorSpecTest
null,
null,
new MaterializedViewTaskConfig(),
- createMock(AuthorizerMapper.class),
+ EasyMock.createMock(AuthorizerMapper.class),
new NoopChatHandlerProvider(),
new SupervisorStateManagerConfig()
);
@@ -193,11 +192,17 @@ public class MaterializedViewSupervisorSpecTest
Assert.assertFalse(spec.isSuspended());
String suspendedSerialized = objectMapper.writeValueAsString(spec.createSuspendedSpec());
- MaterializedViewSupervisorSpec suspendedSpec = objectMapper.readValue(suspendedSerialized, MaterializedViewSupervisorSpec.class);
+ MaterializedViewSupervisorSpec suspendedSpec = objectMapper.readValue(
+ suspendedSerialized,
+ MaterializedViewSupervisorSpec.class
+ );
Assert.assertTrue(suspendedSpec.isSuspended());
String runningSerialized = objectMapper.writeValueAsString(spec.createRunningSpec());
- MaterializedViewSupervisorSpec runningSpec = objectMapper.readValue(runningSerialized, MaterializedViewSupervisorSpec.class);
+ MaterializedViewSupervisorSpec runningSpec = objectMapper.readValue(
+ runningSerialized,
+ MaterializedViewSupervisorSpec.class
+ );
Assert.assertFalse(runningSpec.isSuspended());
}
@@ -208,7 +213,8 @@ public class MaterializedViewSupervisorSpecTest
expectedException.expectMessage(
"baseDataSource cannot be null or empty. Please provide a baseDataSource."
);
- MaterializedViewSupervisorSpec materializedViewSupervisorSpec = new MaterializedViewSupervisorSpec(
+ //noinspection ResultOfObjectAllocationIgnored (this method call will trigger the expected exception)
+ new MaterializedViewSupervisorSpec(
"",
new DimensionsSpec(
Lists.newArrayList(
@@ -241,7 +247,7 @@ public class MaterializedViewSupervisorSpecTest
null,
null,
new MaterializedViewTaskConfig(),
- createMock(AuthorizerMapper.class),
+ EasyMock.createMock(AuthorizerMapper.class),
new NoopChatHandlerProvider(),
new SupervisorStateManagerConfig()
);
@@ -254,7 +260,8 @@ public class MaterializedViewSupervisorSpecTest
expectedException.expectMessage(
"baseDataSource cannot be null or empty. Please provide a baseDataSource."
);
- MaterializedViewSupervisorSpec materializedViewSupervisorSpec = new MaterializedViewSupervisorSpec(
+ //noinspection ResultOfObjectAllocationIgnored (this method call will trigger the expected exception)
+ new MaterializedViewSupervisorSpec(
null,
new DimensionsSpec(
Lists.newArrayList(
@@ -287,7 +294,7 @@ public class MaterializedViewSupervisorSpecTest
null,
null,
new MaterializedViewTaskConfig(),
- createMock(AuthorizerMapper.class),
+ EasyMock.createMock(AuthorizerMapper.class),
new NoopChatHandlerProvider(),
new SupervisorStateManagerConfig()
);
diff --git a/extensions-contrib/materialized-view-maintenance/src/test/java/org/apache/druid/indexing/materializedview/MaterializedViewSupervisorTest.java b/extensions-contrib/materialized-view-maintenance/src/test/java/org/apache/druid/indexing/materializedview/MaterializedViewSupervisorTest.java
index 3b9061de60c..0ac7f6678a1 100644
--- a/extensions-contrib/materialized-view-maintenance/src/test/java/org/apache/druid/indexing/materializedview/MaterializedViewSupervisorTest.java
+++ b/extensions-contrib/materialized-view-maintenance/src/test/java/org/apache/druid/indexing/materializedview/MaterializedViewSupervisorTest.java
@@ -68,9 +68,6 @@ import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-
public class MaterializedViewSupervisorTest
{
@Rule
@@ -78,7 +75,6 @@ public class MaterializedViewSupervisorTest
@Rule
public final ExpectedException expectedException = ExpectedException.none();
- private TestDerbyConnector derbyConnector;
private TaskStorage taskStorage;
private TaskMaster taskMaster;
private IndexerMetadataStorageCoordinator indexerMetadataStorageCoordinator;
@@ -86,28 +82,27 @@ public class MaterializedViewSupervisorTest
private SQLMetadataSegmentManager sqlMetadataSegmentManager;
private TaskQueue taskQueue;
private MaterializedViewSupervisor supervisor;
- private MaterializedViewSupervisorSpec spec;
- private ObjectMapper objectMapper = TestHelper.makeJsonMapper();
-
+ private final ObjectMapper objectMapper = TestHelper.makeJsonMapper();
+
@Before
public void setUp()
{
- derbyConnector = derbyConnectorRule.getConnector();
+ TestDerbyConnector derbyConnector = derbyConnectorRule.getConnector();
derbyConnector.createDataSourceTable();
derbyConnector.createSegmentTable();
- taskStorage = createMock(TaskStorage.class);
- taskMaster = createMock(TaskMaster.class);
+ taskStorage = EasyMock.createMock(TaskStorage.class);
+ taskMaster = EasyMock.createMock(TaskMaster.class);
indexerMetadataStorageCoordinator = new IndexerSQLMetadataStorageCoordinator(
objectMapper,
derbyConnectorRule.metadataTablesConfigSupplier().get(),
derbyConnector
);
- metadataSupervisorManager = createMock(MetadataSupervisorManager.class);
- sqlMetadataSegmentManager = createMock(SQLMetadataSegmentManager.class);
- taskQueue = createMock(TaskQueue.class);
+ metadataSupervisorManager = EasyMock.createMock(MetadataSupervisorManager.class);
+ sqlMetadataSegmentManager = EasyMock.createMock(SQLMetadataSegmentManager.class);
+ taskQueue = EasyMock.createMock(TaskQueue.class);
taskQueue.start();
objectMapper.registerSubtypes(new NamedType(HashBasedNumberedShardSpec.class, "hashed"));
- spec = new MaterializedViewSupervisorSpec(
+ MaterializedViewSupervisorSpec spec = new MaterializedViewSupervisorSpec(
"base",
new DimensionsSpec(Collections.singletonList(new StringDimensionSchema("dim")), null, null),
new AggregatorFactory[]{new LongSumAggregatorFactory("m1", "m1")},
@@ -125,8 +120,8 @@ public class MaterializedViewSupervisorTest
sqlMetadataSegmentManager,
indexerMetadataStorageCoordinator,
new MaterializedViewTaskConfig(),
- createMock(AuthorizerMapper.class),
- createMock(ChatHandlerProvider.class),
+ EasyMock.createMock(AuthorizerMapper.class),
+ EasyMock.createMock(ChatHandlerProvider.class),
new SupervisorStateManagerConfig()
);
supervisor = (MaterializedViewSupervisor) spec.createSupervisor();
@@ -160,9 +155,9 @@ public class MaterializedViewSupervisorTest
)
);
indexerMetadataStorageCoordinator.announceHistoricalSegments(baseSegments);
- expect(taskMaster.getTaskQueue()).andReturn(Optional.of(taskQueue)).anyTimes();
- expect(taskMaster.getTaskRunner()).andReturn(Optional.absent()).anyTimes();
- expect(taskStorage.getActiveTasks()).andReturn(ImmutableList.of()).anyTimes();
+ EasyMock.expect(taskMaster.getTaskQueue()).andReturn(Optional.of(taskQueue)).anyTimes();
+ EasyMock.expect(taskMaster.getTaskRunner()).andReturn(Optional.absent()).anyTimes();
+ EasyMock.expect(taskStorage.getActiveTasks()).andReturn(ImmutableList.of()).anyTimes();
Pair, Map>> toBuildInterval = supervisor.checkSegments();
Map> expectedSegments = new HashMap<>();
expectedSegments.put(
@@ -201,11 +196,15 @@ public class MaterializedViewSupervisorTest
)
);
indexerMetadataStorageCoordinator.announceHistoricalSegments(baseSegments);
- expect(taskMaster.getTaskQueue()).andReturn(Optional.of(taskQueue)).anyTimes();
- expect(taskMaster.getTaskRunner()).andReturn(Optional.absent()).anyTimes();
- expect(taskStorage.getActiveTasks()).andReturn(ImmutableList.of()).anyTimes();
- expect(taskStorage.getStatus("test_task1")).andReturn(Optional.of(TaskStatus.failure("test_task1"))).anyTimes();
- expect(taskStorage.getStatus("test_task2")).andReturn(Optional.of(TaskStatus.running("test_task2"))).anyTimes();
+ EasyMock.expect(taskMaster.getTaskQueue()).andReturn(Optional.of(taskQueue)).anyTimes();
+ EasyMock.expect(taskMaster.getTaskRunner()).andReturn(Optional.absent()).anyTimes();
+ EasyMock.expect(taskStorage.getActiveTasks()).andReturn(ImmutableList.of()).anyTimes();
+ EasyMock.expect(taskStorage.getStatus("test_task1"))
+ .andReturn(Optional.of(TaskStatus.failure("test_task1")))
+ .anyTimes();
+ EasyMock.expect(taskStorage.getStatus("test_task2"))
+ .andReturn(Optional.of(TaskStatus.running("test_task2")))
+ .anyTimes();
EasyMock.replay(taskStorage);
Pair