Skip to content

Commit

Permalink
Add TCP Test Diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
garyrussell committed Feb 7, 2022
1 parent 09ab0af commit 055eadc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import javax.net.ServerSocketFactory;
import javax.net.SocketFactory;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
Expand All @@ -54,6 +54,7 @@
import org.springframework.integration.ip.tcp.connection.TcpNioServerConnectionFactory;
import org.springframework.integration.ip.tcp.serializer.ByteArrayRawSerializer;
import org.springframework.integration.ip.util.TestingUtilities;
import org.springframework.integration.test.condition.LogLevels;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.SubscribableChannel;
Expand Down Expand Up @@ -292,6 +293,7 @@ public void testErrorFlow() throws Exception {
}

@Test
@LogLevels(categories = "org.springframework.integration.ip", level = "DEBUG")
public void testNetCloseStream() throws InterruptedException, IOException {
testCloseStream(new TcpNetServerConnectionFactory(0),
port -> new TcpNetClientConnectionFactory("localhost", port));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,15 @@

import javax.net.SocketFactory;

import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import org.springframework.integration.ip.tcp.serializer.AbstractByteArraySerializer;
import org.springframework.integration.ip.tcp.serializer.ByteArrayCrLfSerializer;
import org.springframework.integration.ip.tcp.serializer.ByteArrayLengthHeaderSerializer;
import org.springframework.integration.ip.tcp.serializer.ByteArrayStxEtxSerializer;
import org.springframework.integration.ip.util.SocketTestUtils;
import org.springframework.integration.ip.util.TestingUtilities;
import org.springframework.integration.test.support.LongRunningIntegrationTest;
import org.springframework.integration.test.condition.LogLevels;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.ErrorMessage;

Expand All @@ -49,11 +48,9 @@
*
* @since 2.0
*/
//@LongRunningTest
public class TcpNioConnectionReadTests {

@Rule
public LongRunningIntegrationTest longRunningIntegrationTest = new LongRunningIntegrationTest();

private final CountDownLatch latch = new CountDownLatch(1);

private AbstractServerConnectionFactory getConnectionFactory(
Expand Down Expand Up @@ -242,6 +239,7 @@ public void removeDeadConnection(TcpConnection connection) {
}

@Test
@LogLevels(categories = "org.springframework.integration.ip", level = "DEBUG")
public void testReadStxEtxOverflow() throws Exception {
ByteArrayStxEtxSerializer serializer = new ByteArrayStxEtxSerializer();
serializer.setMaxMessageSize(1024);
Expand All @@ -251,6 +249,7 @@ public void testReadStxEtxOverflow() throws Exception {

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) {
Expand All @@ -264,6 +263,7 @@ public void testReadStxEtxOverflow() throws Exception {
public void addNewConnection(TcpConnection connection) {
added.add(connection);
semaphore.release();
openedLatch.countDown();
}

@Override
Expand All @@ -277,6 +277,7 @@ public void removeDeadConnection(TcpConnection connection) {
// 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);

Expand Down

0 comments on commit 055eadc

Please sign in to comment.