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 Report integration test #183

Merged
merged 1 commit into from
Aug 26, 2020
Merged
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
58 changes: 16 additions & 42 deletions cli/src/main/java/org/jboss/pnc/build/finder/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -67,11 +68,6 @@
import org.jboss.pnc.build.finder.koji.KojiJSONUtils;
import org.jboss.pnc.build.finder.pnc.client.HashMapCachingPncClient;
import org.jboss.pnc.build.finder.pnc.client.PncClient;
import org.jboss.pnc.build.finder.report.BuildStatisticsReport;
import org.jboss.pnc.build.finder.report.GAVReport;
import org.jboss.pnc.build.finder.report.HTMLReport;
import org.jboss.pnc.build.finder.report.NVRReport;
import org.jboss.pnc.build.finder.report.ProductReport;
import org.jboss.pnc.build.finder.report.Report;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -655,7 +651,7 @@ public Void call() throws KojiClientException {
LOGGER.info("Pnc support: {}", green("disabled"));
}

BuildFinder finder;
BuildFinder finder = null;
Map<BuildSystemInteger, KojiBuild> builds = null;
File buildsFile = new File(outputDirectory, BuildFinder.getBuildsFilename());

Expand Down Expand Up @@ -724,7 +720,7 @@ public Void call() throws KojiClientException {

finder.setOutputDirectory(outputDirectory);

finder.findBuilds(newMap);
builds = finder.findBuilds(newMap);
} catch (KojiClientException e) {
LOGGER.error("Error finding builds: {}", boldRed(e.getMessage()));
LOGGER.debug("Error", e);
Expand Down Expand Up @@ -824,45 +820,23 @@ public Void call() throws KojiClientException {
}
}

BuildSystemInteger zero = new BuildSystemInteger(0, BuildSystem.none);
List<KojiBuild> buildList = builds != null ? new ArrayList<>(builds.values()) : Collections.emptyList();
KojiBuild buildZero = builds != null ? buildList.get(0) : null;
int buildListSize = buildList.size();

