FINERACT-1724: Implemented support for multiple parallel JMS producers for external events

This commit is contained in:
Arnold Galovics
2023-01-19 10:34:11 +01:00
committed by Arnold Gálovics
parent 54aae1c0a3
commit 7d28646c7d
45 changed files with 952 additions and 248 deletions
@@ -0,0 +1,62 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.infrastructure.core.service;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Random;
import org.junit.jupiter.api.Test;
class HashingServiceTest {
private final Random rnd = new Random();
private HashingService underTest = new HashingService();
@Test
public void testConsistentHashGeneratesHashesConsistentlyForTheSameValue() {
// given
int initialResult = underTest.consistentHash(1L, 20);
// when & then
for (int i = 0; i < 20_000; i++) {
int result = underTest.consistentHash(1L, 20);
assertThat(result).isEqualTo(initialResult);
}
}
@Test
public void testConsistentHashWorksForNegativeValues() {
// given
// when
int result = underTest.consistentHash(-1L, 20);
// then
assertThat(result).isBetween(0, 19);
}
@Test
public void testConsistentHashGeneratesHashesWithinBuckets() {
// given
int buckets = 10;
// when & then
for (int i = 0; i < 20_000; i++) {
int result = underTest.consistentHash(rnd.nextLong(), buckets);
assertThat(result).isLessThan(buckets);
}
}
}
@@ -0,0 +1,64 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.infrastructure.event.business.domain;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import java.util.List;
import org.apache.fineract.infrastructure.event.business.domain.client.ClientActivateBusinessEvent;
import org.apache.fineract.infrastructure.event.business.domain.client.ClientCreateBusinessEvent;
import org.apache.fineract.portfolio.client.domain.Client;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class BulkBusinessEventTest {
@Test
public void testConstructorWorksForSameAggregateId() {
// given
// when
new BulkBusinessEvent(List.of(new ClientCreateBusinessEvent(client(1L)), new ClientActivateBusinessEvent(client(1L))));
// then no exception thrown
}
@Test
public void testConstructorThrowsExceptionForDifferentAggregateId() {
// given
// when
Assertions.assertThrows(IllegalArgumentException.class, () -> new BulkBusinessEvent(
List.of(new ClientCreateBusinessEvent(client(1L)), new ClientActivateBusinessEvent(client(2L)))));
// then no exception thrown
}
@Test
public void testConstructorWorksForNullAggregateId() {
// given
// when
new BulkBusinessEvent(List.of(new ClientCreateBusinessEvent(client(1L)), new ClientActivateBusinessEvent(client(null))));
// then no exception thrown
}
private Client client(Long id) {
Client client = mock(Client.class);
given(client.getId()).willReturn(id);
return client;
}
}
@@ -226,6 +226,11 @@ class BusinessEventNotifierServiceImplTest {
public String getCategory() {
return null;
}
@Override
public Long getAggregateRootId() {
return null;
}
}
}
@@ -20,7 +20,6 @@ package org.apache.fineract.infrastructure.event.external.jobs;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -34,6 +33,7 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import org.apache.fineract.avro.MessageV1;
import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService;
@@ -43,8 +43,7 @@ import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
import org.apache.fineract.infrastructure.event.external.exception.AcknowledgementTimeoutException;
import org.apache.fineract.infrastructure.event.external.producer.ExternalEventProducer;
import org.apache.fineract.infrastructure.event.external.repository.ExternalEventRepository;
import org.apache.fineract.infrastructure.event.external.repository.domain.ExternalEvent;
import org.apache.fineract.infrastructure.event.external.repository.domain.ExternalEventStatus;
import org.apache.fineract.infrastructure.event.external.repository.domain.ExternalEventView;
import org.apache.fineract.infrastructure.event.external.service.message.MessageFactory;
import org.apache.fineract.infrastructure.event.external.service.support.ByteBufferConverter;
import org.junit.jupiter.api.BeforeEach;
@@ -54,12 +53,15 @@ import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.data.domain.Pageable;
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
class SendAsynchronousEventsTaskletTest {
@Mock
@@ -81,6 +83,8 @@ class SendAsynchronousEventsTaskletTest {
private SendAsynchronousEventsTasklet underTest;
private RepeatStatus resultStatus;
private Random rnd = new Random();
@BeforeEach
public void setUp() {
ThreadLocalContextUtil.setTenant(new FineractPlatformTenant(1L, "default", "Default", "Asia/Kolkata", null));
@@ -108,8 +112,9 @@ class SendAsynchronousEventsTaskletTest {
@Test
public void givenBatchSize2WhenTaskExecutionThenSend2Events() throws Exception {
// given
List<ExternalEvent> events = Arrays.asList(new ExternalEvent("aType", "aCategory", "aSchema", new byte[0], "aIdempotencyKey"),
new ExternalEvent("aType", "aCategory", "aSchema", new byte[0], "aIdempotencyKey"));
List<ExternalEventView> events = Arrays.asList(
createExternalEventView("aType", "aCategory", "aSchema", new byte[0], "aIdempotencyKey", 1L),
createExternalEventView("aType", "aCategory", "aSchema", new byte[0], "aIdempotencyKey", 1L));
// Dummy Message
MessageV1 dummyMessage = new MessageV1(1, "aSource", "aType", "nocategory", "aCreateDate", "aBusinessDate", "aTenantId",
"anidempotencyKey", "aSchema", Mockito.mock(ByteBuffer.class));
@@ -117,64 +122,95 @@ class SendAsynchronousEventsTaskletTest {
when(repository.findByStatusOrderById(Mockito.any(), Mockito.any())).thenReturn(events);
when(messageFactory.createMessage(Mockito.any())).thenReturn(dummyMessage);
when(byteBufferConverter.convert(Mockito.any(ByteBuffer.class))).thenReturn(new byte[0]);
doNothing().when(eventProducer).sendEvent(Mockito.any());
// when
resultStatus = this.underTest.execute(stepContribution, chunkContext);
resultStatus = underTest.execute(stepContribution, chunkContext);
// then
verify(eventProducer, times(2)).sendEvent(new byte[0]);
verify(repository, times(2)).save(Mockito.any(ExternalEvent.class));
verify(eventProducer).sendEvents(Mockito.any());
verify(repository).markEventsSent(Mockito.eq(events.stream().map(ExternalEventView::getId).toList()), Mockito.any());
assertEquals(RepeatStatus.FINISHED, resultStatus);
}
@Test
public void givenBatchSize2WhenEventSendFailsThenExecutionStops() throws Exception {
// given
List<ExternalEvent> events = Arrays.asList(new ExternalEvent("aType", "aCategory", "aSchema", new byte[0], "aIdempotencyKey"),
new ExternalEvent("aType", "aCategory", "aSchema", new byte[0], "aIdempotencyKey"));
List<ExternalEventView> events = Arrays.asList(
createExternalEventView("aType", "aCategory", "aSchema", new byte[0], "aIdempotencyKey", 1L),
createExternalEventView("aType", "aCategory", "aSchema", new byte[0], "aIdempotencyKey", 1L));
MessageV1 dummyMessage = new MessageV1(1, "aSource", "aType", "nocategory", "aCreateDate", "aBusinessDate", "aTenantId",
"anidempotencyKey", "aSchema", Mockito.mock(ByteBuffer.class));
when(repository.findByStatusOrderById(Mockito.any(), Mockito.any())).thenReturn(events);
when(messageFactory.createMessage(Mockito.any())).thenReturn(dummyMessage);
when(byteBufferConverter.convert(Mockito.any(ByteBuffer.class))).thenReturn(new byte[0]);
doThrow(new AcknowledgementTimeoutException("Event Send Exception", new RuntimeException())).when(eventProducer)
.sendEvent(Mockito.any());
.sendEvents(Mockito.any());
// when
resultStatus = this.underTest.execute(stepContribution, chunkContext);
resultStatus = underTest.execute(stepContribution, chunkContext);
// then
verify(repository, times(0)).save(Mockito.any(ExternalEvent.class));
verify(repository, times(0)).markEventsSent(Mockito.any(), Mockito.any());
assertEquals(RepeatStatus.FINISHED, resultStatus);
}
@Test
public void givenOneEventWhenEventSentThenEventStatusUpdates() throws Exception {
// given
ArgumentCaptor<ExternalEvent> externalEventArgumentCaptor = ArgumentCaptor.forClass(ExternalEvent.class);
List<ExternalEvent> events = Arrays.asList(new ExternalEvent("aType", "aCategory", "aSchema", new byte[0], "aIdempotencyKey"));
List<ExternalEventView> events = Arrays
.asList(createExternalEventView("aType", "aCategory", "aSchema", new byte[0], "aIdempotencyKey", 1L));
MessageV1 dummyMessage = new MessageV1(1, "aSource", "aType", "nocategory", "aCreateDate", "aBusinessDate", "aTenantId",
"anidempotencyKey", "aSchema", Mockito.mock(ByteBuffer.class));
when(repository.findByStatusOrderById(Mockito.any(), Mockito.any())).thenReturn(events);
when(messageFactory.createMessage(Mockito.any())).thenReturn(dummyMessage);
when(byteBufferConverter.convert(Mockito.any(ByteBuffer.class))).thenReturn(new byte[0]);
doNothing().when(eventProducer).sendEvent(Mockito.any());
// when
resultStatus = this.underTest.execute(stepContribution, chunkContext);
resultStatus = underTest.execute(stepContribution, chunkContext);
// then
verify(messageFactory).createMessage(Mockito.any());
verify(repository).save(externalEventArgumentCaptor.capture());
ExternalEvent externalEvent = externalEventArgumentCaptor.getValue();
assertThat(externalEvent.getStatus()).isEqualTo(ExternalEventStatus.SENT);
verify(eventProducer).sendEvents(Mockito.any());
verify(repository).markEventsSent(Mockito.eq(events.stream().map(ExternalEventView::getId).toList()), Mockito.any());
assertEquals(RepeatStatus.FINISHED, resultStatus);
}
@Test
public void testExecuteShouldHandleNullAggregateId() throws Exception {
// given
List<ExternalEventView> events = Arrays
.asList(createExternalEventView("aType", "aCategory", "aSchema", new byte[0], "aIdempotencyKey", null));
MessageV1 dummyMessage = new MessageV1(1, "aSource", "aType", "nocategory", "aCreateDate", "aBusinessDate", "aTenantId",
"anidempotencyKey", "aSchema", Mockito.mock(ByteBuffer.class));
when(repository.findByStatusOrderById(Mockito.any(), Mockito.any())).thenReturn(events);
when(messageFactory.createMessage(Mockito.any())).thenReturn(dummyMessage);
byte[] byteMsg = new byte[0];
when(byteBufferConverter.convert(Mockito.any(ByteBuffer.class))).thenReturn(byteMsg);
// when
resultStatus = underTest.execute(stepContribution, chunkContext);
// then
verify(messageFactory).createMessage(Mockito.any());
verify(eventProducer).sendEvents(Map.of(-1L, List.of(byteMsg)));
verify(repository).markEventsSent(Mockito.eq(events.stream().map(ExternalEventView::getId).toList()), Mockito.any());
assertEquals(RepeatStatus.FINISHED, resultStatus);
}
@Test
public void givenEventBatchSizeIsConfiguredAs10WhenTaskExecutionThenEventReadPageSizeIsCorrect() {
ArgumentCaptor<Pageable> externalEventPageSizeArgumentCaptor = ArgumentCaptor.forClass(Pageable.class);
List<ExternalEvent> events = new ArrayList<>();
List<ExternalEventView> events = new ArrayList<>();
when(repository.findByStatusOrderById(Mockito.any(), Mockito.any())).thenReturn(events);
// when
resultStatus = this.underTest.execute(stepContribution, chunkContext);
resultStatus = underTest.execute(stepContribution, chunkContext);
// then
verify(repository).findByStatusOrderById(Mockito.any(), externalEventPageSizeArgumentCaptor.capture());
assertThat(externalEventPageSizeArgumentCaptor.getValue().getPageSize()).isEqualTo(10);
}
private ExternalEventView createExternalEventView(String type, String category, String schema, byte[] data, String idempotencyKey,
Long aggregateRootId) {
ExternalEventView result = Mockito.mock(ExternalEventView.class);
Mockito.when(result.getId()).thenReturn(rnd.nextLong());
Mockito.when(result.getType()).thenReturn(type);
Mockito.when(result.getCategory()).thenReturn(category);
Mockito.when(result.getSchema()).thenReturn(schema);
Mockito.when(result.getData()).thenReturn(data);
Mockito.when(result.getIdempotencyKey()).thenReturn(idempotencyKey);
Mockito.when(result.getAggregateRootId()).thenReturn(aggregateRootId);
return result;
}
}
@@ -1,120 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.infrastructure.event.external.producer;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.concurrent.atomic.AtomicInteger;
import javax.jms.ConnectionFactory;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.annotation.IntegrationComponentScan;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.config.EnableIntegration;
import org.springframework.integration.config.GlobalChannelInterceptor;
import org.springframework.integration.dsl.IntegrationFlow;
import org.springframework.integration.dsl.IntegrationFlows;
import org.springframework.integration.handler.LoggingHandler;
import org.springframework.integration.jms.dsl.Jms;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.ChannelInterceptor;
import org.springframework.stereotype.Component;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@ExtendWith(SpringExtension.class)
@ContextConfiguration
@DirtiesContext
@TestPropertySource(properties = { "fineract.events.external.enabled=true" })
public class EventsJMSIntegrationTest {
@Autowired
@Qualifier("outboundRequestsEvents")
private DirectChannel outboundRequestsEvents;
@Autowired
private ContextConfiguration.TestChannelInterceptor testChannelInterceptor;
@Autowired
private ExternalEventProducer underTest;
@Test
public void testJmsDownstreamChannelIntegration() {
assertThat(outboundRequestsEvents.getSubscriberCount()).isEqualTo(1);
}
@Test
void given2EventsThenOutBoundChannelIsInvokedTwice() {
// when
underTest.sendEvent(new byte[0]);
underTest.sendEvent(new byte[0]);
// then
assertTrue(outboundRequestsEvents.getInterceptors().contains(this.testChannelInterceptor));
assertThat(testChannelInterceptor.getInvoked()).isEqualTo(2);
}
@Configuration
@IntegrationComponentScan
@EnableIntegration
public static class ContextConfiguration {
private static ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
@Bean
public DirectChannel outboundRequestsEvents() {
return new DirectChannel();
}
@Bean
public IntegrationFlow outboundFlow() {
return IntegrationFlows.from("outboundRequestsEvents") //
.log(LoggingHandler.Level.DEBUG) //
.handle(Jms.outboundAdapter(connectionFactory).destination("destinationChannel")).get();
}
@Component
@GlobalChannelInterceptor(patterns = "outboundRequestsEvents")
public static class TestChannelInterceptor implements ChannelInterceptor {
private final AtomicInteger invoked = new AtomicInteger();
public int getInvoked() {
return invoked.get();
}
@Override
public Message<?> preSend(Message<?> message, MessageChannel channel) {
this.invoked.incrementAndGet();
return message;
}
}
}
}
@@ -0,0 +1,200 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.infrastructure.event.external.producer.jms;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import javax.jms.BytesMessage;
import javax.jms.Connection;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Session;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.fineract.avro.MessageV1;
import org.apache.fineract.infrastructure.core.config.FineractProperties;
import org.apache.fineract.infrastructure.core.messaging.jms.MessageFactory;
import org.apache.fineract.infrastructure.core.service.HashingService;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
class JMSMultiExternalEventProducerTest {
private static final int PRODUCER_COUNT = 3;
private final Random rnd = new Random();
@Mock
private Destination destination;
@Mock
private ActiveMQConnectionFactory connectionFactory;
@Mock
private MessageFactory messageFactory;
@Mock
private HashingService hashingService;
private AsyncTaskExecutor taskExecutor = new SimpleAsyncTaskExecutor();
@Mock
private Connection connection;
@Mock
private Session session1;
@Mock
private Session session2;
@Mock
private Session session3;
@Mock
private MessageProducer producer1;
@Mock
private MessageProducer producer2;
@Mock
private MessageProducer producer3;
private JMSMultiExternalEventProducer underTest;
private FineractProperties fineractProperties;
private List<MessageProducer> producers = new ArrayList<>();
@Test
public void testAfterPropertiesShouldCreateMultipleSessions() throws Exception {
// given
initializeMocks();
// when
underTest.afterPropertiesSet();
// then
verify(connection, times(3)).createSession(false, Session.AUTO_ACKNOWLEDGE);
verify(session1).createProducer(destination);
verify(session2).createProducer(destination);
verify(session3).createProducer(destination);
verify(connection).close();
}
@Test
public void testSendEventsShouldWork() throws Exception {
// given
initializeMocks();
underTest.afterPropertiesSet();
byte[] msg1 = createMessage();
List<byte[]> messages = new ArrayList<>();
messages.add(msg1);
Map<Long, List<byte[]>> partitions = Map.of(1L, messages);
BytesMessage bytesMsg1 = Mockito.mock(BytesMessage.class);
given(messageFactory.createByteMessage(msg1)).willReturn(bytesMsg1);
given(hashingService.consistentHash(1L, producers.size())).willReturn(0);
// when
underTest.sendEvents(partitions);
// then
verify(producer1).send(destination, bytesMsg1);
}
@Test
public void testSendEventsBalancesBetweenProducers() throws Exception {
// given
initializeMocks();
underTest.afterPropertiesSet();
byte[] msg1 = createMessage();
byte[] msg2 = createMessage();
byte[] msg3 = createMessage();
List<byte[]> messages1 = new ArrayList<>();
messages1.add(msg1);
List<byte[]> messages2 = new ArrayList<>();
messages2.add(msg2);
List<byte[]> messages3 = new ArrayList<>();
messages3.add(msg3);
Map<Long, List<byte[]>> partitions = Map.of(1L, messages1, 2L, messages2, 3L, messages3);
BytesMessage bytesMsg1 = Mockito.mock(BytesMessage.class);
BytesMessage bytesMsg2 = Mockito.mock(BytesMessage.class);
BytesMessage bytesMsg3 = Mockito.mock(BytesMessage.class);
given(messageFactory.createByteMessage(msg1)).willReturn(bytesMsg1);
given(messageFactory.createByteMessage(msg2)).willReturn(bytesMsg2);
given(messageFactory.createByteMessage(msg3)).willReturn(bytesMsg3);
given(hashingService.consistentHash(1L, producers.size())).willReturn(0);
given(hashingService.consistentHash(2L, producers.size())).willReturn(1);
given(hashingService.consistentHash(3L, producers.size())).willReturn(2);
// when
underTest.sendEvents(partitions);
// then
verify(producer1).send(destination, bytesMsg1);
verify(producer2).send(destination, bytesMsg2);
verify(producer3).send(destination, bytesMsg3);
}
private byte[] createMessage() throws IOException {
MessageV1 messageV1 = new MessageV1();
messageV1.setId(rnd.nextInt());
messageV1.setSource("");
messageV1.setBusinessDate("");
messageV1.setCategory("");
messageV1.setCreatedAt("");
messageV1.setDataschema("");
messageV1.setIdempotencyKey("");
messageV1.setTenantId("");
messageV1.setType("");
messageV1.setData(ByteBuffer.wrap(new byte[0]));
return messageV1.toByteBuffer().array();
}
private void initializeMocks() throws JMSException {
FineractProperties.FineractExternalEventsProducerJmsProperties jms = new FineractProperties.FineractExternalEventsProducerJmsProperties();
jms.setProducerCount(PRODUCER_COUNT);
FineractProperties.FineractExternalEventsProducerProperties producer = new FineractProperties.FineractExternalEventsProducerProperties();
producer.setJms(jms);
FineractProperties.FineractExternalEventsProperties external = new FineractProperties.FineractExternalEventsProperties();
external.setProducer(producer);
FineractProperties.FineractEventsProperties events = new FineractProperties.FineractEventsProperties();
events.setExternal(external);
fineractProperties = new FineractProperties();
fineractProperties.setEvents(events);
underTest = new JMSMultiExternalEventProducer(destination, connectionFactory, messageFactory, taskExecutor, hashingService,
fineractProperties);
given(connectionFactory.createConnection()).willReturn(connection);
given(connection.createSession(false, Session.AUTO_ACKNOWLEDGE)).willReturn(session1, session2, session3);
given(session1.createProducer(destination)).willReturn(producer1);
given(session2.createProducer(destination)).willReturn(producer2);
given(session3.createProducer(destination)).willReturn(producer3);
producers.add(producer1);
producers.add(producer2);
producers.add(producer3);
}
}