ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dpav...@apache.org
Subject [ignite-teamcity-bot] 02/02: Test occurrences preparation for saving to fat build
Date Wed, 24 Oct 2018 17:00:30 GMT
This is an automated email from the ASF dual-hosted git repository.

dpavlov pushed a commit to branch ignite-9848-load-all-builds
in repository https://gitbox.apache.org/repos/asf/ignite-teamcity-bot.git

commit 9cf9fba8b4a22cfc4b596a654ae010ea320fcfa4
Author: Dmitriy Pavlov <dpavlov@apache.org>
AuthorDate: Wed Oct 24 20:00:08 2018 +0300

    Test occurrences preparation for saving to fat build
---
 .../ci/teamcity/ignited/FatBuildCompacted.java     |  2 +
 .../ignite/ci/teamcity/ignited/FatBuildDao.java    | 43 +++++++++++++++++++---
 .../ignited/IgnitedTcInMemoryIntegrationTest.java  | 37 ++++++++++++-------
 3 files changed, 64 insertions(+), 18 deletions(-)

diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ignited/FatBuildCompacted.java
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ignited/FatBuildCompacted.java
index 7254abe..461f774 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ignited/FatBuildCompacted.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ignited/FatBuildCompacted.java
@@ -104,6 +104,8 @@ public class FatBuildCompacted extends BuildRefCompacted implements IVersionedEn
         type.name(compactor.getStringFromId(name));
         type.projectId(compactor.getStringFromId(projectId));
         res.setBuildType(type);
+
+        res.href = "/app/rest/latest/builds/id:" + id();
     }
 
 }
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ignited/FatBuildDao.java
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ignited/FatBuildDao.java
index e0706d1..427980f 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ignited/FatBuildDao.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ignited/FatBuildDao.java
@@ -23,6 +23,7 @@ import java.util.Objects;
 import java.util.Set;
 import java.util.TreeMap;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 import javax.inject.Inject;
 import javax.inject.Provider;
 import org.apache.ignite.Ignite;
@@ -30,7 +31,7 @@ import org.apache.ignite.IgniteCache;
 import org.apache.ignite.ci.db.TcHelperDb;
 import org.apache.ignite.ci.tcmodel.hist.BuildRef;
 import org.apache.ignite.ci.tcmodel.result.Build;
-import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.ci.tcmodel.result.tests.TestOccurrences;
 
 /**
  *
@@ -55,12 +56,44 @@ public class FatBuildDao {
         buildsCache = igniteProvider.get().getOrCreateCache(TcHelperDb.getCacheV2Config(TEAMCITY_FAT_BUILD_CACHE_NAME));
     }
 
+
+    /**
+     * @param srvIdMaskHigh Server id mask high.
+     * @param build Build data.
+     * @param tests TestOccurrences.
+     */
+    public int saveBuild(long srvIdMaskHigh,
+        Build build,
+        List<TestOccurrences> tests) {
+        Set<Long> ids = Stream.of(build).map(BuildRef::getId)
+            .filter(Objects::nonNull)
+            .map(buildId -> buildIdToCacheKey(srvIdMaskHigh, buildId))
+            .collect(Collectors.toSet());
+
+        Map<Long, FatBuildCompacted> existingEntries = buildsCache.getAll(ids);
+        Map<Long, FatBuildCompacted> entriesToPut = new TreeMap<>();
+
+        FatBuildCompacted compacted = new FatBuildCompacted(compactor, build);
+
+        long cacheKey = buildIdToCacheKey(srvIdMaskHigh, compacted.id());
+        FatBuildCompacted buildPersisted = existingEntries.get(cacheKey);
+
+        if (buildPersisted == null || !buildPersisted.equals(compacted))
+            entriesToPut.put(cacheKey, compacted);
+
+        int size = entriesToPut.size();
+        if (size != 0)
+            buildsCache.putAll(entriesToPut);
+
+        return size;
+    }
+
     /**
      * @param srvIdMaskHigh Server id mask high.
-     * @param ghData Gh data.
+     * @param buildData Gh data.
      */
