Skip to content
Permalink
Browse files
Unit tests fixed
  • Loading branch information
dspavlov committed Aug 3, 2019
1 parent 2d2d35b commit b7163d0eed89ae0f2d28d20ab0388c7d1b947bba
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 28 deletions.
@@ -20,18 +20,15 @@
import com.google.common.collect.Lists;
import com.google.inject.Guice;
import com.google.inject.Injector;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;

import org.apache.ignite.ci.teamcity.ignited.TeamcityIgnitedProviderMock;
import org.apache.ignite.ci.teamcity.ignited.fatbuild.FatBuildCompacted;
import org.apache.ignite.ci.user.ITcBotUserCreds;
import org.apache.ignite.tcbot.common.TcBotConst;
import org.apache.ignite.tcbot.engine.pr.PrChainsProcessor;
import org.apache.ignite.tcbot.engine.ui.ShortSuiteUi;
import org.apache.ignite.tcbot.engine.ui.ShortTestFailureUi;
import org.apache.ignite.tcbot.persistence.IStringCompactor;
import org.apache.ignite.tcignited.ITeamcityIgnitedProvider;
import org.apache.ignite.tcignited.SyncMode;
import org.apache.ignite.tcservice.ITeamcity;
import org.apache.ignite.tcservice.model.conf.BuildType;
@@ -41,19 +38,19 @@
import org.apache.ignite.tcservice.model.result.tests.TestOccurrence;
import org.apache.ignite.tcservice.model.result.tests.TestOccurrenceFull;
import org.apache.ignite.tcservice.model.result.tests.TestRef;
import org.apache.ignite.tcbot.persistence.IStringCompactor;
import org.apache.ignite.tcignited.ITeamcityIgnitedProvider;
import org.apache.ignite.ci.teamcity.ignited.TeamcityIgnitedProviderMock;
import org.apache.ignite.ci.teamcity.ignited.fatbuild.FatBuildCompacted;
import org.apache.ignite.ci.user.ITcBotUserCreds;
import org.jetbrains.annotations.NotNull;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;

import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;

/**
@@ -203,7 +200,7 @@ public void initBuildChainAndMasterHistory(IStringCompactor c, String btId, Stri
public Map<Integer, FatBuildCompacted> initHistory(IStringCompactor c) {
for (int i = 0; i < NUM_OF_TESTS_IN_MASTER; i++) {
FatBuildCompacted cache1InMaster = createFailedBuild(c, CACHE_1,
ITeamcity.DEFAULT, 500 + i, 100000 + (i * 10000))
ITeamcity.DEFAULT, 500 + i, (i * 1000))
.addTests(c, Lists.newArrayList(
createFailedTest(2L, TEST_WITH_HISTORY_FAILING_IN_MASTER),
createPassingTest(3L, TEST_WITH_HISTORY_PASSING_IN_MASTER),
@@ -216,6 +213,10 @@ public Map<Integer, FatBuildCompacted> initHistory(IStringCompactor c) {
cache1InMaster.addProblems(c, Collections.singletonList(timeout));
}

if (i == 0) {
cache1InMaster.changes(new int[]{123}); // emulating change
}

addBuildsToEmulatedStor(cache1InMaster);
}

@@ -18,16 +18,12 @@
package org.apache.ignite.ci.teamcity.ignited;

import com.google.common.base.Preconditions;
import java.util.Comparator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import org.apache.ignite.tcbot.common.conf.ITcServerConfig;
import org.apache.ignite.ci.teamcity.ignited.fatbuild.FatBuildCompacted;
import org.apache.ignite.ci.teamcity.ignited.runhist.Invocation;
import org.apache.ignite.ci.teamcity.ignited.runhist.RunHistCompacted;
import org.apache.ignite.ci.teamcity.ignited.runhist.RunHistKey;
import org.apache.ignite.tcbot.common.TcBotConst;
import org.apache.ignite.tcbot.common.conf.ITcServerConfig;
import org.apache.ignite.tcbot.persistence.IStringCompactor;
import org.apache.ignite.tcignited.ITeamcityIgnited;
import org.apache.ignite.tcignited.SyncMode;
@@ -38,9 +34,13 @@
import org.mockito.Mockito;
import org.mockito.stubbing.Answer;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import java.time.Duration;
import java.util.Comparator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

@@ -168,17 +168,22 @@ public static void initHistory(IStringCompactor c, Map<RunHistKey, RunHistCompac
Map<Integer, FatBuildCompacted> builds, int srvId) {
Map<RunHistKey, RunHistCompacted> histCache = new ConcurrentHashMap<>();

long maxBuildAgeMs = Duration.ofDays(TcBotConst.HISTORY_MAX_DAYS).toMillis();
int successStatusStrId = c.getStringId(TestOccurrence.STATUS_SUCCESS);
for (FatBuildCompacted build : builds.values()) {
if (!build.isFinished(c))
continue;

if (build.getStartDateTs() > 0
&& build.getStartDateTs() < System.currentTimeMillis() - maxBuildAgeMs)
continue;

build.getAllTests().forEach(testCompacted -> {
RunHistKey histKey = new RunHistKey(srvId, testCompacted.testName(), build.branchName());

final RunHistCompacted hist = histCache.computeIfAbsent(histKey, RunHistCompacted::new);

Invocation inv = TestCompactedV2.toInvocation(testCompacted, build, (k, v) -> true, successStatusStrId);
Invocation inv = TestCompactedV2.toInvocation(testCompacted, build, (k, v) -> false, successStatusStrId);

hist.addInvocation(inv);
});
@@ -31,6 +31,7 @@
import org.apache.ignite.tcbot.engine.conf.TcBotJsonConfig;
import org.apache.ignite.tcbot.engine.conf.ITcBotConfig;
import org.apache.ignite.ci.teamcity.ignited.BuildRefCompacted;
import org.apache.ignite.tcignited.buildlog.ILogProductSpecific;
import org.apache.ignite.tcignited.buildref.BuildRefDao;
import org.apache.ignite.ci.teamcity.ignited.buildtype.BuildTypeRefCompacted;
import org.apache.ignite.ci.teamcity.ignited.fatbuild.FatBuildCompacted;
@@ -436,6 +437,7 @@ public void testFatBuild() throws JAXBException, IOException {
@Override protected void configure() {
bind(Ignite.class).toInstance(ignite);
bind(IStringCompactor.class).to(IgniteStringCompactor.class).in(new SingletonScope());
bind(ILogProductSpecific.class).toInstance(Mockito.mock(ILogProductSpecific.class));
}
});

0 comments on commit b7163d0

Please sign in to comment.