Files
alfresco-community-repo/src/test/java/org/alfresco/heartbeat/UsageSystemDataCollectorTest.java
Erik Knizat 310b9d88f3 REPO-3007: This is a squash commit containing scheduling and clustering commits
* Add job cron expression and unique id to HBBaseDataCollector
* Remove HeartBeat class and move its responsibilities to HBDataCollectorServiceImpl
* Refactor HBDataCollectorServiceImpl
* Update collector bean definitions with cron expression
* Add job locking functionality
* Refactor tests to work with new code changes

Squashed commit of the following:

commit 522a8c07b65aa0170387d7cea8b1a89230e019ed
Author: Erik Knizat <erik.knizat@alfresco.com>
Date:   Fri Nov 17 15:22:48 2017 +0000

    Cleaned up code:
    * HBDataCollectorServiceImpl - improved logic so that collectors which fail to schedule job do not get registered
    * HBDataCollectorServiceImpl - clean up code
    * HBDataCollectorServiceImplTest - Revrite old test to work with new changed
    * heartbeat-context.xml - add register method to the base collector template
    * Minor comment updates

commit d75b920a9172b3e53d901d1abbf33bada9419c4d
Author: Martin Müller <martin.muller@alfresco.com>
Date:   Mon Nov 6 20:17:30 2017 +0000

    REPO-3007 bug in usage system collector

commit 2f25ec04868569eab4de34bd804ee9fb3490f9c2
Author: Martin Müller <martin.muller@alfresco.com>
Date:   Mon Nov 6 20:15:41 2017 +0000

    Revert "REPO-3007 try to fix context load errors"

    This reverts commit 30d0f70609e1c774b7989c18cd76ad87ccf239ed.

commit 30d0f70609e1c774b7989c18cd76ad87ccf239ed
Author: Martin Müller <martin.muller@alfresco.com>
Date:   Mon Nov 6 19:57:14 2017 +0000

    REPO-3007 try to fix context load errors

commit 615e72bfdb6d08f1d82cfe581d0a222932eec483
Merge: c128561fc e357becce
Author: Martin Müller <martin.muller@alfresco.com>
Date:   Mon Nov 6 19:30:41 2017 +0000

    Merge branch 'develop' into feature/REPO-2627_Clust-Test

commit c128561fc977979dda5c2d397da9b05993e0db68
Author: Martin Müller <martin.muller@alfresco.com>
Date:   Mon Nov 6 19:13:47 2017 +0000

    REPO-3007 reduced time for TTL and TTL_OFFSET

commit 02184034908775ea835d7022478a9c7b6a8dc66a
Author: Martin Muller <martin.muller@alfresco.com>
Date:   Mon Nov 6 18:47:06 2017 +0000

    REPO-3007 additional life time of the job for keeping the lock longer. Reduced additional work.

commit 63332cdf08d8819518bbe6a3b80e988e2c8bc554
Author: Martin Muller <martin.muller@alfresco.com>
Date:   Mon Nov 6 18:42:22 2017 +0000

    REPO-3007 additional life time of the job for keeping the lock longer. Reduced additional work.

commit 7333ae7f448b5fe3601a99d25c814c8a58ca0e92
Author: Martin Muller <martin.muller@alfresco.com>
Date:   Mon Nov 6 18:12:47 2017 +0000

    REPO-3007 additional life time of the job for keeping the lock longer. Reduced additional work.

commit e43c3cff787d6985cbf4d957dfcf7cf27e4aa495
Author: Martin Muller <martin.muller@alfresco.com>
Date:   Mon Nov 6 18:05:51 2017 +0000

    REPO-3007 additional life time of the job for keeping the lock longer. Reduced additional work.

commit 5f8d19fc05b5ef4855c89aab86e2e786fcc8b0d9
Author: Martin Muller <martin.muller@alfresco.com>
Date:   Wed Nov 1 15:37:27 2017 +0000

    REPO-3007 spell check.

commit e7c8aa3f96939e29cd9ac6b962ad5a5d848269e3
Merge: 2bbcba39f b0f057f0d
Author: Martin Muller <martin.muller@alfresco.com>
Date:   Tue Oct 31 14:47:23 2017 +0000

    Merge branch 'develop' into feature/REPO-2627_Clust-Test

commit 2bbcba39faaa4ba97d9ec81a691256c2292e5f8d
Author: alfresco-build <build@alfresco.com>
Date:   Tue Oct 31 14:03:04 2017 +0000

    [maven-release-plugin] prepare for next development iteration

commit 1e74e1dc6652daa5964d2c8cf1b06ef32147e15f
Author: alfresco-build <build@alfresco.com>
Date:   Tue Oct 31 14:02:57 2017 +0000

    [maven-release-plugin] prepare release alfresco-repository-6.9-REPO-2627_Clust-Test-1

