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"));
}
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();
}
Aggregations