-    public int saveChunk(long srvIdMaskHigh, List<Build> ghData) {
-        Set<Long> ids = ghData.stream().map(BuildRef::getId)
+    public int saveChunk(long srvIdMaskHigh, List<Build> buildData) {
+        Set<Long> ids = buildData.stream().map(BuildRef::getId)
             .filter(Objects::nonNull)
             .map(buildId -> buildIdToCacheKey(srvIdMaskHigh, buildId))
             .collect(Collectors.toSet());
@@ -68,7 +101,7 @@ public class FatBuildDao {
         Map<Long, FatBuildCompacted> existingEntries = buildsCache.getAll(ids);
         Map<Long, FatBuildCompacted> entriesToPut = new TreeMap<>();
 
-        List<FatBuildCompacted> collect = ghData.stream()
+        List<FatBuildCompacted> collect = buildData.stream()
             .map(ref -> new FatBuildCompacted(compactor, ref))
             .collect(Collectors.toList());
 
diff --git a/ignite-tc-helper-web/src/test/java/org/apache/ignite/ci/teamcity/ignited/IgnitedTcInMemoryIntegrationTest.java
b/ignite-tc-helper-web/src/test/java/org/apache/ignite/ci/teamcity/ignited/IgnitedTcInMemoryIntegrationTest.java
index 737cca3..3772983 100644
--- a/ignite-tc-helper-web/src/test/java/org/apache/ignite/ci/teamcity/ignited/IgnitedTcInMemoryIntegrationTest.java
+++ b/ignite-tc-helper-web/src/test/java/org/apache/ignite/ci/teamcity/ignited/IgnitedTcInMemoryIntegrationTest.java
@@ -37,6 +37,7 @@ import org.apache.ignite.ci.di.scheduler.NoOpSheduler;
 import org.apache.ignite.ci.tcmodel.conf.BuildType;
 import org.apache.ignite.ci.tcmodel.hist.BuildRef;
 import org.apache.ignite.ci.tcmodel.result.Build;
+import org.apache.ignite.ci.tcmodel.result.tests.TestOccurrences;
 import org.apache.ignite.ci.teamcity.pure.BuildHistoryEmulator;
 import org.apache.ignite.ci.teamcity.pure.ITeamcityHttpConnection;
 import org.apache.ignite.ci.user.ICredentialsProv;
@@ -242,8 +243,9 @@ public class IgnitedTcInMemoryIntegrationTest {
 
     @Test
     public void testFatBuild() throws JAXBException, IOException {
-        InputStream stream = getClass().getResourceAsStream("/build.xml");
-        Build refBuild = XmlUtil.load(Build.class, new InputStreamReader(stream));
+        Build refBuild = jaxbTestXml("/build.xml", Build.class);
+        TestOccurrences tests = jaxbTestXml("/testList.xml", TestOccurrences.class);
+
         Injector injector = Guice.createInjector(new AbstractModule() {
             @Override protected void configure() {
                 bind(Ignite.class).toInstance(ignite);
@@ -255,22 +257,17 @@ public class IgnitedTcInMemoryIntegrationTest {
         instance.init();
 
         int srvIdMaskHigh = ITeamcityIgnited.serverIdToInt(APACHE);
-        int i = instance.saveChunk(srvIdMaskHigh, Collections.singletonList(refBuild));
+        List<TestOccurrences> occurrences = Collections.singletonList(tests);
+        int i = instance.saveBuild(srvIdMaskHigh, refBuild, occurrences);
         assertEquals(1, i);
 
         FatBuildCompacted fatBuild = instance.getFatBuild(srvIdMaskHigh, 2039380);
 
-        Build actBuild = fatBuild.toBuild(injector.getInstance(IStringCompactor.class));
-
-        try (FileWriter writer = new FileWriter("src/test/resources/build1.xml")) {
-            writer.write(XmlUtil.save(refBuild));
-        }
+        IStringCompactor compactor = injector.getInstance(IStringCompactor.class);
+        Build actBuild = fatBuild.toBuild(compactor);
 
-        String save = XmlUtil.save(actBuild);
-        System.out.println(save);
-        try (FileWriter writer = new FileWriter("src/test/resources/build2.xml")) {
-            writer.write(save);
-        }
+        saveTmpFile(refBuild, "src/test/resources/build1.xml");
+        saveTmpFile(actBuild, "src/test/resources/build2.xml");
 
         assertEquals(refBuild.getId(), actBuild.getId());
         assertEquals(refBuild.status(), actBuild.status());
@@ -285,4 +282,18 @@ public class IgnitedTcInMemoryIntegrationTest {
         assertEquals(refBt.getId(), actBt.getId());
     }
 
+    public void saveTmpFile(Build refBuild, String name) throws IOException, JAXBException
{
+        try (FileWriter writer = new FileWriter(name)) {
+            writer.write(XmlUtil.save(refBuild));
+        }
+    }
+
+    public <E> E jaxbTestXml(String ref, Class<E> cls) throws IOException, JAXBException
{
+        E refBuild;
+        try(InputStream stream = getClass().getResourceAsStream(ref)) {
+            refBuild = XmlUtil.load(cls, new InputStreamReader(stream));
+        }
+        return refBuild;
+    }
+
 }


Mime
View raw message