Skip to content

Commit

Permalink
Shut down pools in tests (#1282)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwalluck authored Nov 20, 2024
1 parent 10fecf7 commit 4d82768
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.jboss.pnc.build.finder.core.ChecksumType;
import org.jboss.pnc.build.finder.core.DistributionAnalyzer;
import org.jboss.pnc.build.finder.core.LocalFile;
import org.jboss.pnc.build.finder.core.Utils;
import org.jboss.pnc.build.finder.koji.ClientSession;
import org.jboss.pnc.build.finder.koji.KojiBuild;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -66,29 +67,34 @@ public boolean matches(Entry<Checksum, Collection<String>> entry) {
void testChecksumsAndFindBuilds(@TempDir File folder) throws Exception {
Timer timer = REGISTRY.timer(name(AbstractRpmIT.class, "checksums"));
ExecutorService pool = Executors.newFixedThreadPool(2);
DistributionAnalyzer analyzer;
Future<Map<ChecksumType, MultiValuedMap<String, LocalFile>>> futureChecksum;

try (Context ignored = timer.time()) {
analyzer = new DistributionAnalyzer(getFiles(), getConfig());
futureChecksum = pool.submit(analyzer);
}
try {
DistributionAnalyzer analyzer;
Future<Map<ChecksumType, MultiValuedMap<String, LocalFile>>> futureChecksum;

try (Context ignored = timer.time()) {
analyzer = new DistributionAnalyzer(getFiles(), getConfig());
futureChecksum = pool.submit(analyzer);
}

Timer timer2 = REGISTRY.timer(name(AbstractRpmIT.class, "builds"));
Timer timer2 = REGISTRY.timer(name(AbstractRpmIT.class, "builds"));

try (Context ignored = timer2.time()) {
ClientSession session = getSession();
BuildFinder finder = new BuildFinder(session, getConfig(), analyzer, null, getPncClient());
finder.setOutputDirectory(folder);
Future<Map<BuildSystemInteger, KojiBuild>> futureBuilds = pool.submit(finder);
try (Context ignored = timer2.time()) {
ClientSession session = getSession();
BuildFinder finder = new BuildFinder(session, getConfig(), analyzer, null, getPncClient());
finder.setOutputDirectory(folder);
Future<Map<BuildSystemInteger, KojiBuild>> futureBuilds = pool.submit(finder);

futureChecksum.get();
futureBuilds.get();
futureChecksum.get();
futureBuilds.get();

verify(analyzer, finder);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw e;
verify(analyzer, finder);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw e;
}
} finally {
Utils.shutdownAndAwaitTermination(pool);
}
}
}
121 changes: 64 additions & 57 deletions core/src/test/java/org/jboss/pnc/build/finder/core/it/FileErrorIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.jboss.pnc.build.finder.core.DistributionAnalyzer;
import org.jboss.pnc.build.finder.core.FileError;
import org.jboss.pnc.build.finder.core.LocalFile;
import org.jboss.pnc.build.finder.core.Utils;
import org.jboss.pnc.build.finder.koji.ClientSession;
import org.jboss.pnc.build.finder.koji.KojiBuild;
import org.junit.jupiter.api.Test;
Expand All @@ -55,68 +56,74 @@ class FileErrorIT extends AbstractKojiIT {
void testChecksumsAndFindBuilds(@TempDir File folder) throws Exception {
Timer timer = REGISTRY.timer(name(FileErrorIT.class, "checksums"));
ExecutorService pool = Executors.newFixedThreadPool(2);
DistributionAnalyzer analyzer;
Future<Map<ChecksumType, MultiValuedMap<String, LocalFile>>> futureChecksum;

try (Context ignored = timer.time()) {
analyzer = new DistributionAnalyzer(Collections.singletonList(URL), getConfig());
futureChecksum = pool.submit(analyzer);
}
try {
DistributionAnalyzer analyzer;
Future<Map<ChecksumType, MultiValuedMap<String, LocalFile>>> futureChecksum;

try (Context ignored = timer.time()) {
analyzer = new DistributionAnalyzer(Collections.singletonList(URL), getConfig());
futureChecksum = pool.submit(analyzer);
}

Timer timer2 = REGISTRY.timer(name(FileErrorIT.class, "builds"));
Timer timer2 = REGISTRY.timer(name(FileErrorIT.class, "builds"));

try (Context ignored = timer2.time()) {
ClientSession session = getSession();
BuildFinder finder = new BuildFinder(session, getConfig(), analyzer, null, getPncClient());
finder.setOutputDirectory(folder);
Future<Map<BuildSystemInteger, KojiBuild>> futureBuilds = pool.submit(finder);
Map<ChecksumType, MultiValuedMap<String, LocalFile>> map = futureChecksum.get();
Map<BuildSystemInteger, KojiBuild> builds = futureBuilds.get();
Collection<FileError> fileErrors = analyzer.getFileErrors();
Map<String, Collection<Checksum>> files = analyzer.getFiles();
Map<Checksum, Collection<String>> foundChecksums = finder.getFoundChecksums();
Map<Checksum, Collection<String>> notFoundChecksums = finder.getNotFoundChecksums();
List<KojiBuild> buildsFound = finder.getBuildsFound();
try (Context ignored = timer2.time()) {
ClientSession session = getSession();
BuildFinder finder = new BuildFinder(session, getConfig(), analyzer, null, getPncClient());
finder.setOutputDirectory(folder);
Future<Map<BuildSystemInteger, KojiBuild>> futureBuilds = pool.submit(finder);
Map<ChecksumType, MultiValuedMap<String, LocalFile>> map = futureChecksum.get();
Map<BuildSystemInteger, KojiBuild> builds = futureBuilds.get();
Collection<FileError> fileErrors = analyzer.getFileErrors();
Map<String, Collection<Checksum>> files = analyzer.getFiles();
Map<Checksum, Collection<String>> foundChecksums = finder.getFoundChecksums();
Map<Checksum, Collection<String>> notFoundChecksums = finder.getNotFoundChecksums();
List<KojiBuild> buildsFound = finder.getBuildsFound();

assertThat(map).hasSize(3);
assertThat(builds).hasSize(2);
assertThat(fileErrors).hasSize(1)
.extracting("filename", "message")
.containsExactly(tuple("jboss-jaxb-intros-1.0.2.GA-sources.jar", "Invalid relative file name."));
assertThat(files).hasSize(1)
.hasEntrySatisfying(
"jboss-jaxb-intros-1.0.2.GA-sources.jar",
cksums -> assertThat(cksums).hasSize(3)
.extracting("filename")
.containsOnly("jboss-jaxb-intros-1.0.2.GA-sources.jar"));
assertThat(analyzer.getChecksums(ChecksumType.md5)).hasSize(1)
.hasEntrySatisfying(
"ac2a6ab1fbf6afba37789e2e88a916a6",
cksums -> assertThat(cksums).extracting("filename", "size")
.containsExactly(tuple("jboss-jaxb-intros-1.0.2.GA-sources.jar", 29537L)));
assertThat(analyzer.getChecksums(ChecksumType.sha1)).hasSize(1)
.hasEntrySatisfying(
"ab2f490dd83035bee3a719d2118cbab90508082f",
cksums -> assertThat(cksums).singleElement()
.extracting("filename", "size")
.containsExactly("jboss-jaxb-intros-1.0.2.GA-sources.jar", 29537L));
assertThat(analyzer.getChecksums(sha256)).hasSize(1)
.hasEntrySatisfying(
"987dd27e51ba77cb067dbec1baa5169eb184313688640e3951e3cb34d9a85c48",
cksums -> assertThat(cksums).singleElement()
.extracting("filename", "size")
.containsExactly("jboss-jaxb-intros-1.0.2.GA-sources.jar", 29537L));
assertThat(notFoundChecksums).isEmpty();
assertThat(foundChecksums).hasSize(1);
assertThat(buildsFound).hasSize(1);
assertThat(builds.get(new BuildSystemInteger(0)).getArchives()).isEmpty();
assertThat(map).hasSize(3);
assertThat(builds).hasSize(2);
assertThat(fileErrors).hasSize(1)
.extracting("filename", "message")
.containsExactly(
tuple("jboss-jaxb-intros-1.0.2.GA-sources.jar", "Invalid relative file name."));
assertThat(files).hasSize(1)
.hasEntrySatisfying(
"jboss-jaxb-intros-1.0.2.GA-sources.jar",
cksums -> assertThat(cksums).hasSize(3)
.extracting("filename")
.containsOnly("jboss-jaxb-intros-1.0.2.GA-sources.jar"));
assertThat(analyzer.getChecksums(ChecksumType.md5)).hasSize(1)
.hasEntrySatisfying(
"ac2a6ab1fbf6afba37789e2e88a916a6",
cksums -> assertThat(cksums).extracting("filename", "size")
.containsExactly(tuple("jboss-jaxb-intros-1.0.2.GA-sources.jar", 29537L)));
assertThat(analyzer.getChecksums(ChecksumType.sha1)).hasSize(1)
.hasEntrySatisfying(
"ab2f490dd83035bee3a719d2118cbab90508082f",
cksums -> assertThat(cksums).singleElement()
.extracting("filename", "size")
.containsExactly("jboss-jaxb-intros-1.0.2.GA-sources.jar", 29537L));
assertThat(analyzer.getChecksums(sha256)).hasSize(1)
.hasEntrySatisfying(
"987dd27e51ba77cb067dbec1baa5169eb184313688640e3951e3cb34d9a85c48",
cksums -> assertThat(cksums).singleElement()
.extracting("filename", "size")
.containsExactly("jboss-jaxb-intros-1.0.2.GA-sources.jar", 29537L));
assertThat(notFoundChecksums).isEmpty();
assertThat(foundChecksums).hasSize(1);
assertThat(buildsFound).hasSize(1);
assertThat(builds.get(new BuildSystemInteger(0)).getArchives()).isEmpty();

LOGGER.info("Map size: {}", map.size());
LOGGER.info("Builds size: {}", builds.size());
LOGGER.info("File errors: {}", fileErrors.size());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw e;
LOGGER.info("Map size: {}", map.size());
LOGGER.info("Builds size: {}", builds.size());
LOGGER.info("File errors: {}", fileErrors.size());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw e;
}
} finally {
Utils.shutdownAndAwaitTermination(pool);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.jboss.pnc.build.finder.core.ChecksumType;
import org.jboss.pnc.build.finder.core.DistributionAnalyzer;
import org.jboss.pnc.build.finder.core.LocalFile;
import org.jboss.pnc.build.finder.core.Utils;
import org.jboss.pnc.build.finder.koji.ClientSession;
import org.jboss.pnc.build.finder.koji.KojiBuild;
import org.junit.jupiter.api.Test;
Expand All @@ -54,37 +55,40 @@ void testChecksumsAndFindBuilds(@TempDir File folder) throws Exception {
.isNotNull();

Timer timer = REGISTRY.timer(name(KojiBuildFinderIT.class, "checksums"));

ExecutorService pool = Executors.newFixedThreadPool(2);

DistributionAnalyzer analyzer;

Future<Map<ChecksumType, MultiValuedMap<String, LocalFile>>> futureChecksum;

try (Context ignored = timer.time()) {
analyzer = new DistributionAnalyzer(Collections.singletonList(URL), getConfig());
futureChecksum = pool.submit(analyzer);
}

Timer timer2 = REGISTRY.timer(name(KojiBuildFinderIT.class, "builds"));

try (Context ignored = timer2.time()) {
ClientSession session = getSession();
BuildFinder finder = new BuildFinder(session, getConfig(), analyzer, null, getPncClient());
finder.setOutputDirectory(folder);
Future<Map<BuildSystemInteger, KojiBuild>> futureBuilds = pool.submit(finder);
Map<BuildSystemInteger, KojiBuild> builds = futureBuilds.get();
Map<ChecksumType, MultiValuedMap<String, LocalFile>> map = futureChecksum.get();

assertThat(getConfig().getChecksumTypes()).hasSizeGreaterThanOrEqualTo(1);
assertThat(map).hasSize(getConfig().getChecksumTypes().size());
assertThat(builds).hasSizeGreaterThanOrEqualTo(1);

LOGGER.info("Map size: {}", map.size());
LOGGER.info("Builds size: {}", builds.size());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw e;
try {
DistributionAnalyzer analyzer;

Future<Map<ChecksumType, MultiValuedMap<String, LocalFile>>> futureChecksum;

try (Context ignored = timer.time()) {
analyzer = new DistributionAnalyzer(Collections.singletonList(URL), getConfig());
futureChecksum = pool.submit(analyzer);
}

Timer timer2 = REGISTRY.timer(name(KojiBuildFinderIT.class, "builds"));

try (Context ignored = timer2.time()) {
ClientSession session = getSession();
BuildFinder finder = new BuildFinder(session, getConfig(), analyzer, null, getPncClient());
finder.setOutputDirectory(folder);
Future<Map<BuildSystemInteger, KojiBuild>> futureBuilds = pool.submit(finder);
Map<BuildSystemInteger, KojiBuild> builds = futureBuilds.get();
Map<ChecksumType, MultiValuedMap<String, LocalFile>> map = futureChecksum.get();

assertThat(getConfig().getChecksumTypes()).hasSizeGreaterThanOrEqualTo(1);
assertThat(map).hasSize(getConfig().getChecksumTypes().size());
assertThat(builds).hasSizeGreaterThanOrEqualTo(1);

LOGGER.info("Map size: {}", map.size());
LOGGER.info("Builds size: {}", builds.size());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw e;
}
} finally {
Utils.shutdownAndAwaitTermination(pool);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.jboss.pnc.build.finder.core.ChecksumType;
import org.jboss.pnc.build.finder.core.DistributionAnalyzer;
import org.jboss.pnc.build.finder.core.LocalFile;
import org.jboss.pnc.build.finder.core.Utils;
import org.jboss.pnc.build.finder.core.it.AbstractKojiIT;
import org.jboss.pnc.build.finder.koji.ClientSession;
import org.jboss.pnc.build.finder.koji.KojiBuild;
Expand All @@ -61,48 +62,56 @@ void testChecksumsAndFindBuildsAndGenerateReports(@TempDir File folder) throws E

ExecutorService pool = newFixedThreadPool(2);

DistributionAnalyzer analyzer;
try {
DistributionAnalyzer analyzer;

Future<Map<ChecksumType, MultiValuedMap<String, LocalFile>>> futureChecksum;
Future<Map<ChecksumType, MultiValuedMap<String, LocalFile>>> futureChecksum;

try (Context ignored = timer.time()) {
analyzer = new DistributionAnalyzer(Collections.singletonList(URL), getConfig());
futureChecksum = pool.submit(analyzer);
}
try (Context ignored = timer.time()) {
analyzer = new DistributionAnalyzer(Collections.singletonList(URL), getConfig());
futureChecksum = pool.submit(analyzer);
}

Timer timer2 = REGISTRY.timer(name(ReportIT.class, "builds"));
Timer timer2 = REGISTRY.timer(name(ReportIT.class, "builds"));

try (Context ignored = timer2.time()) {
ClientSession session = getSession();
BuildFinder finder = new BuildFinder(session, getConfig(), analyzer, null, getPncClient());
finder.setOutputDirectory(folder);
Future<Map<BuildSystemInteger, KojiBuild>> futureBuilds = pool.submit(finder);
Map<BuildSystemInteger, KojiBuild> builds = futureBuilds.get();
Map<ChecksumType, MultiValuedMap<String, LocalFile>> map = futureChecksum.get();
try (Context ignored = timer2.time()) {
ClientSession session = getSession();
BuildFinder finder = new BuildFinder(session, getConfig(), analyzer, null, getPncClient());
finder.setOutputDirectory(folder);
Future<Map<BuildSystemInteger, KojiBuild>> futureBuilds = pool.submit(finder);
Map<BuildSystemInteger, KojiBuild> builds = futureBuilds.get();
Map<ChecksumType, MultiValuedMap<String, LocalFile>> map = futureChecksum.get();

assertThat(map).hasSize(3);
assertThat(builds).hasSizeGreaterThanOrEqualTo(1);
assertThat(map).hasSize(3);
assertThat(builds).hasSizeGreaterThanOrEqualTo(1);

LOGGER.info("Map size: {}", map.size());
LOGGER.info("Builds size: {}", builds.size());
LOGGER.info("Map size: {}", map.size());
LOGGER.info("Builds size: {}", builds.size());

// FIXME: Don't hardcode filenames
Report.generateReports(getConfig(), finder.getBuilds(), finder.getOutputDirectory(), analyzer.getInputs());
// FIXME: Don't hardcode filenames
Report.generateReports(
getConfig(),
finder.getBuilds(),
finder.getOutputDirectory(),
analyzer.getInputs());

File nvrTxt = new File(finder.getOutputDirectory(), "nvr.txt");
File nvrTxt = new File(finder.getOutputDirectory(), "nvr.txt");

assertThat(contentOf(nvrTxt, StandardCharsets.UTF_8)).isNotEmpty();
assertThat(contentOf(nvrTxt, StandardCharsets.UTF_8)).isNotEmpty();

File gavTxt = new File(finder.getOutputDirectory(), "gav.txt");
File gavTxt = new File(finder.getOutputDirectory(), "gav.txt");

assertThat(contentOf(gavTxt)).isNotEmpty();
assertThat(contentOf(gavTxt)).isNotEmpty();

File outputHtml = new File(finder.getOutputDirectory(), "output.html");
File outputHtml = new File(finder.getOutputDirectory(), "output.html");

assertThat(contentOf(outputHtml)).startsWith("<!DOCTYPE html>").endsWith("</html>");
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw e;
assertThat(contentOf(outputHtml)).startsWith("<!DOCTYPE html>").endsWith("</html>");
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw e;
}
} finally {
Utils.shutdownAndAwaitTermination(pool);
}
}
}

0 comments on commit 4d82768

Please sign in to comment.