mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Refactor code
* Split heartbeat-context into 2 * Move new heartbeat-repo-collector-context out of application-context-core
This commit is contained in:
@@ -52,5 +52,5 @@
|
|||||||
<import resource="classpath*:alfresco/dbscripts/*-context.xml" />
|
<import resource="classpath*:alfresco/dbscripts/*-context.xml" />
|
||||||
<import resource="classpath*:alfresco/enterprise/authorization-context.xml" />
|
<import resource="classpath*:alfresco/enterprise/authorization-context.xml" />
|
||||||
<import resource="classpath*:alfresco/enterprise/enterprise-usage-services-context.xml" />
|
<import resource="classpath*:alfresco/enterprise/enterprise-usage-services-context.xml" />
|
||||||
<import resource="classpath:alfresco/heartbeat-context.xml"/>
|
<import resource="classpath:alfresco/heartbeat/heartbeat-context.xml"/>
|
||||||
</beans>
|
</beans>
|
||||||
|
@@ -43,4 +43,5 @@
|
|||||||
<import resource="classpath*:alfresco/domain/*-context.xml" />
|
<import resource="classpath*:alfresco/domain/*-context.xml" />
|
||||||
<import resource="classpath*:alfresco/smartfolder-context.xml" />
|
<import resource="classpath*:alfresco/smartfolder-context.xml" />
|
||||||
<import resource="classpath*:alfresco/reset-password-context.xml" />
|
<import resource="classpath*:alfresco/reset-password-context.xml" />
|
||||||
|
<import resource="classpath:alfresco/heartbeat/heartbeat-repo-collector-context.xml"/>
|
||||||
</beans>
|
</beans>
|
||||||
|
@@ -23,14 +23,4 @@
|
|||||||
<property name="hbDataCollectorService" ref="hbDataCollectorService"/>
|
<property name="hbDataCollectorService" ref="hbDataCollectorService"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<!-- HeartBeat repository data collector -->
|
|
||||||
<bean id="repositoryDataCollector" class="org.alfresco.heartbeat.RepositoryDataCollector" parent="hbBaseDataCollector" init-method="register">
|
|
||||||
<property name="currentRepoDescriptorDAO" ref="currentRepoDescriptorDAO"/>
|
|
||||||
<property name="serverDescriptorDAO" ref="serverDescriptorDAO"/>
|
|
||||||
<property name="authorityService" ref="authorityService"/>
|
|
||||||
<property name="repoUsageComponent" ref="repoUsageComponent"/>
|
|
||||||
<property name="transactionService" ref="transactionService"/>
|
|
||||||
<property name="customModelService" ref="customModelService"/>
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
</beans>
|
</beans>
|
@@ -0,0 +1,16 @@
|
|||||||
|
<?xml version='1.0' encoding='UTF-8'?>
|
||||||
|
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
|
||||||
|
|
||||||
|
<beans>
|
||||||
|
|
||||||
|
<!-- HeartBeat repository data collector -->
|
||||||
|
<bean id="repositoryDataCollector" class="org.alfresco.heartbeat.RepositoryDataCollector" parent="hbBaseDataCollector" init-method="register">
|
||||||
|
<property name="currentRepoDescriptorDAO" ref="currentRepoDescriptorDAO"/>
|
||||||
|
<property name="serverDescriptorDAO" ref="serverDescriptorDAO"/>
|
||||||
|
<property name="authorityService" ref="authorityService"/>
|
||||||
|
<property name="repoUsageComponent" ref="repoUsageComponent"/>
|
||||||
|
<property name="transactionService" ref="transactionService"/>
|
||||||
|
<property name="customModelService" ref="customModelService"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
</beans>
|
@@ -77,13 +77,11 @@ public class HBDataCollectorServiceImplTest
|
|||||||
|
|
||||||
dataCollectorService.enabled(true);
|
dataCollectorService.enabled(true);
|
||||||
verify(mockDataSenderService).enable(true);
|
verify(mockDataSenderService).enable(true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCollectAndSendData()
|
public void testCollectAndSendData()
|
||||||
{
|
{
|
||||||
|
|
||||||
// Set up dummy collector 1
|
// Set up dummy collector 1
|
||||||
HBData c1Data = new HBData("sys", "c1","1.0",null);
|
HBData c1Data = new HBData("sys", "c1","1.0",null);
|
||||||
HBBaseDataCollector c1 = new DummyCollector(c1Data);
|
HBBaseDataCollector c1 = new DummyCollector(c1Data);
|
||||||
|
@@ -36,9 +36,7 @@ import org.quartz.SchedulerException;
|
|||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
@@ -46,11 +44,15 @@ import static org.mockito.Mockito.mock;
|
|||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author eknizat
|
||||||
|
*/
|
||||||
public class HeartBeatTest
|
public class HeartBeatTest
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private static final String[] CONFIG_LOCATIONS = new String[] {
|
||||||
private static final String[] CONFIG_LOCATIONS = new String[] {"alfresco/scheduler-core-context.xml", "org/alfresco/util/test-scheduled-jobs-context.xml"};
|
"classpath:alfresco/scheduler-core-context.xml",
|
||||||
|
"classpath:org/alfresco/heartbeat/test-heartbeat-context.xml"};
|
||||||
private ApplicationContext context;
|
private ApplicationContext context;
|
||||||
|
|
||||||
LicenseService mockLicenseService;
|
LicenseService mockLicenseService;
|
||||||
@@ -60,7 +62,6 @@ public class HeartBeatTest
|
|||||||
@Before
|
@Before
|
||||||
public void setUp()
|
public void setUp()
|
||||||
{
|
{
|
||||||
|
|
||||||
// New context with scheduler
|
// New context with scheduler
|
||||||
context = new ClassPathXmlApplicationContext(CONFIG_LOCATIONS);
|
context = new ClassPathXmlApplicationContext(CONFIG_LOCATIONS);
|
||||||
|
|
||||||
@@ -71,13 +72,11 @@ public class HeartBeatTest
|
|||||||
((ConfigurableApplicationContext) context).getBeanFactory().registerSingleton("hbDataCollectorService",mockDataCollectorService);
|
((ConfigurableApplicationContext) context).getBeanFactory().registerSingleton("hbDataCollectorService",mockDataCollectorService);
|
||||||
|
|
||||||
mockDataSenderService = mock(HBDataSenderService.class);
|
mockDataSenderService = mock(HBDataSenderService.class);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHBRegistersWithLicenceService()
|
public void testHBRegistersWithLicenceService()
|
||||||
{
|
{
|
||||||
|
|
||||||
HeartBeat heartbeat = new HeartBeat(context,false);
|
HeartBeat heartbeat = new HeartBeat(context,false);
|
||||||
|
|
||||||
// Check that HearBeat registers itself with the licence service
|
// Check that HearBeat registers itself with the licence service
|
||||||
@@ -87,7 +86,6 @@ public class HeartBeatTest
|
|||||||
@Test
|
@Test
|
||||||
public void testJobSchedulingWhenEnabled()
|
public void testJobSchedulingWhenEnabled()
|
||||||
{
|
{
|
||||||
|
|
||||||
// Enable heartbeat in data collector service ( as if set in prop file)
|
// Enable heartbeat in data collector service ( as if set in prop file)
|
||||||
when(mockDataCollectorService.isEnabledByDefault()).thenReturn(true);
|
when(mockDataCollectorService.isEnabledByDefault()).thenReturn(true);
|
||||||
|
|
||||||
@@ -97,29 +95,24 @@ public class HeartBeatTest
|
|||||||
assertTrue("Job was not scheduled but HB is enabled", isJobScheduled());
|
assertTrue("Job was not scheduled but HB is enabled", isJobScheduled());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJobSchedulingWhenDisabled()
|
public void testJobSchedulingWhenDisabled()
|
||||||
{
|
{
|
||||||
|
|
||||||
// Disable heartbeat in data collector service ( as if set in prop file)
|
// Disable heartbeat in data collector service ( as if set in prop file)
|
||||||
when(mockDataCollectorService.isEnabledByDefault()).thenReturn(false);
|
when(mockDataCollectorService.isEnabledByDefault()).thenReturn(false);
|
||||||
|
|
||||||
HeartBeat heartbeat = new HeartBeat(context,true);
|
HeartBeat heartbeat = new HeartBeat(context,true);
|
||||||
|
|
||||||
// Check that the job is scheduled when heartbeat is disabled
|
// Check that the job is not scheduled when heartbeat is disabled
|
||||||
assertFalse("Job was scheduled but HB is disabled", isJobScheduled());
|
assertFalse("Job was scheduled but HB is disabled", isJobScheduled());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Heartbeat enabled by default but disabled in licence on onLicenseChange
|
* Heartbeat enabled by default but disabled in licence on onLicenseChange
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testOnLicenseChangeOverridesDefaultEnabled()
|
public void testOnLicenseChangeOverridesDefaultEnabled()
|
||||||
{
|
{
|
||||||
|
|
||||||
// Enable heartbeat in data collector service ( as if set in prop file)
|
// Enable heartbeat in data collector service ( as if set in prop file)
|
||||||
when(mockDataCollectorService.isEnabledByDefault()).thenReturn(true);
|
when(mockDataCollectorService.isEnabledByDefault()).thenReturn(true);
|
||||||
|
|
||||||
@@ -137,7 +130,6 @@ public class HeartBeatTest
|
|||||||
// Check heartbeat is disabled and job unscheduled
|
// Check heartbeat is disabled and job unscheduled
|
||||||
assertFalse(heartbeat.isEnabled());
|
assertFalse(heartbeat.isEnabled());
|
||||||
assertFalse("Job should be unscheduled.",isJobScheduled());
|
assertFalse("Job should be unscheduled.",isJobScheduled());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -165,11 +157,9 @@ public class HeartBeatTest
|
|||||||
assertTrue("Job should be scheduled.",isJobScheduled());
|
assertTrue("Job should be scheduled.",isJobScheduled());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOnLicenceFailRevertsToEnabled()
|
public void testOnLicenceFailRevertsToEnabled()
|
||||||
{
|
{
|
||||||
|
|
||||||
// Enable heartbeat in data collector service ( as if set in prop file)
|
// Enable heartbeat in data collector service ( as if set in prop file)
|
||||||
when(mockDataCollectorService.isEnabledByDefault()).thenReturn(true);
|
when(mockDataCollectorService.isEnabledByDefault()).thenReturn(true);
|
||||||
|
|
||||||
@@ -189,15 +179,11 @@ public class HeartBeatTest
|
|||||||
// Check heartbeat is disabled and job unscheduled
|
// Check heartbeat is disabled and job unscheduled
|
||||||
assertTrue(heartbeat.isEnabled());
|
assertTrue(heartbeat.isEnabled());
|
||||||
assertTrue("Job should be unscheduled.",isJobScheduled());
|
assertTrue("Job should be unscheduled.",isJobScheduled());
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOnLicenceFailRevertsToDisabled()
|
public void testOnLicenceFailRevertsToDisabled()
|
||||||
{
|
{
|
||||||
|
|
||||||
// Disable heartbeat in data collector service ( as if set in prop file)
|
// Disable heartbeat in data collector service ( as if set in prop file)
|
||||||
when(mockDataCollectorService.isEnabledByDefault()).thenReturn(false);
|
when(mockDataCollectorService.isEnabledByDefault()).thenReturn(false);
|
||||||
|
|
||||||
@@ -217,22 +203,21 @@ public class HeartBeatTest
|
|||||||
// Check heartbeat is disabled and job unscheduled
|
// Check heartbeat is disabled and job unscheduled
|
||||||
assertFalse(heartbeat.isEnabled());
|
assertFalse(heartbeat.isEnabled());
|
||||||
assertFalse("Job should be unscheduled.",isJobScheduled());
|
assertFalse("Job should be unscheduled.",isJobScheduled());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private boolean isJobScheduled()
|
private boolean isJobScheduled()
|
||||||
{
|
{
|
||||||
Scheduler scheduler = (Scheduler) context.getBean("schedulerFactory");
|
Scheduler scheduler = (Scheduler) context.getBean("schedulerFactory");
|
||||||
String[] jobs = {};
|
String[] jobs = {};
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
jobs = scheduler.getJobNames( Scheduler.DEFAULT_GROUP);
|
jobs = scheduler.getJobNames( Scheduler.DEFAULT_GROUP);
|
||||||
} catch (SchedulerException e) {
|
} catch (SchedulerException e)
|
||||||
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
fail("Exception before assertion.");
|
fail("Exception before assertion.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return Arrays.asList(jobs).contains("heartbeat");
|
return Arrays.asList(jobs).contains("heartbeat");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user