Add EmptyLineSeparator Checkstyle rule

* Support "blank lines around" via `spring-framework.xml` IDEA config
* Fix all the Checkstyle violations
This commit is contained in:
Artem Bilan
2024-03-27 16:54:25 -04:00
parent f71a2234d8
commit c155d5d418
932 changed files with 1341 additions and 2485 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -59,7 +59,6 @@ public abstract class AbstractInternetProtocolReceivingChannelAdapter
private volatile boolean listening;
public AbstractInternetProtocolReceivingChannelAdapter(int port) {
this.port = port;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -57,7 +57,6 @@ public abstract class AbstractInternetProtocolSendingMessageHandler extends Abst
this.port = port;
}
/**
* @param timeout The timeout.
* @see java.net.DatagramSocket#setSoTimeout(int)
@@ -91,7 +90,6 @@ public abstract class AbstractInternetProtocolSendingMessageHandler extends Abst
return this.host;
}
/**
* @return the port
*/
@@ -99,7 +97,6 @@ public abstract class AbstractInternetProtocolSendingMessageHandler extends Abst
return this.port;
}
/**
* @return the destinationAddress
*/
@@ -107,7 +104,6 @@ public abstract class AbstractInternetProtocolSendingMessageHandler extends Abst
return this.destinationAddress;
}
/**
* @return the soTimeout
*/
@@ -115,7 +111,6 @@ public abstract class AbstractInternetProtocolSendingMessageHandler extends Abst
return this.soTimeout;
}
/**
* @return the soSendBufferSize
*/
@@ -123,7 +118,6 @@ public abstract class AbstractInternetProtocolSendingMessageHandler extends Abst
return this.soSendBufferSize;
}
@Override
public void start() {
this.lock.lock();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -132,7 +132,6 @@ public class TcpConnectionFactoryFactoryBean extends AbstractFactoryBean<Abstrac
private ApplicationContext applicationContext;
public TcpConnectionFactoryFactoryBean() {
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -76,7 +76,6 @@ public abstract class AbstractClientConnectionFactory extends AbstractConnection
return this.connectTimeout;
}
/**
* Set whether to automatically (default) or manually add a {@link TcpListener} to the
* connections created by this factory. By default, the factory automatically configures

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2001-2023 the original author or authors.
* Copyright 2001-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -54,7 +54,6 @@ public abstract class AbstractServerConnectionFactory extends AbstractConnection
private volatile boolean shuttingDown;
/**
* The port on which the factory will listen.
* @param port The port.
@@ -106,7 +105,6 @@ public abstract class AbstractServerConnectionFactory extends AbstractConnection
this.listening = listening;
}
/**
*
* @return true if the server is listening on the port.
@@ -174,7 +172,6 @@ public abstract class AbstractServerConnectionFactory extends AbstractConnection
this.localAddress = localAddress;
}
/**
* The number of sockets in the server connection backlog.
* @return The backlog.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -42,6 +42,7 @@ import org.springframework.messaging.support.ErrorMessage;
*
* @author Gary Russell
* @author Christian Tzolov
* @author Artem Bilan
*
* @since 2.2
*
@@ -65,30 +66,7 @@ public class CachingClientConnectionFactory extends AbstractClientConnectionFact
// override single-use to true so the target creates multiple connections
target.setSingleUse(true);
this.targetConnectionFactory = target;
class Callback implements SimplePool.PoolItemCallback<TcpConnectionSupport> {
@Override
public TcpConnectionSupport createForPool() {
try {
return CachingClientConnectionFactory.this.targetConnectionFactory.getConnection();
}
catch (Exception e) {
throw new MessagingException("Failed to obtain connection", e);
}
}
@Override
public boolean isStale(TcpConnectionSupport connection) {
return !connection.isOpen();
}
@Override
public void removedFromPool(TcpConnectionSupport connection) {
connection.close();
}
}
this.pool = new SimplePool<TcpConnectionSupport>(poolSize, new Callback());
this.pool = new SimplePool<>(poolSize, new TcpConnectionPoolItemCallback(this.targetConnectionFactory));
}
/**
@@ -144,8 +122,6 @@ public class CachingClientConnectionFactory extends AbstractClientConnectionFact
return new CachedConnection(this.pool.getItem(), getListener());
}
///////////////// DELEGATE METHODS ///////////////////////
@Override
public boolean isRunning() {
return this.targetConnectionFactory.isRunning();
@@ -291,7 +267,7 @@ public class CachingClientConnectionFactory extends AbstractClientConnectionFact
* it's listening logic (active thread) is terminated.
* <p>
* The listener registered with a factory is provided to each
* connection it creates so it can call the onMessage() method.
* connection it creates, so it can call the onMessage() method.
* <p>
* This code satisfies the first requirement in that this
* listener signals to the factory that it needs to run
@@ -347,7 +323,7 @@ public class CachingClientConnectionFactory extends AbstractClientConnectionFact
*/
@Override
public void setSingleUse(boolean singleUse) {
if (!singleUse && logger.isDebugEnabled()) {
if (!singleUse) {
logger.debug("singleUse=false is not supported; cached connections are never closed");
}
}
@@ -367,11 +343,10 @@ public class CachingClientConnectionFactory extends AbstractClientConnectionFact
return this.targetConnectionFactory.isLookupHost();
}
@Override
public void forceClose(TcpConnection connection) {
if (connection instanceof CachedConnection) {
((CachedConnection) connection).physicallyClose();
if (connection instanceof CachedConnection cachedConnection) {
cachedConnection.physicallyClose();
}
// will be returned to pool but stale, so will be re-established
super.forceClose(connection);
@@ -403,7 +378,7 @@ public class CachingClientConnectionFactory extends AbstractClientConnectionFact
}
@Override
public void destroy() throws Exception {
public void destroy() {
this.pool.close();
}
@@ -460,7 +435,7 @@ public class CachingClientConnectionFactory extends AbstractClientConnectionFact
public boolean onMessage(Message<?> message) {
Message<?> modifiedMessage;
if (message instanceof ErrorMessage) {
Map<String, Object> headers = new HashMap<String, Object>(message.getHeaders());
Map<String, Object> headers = new HashMap<>(message.getHeaders());
headers.put(IpHeaders.CONNECTION_ID, getConnectionId());
if (headers.get(IpHeaders.ACTUAL_CONNECTION_ID) == null) {
headers.put(IpHeaders.ACTUAL_CONNECTION_ID,
@@ -497,4 +472,29 @@ public class CachingClientConnectionFactory extends AbstractClientConnectionFact
}
private record TcpConnectionPoolItemCallback(AbstractClientConnectionFactory targetConnectionFactory)
implements SimplePool.PoolItemCallback<TcpConnectionSupport> {
@Override
public TcpConnectionSupport createForPool() {
try {
return this.targetConnectionFactory.getConnection();
}
catch (Exception ex) {
throw new MessagingException("Failed to obtain connection", ex);
}
}
@Override
public boolean isStale(TcpConnectionSupport connection) {
return !connection.isOpen();
}
@Override
public void removedFromPool(TcpConnectionSupport connection) {
connection.close();
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2001-2022 the original author or authors.
* Copyright 2001-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,7 +18,6 @@ package org.springframework.integration.ip.tcp.connection;
import org.springframework.integration.support.management.ManageableLifecycle;
/**
* A factory used to create TcpConnection objects.
*

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 the original author or authors.
* Copyright 2017-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,7 +24,6 @@ import java.net.Socket;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.lang.Nullable;
/**
* Default implementation of {@link TcpNetConnectionSupport}.
*

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,7 +23,6 @@ import java.nio.channels.SocketChannel;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.lang.Nullable;
/**
* Implementation of {@link TcpNioConnectionSupport} for non-SSL
* NIO connections.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
package org.springframework.integration.ip.tcp.connection;
/**
* @author Gary Russell
* @since 3.0

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
package org.springframework.integration.ip.tcp.connection;
/**
* ApplicationEvent representing exceptions on a {@link TcpConnection}.
* @author Gary Russell

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2022 the original author or authors.
* Copyright 2015-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@ package org.springframework.integration.ip.tcp.connection;
import org.springframework.integration.ip.event.IpIntegrationEvent;
import org.springframework.messaging.MessagingException;
/**
* An event emitted when an endpoint cannot correlate a connection id to a
* connection; the cause is a messaging exception with the failed message.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2022 the original author or authors.
* Copyright 2016-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,7 +18,6 @@ package org.springframework.integration.ip.tcp.connection;
import org.springframework.integration.ip.event.IpIntegrationEvent;
/**
* An event emitted when a connection could not be established for some
* reason.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2001-2019 the original author or authors.
* Copyright 2001-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
package org.springframework.integration.ip.tcp.connection;
/**
* Interface for TCP connection interceptor factories.
*
@@ -33,5 +32,6 @@ public interface TcpConnectionInterceptorFactory {
* @return the TcpInterceptor
*/
TcpConnectionInterceptorSupport getInterceptor();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -54,7 +54,6 @@ public abstract class TcpConnectionInterceptorSupport extends TcpConnectionSuppo
private boolean removed;
public TcpConnectionInterceptorSupport() {
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
package org.springframework.integration.ip.tcp.connection;
/**
* @author Gary Russell
* @since 3.0

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 the original author or authors.
* Copyright 2017-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@ import java.net.Socket;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.lang.Nullable;
/**
* Used by NET connection factories to instantiate a {@link TcpNetConnection} object.
*

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,7 +33,6 @@ import java.util.concurrent.LinkedBlockingQueue;
import org.springframework.scheduling.SchedulingAwareRunnable;
import org.springframework.util.Assert;
/**
* A client connection factory that creates {@link TcpNioConnection}s.
*

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@ import java.nio.channels.SocketChannel;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.lang.Nullable;
/**
* Used by NIO connection factories to instantiate a {@link TcpNioConnection} object.
* Implementations for SSL and non-SSL {@link TcpNioConnection}s are provided.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
/**
* Reads data in an InputStream to a byte[]; data must be preceded by
* a binary length (network byte order, not included in resulting byte[]).

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2001-2023 the original author or authors.
* Copyright 2001-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -70,7 +70,6 @@ public class MulticastSendingMessageHandler extends UnicastSendingMessageHandler
super(address, port, lengthCheck);
}
/**
* Constructs a MulticastSendingMessageHandler to send data to the multicast address/port
* and enables setting the acknowledge option, where the destination sends a receipt acknowledgment.
@@ -178,7 +177,6 @@ public class MulticastSendingMessageHandler extends UnicastSendingMessageHandler
}
}
/**
* If acknowledge = true; how many acks needed for success.
* @param minAcksForSuccess The minimum number of acks that will represent success.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -157,4 +157,5 @@ public final class TestingUtilities {
}
throw new IllegalStateException("Connections=" + factory.getOpenConnectionIds().size() + "wanted=" + n);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2022 the original author or authors.
* Copyright 2014-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -41,7 +41,6 @@ public class TcpConnectionFactoryFactoryBeanTest {
assertThat(TestUtils.getPropertyValue(fb.getObject(), "readDelay")).isEqualTo(100L);
}
@Test
public void testReadDelay() throws Exception {
TcpConnectionFactoryFactoryBean fb = new TcpConnectionFactoryFactoryBean();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2023 the original author or authors.
* Copyright 2016-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -207,16 +207,11 @@ public class IpIntegrationTests {
.get();
CountDownLatch latch = new CountDownLatch(1);
AtomicInteger port = new AtomicInteger();
class Listener implements ApplicationListener<TcpConnectionServerListeningEvent> {
@Override
public void onApplicationEvent(TcpConnectionServerListeningEvent event) {
port.set(event.getPort());
latch.countDown();
}
}
this.applicationContext.addApplicationListener(new Listener());
this.applicationContext.addApplicationListener(
(ApplicationListener<TcpConnectionServerListeningEvent>) event -> {
port.set(event.getPort());
latch.countDown();
});
this.flowContext.registration(server)
.id("streamCloseServer")
.register();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -64,4 +64,5 @@ public class AutoStartTests {
tcpNetIn.stop();
TestingUtilities.waitStopListening(cfS1, null);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -47,7 +47,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Gary Russell
* @author Gunnar Hillert

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@ import org.junit.Test;
import org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory;
import org.springframework.integration.ip.tcp.connection.TcpNetServerConnectionFactory;
/**
* @author Gary Russell
* @since 2.0.4
@@ -42,4 +41,5 @@ public class FactoryStopStartTests {
public static void main(String[] args) {
new FactoryStopStartTests().testRestart();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -223,7 +223,6 @@ public class TcpConfigOutboundGatewayTests {
assertThat(new String(bytes).trim()).isEqualTo("echo:test");
}
private void testOutboundUsingConfig() {
Message<String> message = MessageBuilder.withPayload("test").build();
requestChannel.send(message);

View File

@@ -345,7 +345,6 @@ public class TcpInboundGatewayTests {
client.stop();
}
private void readFully(InputStream is, byte[] buff) throws IOException {
for (int i = 0; i < buff.length; i++) {
buff[i] = (byte) is.read();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -1096,7 +1096,7 @@ public class TcpOutboundGatewayTests {
given(connection.getConnectionId()).willReturn("testId");
willThrow(new RuntimeException("intentional"))
.given(connection)
.send(any(Message.class));
.send(any(Message.class));
willReturn(connection)
.given(ccf)

View File

@@ -654,6 +654,7 @@ public class TcpReceivingChannelAdapterTests extends AbstractTcpChannelAdapterTe
public String serviceMethod(byte[] bytes) {
throw new RuntimeException("Failed");
}
}
}

View File

@@ -80,7 +80,6 @@ import static org.assertj.core.api.Assertions.fail;
import static org.awaitility.Awaitility.await;
import static org.mockito.Mockito.mock;
/**
* @author Gary Russell
* @author Artem Bilan

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -61,4 +61,5 @@ public class TcpSendingNoSocketTests {
public void exceptionTrapped() {
advised.send(new GenericMessage<String>("foo"));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -227,6 +227,7 @@ public class ConnectionTimeoutTests {
return false;
});
server.registerSender(new TcpSender() {
@Override
public void addNewConnection(TcpConnection connection) {
serverConnection.set(connection);
@@ -241,6 +242,7 @@ public class ConnectionTimeoutTests {
public void setupClientCallback(AbstractClientConnectionFactory client) {
client.setComponentName("clientFactory");
client.registerSender(new TcpSender() {
@Override
public void addNewConnection(TcpConnection connection) {
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@ package org.springframework.integration.ip.tcp.connection;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
/**
* @author Gary Russell
* @since 2.0

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -102,7 +102,6 @@ public class TcpNioConnectionReadTests {
done.countDown();
}
@SuppressWarnings("unchecked")
@Test
public void testFragmented() throws Exception {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -93,7 +93,6 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
/**
* @author Gary Russell
* @author John Anderson

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 the original author or authors.
* Copyright 2022-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,7 +24,6 @@ import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.jupiter.api.Test;
@@ -33,6 +32,8 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Gary Russell
* @author Kazuki Shimizu
* @author Artem Bilan
*
* @since 5.3.10
*
*/
@@ -83,7 +84,6 @@ public class TcpSenderTests {
AtomicInteger instances = new AtomicInteger();
List<Integer> addOrder = Collections.synchronizedList(new ArrayList<>());
List<Integer> remOrder = Collections.synchronizedList(new ArrayList<>());
AtomicReference<Thread> thread = new AtomicReference<>();
Map<Integer, TcpConnection> interceptorsPerInstance = new HashMap<>();
List<TcpConnection> passedConnectionsToSenderViaAddNewConnection = new ArrayList<>();
class InterceptorFactory extends HelloWorldInterceptorFactory {
@@ -118,6 +118,7 @@ public class TcpSenderTests {
}
}
chain.setInterceptor(new InterceptorFactory(), new InterceptorFactory(), new InterceptorFactory());
client.setInterceptorFactoryChain(chain);
CountDownLatch firstClosed = new CountDownLatch(1);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,7 +24,6 @@ import java.net.ServerSocket;
import java.net.Socket;
import java.nio.ByteBuffer;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicReference;
import javax.net.ServerSocketFactory;
@@ -33,8 +32,6 @@ import org.junit.Rule;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.core.serializer.DefaultDeserializer;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.integration.channel.QueueChannel;
@@ -57,6 +54,7 @@ import static org.mockito.Mockito.mock;
/**
* @author Gary Russell
* @author Gavin Gray
* @author Artem Bilan
*
* @since 2.0
*/
@@ -183,7 +181,6 @@ public class DeserializationTests {
}
catch (IOException e) {
if (!e.getMessage().startsWith("Message length")) {
e.printStackTrace();
fail("Unexpected IO Error:" + e.getMessage());
}
}
@@ -206,7 +203,6 @@ public class DeserializationTests {
}
catch (IOException e) {
if (!e.getMessage().startsWith("Read timed out")) {
e.printStackTrace();
fail("Unexpected IO Error:" + e.getMessage());
}
}
@@ -230,7 +226,6 @@ public class DeserializationTests {
}
catch (IOException e) {
if (!e.getMessage().startsWith("ETX not found")) {
e.printStackTrace();
fail("Unexpected IO Error:" + e.getMessage());
}
}
@@ -253,7 +248,6 @@ public class DeserializationTests {
}
catch (IOException e) {
if (!e.getMessage().startsWith("Read timed out")) {
e.printStackTrace();
fail("Unexpected IO Error:" + e.getMessage());
}
}
@@ -277,7 +271,6 @@ public class DeserializationTests {
}
catch (IOException e) {
if (!e.getMessage().startsWith("CRLF not found")) {
e.printStackTrace();
fail("Unexpected IO Error:" + e.getMessage());
}
}
@@ -289,22 +282,18 @@ public class DeserializationTests {
public void canDeserializeMultipleSubsequentTerminators() throws IOException {
byte terminator = (byte) '\n';
ByteArraySingleTerminatorSerializer serializer = new ByteArraySingleTerminatorSerializer(terminator);
ByteArrayInputStream inputStream = new ByteArrayInputStream("s\n\n".getBytes());
try {
try (ByteArrayInputStream inputStream = new ByteArrayInputStream("s\n\n".getBytes())) {
byte[] bytes = serializer.deserialize(inputStream);
assertThat(bytes.length).isEqualTo(1);
assertThat(bytes[0]).isEqualTo("s".getBytes()[0]);
bytes = serializer.deserialize(inputStream);
assertThat(bytes.length).isEqualTo(0);
}
finally {
inputStream.close();
}
}
@Test
public void deserializationEvents() throws Exception {
public void deserializationEvents() {
doDeserialize(new ByteArrayCrLfSerializer(), "CRLF not found before max message length: 5");
doDeserialize(new ByteArrayLengthHeaderSerializer(), "Message length 1718579042 exceeds max message length: 5");
TcpDeserializationExceptionEvent event = doDeserialize(new ByteArrayLengthHeaderSerializer(),
@@ -330,24 +319,11 @@ public class DeserializationTests {
private TcpDeserializationExceptionEvent doDeserialize(AbstractByteArraySerializer deser, String expectedMessage,
byte[] data, int mms) {
final AtomicReference<TcpDeserializationExceptionEvent> event =
new AtomicReference<TcpDeserializationExceptionEvent>();
class Publisher implements ApplicationEventPublisher {
@Override
public void publishEvent(ApplicationEvent anEvent) {
event.set((TcpDeserializationExceptionEvent) anEvent);
}
AtomicReference<TcpDeserializationExceptionEvent> event = new AtomicReference<>();
@Override
public void publishEvent(Object event) {
}
}
Publisher publisher = new Publisher();
ByteArrayInputStream bais = new ByteArrayInputStream(data);
deser.setApplicationEventPublisher(publisher);
deser.setApplicationEventPublisher(anEvent -> event.set((TcpDeserializationExceptionEvent) anEvent));
deser.setMaxMessageSize(mms);
try {
deser.deserialize(bais);
@@ -362,16 +338,16 @@ public class DeserializationTests {
}
@Test
public void testTimeoutWithCustomDeserializer() throws Exception {
public void testTimeoutWithCustomDeserializer() {
testTimeoutWhileDecoding(new CustomDeserializer(), "\u0000\u0002\u0000\u0005reply");
}
@Test
public void testTimeoutWithRawDeserializer() throws Exception {
public void testTimeoutWithRawDeserializer() {
testTimeoutWhileDecoding(new ByteArrayRawSerializer(), "reply");
}
public void testTimeoutWhileDecoding(AbstractByteArraySerializer deserializer, String reply) throws Exception {
private void testTimeoutWhileDecoding(AbstractByteArraySerializer deserializer, String reply) {
ByteArrayRawSerializer serializer = new ByteArrayRawSerializer();
TcpNioServerConnectionFactory serverNio = new TcpNioServerConnectionFactory(0);
ByteArrayLengthHeaderSerializer lengthHeaderSerializer = new ByteArrayLengthHeaderSerializer(1);
@@ -407,23 +383,21 @@ public class DeserializationTests {
// eat SocketTimeoutException. Doesn't matter for this test
}
};
Executor exec = new SimpleAsyncTaskExecutor("-");
try (SimpleAsyncTaskExecutor exec = new SimpleAsyncTaskExecutor("-")) {
exec.execute(command);
}
Message<?> message;
// short reply should not be received.
exec.execute(command);
message = serverSideChannel.receive(10000);
Message<?> message = serverSideChannel.receive(10000);
assertThat(message).isNotNull();
assertThat(new String((byte[]) message.getPayload())).isEqualTo("Test");
String shortReply = reply.substring(0, reply.length() - 1);
((MessageChannel) message.getHeaders().getReplyChannel()).send(new GenericMessage<String>(shortReply));
((MessageChannel) message.getHeaders().getReplyChannel()).send(new GenericMessage<>(shortReply));
message = outputChannel.receive(1000);
assertThat(message).isNull();
}
@Test
public void testTimeoutWithRawDeserializerEofIsTerminator() throws Exception {
public void testTimeoutWithRawDeserializerEofIsTerminator() {
ByteArrayRawSerializer serializer = new ByteArrayRawSerializer();
TcpNioServerConnectionFactory serverNio = new TcpNioServerConnectionFactory(0);
ByteArrayLengthHeaderSerializer lengthHeaderSerializer = new ByteArrayLengthHeaderSerializer(1);
@@ -459,15 +433,15 @@ public class DeserializationTests {
// eat SocketTimeoutException. Doesn't matter for this test
}
};
Executor exec = new SimpleAsyncTaskExecutor("testTimeoutWithRawDeserializerEofIsTerminator-");
Message<?> message;
try (SimpleAsyncTaskExecutor exec = new SimpleAsyncTaskExecutor("testTimeoutWithRawDeserializerEofIsTerminator-")) {
exec.execute(command);
}
exec.execute(command);
message = serverSideChannel.receive(10000);
Message<?> message = serverSideChannel.receive(10000);
assertThat(message).isNotNull();
assertThat(new String((byte[]) message.getPayload())).isEqualTo("Test");
((MessageChannel) message.getHeaders().getReplyChannel()).send(new GenericMessage<String>("reply"));
((MessageChannel) message.getHeaders().getReplyChannel()).send(new GenericMessage<>("reply"));
message = outputChannel.receive(10000);
assertThat(message).isNotNull();
assertThat(new String(((byte[]) message.getPayload()))).isEqualTo("reply");
@@ -529,7 +503,7 @@ public class DeserializationTests {
}
@Override
public void serialize(byte[] object, OutputStream outputStream) throws IOException {
public void serialize(byte[] object, OutputStream outputStream) {
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,7 +27,6 @@ import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
/**
* @author Gary Russell
* @author Artem Bilan

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -41,4 +41,5 @@ public class MapJsonSerializerTests {
map = deserializer.deserialize(bais);
assertThat(map).isNotNull();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,7 +28,6 @@ import org.springframework.messaging.Message;
import static org.assertj.core.api.Assertions.assertThat;
/**
*
* For both .net. and .nio. adapters, creates a single server and 10 clients

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,4 +36,5 @@ public class SyslogdTests {
System.in.read();
ctx.close();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -77,7 +77,6 @@ public class UdpMulticastEndToEndTests implements Runnable {
private static long hangAroundFor = 0;
@Test
public void runIt() throws Exception {
String location = "org/springframework/integration/ip/udp/testIp-out-multicast-context.xml";
@@ -198,7 +197,6 @@ public class UdpMulticastEndToEndTests implements Runnable {
ctx.close();
}
public static void main(String[] args) throws Exception {
hangAroundFor = 120000;
new UdpMulticastEndToEndTests().runIt();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -124,7 +124,6 @@ public class UdpUnicastEndToEndTests implements Runnable {
return applicationContext;
}
public void launchSender(ApplicationContext applicationContext) throws Exception {
DestinationResolver<MessageChannel> channelResolver = new BeanFactoryChannelResolver(applicationContext);
MessageChannel inputChannel = channelResolver.resolveDestination("inputChannel");
@@ -213,7 +212,6 @@ public class UdpUnicastEndToEndTests implements Runnable {
ctx.close();
}
public static void main(String[] args) throws Exception {
hangAroundFor = 120000;
new UdpUnicastEndToEndTests().runIt();