mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-01 14:41:46 +00:00
ACS-5451: Toggle for direct Event sending (#2082)
* ACS-5451: Toggle for direct Event sending - added new bean allowing direct event sending and a toggle (switch) property - refactored EventGenerator logic related with creating and sending events - refactored consolidators - renamed EventConsolidator -> NodeEventConsolidator, and moved common logic to new abstract EventConsolidator - added integration tests - added JavaDoc - refactored events related tests
This commit is contained in:
committed by
GitHub
parent
3c242bc62b
commit
e8a27dd68d
@@ -23,7 +23,6 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.event2;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
@@ -72,6 +71,7 @@ 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;
|
||||
|
||||
@@ -108,23 +108,24 @@ public abstract class AbstractContextAwareRepoEvent extends BaseSpringTest
|
||||
@Autowired
|
||||
protected CustomModelService customModelService;
|
||||
|
||||
@Qualifier("descriptorComponent")
|
||||
@Autowired
|
||||
@Qualifier("descriptorComponent")
|
||||
protected DescriptorService descriptorService;
|
||||
|
||||
@Autowired
|
||||
protected ObjectMapper event2ObjectMapper;
|
||||
@Qualifier("event2ObjectMapper")
|
||||
protected ObjectMapper objectMapper;
|
||||
|
||||
@Autowired @Qualifier("eventGeneratorV2")
|
||||
@Autowired
|
||||
@Qualifier("eventGeneratorV2")
|
||||
protected EventGenerator eventGenerator;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("eventGeneratorQueue")
|
||||
protected EventGeneratorQueue eventQueue;
|
||||
|
||||
@Autowired
|
||||
private NamespaceDAO namespaceDAO;
|
||||
|
||||
@Value("${repo.event2.queue.skip}")
|
||||
protected boolean skipEventQueue;
|
||||
|
||||
protected NodeRef rootNodeRef;
|
||||
|
||||
@BeforeClass
|
||||
@@ -134,7 +135,7 @@ public abstract class AbstractContextAwareRepoEvent extends BaseSpringTest
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterAll() throws Exception
|
||||
public static void afterAll()
|
||||
{
|
||||
CAMEL_CONTEXT.stop();
|
||||
}
|
||||
@@ -144,7 +145,7 @@ public abstract class AbstractContextAwareRepoEvent extends BaseSpringTest
|
||||
{
|
||||
if (!isCamelConfigured)
|
||||
{
|
||||
dataFormat = new JacksonDataFormat(event2ObjectMapper, RepoEvent.class);
|
||||
dataFormat = new JacksonDataFormat(objectMapper, RepoEvent.class);
|
||||
configRoute();
|
||||
isCamelConfigured = true;
|
||||
}
|
||||
|
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2023 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.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.context.ContextConfiguration;
|
||||
import org.springframework.test.context.ContextHierarchy;
|
||||
|
||||
@ContextHierarchy({
|
||||
// Context hierarchy inherits context config from parent classes and extends it with TestConfig from this class
|
||||
@ContextConfiguration(classes = DirectEventGeneratorTest.TestConfig.class)
|
||||
})
|
||||
public class DirectEventGeneratorTest extends EventGeneratorTest
|
||||
{
|
||||
@Autowired
|
||||
private InstantiatedBeansRegistry instantiatedBeansRegistry;
|
||||
|
||||
@Autowired
|
||||
private EventSender directEventSender;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass()
|
||||
{
|
||||
System.setProperty("repo.event2.queue.skip", "true");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIfEnqueuingEventSenderIsNotInstantiated()
|
||||
{
|
||||
final Set<String> instantiatedBeans = this.instantiatedBeansRegistry.getBeans();
|
||||
|
||||
assertTrue(skipEventQueue);
|
||||
assertFalse(instantiatedBeans.contains("enqueuingEventSender"));
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2023 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.repo.event2;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
public class EnqueuingEventGeneratorTest extends EventGeneratorTest
|
||||
{
|
||||
@Autowired
|
||||
private EventSender enqueuingEventSender;
|
||||
|
||||
@Test
|
||||
public void testIfEnqueuingSenderIsSetInEventGenerator()
|
||||
{
|
||||
assertFalse(skipEventQueue);
|
||||
assertEquals(enqueuingEventSender, eventGenerator.getEventSender());
|
||||
}
|
||||
}
|
@@ -2,7 +2,7 @@
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2021 Alfresco Software Limited
|
||||
* Copyright (C) 2005 - 2023 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
@@ -35,6 +35,7 @@ import static org.mockito.Mockito.when;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.Executor;
|
||||
@@ -51,9 +52,9 @@ import org.mockito.Mockito;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
public class EventGeneratorQueueUnitTest
|
||||
public class EnqueuingEventSenderUnitTest
|
||||
{
|
||||
private EventGeneratorQueue queue;
|
||||
private EnqueuingEventSender eventSender;
|
||||
|
||||
private Event2MessageProducer bus;
|
||||
private ExecutorService enqueuePool;
|
||||
@@ -64,15 +65,15 @@ public class EventGeneratorQueueUnitTest
|
||||
@Before
|
||||
public void setup()
|
||||
{
|
||||
queue = new EventGeneratorQueue();
|
||||
eventSender = new EnqueuingEventSender();
|
||||
|
||||
enqueuePool = newThreadPool();
|
||||
queue.setEnqueueThreadPoolExecutor(enqueuePool);
|
||||
eventSender.setEnqueueThreadPoolExecutor(enqueuePool);
|
||||
dequeuePool = newThreadPool();
|
||||
queue.setDequeueThreadPoolExecutor(dequeuePool);
|
||||
eventSender.setDequeueThreadPoolExecutor(dequeuePool);
|
||||
|
||||
bus = mock(Event2MessageProducer.class);
|
||||
queue.setEvent2MessageProducer(bus);
|
||||
eventSender.setEvent2MessageProducer(bus);
|
||||
|
||||
events = new HashMap<>();
|
||||
|
||||
@@ -83,6 +84,7 @@ public class EventGeneratorQueueUnitTest
|
||||
public void teardown()
|
||||
{
|
||||
enqueuePool.shutdown();
|
||||
dequeuePool.shutdown();
|
||||
}
|
||||
|
||||
private void setupEventsRecorder()
|
||||
@@ -104,7 +106,7 @@ public class EventGeneratorQueueUnitTest
|
||||
@Test
|
||||
public void shouldReceiveSingleQuickMessage() throws Exception
|
||||
{
|
||||
queue.accept(messageWithDelay("A", 55l));
|
||||
eventSender.accept(messageWithDelay("A", 55l));
|
||||
|
||||
sleep(150l);
|
||||
|
||||
@@ -115,7 +117,7 @@ public class EventGeneratorQueueUnitTest
|
||||
@Test
|
||||
public void shouldNotReceiveEventsWhenMessageIsNull() throws Exception
|
||||
{
|
||||
queue.accept(() -> { return null; });
|
||||
eventSender.accept(() -> { return null; });
|
||||
|
||||
sleep(150l);
|
||||
|
||||
@@ -124,9 +126,9 @@ public class EventGeneratorQueueUnitTest
|
||||
|
||||
@Test
|
||||
public void shouldReceiveMultipleMessagesPreservingOrderScenarioOne() throws Exception {
|
||||
queue.accept(messageWithDelay("A", 0l));
|
||||
queue.accept(messageWithDelay("B", 100l));
|
||||
queue.accept(messageWithDelay("C", 200l));
|
||||
eventSender.accept(messageWithDelay("A", 0l));
|
||||
eventSender.accept(messageWithDelay("B", 100l));
|
||||
eventSender.accept(messageWithDelay("C", 200l));
|
||||
|
||||
sleep(450l);
|
||||
|
||||
@@ -139,9 +141,9 @@ public class EventGeneratorQueueUnitTest
|
||||
@Test
|
||||
public void shouldReceiveMultipleMessagesPreservingOrderScenarioTwo() throws Exception
|
||||
{
|
||||
queue.accept(messageWithDelay("A", 300l));
|
||||
queue.accept(messageWithDelay("B", 150l));
|
||||
queue.accept(messageWithDelay("C", 0l));
|
||||
eventSender.accept(messageWithDelay("A", 300l));
|
||||
eventSender.accept(messageWithDelay("B", 150l));
|
||||
eventSender.accept(messageWithDelay("C", 0l));
|
||||
|
||||
sleep(950l);
|
||||
|
||||
@@ -154,10 +156,10 @@ public class EventGeneratorQueueUnitTest
|
||||
@Test
|
||||
public void shouldReceiveMultipleMessagesPreservingOrderEvenWhenMakerPoisoned() throws Exception
|
||||
{
|
||||
queue.accept(messageWithDelay("A", 300l));
|
||||
queue.accept(() -> {throw new RuntimeException("Boom! (not to worry, this is a test)");});
|
||||
queue.accept(messageWithDelay("B", 55l));
|
||||
queue.accept(messageWithDelay("C", 0l));
|
||||
eventSender.accept(messageWithDelay("A", 300l));
|
||||
eventSender.accept(() -> {throw new RuntimeException("Boom! (not to worry, this is a test)");});
|
||||
eventSender.accept(messageWithDelay("B", 55l));
|
||||
eventSender.accept(messageWithDelay("C", 0l));
|
||||
|
||||
sleep(950l);
|
||||
|
||||
@@ -170,12 +172,12 @@ public class EventGeneratorQueueUnitTest
|
||||
@Test
|
||||
public void shouldReceiveMultipleMessagesPreservingOrderEvenWhenSenderPoisoned() throws Exception
|
||||
{
|
||||
Callable<RepoEvent<?>> makerB = messageWithDelay("B", 55l);
|
||||
RepoEvent<?> messageB = makerB.call();
|
||||
Callable<Optional<RepoEvent<?>>> makerB = messageWithDelay("B", 55l);
|
||||
RepoEvent<?> messageB = makerB.call().get();
|
||||
doThrow(new RuntimeException("Boom! (not to worry, this is a test)")).when(bus).send(messageB);
|
||||
queue.accept(messageWithDelay("A", 300l));
|
||||
queue.accept(makerB);
|
||||
queue.accept(messageWithDelay("C", 0l));
|
||||
eventSender.accept(messageWithDelay("A", 300l));
|
||||
eventSender.accept(makerB);
|
||||
eventSender.accept(messageWithDelay("C", 0l));
|
||||
|
||||
sleep(950l);
|
||||
|
||||
@@ -187,10 +189,10 @@ public class EventGeneratorQueueUnitTest
|
||||
@Test
|
||||
public void shouldReceiveMultipleMessagesPreservingOrderEvenWhenMakerPoisonedWithError() throws Exception
|
||||
{
|
||||
queue.accept(messageWithDelay("A", 300l));
|
||||
queue.accept(() -> {throw new OutOfMemoryError("Boom! (not to worry, this is a test)");});
|
||||
queue.accept(messageWithDelay("B", 55l));
|
||||
queue.accept(messageWithDelay("C", 0l));
|
||||
eventSender.accept(messageWithDelay("A", 300l));
|
||||
eventSender.accept(() -> {throw new OutOfMemoryError("Boom! (not to worry, this is a test)");});
|
||||
eventSender.accept(messageWithDelay("B", 55l));
|
||||
eventSender.accept(messageWithDelay("C", 0l));
|
||||
|
||||
sleep(950l);
|
||||
|
||||
@@ -203,12 +205,12 @@ public class EventGeneratorQueueUnitTest
|
||||
@Test
|
||||
public void shouldReceiveMultipleMessagesPreservingOrderEvenWhenSenderPoisonedWithError() throws Exception
|
||||
{
|
||||
Callable<RepoEvent<?>> makerB = messageWithDelay("B", 55l);
|
||||
RepoEvent<?> messageB = makerB.call();
|
||||
Callable<Optional<RepoEvent<?>>> makerB = messageWithDelay("B", 55l);
|
||||
RepoEvent<?> messageB = makerB.call().get();
|
||||
doThrow(new OutOfMemoryError("Boom! (not to worry, this is a test)")).when(bus).send(messageB);
|
||||
queue.accept(messageWithDelay("A", 300l));
|
||||
queue.accept(makerB);
|
||||
queue.accept(messageWithDelay("C", 0l));
|
||||
eventSender.accept(messageWithDelay("A", 300l));
|
||||
eventSender.accept(makerB);
|
||||
eventSender.accept(messageWithDelay("C", 0l));
|
||||
|
||||
sleep(950l);
|
||||
|
||||
@@ -217,33 +219,32 @@ public class EventGeneratorQueueUnitTest
|
||||
assertEquals("C", recordedEvents.get(1).getId());
|
||||
}
|
||||
|
||||
private Callable<RepoEvent<?>> messageWithDelay(String id, long delay)
|
||||
private Callable<Optional<RepoEvent<?>>> messageWithDelay(String id, long delay)
|
||||
{
|
||||
Callable<RepoEvent<?>> res = new Callable<RepoEvent<?>>() {
|
||||
|
||||
return new Callable<Optional<RepoEvent<?>>>()
|
||||
{
|
||||
@Override
|
||||
public RepoEvent<?> call() throws Exception
|
||||
public Optional<RepoEvent<?>> call() throws Exception
|
||||
{
|
||||
if(delay != 0)
|
||||
if (delay != 0)
|
||||
{
|
||||
sleep(delay);
|
||||
sleep(delay);
|
||||
}
|
||||
return newRepoEvent(id);
|
||||
}
|
||||
|
||||
return Optional.of(newRepoEvent(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
};
|
||||
return res;
|
||||
}
|
||||
|
||||
private RepoEvent<?> newRepoEvent(String id)
|
||||
{
|
||||
RepoEvent<?> ev = events.get(id);
|
||||
if (ev!=null)
|
||||
if (ev != null)
|
||||
return ev;
|
||||
|
||||
ev = mock(RepoEvent.class);
|
@@ -2,7 +2,7 @@
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2020 Alfresco Software Limited
|
||||
* Copyright (C) 2005 - 2023 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
@@ -43,7 +43,7 @@ public class EventConsolidatorUnitTest
|
||||
@Test
|
||||
public void testGetMappedAspectsBeforeRemovedAndAddedEmpty()
|
||||
{
|
||||
EventConsolidator eventConsolidator = new EventConsolidator(nodeResourceHelper);
|
||||
NodeEventConsolidator eventConsolidator = new NodeEventConsolidator(nodeResourceHelper);
|
||||
|
||||
Set<String> currentAspects = new HashSet<>();
|
||||
currentAspects.add("cm:geographic");
|
||||
@@ -57,7 +57,7 @@ public class EventConsolidatorUnitTest
|
||||
@Test
|
||||
public void testGetMappedAspectsBefore_AspectRemoved()
|
||||
{
|
||||
EventConsolidator eventConsolidator = new EventConsolidator(nodeResourceHelper);
|
||||
NodeEventConsolidator eventConsolidator = new NodeEventConsolidator(nodeResourceHelper);
|
||||
eventConsolidator.addAspect(ContentModel.ASSOC_CONTAINS);
|
||||
|
||||
Set<String> currentAspects = new HashSet<>();
|
||||
@@ -79,7 +79,7 @@ public class EventConsolidatorUnitTest
|
||||
@Test
|
||||
public void testGetMappedAspectsBefore_AspectAdded()
|
||||
{
|
||||
EventConsolidator eventConsolidator = new EventConsolidator(nodeResourceHelper);
|
||||
NodeEventConsolidator eventConsolidator = new NodeEventConsolidator(nodeResourceHelper);
|
||||
eventConsolidator.addAspect(ContentModel.ASSOC_CONTAINS);
|
||||
|
||||
Set<String> currentAspects = new HashSet<>();
|
||||
@@ -102,7 +102,7 @@ public class EventConsolidatorUnitTest
|
||||
@Test
|
||||
public void testGetMappedAspectsBefore_AspectAddedAndRemoved()
|
||||
{
|
||||
EventConsolidator eventConsolidator = new EventConsolidator(nodeResourceHelper);
|
||||
NodeEventConsolidator eventConsolidator = new NodeEventConsolidator(nodeResourceHelper);
|
||||
eventConsolidator.addAspect(ContentModel.ASSOC_CONTAINS);
|
||||
|
||||
Set<String> currentAspects = new HashSet<>();
|
||||
@@ -125,7 +125,7 @@ public class EventConsolidatorUnitTest
|
||||
@Test
|
||||
public void testGetMappedAspectsBefore_AspectRemovedAndAdded()
|
||||
{
|
||||
EventConsolidator eventConsolidator = new EventConsolidator(nodeResourceHelper);
|
||||
NodeEventConsolidator eventConsolidator = new NodeEventConsolidator(nodeResourceHelper);
|
||||
eventConsolidator.addAspect(ContentModel.ASSOC_CONTAINS);
|
||||
eventConsolidator.removeAspect(ContentModel.ASSOC_CONTAINS);
|
||||
|
||||
@@ -150,7 +150,7 @@ public class EventConsolidatorUnitTest
|
||||
@Test
|
||||
public void testGetMappedAspectsBefore_AspectAddedTwiceRemovedOnce()
|
||||
{
|
||||
EventConsolidator eventConsolidator = new EventConsolidator(nodeResourceHelper);
|
||||
NodeEventConsolidator eventConsolidator = new NodeEventConsolidator(nodeResourceHelper);
|
||||
|
||||
eventConsolidator.addAspect(ContentModel.ASSOC_CONTAINS);
|
||||
eventConsolidator.addAspect(ContentModel.ASSOC_CONTAINS);
|
||||
@@ -178,7 +178,7 @@ public class EventConsolidatorUnitTest
|
||||
@Test
|
||||
public void testGetMappedAspectsBefore_AspectRemovedTwiceAddedOnce()
|
||||
{
|
||||
EventConsolidator eventConsolidator = new EventConsolidator(nodeResourceHelper);
|
||||
NodeEventConsolidator eventConsolidator = new NodeEventConsolidator(nodeResourceHelper);
|
||||
|
||||
eventConsolidator.addAspect(ContentModel.ASSOC_CONTAINS);
|
||||
eventConsolidator.addAspect(ContentModel.ASSOC_CONTAINS);
|
||||
@@ -206,7 +206,7 @@ public class EventConsolidatorUnitTest
|
||||
@Test
|
||||
public void testGetMappedAspectsBefore_FilteredAspectAdded()
|
||||
{
|
||||
EventConsolidator eventConsolidator = new EventConsolidator(nodeResourceHelper);
|
||||
NodeEventConsolidator eventConsolidator = new NodeEventConsolidator(nodeResourceHelper);
|
||||
eventConsolidator.addAspect(ContentModel.ASPECT_COPIEDFROM);
|
||||
|
||||
Set<String> currentAspects = new HashSet<>();
|
||||
@@ -227,7 +227,7 @@ public class EventConsolidatorUnitTest
|
||||
@Test
|
||||
public void testAddAspect()
|
||||
{
|
||||
EventConsolidator eventConsolidator = new EventConsolidator(nodeResourceHelper);
|
||||
NodeEventConsolidator eventConsolidator = new NodeEventConsolidator(nodeResourceHelper);
|
||||
eventConsolidator.addAspect(ContentModel.ASSOC_CONTAINS);
|
||||
|
||||
assertEquals(1, eventConsolidator.getAspectsAdded().size());
|
||||
@@ -238,7 +238,7 @@ public class EventConsolidatorUnitTest
|
||||
@Test
|
||||
public void testRemoveAspect()
|
||||
{
|
||||
EventConsolidator eventConsolidator = new EventConsolidator(nodeResourceHelper);
|
||||
NodeEventConsolidator eventConsolidator = new NodeEventConsolidator(nodeResourceHelper);
|
||||
eventConsolidator.removeAspect(ContentModel.ASSOC_CONTAINS);
|
||||
|
||||
assertEquals(0, eventConsolidator.getAspectsAdded().size());
|
||||
@@ -249,7 +249,7 @@ public class EventConsolidatorUnitTest
|
||||
@Test
|
||||
public void testAddAspectRemoveAspect()
|
||||
{
|
||||
EventConsolidator eventConsolidator = new EventConsolidator(nodeResourceHelper);
|
||||
NodeEventConsolidator eventConsolidator = new NodeEventConsolidator(nodeResourceHelper);
|
||||
eventConsolidator.addAspect(ContentModel.ASSOC_CONTAINS);
|
||||
eventConsolidator.removeAspect(ContentModel.ASSOC_CONTAINS);
|
||||
|
||||
@@ -260,7 +260,7 @@ public class EventConsolidatorUnitTest
|
||||
@Test
|
||||
public void testRemoveAspectAddAspect()
|
||||
{
|
||||
EventConsolidator eventConsolidator = new EventConsolidator(nodeResourceHelper);
|
||||
NodeEventConsolidator eventConsolidator = new NodeEventConsolidator(nodeResourceHelper);
|
||||
eventConsolidator.removeAspect(ContentModel.ASSOC_CONTAINS);
|
||||
eventConsolidator.addAspect(ContentModel.ASSOC_CONTAINS);
|
||||
|
||||
@@ -271,7 +271,7 @@ public class EventConsolidatorUnitTest
|
||||
@Test
|
||||
public void testAddAspectTwiceRemoveAspectOnce()
|
||||
{
|
||||
EventConsolidator eventConsolidator = new EventConsolidator(nodeResourceHelper);
|
||||
NodeEventConsolidator eventConsolidator = new NodeEventConsolidator(nodeResourceHelper);
|
||||
eventConsolidator.addAspect(ContentModel.ASSOC_CONTAINS);
|
||||
eventConsolidator.removeAspect(ContentModel.ASSOC_CONTAINS);
|
||||
eventConsolidator.addAspect(ContentModel.ASSOC_CONTAINS);
|
||||
@@ -284,7 +284,7 @@ public class EventConsolidatorUnitTest
|
||||
@Test
|
||||
public void testAddAspectOnceRemoveAspectTwice()
|
||||
{
|
||||
EventConsolidator eventConsolidator = new EventConsolidator(nodeResourceHelper);
|
||||
NodeEventConsolidator eventConsolidator = new NodeEventConsolidator(nodeResourceHelper);
|
||||
eventConsolidator.removeAspect(ContentModel.ASSOC_CONTAINS);
|
||||
eventConsolidator.addAspect(ContentModel.ASSOC_CONTAINS);
|
||||
eventConsolidator.removeAspect(ContentModel.ASSOC_CONTAINS);
|
||||
|
@@ -25,94 +25,16 @@
|
||||
*/
|
||||
package org.alfresco.repo.event2;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import jakarta.jms.Destination;
|
||||
import jakarta.jms.JMSException;
|
||||
import jakarta.jms.Message;
|
||||
import jakarta.jms.MessageConsumer;
|
||||
import jakarta.jms.MessageListener;
|
||||
import jakarta.jms.Session;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.event.v1.model.RepoEvent;
|
||||
import org.apache.activemq.ActiveMQConnection;
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.command.ActiveMQTextMessage;
|
||||
import org.awaitility.Awaitility;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
public class EventGeneratorDisabledTest extends AbstractContextAwareRepoEvent
|
||||
public class EventGeneratorDisabledTest extends EventGeneratorTest
|
||||
{
|
||||
private static final String EVENT2_TOPIC_NAME = "alfresco.repo.event2";
|
||||
private static final String BROKER_URL = "tcp://localhost:61616";
|
||||
|
||||
@Autowired @Qualifier("event2ObjectMapper")
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@Autowired
|
||||
protected ObjectMapper event2ObjectMapper;
|
||||
|
||||
//private EventGenerator eventGenerator;
|
||||
|
||||
private ActiveMQConnection connection;
|
||||
protected List<RepoEvent<?>> receivedEvents;
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception
|
||||
{
|
||||
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(BROKER_URL);
|
||||
connection = (ActiveMQConnection) connectionFactory.createConnection();
|
||||
connection.start();
|
||||
|
||||
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
Destination destination = session.createTopic(EVENT2_TOPIC_NAME);
|
||||
MessageConsumer consumer = session.createConsumer(destination);
|
||||
|
||||
receivedEvents = Collections.synchronizedList(new LinkedList<>());
|
||||
consumer.setMessageListener(new MessageListener()
|
||||
{
|
||||
@Override
|
||||
public void onMessage(Message message)
|
||||
{
|
||||
String text = getText(message);
|
||||
RepoEvent<?> event = toRepoEvent(text);
|
||||
receivedEvents.add(event);
|
||||
}
|
||||
|
||||
private RepoEvent<?> toRepoEvent(String json)
|
||||
{
|
||||
try
|
||||
{
|
||||
return objectMapper.readValue(json, RepoEvent.class);
|
||||
} catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@After
|
||||
public void shutdownTopicListener() throws Exception
|
||||
{
|
||||
connection.close();
|
||||
connection = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotReceiveEvent2EventsOnNodeCreation() throws Exception
|
||||
public void shouldNotReceiveEvent2EventsOnNodeCreation()
|
||||
{
|
||||
if (eventGenerator.isEnabled())
|
||||
{
|
||||
@@ -127,44 +49,29 @@ public class EventGeneratorDisabledTest extends AbstractContextAwareRepoEvent
|
||||
assertTrue(receivedEvents.size() == 0);
|
||||
|
||||
eventGenerator.enable();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReceiveEvent2EventsOnNodeCreation() throws Exception
|
||||
@Override
|
||||
public void shouldReceiveEvent2EventsOnNodeCreation()
|
||||
{
|
||||
if (!eventGenerator.isEnabled())
|
||||
{
|
||||
eventGenerator.enable();
|
||||
}
|
||||
|
||||
createNode(ContentModel.TYPE_CONTENT);
|
||||
|
||||
Awaitility.await().atMost(6, TimeUnit.SECONDS).until(() -> receivedEvents.size() == 1);
|
||||
|
||||
assertTrue(EVENT_CONTAINER.getEvents().size() == 1);
|
||||
assertTrue(receivedEvents.size() == 1);
|
||||
|
||||
RepoEvent<?> sent = getRepoEvent(1);
|
||||
RepoEvent<?> received = receivedEvents.get(0);
|
||||
assertEventsEquals("Events are different!", sent, received);
|
||||
}
|
||||
|
||||
private void assertEventsEquals(String message, RepoEvent<?> expected, RepoEvent<?> current)
|
||||
{
|
||||
assertEquals(message, expected, current);
|
||||
super.shouldReceiveEvent2EventsOnNodeCreation();
|
||||
}
|
||||
|
||||
private static String getText(Message message)
|
||||
@Test
|
||||
@Override
|
||||
public void shouldReceiveEvent2EventsInOrder()
|
||||
{
|
||||
try
|
||||
if (!eventGenerator.isEnabled())
|
||||
{
|
||||
ActiveMQTextMessage am = (ActiveMQTextMessage) message;
|
||||
return am.getText();
|
||||
} catch (JMSException e)
|
||||
{
|
||||
return null;
|
||||
eventGenerator.enable();
|
||||
}
|
||||
}
|
||||
|
||||
super.shouldReceiveEvent2EventsInOrder();
|
||||
}
|
||||
}
|
||||
|
@@ -39,7 +39,6 @@ import jakarta.jms.MessageListener;
|
||||
import jakarta.jms.Session;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.event.databind.ObjectMapperFactory;
|
||||
import org.alfresco.repo.event.v1.model.RepoEvent;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.apache.activemq.ActiveMQConnection;
|
||||
@@ -51,24 +50,25 @@ 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;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
public class EventGeneratorTest extends AbstractContextAwareRepoEvent
|
||||
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
|
||||
public abstract class EventGeneratorTest extends AbstractContextAwareRepoEvent
|
||||
{
|
||||
private static final String EVENT2_TOPIC_NAME = "alfresco.repo.event2";
|
||||
|
||||
private static final long DUMP_BROKER_TIMEOUT = 50000000l;
|
||||
|
||||
@Autowired @Qualifier("event2ObjectMapper")
|
||||
private ObjectMapper objectMapper;
|
||||
private static final long DUMP_BROKER_TIMEOUT = 50000000L;
|
||||
|
||||
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
|
||||
{
|
||||
@@ -116,11 +116,6 @@ public class EventGeneratorTest extends AbstractContextAwareRepoEvent
|
||||
}
|
||||
}
|
||||
|
||||
protected ObjectMapper createObjectMapper()
|
||||
{
|
||||
return ObjectMapperFactory.createInstance();
|
||||
}
|
||||
|
||||
@After
|
||||
public void shutdownTopicListener() throws Exception
|
||||
{
|
||||
@@ -129,30 +124,21 @@ public class EventGeneratorTest extends AbstractContextAwareRepoEvent
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReceiveEvent2EventsOnNodeCreation() throws Exception
|
||||
public void shouldReceiveEvent2EventsOnNodeCreation()
|
||||
{
|
||||
createNode(ContentModel.TYPE_CONTENT);
|
||||
|
||||
Awaitility.await().atMost(6, TimeUnit.SECONDS).until(() -> receivedEvents.size() == 1);
|
||||
|
||||
assertEquals(1, EVENT_CONTAINER.getEvents().size());
|
||||
assertEquals(1, receivedEvents.size());
|
||||
RepoEvent<?> sent = getRepoEvent(1);
|
||||
RepoEvent<?> received = receivedEvents.get(0);
|
||||
assertEventsEquals("Events are different!", sent, received);
|
||||
}
|
||||
|
||||
private void assertEventsEquals(String message, RepoEvent<?> expected, RepoEvent<?> current)
|
||||
{
|
||||
if (DEBUG)
|
||||
{
|
||||
System.err.println("XP: " + expected);
|
||||
System.err.println("CU: " + current);
|
||||
}
|
||||
|
||||
assertEquals(message, expected, current);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReceiveEvent2EventsInOrder() throws Exception
|
||||
public void shouldReceiveEvent2EventsInOrder()
|
||||
{
|
||||
NodeRef nodeRef = createNode(ContentModel.TYPE_CONTENT);
|
||||
updateNodeName(nodeRef, "TestFile-" + System.currentTimeMillis() + ".txt");
|
||||
@@ -163,9 +149,20 @@ public class EventGeneratorTest extends AbstractContextAwareRepoEvent
|
||||
RepoEvent<?> sentCreation = getRepoEvent(1);
|
||||
RepoEvent<?> sentUpdate = getRepoEvent(2);
|
||||
RepoEvent<?> sentDeletion = getRepoEvent(3);
|
||||
assertEquals("Expected create event!", sentCreation, (RepoEvent<?>) receivedEvents.get(0));
|
||||
assertEquals("Expected update event!", sentUpdate, (RepoEvent<?>) receivedEvents.get(1));
|
||||
assertEquals("Expected delete event!", sentDeletion, (RepoEvent<?>) receivedEvents.get(2));
|
||||
assertEquals("Expected create event!", sentCreation, receivedEvents.get(0));
|
||||
assertEquals("Expected update event!", sentUpdate, receivedEvents.get(1));
|
||||
assertEquals("Expected delete event!", sentDeletion, receivedEvents.get(2));
|
||||
}
|
||||
|
||||
private void assertEventsEquals(String message, RepoEvent<?> expected, RepoEvent<?> current)
|
||||
{
|
||||
if (DEBUG)
|
||||
{
|
||||
System.err.println("XP: " + expected);
|
||||
System.err.println("CU: " + current);
|
||||
}
|
||||
|
||||
assertEquals(message, expected, current);
|
||||
}
|
||||
|
||||
private static String getText(Message message)
|
||||
@@ -174,7 +171,8 @@ public class EventGeneratorTest extends AbstractContextAwareRepoEvent
|
||||
{
|
||||
ActiveMQTextMessage am = (ActiveMQTextMessage) message;
|
||||
return am.getText();
|
||||
} catch (JMSException e)
|
||||
}
|
||||
catch (JMSException e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -206,7 +204,8 @@ public class EventGeneratorTest extends AbstractContextAwareRepoEvent
|
||||
try
|
||||
{
|
||||
System.out.println("- " + queue.getQueueName());
|
||||
} catch (JMSException e)
|
||||
}
|
||||
catch (JMSException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -219,7 +218,8 @@ public class EventGeneratorTest extends AbstractContextAwareRepoEvent
|
||||
try
|
||||
{
|
||||
System.out.println("- " + topic.getTopicName());
|
||||
} catch (JMSException e)
|
||||
}
|
||||
catch (JMSException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -230,18 +230,14 @@ public class EventGeneratorTest extends AbstractContextAwareRepoEvent
|
||||
MessageConsumer consumer = session.createConsumer(destination);
|
||||
|
||||
System.out.println("\nListening to topic " + EVENT2_TOPIC_NAME + "...");
|
||||
consumer.setMessageListener(new MessageListener()
|
||||
{
|
||||
@Override
|
||||
public void onMessage(Message message)
|
||||
{
|
||||
String text = getText(message);
|
||||
System.out.println("Received message " + message + "\n" + text + "\n");
|
||||
}
|
||||
consumer.setMessageListener(message -> {
|
||||
String text = getText(message);
|
||||
System.out.println("Received message " + message + "\n" + text + "\n");
|
||||
});
|
||||
|
||||
Thread.sleep(timeout);
|
||||
} finally
|
||||
}
|
||||
finally
|
||||
{
|
||||
connection.close();
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2020 Alfresco Software Limited
|
||||
* Copyright (C) 2005 - 2023 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
@@ -35,7 +35,8 @@ import org.junit.runners.Suite.SuiteClasses;
|
||||
DeleteRepoEventIT.class,
|
||||
ChildAssociationRepoEventIT.class,
|
||||
PeerAssociationRepoEventIT.class,
|
||||
EventGeneratorTest.class,
|
||||
EnqueuingEventGeneratorTest.class,
|
||||
DirectEventGeneratorTest.class,
|
||||
EventGeneratorDisabledTest.class
|
||||
})
|
||||
public class RepoEvent2ITSuite
|
||||
|
@@ -23,7 +23,6 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.event2;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -34,7 +33,7 @@ import org.junit.runners.Suite.SuiteClasses;
|
||||
@SuiteClasses({ EventFilterUnitTest.class,
|
||||
EventConsolidatorUnitTest.class,
|
||||
EventJSONSchemaUnitTest.class,
|
||||
EventGeneratorQueueUnitTest.class,
|
||||
EnqueuingEventSenderUnitTest.class,
|
||||
NodeResourceHelperUnitTest.class
|
||||
})
|
||||
public class RepoEvent2UnitSuite
|
||||
|
Reference in New Issue
Block a user