if (builds != null && builds.containsKey(zero)
&& (!builds.get(zero).getArchives().isEmpty() || builds.keySet().size() > 1)) {
List<KojiBuild> buildList = builds.entrySet()
.stream()
.sorted(Entry.comparingByKey())
.map(Entry::getValue)
.collect(Collectors.toList());
List<Report> reports = new ArrayList<>(4);

reports.add(new BuildStatisticsReport(outputDirectory, buildList));
reports.add(new ProductReport(outputDirectory, buildList));
reports.add(new NVRReport(outputDirectory, buildList));
reports.add(new GAVReport(outputDirectory, buildList));

LOGGER.info("Generating {} reports", green(reports.size()));

for (Report report : reports) {
try {
report.outputText();
} catch (IOException e) {
LOGGER.error("Error writing {} report", boldRed(report.getName()));
LOGGER.debug("Report error", e);
}
}

Report report = new HTMLReport(
outputDirectory,
files,
buildList,
config.getKojiWebURL(),
config.getPncURL(),
Collections.unmodifiableList(reports));
if (buildListSize > 1) {
buildList.sort(Comparator.comparingInt(build -> build.getBuildInfo().getId()));
}

if (buildListSize > 1 || buildZero != null && !buildZero.getArchives().isEmpty()) {
try {
report.outputHTML();
Report.generateReports(config, buildList, outputDirectory, files);
} catch (IOException e) {
LOGGER.error("Error writing {} report", boldRed(report.getName()));
LOGGER.error(
"Error writing reports for files {} with {} builds to output directory {}",
boldRed(files),
boldRed(buildListSize),
boldRed(outputDirectory));
LOGGER.debug("Report error", e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class DistributionAnalyzer implements Callable<Map<ChecksumType, MultiVal

private static final String CHECKSUMS_FILENAME_BASENAME = "checksums-";

private final List<String> files;
private final List<String> inputs;

private final MultiValuedMap<String, Checksum> inverseMap;

Expand Down Expand Up @@ -102,12 +102,12 @@ public class DistributionAnalyzer implements Callable<Map<ChecksumType, MultiVal

private DistributionAnalyzerListener listener;

public DistributionAnalyzer(List<String> files, BuildConfig config) {
this(files, config, null);
public DistributionAnalyzer(List<String> inputs, BuildConfig config) {
this(inputs, config, null);
}

public DistributionAnalyzer(List<String> files, BuildConfig config, EmbeddedCacheManager cacheManager) {
this.files = Collections.unmodifiableList(files);
public DistributionAnalyzer(List<String> inputs, BuildConfig config, EmbeddedCacheManager cacheManager) {
this.inputs = inputs;
this.config = config;
checksumTypesToCheck = EnumSet.copyOf(config.getChecksumTypes());
map = new EnumMap<>(ChecksumType.class);
Expand Down Expand Up @@ -164,12 +164,12 @@ public Map<ChecksumType, MultiValuedMap<String, String>> checksumFiles() throws
green(Arrays.asList(sfs.getSchemes())));
}

for (String file : files) {
for (String input : inputs) {
try {
URI uri = URI.create(file);
URI uri = URI.create(input);
fo = sfs.resolveFile(uri);
} catch (IllegalArgumentException | FileSystemException e) {
fo = sfs.resolveFile(new File(file).toURI());
fo = sfs.resolveFile(new File(input).toURI());
}

if (LOGGER.isInfoEnabled()) {
Expand Down Expand Up @@ -487,6 +487,10 @@ private void listChildren(FileObject fo) throws IOException {
}
}

public List<String> getInputs() {
return Collections.unmodifiableList(inputs);
}

public File getChecksumFile(ChecksumType checksumType) {
return new File(config.getOutputDirectory(), CHECKSUMS_FILENAME_BASENAME + checksumType + ".json");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ public class KojiBuild {

private transient List<KojiArchiveInfo> duplicateArchives;

private transient boolean pnc;

public KojiBuild() {
this.archives = new ArrayList<>();
this.rpms = new ArrayList<>();
Expand Down Expand Up @@ -199,12 +197,8 @@ public void setDuplicateArchives(List<KojiArchiveInfo> duplicateArchives) {

@JsonIgnore
public boolean isPnc() {
return pnc;
}

@JsonIgnore
public void setPnc(boolean pnc) {
this.pnc = pnc;
return buildInfo != null && buildInfo.getExtra() != null
&& "PNC".equals(buildInfo.getExtra().get(KojiJsonConstants.BUILD_SYSTEM));
}

@JsonIgnore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,6 @@ public static KojiBuild pncBuildToKojiBuild(PncBuild pncbuild) {

build.setBuildInfo(buildInfo);

build.setPnc(true);

return build;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
public abstract class AbstractKojiIT {
static final int MAX_CONNECTIONS = 20;

static final MetricRegistry REGISTRY = new MetricRegistry();
protected static final MetricRegistry REGISTRY = new MetricRegistry();

private static final Logger LOGGER = LoggerFactory.getLogger(AbstractKojiIT.class);

Expand Down Expand Up @@ -97,7 +97,7 @@ public void setup() throws IOException, KojiClientException {
reporter.start(600L, TimeUnit.SECONDS);
}

KojiClientSession getSession() {
protected KojiClientSession getSession() {
return session;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ abstract class AbstractRpmIT extends AbstractKojiIT {
abstract void verify(DistributionAnalyzer analyzer, BuildFinder finder);

@Test
void testChecksumsAndFindBuilds(@TempDir File folder) throws ExecutionException {
void testChecksumsAndFindBuilds(@TempDir File folder) throws ExecutionException, InterruptedException {
Timer timer = REGISTRY.timer(MetricRegistry.name(AbstractRpmIT.class, "checksums"));
ExecutorService pool = Executors.newFixedThreadPool(1 + getConfig().getChecksumTypes().size());
DistributionAnalyzer analyzer;
Expand All @@ -74,6 +74,7 @@ void testChecksumsAndFindBuilds(@TempDir File folder) throws ExecutionException
verify(analyzer, finder);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw e;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class FileErrorIT extends AbstractKojiIT {
private static final int READ_TIMEOUT = 900000;

@Test
void testChecksumsAndFindBuilds(@TempDir File folder) throws ExecutionException {
void testChecksumsAndFindBuilds(@TempDir File folder) throws ExecutionException, InterruptedException {
Timer timer = REGISTRY.timer(MetricRegistry.name(FileErrorIT.class, "checksums"));
ExecutorService pool = Executors.newFixedThreadPool(1 + getConfig().getChecksumTypes().size());
DistributionAnalyzer analyzer;
Expand Down Expand Up @@ -135,6 +135,7 @@ void testChecksumsAndFindBuilds(@TempDir File folder) throws ExecutionException
LOGGER.info("File errors: {}", fileErrors.size());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw e;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class KojiBuildFinderIT extends AbstractKojiIT {
private static final int READ_TIMEOUT = 900000;

@Test
void testChecksumsAndFindBuilds(@TempDir File folder) throws ExecutionException {
void testChecksumsAndFindBuilds(@TempDir File folder) throws ExecutionException, InterruptedException {
assertThat(
"You must set the property " + PROPERTY + " pointing to the URL of the distribution to test with",
URL,
Expand Down Expand Up @@ -95,6 +95,7 @@ void testChecksumsAndFindBuilds(@TempDir File folder) throws ExecutionException
LOGGER.info("Builds size: {}", builds.size());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw e;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void testSequential() throws KojiClientException {
}

@Test
void testThreads() {
void testThreads() throws InterruptedException {
Timer timer = REGISTRY.timer(MetricRegistry.name(KojiPerformanceIT.class, "threads"));

for (int i = 0; i < NUM_LOOPS; i++) {
Expand All @@ -73,6 +73,7 @@ void testThreads() {
threads[j].join();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw e;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public GAVReport(File outputDirectory, Collection<KojiBuild> builds) {

@Override
public String renderText() {
return this.gavs.stream().map(Object::toString).collect(Collectors.joining("\n"));
return this.gavs.stream().map(Object::toString).collect(Collectors.joining("\n")) + "\n";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public NVRReport(File outputDirectory, Collection<KojiBuild> builds) {

@Override
public String renderText() {
return this.nvrs.stream().filter(Objects::nonNull).map(Object::toString).collect(Collectors.joining("\n"));
return this.nvrs.stream().filter(Objects::nonNull).map(Object::toString).collect(Collectors.joining("\n"))
+ "\n";
}

@Override
Expand Down
32 changes: 32 additions & 0 deletions report/src/main/java/org/jboss/pnc/build/finder/report/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.jboss.pnc.build.finder.core.BuildConfig;
import org.jboss.pnc.build.finder.koji.KojiBuild;

import j2html.tags.ContainerTag;

Expand All @@ -32,6 +37,33 @@ public abstract class Report {

private File outputDirectory;

public static void generateReports(
BuildConfig config,
List<KojiBuild> buildList,
File outputDirectory,
List<String> files) throws IOException {
List<Report> reports = new ArrayList<>(4);

reports.add(new BuildStatisticsReport(outputDirectory, buildList));
reports.add(new ProductReport(outputDirectory, buildList));
reports.add(new NVRReport(outputDirectory, buildList));
reports.add(new GAVReport(outputDirectory, buildList));

for (Report report : reports) {
report.outputText();
}

Report report = new HTMLReport(
outputDirectory,
files,
buildList,
config.getKojiWebURL(),
config.getPncURL(),
Collections.unmodifiableList(reports));

report.outputHTML();
}

public String renderText() {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ void verifyBuilds() {
void verifyNVRReport(@TempDir File folder) throws IOException {
final String nvrExpected = "artemis-native-linux-2.3.0.amq_710003-1.redhat_1.el6\n"
+ "commons-beanutils-commons-beanutils-1.9.2.redhat_1-1\ncommons-lang-commons-lang-2.6-1\n"
+ "commons-lang-commons-lang-2.6-2\norg.wildfly.swarm-config-api-parent-1.1.0.Final_redhat_14-1";
+ "commons-lang-commons-lang-2.6-2\norg.wildfly.swarm-config-api-parent-1.1.0.Final_redhat_14-1\n";
NVRReport report = new NVRReport(folder, builds);
assertThat(report.renderText(), is(nvrExpected));
report.outputText();
Expand All @@ -222,7 +222,7 @@ void verifyNVRReport(@TempDir File folder) throws IOException {
void verifyGAVReport(@TempDir File folder) throws IOException {
final String gavExpected = "commons-beanutils:commons-beanutils:1.9.2.redhat-1\n"
+ "commons-lang:commons-lang:2.6\norg.apache.activemq:libartemis-native-32:2.3.0.amq_710003-redhat-1\n"
+ "org.wildfly.swarm:config-api:1.1.0.Final-redhat-14";
+ "org.wildfly.swarm:config-api:1.1.0.Final-redhat-14\n";
GAVReport report = new GAVReport(folder, builds);
assertThat(report.renderText(), is(gavExpected));
report.outputText();
Expand Down
Loading