mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-01 14:41:46 +00:00
ACS-8323 Extend the possibility to configure the event sending strategy (#2765)
This commit is contained in:
@@ -44,11 +44,6 @@ import org.junit.runners.Suite;
|
||||
@RunWith(Categories.class)
|
||||
@Categories.ExcludeCategory({DBTests.class, NonBuildTests.class})
|
||||
@Suite.SuiteClasses({
|
||||
// Requires a running ActiveMQ
|
||||
org.alfresco.repo.rawevents.EventBehaviourTest.class,
|
||||
org.alfresco.repo.rawevents.TransactionAwareEventProducerTest.class,
|
||||
org.alfresco.repo.event2.RepoEvent2ITSuite.class,
|
||||
|
||||
// Requires running transformers
|
||||
org.alfresco.transform.registry.LocalTransformServiceRegistryConfigTest.class,
|
||||
org.alfresco.repo.rendition2.RenditionService2IntegrationTest.class,
|
||||
@@ -71,7 +66,12 @@ import org.junit.runners.Suite;
|
||||
org.alfresco.repo.blog.BlogServiceImplTest.class,
|
||||
org.alfresco.repo.action.scheduled.ScheduledPersistedActionServiceTest.class,
|
||||
|
||||
org.alfresco.repo.rendition2.RenditionDefinitionTest.class
|
||||
org.alfresco.repo.rendition2.RenditionDefinitionTest.class,
|
||||
|
||||
// Requires a running ActiveMQ
|
||||
org.alfresco.repo.rawevents.EventBehaviourTest.class,
|
||||
org.alfresco.repo.rawevents.TransactionAwareEventProducerTest.class,
|
||||
org.alfresco.repo.event2.RepoEvent2ITSuite.class,
|
||||
})
|
||||
public class AppContext06TestSuite
|
||||
{
|
||||
|
@@ -2,7 +2,7 @@
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2023 Alfresco Software Limited
|
||||
* Copyright (C) 2005 - 2024 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
@@ -71,14 +71,14 @@ import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
|
||||
/**
|
||||
* @author Iulian Aftene
|
||||
*/
|
||||
|
||||
@TestPropertySource(properties = {"repo.event2.queue.skip=false"})
|
||||
public abstract class AbstractContextAwareRepoEvent extends BaseSpringTest
|
||||
{
|
||||
protected static final boolean DEBUG = false;
|
||||
@@ -123,9 +123,6 @@ public abstract class AbstractContextAwareRepoEvent extends BaseSpringTest
|
||||
@Autowired
|
||||
private NamespaceDAO namespaceDAO;
|
||||
|
||||
@Value("${repo.event2.queue.skip}")
|
||||
protected boolean skipEventQueue;
|
||||
|
||||
protected NodeRef rootNodeRef;
|
||||
|
||||
@BeforeClass
|
||||
|
@@ -2,7 +2,7 @@
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2023 Alfresco Software Limited
|
||||
* Copyright (C) 2005 - 2024 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
@@ -25,78 +25,32 @@
|
||||
*/
|
||||
package org.alfresco.repo.event2;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.ContextHierarchy;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
|
||||
@ContextHierarchy({
|
||||
// Context hierarchy inherits context config from parent classes and extends it with TestConfig from this class
|
||||
@ContextConfiguration(classes = DirectEventGeneratorTest.TestConfig.class)
|
||||
})
|
||||
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
|
||||
import java.util.Collection;
|
||||
|
||||
@TestPropertySource(properties = {"repo.event2.queue.skip=true"})
|
||||
public class DirectEventGeneratorTest extends EventGeneratorTest
|
||||
{
|
||||
@Autowired
|
||||
private InstantiatedBeansRegistry instantiatedBeansRegistry;
|
||||
|
||||
private EventSender eventSender;
|
||||
@Autowired
|
||||
private EventSender directEventSender;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass()
|
||||
{
|
||||
System.setProperty("repo.event2.queue.skip", "true");
|
||||
}
|
||||
private Collection<EventSender> allEventSenderBeans;
|
||||
|
||||
@Test
|
||||
public void testIfEnqueuingEventSenderIsNotInstantiated()
|
||||
public void testIfOnlyRequiredEventSenderIsInstantiated()
|
||||
{
|
||||
final Set<String> instantiatedBeans = this.instantiatedBeansRegistry.getBeans();
|
||||
|
||||
assertTrue(skipEventQueue);
|
||||
assertFalse(instantiatedBeans.contains("enqueuingEventSender"));
|
||||
assertEquals(1, allEventSenderBeans.size());
|
||||
assertTrue(allEventSenderBeans.contains(eventSender));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testIfDirectSenderIsSetInEventGenerator()
|
||||
{
|
||||
assertTrue(skipEventQueue);
|
||||
assertEquals(directEventSender, eventGenerator.getEventSender());
|
||||
}
|
||||
|
||||
@Configuration
|
||||
public static class TestConfig
|
||||
{
|
||||
@Bean
|
||||
public BeanPostProcessor instantiatedBeansRegistry()
|
||||
{
|
||||
return new InstantiatedBeansRegistry();
|
||||
}
|
||||
}
|
||||
|
||||
protected static class InstantiatedBeansRegistry implements BeanPostProcessor
|
||||
{
|
||||
private final Set<String> registeredBeans = new HashSet<>();
|
||||
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(final Object bean, final String beanName) throws BeansException
|
||||
{
|
||||
registeredBeans.add(beanName);
|
||||
return bean;
|
||||
}
|
||||
|
||||
public Set<String> getBeans() {
|
||||
return registeredBeans;
|
||||
}
|
||||
assertEquals(DirectEventSender.class, eventSender.getClass());
|
||||
assertEquals(eventSender, eventGenerator.getEventSender());
|
||||
}
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2023 Alfresco Software Limited
|
||||
* Copyright (C) 2005 - 2024 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
@@ -27,9 +27,9 @@ package org.alfresco.repo.event2;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
|
||||
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
|
||||
@TestPropertySource(properties = {"repo.event2.queue.skip=false"})
|
||||
public class EnqueuingEventGeneratorTest extends EventGeneratorTest
|
||||
{
|
||||
@Autowired
|
||||
@@ -38,7 +38,7 @@ public class EnqueuingEventGeneratorTest extends EventGeneratorTest
|
||||
@Test
|
||||
public void testIfEnqueuingSenderIsSetInEventGenerator()
|
||||
{
|
||||
assertFalse(skipEventQueue);
|
||||
assertEquals(EnqueuingEventSender.class, enqueuingEventSender.getClass());
|
||||
assertEquals(enqueuingEventSender, eventGenerator.getEventSender());
|
||||
}
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2023 Alfresco Software Limited
|
||||
* Copyright (C) 2005 - 2024 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
@@ -65,15 +65,11 @@ public class EnqueuingEventSenderUnitTest
|
||||
@Before
|
||||
public void setup()
|
||||
{
|
||||
eventSender = new EnqueuingEventSender();
|
||||
|
||||
enqueuePool = newThreadPool();
|
||||
eventSender.setEnqueueThreadPoolExecutor(enqueuePool);
|
||||
dequeuePool = newThreadPool();
|
||||
eventSender.setDequeueThreadPoolExecutor(dequeuePool);
|
||||
|
||||
bus = mock(Event2MessageProducer.class);
|
||||
eventSender.setEvent2MessageProducer(bus);
|
||||
enqueuePool = newThreadPool();
|
||||
dequeuePool = newThreadPool();
|
||||
eventSender = new EnqueuingEventSender(bus, enqueuePool, dequeuePool);
|
||||
eventSender.initialize();
|
||||
|
||||
events = new HashMap<>();
|
||||
|
||||
|
@@ -2,7 +2,7 @@
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2023 Alfresco Software Limited
|
||||
* Copyright (C) 2005 - 2024 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
@@ -49,7 +49,6 @@ import org.apache.activemq.command.ActiveMQTopic;
|
||||
import org.awaitility.Awaitility;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
public abstract class EventGeneratorTest extends AbstractContextAwareRepoEvent
|
||||
@@ -60,12 +59,6 @@ public abstract class EventGeneratorTest extends AbstractContextAwareRepoEvent
|
||||
private ActiveMQConnection connection;
|
||||
protected List<RepoEvent<?>> receivedEvents;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass()
|
||||
{
|
||||
System.setProperty("repo.event2.queue.skip", "false");
|
||||
}
|
||||
|
||||
@Before
|
||||
public void startupTopicListener() throws Exception
|
||||
{
|
||||
|
Reference in New Issue
Block a user