Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JMH to functional tests iterating over threads (fibers) #8

Open
wants to merge 17 commits into
base: jmh_fibers
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,12 @@
<artifactId>url-connection-client</artifactId>
<version>${aws-sdk.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.10.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<repositories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import edu.illinois.library.cantaloupe.test.TestUtil;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -188,8 +190,9 @@ void testNewDerivativeImageInputStreamWithNonexistentImage()
assertNotExists(instance, ops);
}

@Test
void testNewDerivativeImageInputStreamConcurrently() throws Exception {
@ParameterizedTest
@ValueSource(ints = {500})
void testNewDerivativeImageInputStreamConcurrently(int numThreads) throws Exception {
final DerivativeCache instance = newInstance();
final OperationList ops = OperationList.builder()
.withIdentifier(new Identifier("cats"))
Expand All @@ -213,7 +216,7 @@ void testNewDerivativeImageInputStreamConcurrently() throws Exception {
}
}
return null;
}).run();
}, numThreads).run();
}

/* newDerivativeImageOutputStream() */
Expand Down Expand Up @@ -559,8 +562,9 @@ void testPutWithInfo() throws Exception {
* DerivativeCache#put(Identifier, Info)} and {@link
* DerivativeCache#getInfo(Identifier)} don't conflict.
*/
@Test
void testPutWithInfoConcurrently() throws Exception {
@ParameterizedTest
@ValueSource(ints = {500})
void testPutWithInfoConcurrently(int numThreads) throws Exception {
final DerivativeCache instance = newInstance();
final Identifier identifier = new Identifier("monkeys");
final Info info = new Info();
Expand All @@ -574,7 +578,7 @@ void testPutWithInfoConcurrently() throws Exception {
fail();
}
return null;
}).run();
}, numThreads).run();
}

@Test
Expand Down Expand Up @@ -610,8 +614,9 @@ void testPutWithString() throws Exception {
* DerivativeCache#put(Identifier, String)} and {@link
* DerivativeCache#getInfo(Identifier)} don't conflict.
*/
@Test
void testPutWithStringConcurrently() throws Exception {
@ParameterizedTest
@ValueSource(ints = {500})
void testPutWithStringConcurrently(int numThreads) throws Exception {
final DerivativeCache instance = newInstance();
final Identifier identifier = new Identifier("monkeys");
final Info info = new Info();
Expand All @@ -626,7 +631,7 @@ void testPutWithStringConcurrently() throws Exception {
fail();
}
return null;
}).run();
}, numThreads).run();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,42 @@
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assumptions.assumeFalse;

import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.annotations.Warmup;
import static edu.illinois.library.cantaloupe.test.PerformanceTestConstants.*;

@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
@Warmup(iterations = WARMUP_ITERATIONS,
time = WARMUP_TIME)
@Measurement(iterations = MEASUREMENT_ITERATIONS,
time = MEASUREMENT_TIME)
@State(Scope.Benchmark)
@Fork(value = 1, jvmArgs = { "-server", "-Xms128M", "-Xmx128M", "-Dcantaloupe.config=memory" })
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is from an existing JMH test class

public class FilesystemCacheTest extends AbstractCacheTest {

private Path fixturePath;
private Path infoPath;
private Path sourceImagePath;
private Path derivativeImagePath;
private FilesystemCache instance;

@Param({"10", "50", "100", "500", "1000", "5000"})
private int numThreads;

@BeforeEach
@Setup
public void setUp() throws Exception {
super.setUp();

Expand All @@ -57,6 +84,7 @@ public void setUp() throws Exception {
}

@AfterEach
@TearDown
public void tearDown() throws IOException {
try {
Files.walkFileTree(fixturePath, new DeletingFileVisitor());
Expand Down Expand Up @@ -374,7 +402,8 @@ void testGetSourceImageFileWithNonzeroTTL() throws Exception {
}

@Test
void testGetSourceImageFileConcurrently() throws Exception {
@Benchmark
public void testGetSourceImageFileConcurrently() throws Exception {
assumeFalse(SystemUtils.IS_OS_WINDOWS); // TODO: this fails in Windows CI with a flurry of AccessDeniedExceptions
final Identifier identifier = new Identifier("monkeys");

Expand All @@ -387,14 +416,24 @@ void testGetSourceImageFileConcurrently() throws Exception {
}, () -> {
instance.getSourceImageFile(identifier);
return null;
}).run();
}, numThreads).run();
}

@Test
@Override
void testNewDerivativeImageInputStreamConcurrently() throws Exception {
@Benchmark
public void testNewDerivativeImageInputStreamConcurrently() throws Exception {
assumeFalse(SystemUtils.IS_OS_WINDOWS); // TODO: this fails in Windows CI with a flurry of AccessDeniedExceptions
super.testNewDerivativeImageInputStreamConcurrently();
super.testNewDerivativeImageInputStreamConcurrently(numThreads);
}

@Benchmark
public void testPutWithInfoConcurrently() throws Exception {
super.testPutWithInfoConcurrently(numThreads);
}

@Benchmark
public void testPutWithStringConcurrently() throws Exception {
super.testPutWithStringConcurrently(numThreads);
}

/* newSourceImageOutputStream(Identifier) */
Expand Down
Loading
Loading