commit fdf8b40dc6ad00433c3601782864c5cdaec63706
Author: Martin Muller <martin.muller@alfresco.com>
Date:   Tue Oct 31 13:45:02 2017 +0000

    REPO-3007 Some syntax clean ups

commit ca1b8a2b6019b1a21c84eb949bbe57ae9bbdef9c
Author: Martin Muller <martin.muller@alfresco.com>
Date:   Tue Oct 31 11:59:48 2017 +0000

    REPO-3007 Bring back the concrete collector tests. And little refactoring of them.

commit 73fbafc4732f06e0c48d0fa0e6225ba26265d75c
Author: Martin Müller <martin.muller@alfresco.com>
Date:   Mon Oct 30 16:49:21 2017 +0000

    REPO-3007 Implemented each data collection in his own data collector. Removed some unnecessary tests.

commit e41d3afd7b414aae921599aa193d6fbd167ab35a
Author: Martin Müller <martin.muller@alfresco.com>
Date:   Mon Oct 30 16:08:00 2017 +0000

    REPO-3007 Implemented each data collection in his own data collector. Removed some unnecessary tests.

commit f13ec13a5b4dc6fb490fcc93c06a13d0b0348df5
Author: Martin Müller <martin.muller@alfresco.com>
Date:   Mon Oct 30 11:54:33 2017 +0000

    REPO-3007 Implemented each data collection in his own data collector. Removed some unnecessary tests.

commit 37115ba39a73b9ea4fc7e5d562c83bb792b11c9b
Author: Martin Muller <martin.muller@alfresco.com>
Date:   Fri Oct 27 18:00:44 2017 +0100

    REPO-3007 Remove old HeartBeat.java references

commit cd6af905914119bc4f8526500303d29b4759a6e2
Author: Martin Muller <martin.muller@alfresco.com>
Date:   Fri Oct 27 17:50:39 2017 +0100

    REPO-3007 Reduce mocking objects

commit 4c5b82a50f1d42b35162dfcf31a21a303fddbc6b
Author: Martin Muller <martin.muller@alfresco.com>
Date:   Fri Oct 27 17:38:09 2017 +0100

    REPO-3007 Improve tests for hb default enabled

commit 7abd1467de33b72f304c26bdf18f3769ef9632b1
Author: Martin Muller <martin.muller@alfresco.com>
Date:   Fri Oct 27 14:22:53 2017 +0100

    REPO-3007 Delete old HeartBeat files

commit 301ab0525f1a146223f21aaba0122a70384c6342
Author: Martin Muller <martin.muller@alfresco.com>
Date:   Fri Oct 27 14:21:58 2017 +0100

    Delete old HeartBeat files

commit c3a84596d7f809aa7ebb7789ae98f953f44b4d36
Author: Martin Muller <martin.muller@alfresco.com>
Date:   Fri Oct 27 14:13:50 2017 +0100

    REPO-3007 Some CollectorServiceImplTests

commit e7071811e9e0276861c374248215fdde94285623
Author: Martin Muller <martin.muller@alfresco.com>
Date:   Fri Oct 27 14:11:39 2017 +0100

    Some CollectorServiceImplTests

commit ac5aa8e9a295f250920f8ebbe2a5ad97ba4270eb
Author: Martin Muller <martin.muller@alfresco.com>
Date:   Fri Oct 27 13:26:25 2017 +0100

    Continued refactoring. Get some tests running

commit d5ef15fe0080cebb586360f10a21eef94ba63d51
Author: Martin Muller <martin.muller@alfresco.com>
Date:   Fri Oct 27 12:45:05 2017 +0100

    Continued refactoring. Get some tests running

commit f7ae53236daaa5e48dbd829f5f1cd984c2c06e8c
Author: Martin Muller <martin.muller@alfresco.com>
Date:   Fri Oct 27 12:24:36 2017 +0100

    Continued refactoring. Get some tests running

commit 7c200d0f7633efe7cda4a68e7ef279e85b7e5d99
Author: Martin Muller <martin.muller@alfresco.com>
Date:   Thu Oct 26 17:32:37 2017 +0100

    REPO-3007 implemented dynamic lock with JobLockCallBack

commit 5def15950b87b9df4136fedff447d4f54aa87736
Author: Martin Muller <martin.muller@alfresco.com>
Date:   Thu Oct 26 17:28:09 2017 +0100

    REPO-3007 implemented dynamic lock with JobLockCallBack

commit bdbbe49a081661373a2114b7cf2cb415d4383afd
Author: Martin Muller <martin.muller@alfresco.com>
Date:   Thu Oct 26 17:25:28 2017 +0100

    REPO-3007 implemented dynamic lock with JobLockCallBack

commit a5d1f45f28a0ae228a8c9bf2f8a4171413a692e7
Author: Martin Muller <martin.muller@alfresco.com>
Date:   Thu Oct 26 16:07:46 2017 +0100

    Update heartbeat-context.xml

    We don't need the licenseService here

