Search in sources :

Example 1 with LogLevels

use of org.springframework.integration.test.condition.LogLevels in project spring-integration by spring-projects.

the class AvroTests method testTransformers.

@Test
@LogLevels(classes = DirectChannel.class, categories = "bar", level = "DEBUG")
void testTransformers(@Autowired Config config) {
    AvroTestClass1 test = new AvroTestClass1("baz", "fiz");
    LogAccessor spied = spy(TestUtils.getPropertyValue(config.in1(), "logger", LogAccessor.class));
    new DirectFieldAccessor(config.in1()).setPropertyValue("logger", spied);
    config.in1().send(new GenericMessage<>(test));
    assertThat(config.tapped().receive(0)).isNotNull().extracting(msg -> msg.getPayload()).isInstanceOf(byte[].class);
    Message<?> received = config.out().receive(0);
    assertThat(received).isNotNull().extracting(msg -> msg.getPayload()).isEqualTo(test).isNotSameAs(test);
    assertThat(received.getHeaders().get("flow")).isEqualTo("flow1");
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    verify(spied, atLeastOnce()).debug(captor.capture());
    assertThat(captor.getAllValues()).anyMatch(s -> s.contains("preSend on channel"));
    assertThat(captor.getAllValues()).anyMatch(s -> s.contains("postSend (sent=true) on channel"));
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) AvroHeaders(org.springframework.integration.transformer.support.AvroHeaders) IntegrationFlow(org.springframework.integration.dsl.IntegrationFlow) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) Autowired(org.springframework.beans.factory.annotation.Autowired) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) LogAccessor(org.springframework.core.log.LogAccessor) EnableIntegration(org.springframework.integration.config.EnableIntegration) Mockito.spy(org.mockito.Mockito.spy) TestUtils(org.springframework.integration.test.util.TestUtils) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Configuration(org.springframework.context.annotation.Configuration) SpringJUnitConfig(org.springframework.test.context.junit.jupiter.SpringJUnitConfig) ArgumentCaptor(org.mockito.ArgumentCaptor) LogLevels(org.springframework.integration.test.condition.LogLevels) IntegrationFlows(org.springframework.integration.dsl.IntegrationFlows) Message(org.springframework.messaging.Message) PollableChannel(org.springframework.messaging.PollableChannel) Bean(org.springframework.context.annotation.Bean) GenericMessage(org.springframework.messaging.support.GenericMessage) DirectChannel(org.springframework.integration.channel.DirectChannel) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) LogAccessor(org.springframework.core.log.LogAccessor) Test(org.junit.jupiter.api.Test) LogLevels(org.springframework.integration.test.condition.LogLevels)

Example 2 with LogLevels

use of org.springframework.integration.test.condition.LogLevels in project spring-integration by spring-projects.

the class TcpNioConnectionReadTests method testReadStxEtxOverflow.

@Test
@LogLevels(categories = "org.springframework.integration.ip", level = "DEBUG")
public void testReadStxEtxOverflow() throws Exception {
    ByteArrayStxEtxSerializer serializer = new ByteArrayStxEtxSerializer();
    serializer.setMaxMessageSize(1024);
    final Semaphore semaphore = new Semaphore(0);
    final List<TcpConnection> added = new ArrayList<>();
    final List<TcpConnection> removed = new ArrayList<>();
    final CountDownLatch errorMessageLetch = new CountDownLatch(1);
    final AtomicReference<Throwable> errorMessageRef = new AtomicReference<>();
    final CountDownLatch openedLatch = new CountDownLatch(1);
    AbstractServerConnectionFactory scf = getConnectionFactory(serializer, message -> {
        if (message instanceof ErrorMessage) {
            errorMessageRef.set(((ErrorMessage) message).getPayload());
            errorMessageLetch.countDown();
        }
        return false;
    }, new TcpSender() {

        @Override
        public void addNewConnection(TcpConnection connection) {
            added.add(connection);
            semaphore.release();
            openedLatch.countDown();
        }

        @Override
        public void removeDeadConnection(TcpConnection connection) {
            removed.add(connection);
            semaphore.release();
        }
    });
    // Fire up the sender.
    CountDownLatch done = SocketTestUtils.testSendStxEtxOverflow(scf.getPort());
    assertThat(openedLatch.await(10, TimeUnit.SECONDS)).isTrue();
    whileOpen(semaphore, added);
    assertThat(added.size()).isEqualTo(1);
    assertThat(errorMessageLetch.await(10, TimeUnit.SECONDS)).isTrue();
    assertThat(errorMessageRef.get().getMessage()).satisfiesAnyOf(s -> assertThat(s).contains("ETX not found before max message length: 1024"), s -> assertThat(s).contains("Connection is closed"));
    assertThat(semaphore.tryAcquire(10000, TimeUnit.MILLISECONDS)).isTrue();
    assertThat(removed).hasSizeGreaterThan(0);
    scf.stop();
    done.countDown();
}
Also used : ArrayList(java.util.ArrayList) AtomicReference(java.util.concurrent.atomic.AtomicReference) Semaphore(java.util.concurrent.Semaphore) CountDownLatch(java.util.concurrent.CountDownLatch) ByteArrayStxEtxSerializer(org.springframework.integration.ip.tcp.serializer.ByteArrayStxEtxSerializer) ErrorMessage(org.springframework.messaging.support.ErrorMessage) Test(org.junit.jupiter.api.Test) LogLevels(org.springframework.integration.test.condition.LogLevels)

Aggregations

Test (org.junit.jupiter.api.Test)2 LogLevels (org.springframework.integration.test.condition.LogLevels)2 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Semaphore (java.util.concurrent.Semaphore)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 ArgumentCaptor (org.mockito.ArgumentCaptor)1 Mockito.atLeastOnce (org.mockito.Mockito.atLeastOnce)1 Mockito.spy (org.mockito.Mockito.spy)1 Mockito.verify (org.mockito.Mockito.verify)1 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Bean (org.springframework.context.annotation.Bean)1 Configuration (org.springframework.context.annotation.Configuration)1 LogAccessor (org.springframework.core.log.LogAccessor)1 DirectChannel (org.springframework.integration.channel.DirectChannel)1 QueueChannel (org.springframework.integration.channel.QueueChannel)1 EnableIntegration (org.springframework.integration.config.EnableIntegration)1 IntegrationFlow (org.springframework.integration.dsl.IntegrationFlow)1