From c5951963431a50e4baf03ee0433c06a6013f648a Mon Sep 17 00:00:00 2001 From: Angel Borroy Date: Wed, 2 Dec 2020 13:00:38 +0100 Subject: [PATCH 1/4] SEARCH-2602: Fix JSON getString methods for values containing Number --- .../SolrChildApplicationContextFactory.java | 147 +++++++----------- 1 file changed, 58 insertions(+), 89 deletions(-) diff --git a/repository/src/main/java/org/alfresco/repo/search/impl/solr/SolrChildApplicationContextFactory.java b/repository/src/main/java/org/alfresco/repo/search/impl/solr/SolrChildApplicationContextFactory.java index d488e5db6d..1c1afe77f1 100644 --- a/repository/src/main/java/org/alfresco/repo/search/impl/solr/SolrChildApplicationContextFactory.java +++ b/repository/src/main/java/org/alfresco/repo/search/impl/solr/SolrChildApplicationContextFactory.java @@ -26,14 +26,13 @@ package org.alfresco.repo.search.impl.solr; import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; import java.util.Set; import java.util.TreeSet; import org.alfresco.repo.management.subsystems.ChildApplicationContextFactory; import org.alfresco.repo.search.QueryParserException; -import org.alfresco.service.cmr.repository.datatype.Duration; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.json.JSONException; import org.json.JSONObject; import org.springframework.context.ApplicationContext; @@ -43,38 +42,40 @@ import org.springframework.context.ApplicationContext; */ public class SolrChildApplicationContextFactory extends ChildApplicationContextFactory { + + private static final Log LOGGER = LogFactory.getLog(SolrChildApplicationContextFactory.class); - private static String ALFRESCO_ACTIVE = "tracker.alfresco.active"; + private static final String ALFRESCO_ACTIVE = "tracker.alfresco.active"; - private static String ALFRESCO_LAG = "tracker.alfresco.lag"; + private static final String ALFRESCO_LAG = "tracker.alfresco.lag"; - private static String ALFRESCO_LAG_DURATION = "tracker.alfresco.lag.duration"; + private static final String ALFRESCO_LAG_DURATION = "tracker.alfresco.lag.duration"; - private static String ALFRESCO_LAST_INDEXED_TXN = "tracker.alfresco.last.indexed.txn"; + private static final String ALFRESCO_LAST_INDEXED_TXN = "tracker.alfresco.last.indexed.txn"; - private static String ALFRESCO_APPROX_TXNS_REMAINING = "tracker.alfresco.approx.txns.remaining"; + private static final String ALFRESCO_APPROX_TXNS_REMAINING = "tracker.alfresco.approx.txns.remaining"; - private static String ALFRESCO_APPROX_INDEXING_TIME_REMAINING = "tracker.alfresco.approx.indexing.time.remaining"; + private static final String ALFRESCO_APPROX_INDEXING_TIME_REMAINING = "tracker.alfresco.approx.indexing.time.remaining"; - private static String ALFRESCO_DISK = "tracker.alfresco.disk"; + private static final String ALFRESCO_DISK = "tracker.alfresco.disk"; - private static String ALFRESCO_MEMORY = "tracker.alfresco.memory"; + private static final String ALFRESCO_MEMORY = "tracker.alfresco.memory"; - private static String ARCHIVE_ACTIVE = "tracker.archive.active"; + private static final String ARCHIVE_ACTIVE = "tracker.archive.active"; - private static String ARCHIVE_LAG = "tracker.archive.lag"; + private static final String ARCHIVE_LAG = "tracker.archive.lag"; - private static String ARCHIVE_LAG_DURATION = "tracker.archive.lag.duration"; + private static final String ARCHIVE_LAG_DURATION = "tracker.archive.lag.duration"; - private static String ARCHIVE_LAST_INDEXED_TXN = "tracker.archive.last.indexed.txn"; + private static final String ARCHIVE_LAST_INDEXED_TXN = "tracker.archive.last.indexed.txn"; - private static String ARCHIVE_APPROX_TXNS_REMAINING = "tracker.archive.approx.txns.remaining"; + private static final String ARCHIVE_APPROX_TXNS_REMAINING = "tracker.archive.approx.txns.remaining"; - private static String ARCHIVE_APPROX_INDEXING_TIME_REMAINING = "tracker.archive.approx.indexing.time.remaining"; + private static final String ARCHIVE_APPROX_INDEXING_TIME_REMAINING = "tracker.archive.approx.indexing.time.remaining"; - private static String ARCHIVE_DISK = "tracker.archive.disk"; + private static final String ARCHIVE_DISK = "tracker.archive.disk"; - private static String ARCHIVE_MEMORY = "tracker.archive.memory"; + private static final String ARCHIVE_MEMORY = "tracker.archive.memory"; @Override @@ -101,6 +102,40 @@ public class SolrChildApplicationContextFactory extends ChildApplicationContextF && !name.equals(SolrChildApplicationContextFactory.ARCHIVE_MEMORY) ; } + + private String getPropertyValue(JSONObject core, String name) + { + switch (name) + { + case SolrChildApplicationContextFactory.ALFRESCO_ACTIVE: + case SolrChildApplicationContextFactory.ARCHIVE_ACTIVE: + return core.getBoolean("Active") ? "true" : "false"; + case SolrChildApplicationContextFactory.ALFRESCO_LAG: + case SolrChildApplicationContextFactory.ARCHIVE_LAG: + return core.getString("TX Lag"); + case SolrChildApplicationContextFactory.ALFRESCO_LAG_DURATION: + case SolrChildApplicationContextFactory.ARCHIVE_LAG_DURATION: + return core.getString("TX Duration"); + case SolrChildApplicationContextFactory.ALFRESCO_LAST_INDEXED_TXN: + case SolrChildApplicationContextFactory.ARCHIVE_LAST_INDEXED_TXN: + return core.getNumber("Id for last TX in index").toString(); + case SolrChildApplicationContextFactory.ALFRESCO_APPROX_TXNS_REMAINING: + case SolrChildApplicationContextFactory.ARCHIVE_APPROX_TXNS_REMAINING: + return core.getNumber("Approx transactions remaining").toString(); + case SolrChildApplicationContextFactory.ALFRESCO_APPROX_INDEXING_TIME_REMAINING: + case SolrChildApplicationContextFactory.ARCHIVE_APPROX_INDEXING_TIME_REMAINING: + return core.getString("Approx transaction indexing time remaining"); + case SolrChildApplicationContextFactory.ALFRESCO_DISK: + case SolrChildApplicationContextFactory.ARCHIVE_DISK: + return core.getNumber("On disk (GB)").toString(); + case SolrChildApplicationContextFactory.ALFRESCO_MEMORY: + case SolrChildApplicationContextFactory.ARCHIVE_MEMORY: + return core.getNumber("Total Searcher Cache (GB)").toString(); + default: + return null; + + } + } @Override public String getProperty(String name) @@ -126,48 +161,12 @@ public class SolrChildApplicationContextFactory extends ChildApplicationContextF catch (JSONException e) { // The core might be absent. + LOGGER.debug("Node alfresco not found", e); } if (alfresco != null) { - if (name.equals(SolrChildApplicationContextFactory.ALFRESCO_ACTIVE)) - { - String alfrescoActive = alfresco.getString("Active"); - if (alfrescoActive == null || alfrescoActive.isEmpty()) - { - // Admin Console is expecting a true/false value, not blank - return "false"; - } - return alfrescoActive; - } - else if (name.equals(SolrChildApplicationContextFactory.ALFRESCO_LAG)) - { - return alfresco.getString("TX Lag"); - } - else if (name.equals(SolrChildApplicationContextFactory.ALFRESCO_LAG_DURATION)) - { - return alfresco.getString("TX Duration"); - } - else if (name.equals(SolrChildApplicationContextFactory.ALFRESCO_LAST_INDEXED_TXN)) - { - return alfresco.getString("Id for last TX in index"); - } - else if (name.equals(SolrChildApplicationContextFactory.ALFRESCO_APPROX_TXNS_REMAINING)) - { - return alfresco.getString("Approx transactions remaining"); - } - else if (name.equals(SolrChildApplicationContextFactory.ALFRESCO_APPROX_INDEXING_TIME_REMAINING)) - { - return alfresco.getString("Approx transaction indexing time remaining"); - } - else if (name.equals(SolrChildApplicationContextFactory.ALFRESCO_DISK)) - { - return alfresco.getString("On disk (GB)"); - } - else if (name.equals(SolrChildApplicationContextFactory.ALFRESCO_MEMORY)) - { - return alfresco.getString("Total Searcher Cache (GB)"); - } + return getPropertyValue(alfresco, name); } JSONObject archive = null; @@ -178,42 +177,12 @@ public class SolrChildApplicationContextFactory extends ChildApplicationContextF catch (JSONException e) { // The core might be absent. + LOGGER.debug("Node archive not found", e); } if (archive != null) { - if (name.equals(SolrChildApplicationContextFactory.ARCHIVE_ACTIVE)) - { - return archive.getString("Active"); - } - else if (name.equals(SolrChildApplicationContextFactory.ARCHIVE_LAG)) - { - return archive.getString("TX Lag"); - } - else if (name.equals(SolrChildApplicationContextFactory.ARCHIVE_LAG_DURATION)) - { - return archive.getString("TX Duration"); - } - else if (name.equals(SolrChildApplicationContextFactory.ARCHIVE_LAST_INDEXED_TXN)) - { - return archive.getString("Id for last TX in index"); - } - else if (name.equals(SolrChildApplicationContextFactory.ARCHIVE_APPROX_TXNS_REMAINING)) - { - return archive.getString("Approx transactions remaining"); - } - else if (name.equals(SolrChildApplicationContextFactory.ARCHIVE_APPROX_INDEXING_TIME_REMAINING)) - { - return archive.getString("Approx transaction indexing time remaining"); - } - else if (name.equals(SolrChildApplicationContextFactory.ARCHIVE_DISK)) - { - return archive.getString("On disk (GB)"); - } - else if (name.equals(SolrChildApplicationContextFactory.ARCHIVE_MEMORY)) - { - return archive.getString("Total Searcher Cache (GB)"); - } + return getPropertyValue(alfresco, name); } // Did not find the property in JSON or the core is turned off From 796c887f1bd9855361369be346a9ddf89f972001 Mon Sep 17 00:00:00 2001 From: Angel Borroy Date: Thu, 3 Dec 2020 14:27:06 +0100 Subject: [PATCH 2/4] SEARCH-2602: Fix JSON getString methods for values containing Number --- .../SolrChildApplicationContextFactory.java | 156 ++++++++++-------- 1 file changed, 89 insertions(+), 67 deletions(-) diff --git a/repository/src/main/java/org/alfresco/repo/search/impl/solr/SolrChildApplicationContextFactory.java b/repository/src/main/java/org/alfresco/repo/search/impl/solr/SolrChildApplicationContextFactory.java index 1c1afe77f1..4885055379 100644 --- a/repository/src/main/java/org/alfresco/repo/search/impl/solr/SolrChildApplicationContextFactory.java +++ b/repository/src/main/java/org/alfresco/repo/search/impl/solr/SolrChildApplicationContextFactory.java @@ -45,39 +45,51 @@ public class SolrChildApplicationContextFactory extends ChildApplicationContextF private static final Log LOGGER = LogFactory.getLog(SolrChildApplicationContextFactory.class); - private static final String ALFRESCO_ACTIVE = "tracker.alfresco.active"; + protected static final String ALFRESCO_ACTIVE = "tracker.alfresco.active"; + protected static final String ALFRESCO_LAG = "tracker.alfresco.lag"; + protected static final String ALFRESCO_LAG_DURATION = "tracker.alfresco.lag.duration"; + protected static final String ALFRESCO_LAST_INDEXED_TXN = "tracker.alfresco.last.indexed.txn"; + protected static final String ALFRESCO_APPROX_TXNS_REMAINING = "tracker.alfresco.approx.txns.remaining"; + protected static final String ALFRESCO_APPROX_INDEXING_TIME_REMAINING = "tracker.alfresco.approx.indexing.time.remaining"; + protected static final String ALFRESCO_DISK = "tracker.alfresco.disk"; + protected static final String ALFRESCO_MEMORY = "tracker.alfresco.memory"; - private static final String ALFRESCO_LAG = "tracker.alfresco.lag"; + protected static final String ARCHIVE_ACTIVE = "tracker.archive.active"; + protected static final String ARCHIVE_LAG = "tracker.archive.lag"; + protected static final String ARCHIVE_LAG_DURATION = "tracker.archive.lag.duration"; + protected static final String ARCHIVE_LAST_INDEXED_TXN = "tracker.archive.last.indexed.txn"; + protected static final String ARCHIVE_APPROX_TXNS_REMAINING = "tracker.archive.approx.txns.remaining"; + protected static final String ARCHIVE_APPROX_INDEXING_TIME_REMAINING = "tracker.archive.approx.indexing.time.remaining"; + protected static final String ARCHIVE_DISK = "tracker.archive.disk"; + protected static final String ARCHIVE_MEMORY = "tracker.archive.memory"; + + private SolrAdminHTTPClient adminClient; + + public void setAdminClient(SolrAdminHTTPClient adminClient) + { + this.adminClient = adminClient; + } + + public SolrAdminHTTPClient getAdminClient() + { + if (adminClient == null) + { + ApplicationContext ctx = getApplicationContext(); + adminClient = (SolrAdminHTTPClient) ctx.getBean("search.solrAdminHTTPCLient"); + } + return adminClient; + } + + private static boolean isAlfrescoCoreProperty(String name) + { + return name.startsWith("tracker.alfresco."); + } - private static final String ALFRESCO_LAG_DURATION = "tracker.alfresco.lag.duration"; + private static boolean isArchiveCoreProperty(String name) + { + return name.startsWith("tracker.archive."); + } - private static final String ALFRESCO_LAST_INDEXED_TXN = "tracker.alfresco.last.indexed.txn"; - - private static final String ALFRESCO_APPROX_TXNS_REMAINING = "tracker.alfresco.approx.txns.remaining"; - - private static final String ALFRESCO_APPROX_INDEXING_TIME_REMAINING = "tracker.alfresco.approx.indexing.time.remaining"; - - private static final String ALFRESCO_DISK = "tracker.alfresco.disk"; - - private static final String ALFRESCO_MEMORY = "tracker.alfresco.memory"; - - private static final String ARCHIVE_ACTIVE = "tracker.archive.active"; - - private static final String ARCHIVE_LAG = "tracker.archive.lag"; - - private static final String ARCHIVE_LAG_DURATION = "tracker.archive.lag.duration"; - - private static final String ARCHIVE_LAST_INDEXED_TXN = "tracker.archive.last.indexed.txn"; - - private static final String ARCHIVE_APPROX_TXNS_REMAINING = "tracker.archive.approx.txns.remaining"; - - private static final String ARCHIVE_APPROX_INDEXING_TIME_REMAINING = "tracker.archive.approx.indexing.time.remaining"; - - private static final String ARCHIVE_DISK = "tracker.archive.disk"; - - private static final String ARCHIVE_MEMORY = "tracker.archive.memory"; - - @Override public boolean isUpdateable(String name) { @@ -136,53 +148,63 @@ public class SolrChildApplicationContextFactory extends ChildApplicationContextF } } - + + private JSONObject getSolrSummary() + { + HashMap args = new HashMap(); + args.put("action", "SUMMARY"); + args.put("wt", "json"); + JSONObject json = getAdminClient().execute(args); + return json.getJSONObject("Summary"); + } + @Override public String getProperty(String name) { - // MNT-9254 fix, use search.solrAdminHTTPCLient bean to retrive property value only if sorl subsystem is active and started (application context in state should be not null) + // MNT-9254 fix, use search.solrAdminHTTPCLient bean to retrieve property value only if sorl subsystem is active and started (application context in state should be not null) if (false == isUpdateable(name) && ((ApplicationContextState) getState(false)).getApplicationContext(false) != null) { try { - ApplicationContext ctx = getApplicationContext(); - SolrAdminHTTPClient adminClient = (SolrAdminHTTPClient) ctx.getBean("search.solrAdminHTTPCLient"); - HashMap args = new HashMap(); - args.put("action", "SUMMARY"); - args.put("wt", "json"); - JSONObject json = adminClient.execute(args); - JSONObject summary = json.getJSONObject("Summary"); - - JSONObject alfresco = null; - try + + JSONObject summary = getSolrSummary(); + + if (isAlfrescoCoreProperty(name)) { - alfresco = summary.getJSONObject("alfresco"); + JSONObject alfresco = null; + try + { + alfresco = summary.getJSONObject("alfresco"); + } + catch (JSONException e) + { + // The core might be absent. + LOGGER.debug("Node alfresco not found", e); + } + + if (alfresco != null) + { + return getPropertyValue(alfresco, name); + } } - catch (JSONException e) + + if (isArchiveCoreProperty(name)) { - // The core might be absent. - LOGGER.debug("Node alfresco not found", e); - } - - if (alfresco != null) - { - return getPropertyValue(alfresco, name); - } - - JSONObject archive = null; - try - { - archive = summary.getJSONObject("archive"); - } - catch (JSONException e) - { - // The core might be absent. - LOGGER.debug("Node archive not found", e); - } - - if (archive != null) - { - return getPropertyValue(alfresco, name); + JSONObject archive = null; + try + { + archive = summary.getJSONObject("archive"); + } + catch (JSONException e) + { + // The core might be absent. + LOGGER.debug("Node archive not found", e); + } + + if (archive != null) + { + return getPropertyValue(archive, name); + } } // Did not find the property in JSON or the core is turned off From 908157bc01f38f3cc840d4a097ee99990db41ce3 Mon Sep 17 00:00:00 2001 From: Angel Borroy Date: Thu, 3 Dec 2020 14:32:46 +0100 Subject: [PATCH 3/4] 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"); + } + +} From 64454ddc09a2d9348332760b73a00add295cda0e Mon Sep 17 00:00:00 2001 From: Angel Borroy Date: Fri, 4 Dec 2020 11:27:43 +0100 Subject: [PATCH 4/4] SEARCH-2602: Extract Strings to Constants. --- .../SolrChildApplicationContextFactory.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/repository/src/main/java/org/alfresco/repo/search/impl/solr/SolrChildApplicationContextFactory.java b/repository/src/main/java/org/alfresco/repo/search/impl/solr/SolrChildApplicationContextFactory.java index 4885055379..d15fd58ac6 100644 --- a/repository/src/main/java/org/alfresco/repo/search/impl/solr/SolrChildApplicationContextFactory.java +++ b/repository/src/main/java/org/alfresco/repo/search/impl/solr/SolrChildApplicationContextFactory.java @@ -63,6 +63,15 @@ public class SolrChildApplicationContextFactory extends ChildApplicationContextF protected static final String ARCHIVE_DISK = "tracker.archive.disk"; protected static final String ARCHIVE_MEMORY = "tracker.archive.memory"; + private static final String SUMMARY_FIELD_TOTAL_SEARCHER_CACHE_GB = "Total Searcher Cache (GB)"; + private static final String SUMMARY_FIELD_ON_DISK_GB = "On disk (GB)"; + private static final String SUMMARY_FIELD_APPROX_TRANSACTION_INDEXING_TIME_REMAINING = "Approx transaction indexing time remaining"; + private static final String SUMMARY_FIELD_APPROX_TRANSACTIONS_REMAINING = "Approx transactions remaining"; + private static final String SUMMARY_FIELD_ID_FOR_LAST_TX_IN_INDEX = "Id for last TX in index"; + private static final String SUMMARY_FIELD_TX_DURATION = "TX Duration"; + private static final String SUMMARY_FIELD_TX_LAG = "TX Lag"; + private static final String SUMMARY_FIELD_ACTIVE = "Active"; + private SolrAdminHTTPClient adminClient; public void setAdminClient(SolrAdminHTTPClient adminClient) @@ -121,28 +130,28 @@ public class SolrChildApplicationContextFactory extends ChildApplicationContextF { case SolrChildApplicationContextFactory.ALFRESCO_ACTIVE: case SolrChildApplicationContextFactory.ARCHIVE_ACTIVE: - return core.getBoolean("Active") ? "true" : "false"; + return core.getBoolean(SUMMARY_FIELD_ACTIVE) ? "true" : "false"; case SolrChildApplicationContextFactory.ALFRESCO_LAG: case SolrChildApplicationContextFactory.ARCHIVE_LAG: - return core.getString("TX Lag"); + return core.getString(SUMMARY_FIELD_TX_LAG); case SolrChildApplicationContextFactory.ALFRESCO_LAG_DURATION: case SolrChildApplicationContextFactory.ARCHIVE_LAG_DURATION: - return core.getString("TX Duration"); + return core.getString(SUMMARY_FIELD_TX_DURATION); case SolrChildApplicationContextFactory.ALFRESCO_LAST_INDEXED_TXN: case SolrChildApplicationContextFactory.ARCHIVE_LAST_INDEXED_TXN: - return core.getNumber("Id for last TX in index").toString(); + return core.getNumber(SUMMARY_FIELD_ID_FOR_LAST_TX_IN_INDEX).toString(); case SolrChildApplicationContextFactory.ALFRESCO_APPROX_TXNS_REMAINING: case SolrChildApplicationContextFactory.ARCHIVE_APPROX_TXNS_REMAINING: - return core.getNumber("Approx transactions remaining").toString(); + return core.getNumber(SUMMARY_FIELD_APPROX_TRANSACTIONS_REMAINING).toString(); case SolrChildApplicationContextFactory.ALFRESCO_APPROX_INDEXING_TIME_REMAINING: case SolrChildApplicationContextFactory.ARCHIVE_APPROX_INDEXING_TIME_REMAINING: - return core.getString("Approx transaction indexing time remaining"); + return core.getString(SUMMARY_FIELD_APPROX_TRANSACTION_INDEXING_TIME_REMAINING); case SolrChildApplicationContextFactory.ALFRESCO_DISK: case SolrChildApplicationContextFactory.ARCHIVE_DISK: - return core.getNumber("On disk (GB)").toString(); + return core.getNumber(SUMMARY_FIELD_ON_DISK_GB).toString(); case SolrChildApplicationContextFactory.ALFRESCO_MEMORY: case SolrChildApplicationContextFactory.ARCHIVE_MEMORY: - return core.getNumber("Total Searcher Cache (GB)").toString(); + return core.getNumber(SUMMARY_FIELD_TOTAL_SEARCHER_CACHE_GB).toString(); default: return null;