commit c2efe1bd325f89f0a4c0ebf95b5a0e99baa249f4
Author: Martin Muller <martin.muller@alfresco.com>
Date:   Thu Oct 26 16:07:03 2017 +0100

    Update HBDataCollectorServiceImpl.java

    We don't need the licenseService here

commit 8f1bd298e1f03f0a45be31b28f14289ad1684c9f
Author: Martin Muller <martin.muller@alfresco.com>
Date:   Thu Oct 26 14:41:53 2017 +0100

    REPO-3007 the collectors are unique

commit 2f8ad8fff384c1f525759be59ab8c1ba5b05b5f2
Author: Martin Muller <martin.muller@alfresco.com>
Date:   Thu Oct 26 14:32:02 2017 +0100

    REPO-3007 starting refactoring

commit 5a3e7f2d25d9c20017f12b8fec26198a4f7d705b
Author: Martin Muller <martin.muller@alfresco.com>
Date:   Thu Oct 26 14:26:32 2017 +0100

    REPO-3007 starting refactoring

commit ed111b77f6f311be967929ba09025d6bb4fb9ab8
Author: Martin Muller <martin.muller@alfresco.com>
Date:   Thu Oct 26 14:16:49 2017 +0100

    REPO-3007 starting refactoring

commit 8e2497dc1f05f71451736b8366b3be1f420bf8a6
Author: alfresco-build <build@alfresco.com>
Date:   Thu Oct 26 11:26:19 2017 +0100

    [maven-release-plugin] prepare for next development iteration

commit e15f02390fc09ab7baaad1e186ed35e27e1f7445
Author: alfresco-build <build@alfresco.com>
Date:   Thu Oct 26 11:26:12 2017 +0100

    [maven-release-plugin] prepare release alfresco-repository-6.9-REPO-2627_Clust-Test

commit 35eed74bd869ee8a6a9f4a30c86b9f7cd4bd331b
Author: Martin Muller <martin.muller@alfresco.com>
Date:   Wed Oct 25 13:41:47 2017 +0100

    REPO-2627 Implemented job locking for hb collectors and added unit cluster test

commit b67fc751cd11a9a73fee6873663216bbd05422e1
Author: Martin Muller <martin.muller@alfresco.com>
Date:   Wed Oct 25 13:22:05 2017 +0100

    REPO-2627 Implemented job locking for hb collectors and added unit cluster test
2017-11-17 16:12:24 +00:00

117 lines
4.0 KiB
Java

/*
* #%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 <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.heartbeat;
import org.alfresco.heartbeat.datasender.HBData;
import org.alfresco.repo.descriptor.DescriptorDAO;
import org.alfresco.repo.dictionary.CustomModelsInfo;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.service.cmr.dictionary.CustomModelService;
import org.alfresco.service.cmr.repository.HBDataCollectorService;
import org.alfresco.service.descriptor.Descriptor;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.ApplicationContextHelper;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/**
* @author eknizat
*/
public class UsageSystemDataCollectorTest
{
private UsageSystemDataCollector usageSystemCollector;
private HBDataCollectorService mockCollectorService;
private DescriptorDAO mockDescriptorDAO;
private List<HBData> collectedData;
@Before
public void setUp()
{
mockDescriptorDAO = mock(DescriptorDAO.class);
mockCollectorService = mock(HBDataCollectorService.class);
Descriptor mockDescriptor = mock(Descriptor.class);
when(mockDescriptor.getId()).thenReturn("mock_id");
when(mockDescriptorDAO.getDescriptor()).thenReturn(mockDescriptor);
usageSystemCollector = new UsageSystemDataCollector("acs.repository.usage.system");
usageSystemCollector.setCollectorVersion("1.0");
usageSystemCollector.setHbDataCollectorService(mockCollectorService);
usageSystemCollector.setCurrentRepoDescriptorDAO(mockDescriptorDAO);
collectedData = usageSystemCollector.collectData();
}
@Test
public void testHBDataFields()
{
for(HBData data : this.collectedData)
{
assertNotNull(data.getCollectorId());
assertNotNull(data.getCollectorVersion());
assertNotNull(data.getSchemaVersion());
assertNotNull(data.getSystemId());
assertNotNull(data.getTimestamp());
}
}
@Test
public void testSystemUsageDataIsCollected()
{
HBData systemUsage = grabDataByCollectorId(usageSystemCollector.getCollectorId());
assertNotNull("Repository usage data missing.", systemUsage);
Map<String,Object> data = systemUsage.getData();
assertTrue(data.containsKey("memFree"));
assertTrue(data.containsKey("memMax"));
assertTrue(data.containsKey("memTotal"));
}
private HBData grabDataByCollectorId(String collectorId)
{
for (HBData d : this.collectedData)
{
if(d.getCollectorId()!=null && d.getCollectorId().equals(collectorId))
{
return d;
}
}
return null;
}
}