From 908157bc01f38f3cc840d4a097ee99990db41ce3 Mon Sep 17 00:00:00 2001 From: Angel Borroy Date: Thu, 3 Dec 2020 14:32:46 +0100 Subject: [PATCH] SEARCH-2602: Mock test for Solr Summary report unmarshalling --- .travis.yml | 6 + .../alfresco/repo/search/SearchTestSuite.java | 47 +++--- ...olrChildApplicationContextFactoryTest.java | 134 ++++++++++++++++++ 3 files changed, 158 insertions(+), 29 deletions(-) create mode 100644 repository/src/test/java/org/alfresco/repo/search/impl/solr/SolrChildApplicationContextFactoryTest.java diff --git a/.travis.yml b/.travis.yml index 183f513c68..c980ceff8e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -124,6 +124,12 @@ jobs: - docker run -d -p 8090:8090 -e JAVA_OPTS=" -Xms256m -Xmx256m" alfresco/alfresco-transform-core-aio:2.3.6 script: travis_wait 20 mvn -B test -pl repository -Dtest=MiscContextTestSuite -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco -Dalfresco-pdf-renderer.url=http://localhost:8090/ -Djodconverter.url=http://localhost:8090/ -Dimg.url=http://localhost:8090/ -Dtika.url=http://localhost:8090/ -Dtransform.misc.url=http://localhost:8090/ + - name: "Repository - SearchTestSuite" + before_script: + - docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:11.7 postgres -c 'max_connections=300' + - docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.15.8 + script: travis_wait 20 mvn -B test -pl repository -Dtest=SearchTestSuite -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco -Dindex.subsystem.name=solr6 + - name: "Repository - MySQL tests" if: commit_message !~ /\[skip db\]/ before_script: diff --git a/repository/src/test/java/org/alfresco/repo/search/SearchTestSuite.java b/repository/src/test/java/org/alfresco/repo/search/SearchTestSuite.java index a72e744a50..d01be4c55f 100644 --- a/repository/src/test/java/org/alfresco/repo/search/SearchTestSuite.java +++ b/repository/src/test/java/org/alfresco/repo/search/SearchTestSuite.java @@ -25,39 +25,28 @@ */ package org.alfresco.repo.search; -import junit.framework.Test; -import junit.framework.TestSuite; - import org.alfresco.repo.search.impl.parsers.CMISTest; import org.alfresco.repo.search.impl.parsers.CMIS_FTSTest; import org.alfresco.repo.search.impl.parsers.FTSTest; +import org.alfresco.repo.search.impl.solr.SolrChildApplicationContextFactoryTest; import org.alfresco.util.NumericEncodingTest; +import org.junit.experimental.categories.Categories; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; -/** - * @author Andy Hind - * - */ -public class SearchTestSuite extends TestSuite +@RunWith(Categories.class) +@Suite.SuiteClasses({ + MLAnaysisModeExpansionTest.class, + QueryRegisterComponentTest.class, + SearcherComponentTest.class, + DocumentNavigatorTest.class, + NumericEncodingTest.class, + CMIS_FTSTest.class, + CMISTest.class, + FTSTest.class, + SolrChildApplicationContextFactoryTest.class +}) + +public class SearchTestSuite { - - /** - * Creates the test suite - * - * @return the test suite - */ - public static Test suite() - { - TestSuite suite = new TestSuite(); - suite.addTestSuite(MLAnaysisModeExpansionTest.class); - suite.addTestSuite(QueryRegisterComponentTest.class); - suite.addTestSuite(SearcherComponentTest.class); - suite.addTestSuite(SearchServiceTest.class); - suite.addTestSuite(DocumentNavigatorTest.class); - suite.addTestSuite(NumericEncodingTest.class); - suite.addTestSuite(CMIS_FTSTest.class); - suite.addTestSuite(CMISTest.class); - suite.addTestSuite(FTSTest.class); - - return suite; - } } diff --git a/repository/src/test/java/org/alfresco/repo/search/impl/solr/SolrChildApplicationContextFactoryTest.java b/repository/src/test/java/org/alfresco/repo/search/impl/solr/SolrChildApplicationContextFactoryTest.java new file mode 100644 index 0000000000..a8504e74d6 --- /dev/null +++ b/repository/src/test/java/org/alfresco/repo/search/impl/solr/SolrChildApplicationContextFactoryTest.java @@ -0,0 +1,134 @@ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ + +package org.alfresco.repo.search.impl.solr; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +import org.alfresco.repo.management.subsystems.SwitchableApplicationContextFactory; +import org.alfresco.util.BaseSpringTest; +import org.json.JSONObject; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.springframework.context.ApplicationContext; + +public class SolrChildApplicationContextFactoryTest extends BaseSpringTest +{ + + /** + * Sample partial response from http://127.0.0.1:8983/solr/admin/cores?action=SUMMARY&wt=json + */ + private static JSONObject json = new JSONObject( + "{\n" + + " \"responseHeader\":{\n" + + " \"status\":0,\n" + + " \"QTime\":1221\n" + + " },\n" + + " \"Summary\":{\n" + + " \"alfresco\":{\n" + + " \"Total Searcher Cache (GB)\":0,\n" + + " \"On disk (GB)\":\"0.006584\",\n" + + " \"Active\":false,\n" + + " \"TX Lag\":\"0 s\",\n" + + " \"TX Duration\":\"P0Y\",\n" + + " \"Approx transactions remaining\":0,\n" + + " \"Approx transaction indexing time remaining\":\"0 Seconds\",\n" + + " \"Id for last TX in index\":16\n" + + " },\n" + + " \"archive\":{\n" + + " \"Total Searcher Cache (GB)\":1,\n" + + " \"On disk (GB)\":\"0.001554\",\n" + + " \"Active\":true,\n" + + " \"TX Lag\":\"1 s\",\n" + + " \"TX Duration\":\"P1Y\",\n" + + " \"Approx transactions remaining\":1,\n" + + " \"Approx transaction indexing time remaining\":\"30 Seconds\",\n" + + " \"Id for last TX in index\":15\n" + + " }\n" + + " }\n" + + "}"); + + private SolrChildApplicationContextFactory solrChildApplicationContextFactory; + + @Mock + private SolrAdminHTTPClient adminClient; + + @Before + public void before() + { + + SwitchableApplicationContextFactory subsystemManager = ((SwitchableApplicationContextFactory) applicationContext + .getBean("Search")); + ApplicationContext solrContext = subsystemManager.getApplicationContext(); + solrChildApplicationContextFactory = (SolrChildApplicationContextFactory) solrContext.getBean("solr6"); + + adminClient = Mockito.mock(SolrAdminHTTPClient.class); + when(adminClient.execute(any())).thenReturn(json); + solrChildApplicationContextFactory.setAdminClient(adminClient); + + } + + @Test + public void test() + { + assertEquals(solrChildApplicationContextFactory.getProperty( + SolrChildApplicationContextFactory.ALFRESCO_ACTIVE), "false"); + assertEquals(solrChildApplicationContextFactory.getProperty( + SolrChildApplicationContextFactory.ALFRESCO_LAG), "0 s"); + assertEquals(solrChildApplicationContextFactory.getProperty( + SolrChildApplicationContextFactory.ALFRESCO_LAG_DURATION), "P0Y"); + assertEquals(solrChildApplicationContextFactory.getProperty( + SolrChildApplicationContextFactory.ALFRESCO_LAST_INDEXED_TXN), "16"); + assertEquals(solrChildApplicationContextFactory.getProperty( + SolrChildApplicationContextFactory.ALFRESCO_APPROX_TXNS_REMAINING), "0"); + assertEquals(solrChildApplicationContextFactory.getProperty( + SolrChildApplicationContextFactory.ALFRESCO_APPROX_INDEXING_TIME_REMAINING), "0 Seconds"); + assertEquals(solrChildApplicationContextFactory.getProperty( + SolrChildApplicationContextFactory.ALFRESCO_DISK), "0.006584"); + assertEquals(solrChildApplicationContextFactory.getProperty(SolrChildApplicationContextFactory.ALFRESCO_MEMORY), "0"); + + assertEquals(solrChildApplicationContextFactory.getProperty( + SolrChildApplicationContextFactory.ARCHIVE_ACTIVE), "true"); + assertEquals(solrChildApplicationContextFactory.getProperty( + SolrChildApplicationContextFactory.ARCHIVE_LAG), "1 s"); + assertEquals(solrChildApplicationContextFactory.getProperty( + SolrChildApplicationContextFactory.ARCHIVE_LAG_DURATION), "P1Y"); + assertEquals(solrChildApplicationContextFactory.getProperty( + SolrChildApplicationContextFactory.ARCHIVE_LAST_INDEXED_TXN), "15"); + assertEquals(solrChildApplicationContextFactory.getProperty( + SolrChildApplicationContextFactory.ARCHIVE_APPROX_TXNS_REMAINING), "1"); + assertEquals(solrChildApplicationContextFactory.getProperty( + SolrChildApplicationContextFactory.ARCHIVE_APPROX_INDEXING_TIME_REMAINING), "30 Seconds"); + assertEquals(solrChildApplicationContextFactory.getProperty( + SolrChildApplicationContextFactory.ARCHIVE_DISK), "0.001554"); + assertEquals(solrChildApplicationContextFactory.getProperty( + SolrChildApplicationContextFactory.ARCHIVE_MEMORY), "1"); + } + +}