Lengthen CompressionStrategyTest::testKnownSizeConcurrency() to have 2m timeout on its test to account for shared Jenkins build lag

This commit is contained in:
Charles Allen 2014-12-19 12:52:22 -08:00
parent 63df70cbe2
commit 971afab36f
1 changed files with 13 additions and 17 deletions

View File

@ -21,6 +21,10 @@ package io.druid.segment.data;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import io.druid.segment.CompressedPools; import io.druid.segment.CompressedPools;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
@ -35,11 +39,13 @@ import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -158,26 +164,20 @@ public class CompressionStrategyTest
} }
@Test @Test(timeout = 120000)
public void testKnownSizeConcurrency() throws InterruptedException, ExecutionException, TimeoutException public void testKnownSizeConcurrency() throws InterruptedException, ExecutionException, TimeoutException
{ {
final int numThreads = 20; final int numThreads = 20;
BlockingQueue<Runnable> queue = new ArrayBlockingQueue<>(numThreads);
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor( ListeningExecutorService threadPoolExecutor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(numThreads));
numThreads, List<ListenableFuture<?>> results = new ArrayList<>();
numThreads,
100,
TimeUnit.MILLISECONDS,
queue
);
Collection<Future<Boolean>> results = new ArrayList<>();
for (int i = 0; i < numThreads; ++i) { for (int i = 0; i < numThreads; ++i) {
results.add( results.add(
threadPoolExecutor.submit( threadPoolExecutor.submit(
new Callable<Boolean>() new Runnable()
{ {
@Override @Override
public Boolean call() throws Exception public void run()
{ {
ByteBuffer compressed = ByteBuffer.wrap(compressionStrategy.getCompressor().compress(originalData)); ByteBuffer compressed = ByteBuffer.wrap(compressionStrategy.getCompressor().compress(originalData));
ByteBuffer output = ByteBuffer.allocate(originalData.length); ByteBuffer output = ByteBuffer.allocate(originalData.length);
@ -187,15 +187,11 @@ public class CompressionStrategyTest
byte[] checkArray = new byte[DATA_SIZER]; byte[] checkArray = new byte[DATA_SIZER];
output.get(checkArray); output.get(checkArray);
Assert.assertArrayEquals("Uncompressed data does not match", originalData, checkArray); Assert.assertArrayEquals("Uncompressed data does not match", originalData, checkArray);
return true;
} }
} }
) )
); );
} }
threadPoolExecutor.shutdown(); Futures.allAsList(results).get();
for (Future result : results) {
Assert.assertTrue((Boolean) result.get(500, TimeUnit.MILLISECONDS));
}
} }
} }