INT-1854 Shutdown task executor (if internal), close all sockets on close()

This commit is contained in:
Gary Russell
2011-04-26 21:10:46 -04:00
parent 54e7a7b994
commit 8b0b8a76ae
13 changed files with 140 additions and 56 deletions

View File

@@ -26,7 +26,9 @@ import java.util.Properties;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.Message;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.history.MessageHistory;
@@ -60,6 +62,20 @@ public class ConnectionToConnectionTests {
@Autowired
private QueueChannel serverSideChannel;
// Test jvm shutdown
public static void main(String[] args) {
ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(
ConnectionToConnectionTests.class.getPackage().getName()
.replaceAll("\\.", "/")
+ "/common-context.xml");
ctx.close();
ctx = new ClassPathXmlApplicationContext(
ConnectionToConnectionTests.class.getPackage().getName()
.replaceAll("\\.", "/")
+ "/ConnectionToConnectionTests-context.xml");
ctx.close();
}
@Test
public void testConnect() throws Exception {
@@ -115,4 +131,5 @@ public class ConnectionToConnectionTests {
assertFalse(connection.getConnectionId().contains("localhost"));
connection.close();
}
}

View File

@@ -231,7 +231,7 @@ public class TcpInboundGatewayTests {
private class FailingService {
@SuppressWarnings("unused")
public String serviceMethod(byte[] bytes) {
throw new RuntimeException("Failed");
throw new RuntimeException("Planned Failure For Tests");
}
}

View File

@@ -157,6 +157,7 @@ public class TcpOutboundGatewayTests {
for (int i = 0; i < 10; i++) {
assertTrue(replies.remove("Reply" + i));
}
done.set(true);
}
@Test
@@ -236,6 +237,7 @@ public class TcpOutboundGatewayTests {
for (int i = 0; i < 1; i++) {
assertTrue(replies.remove("Reply" + i));
}
done.set(true);
}

View File

@@ -937,11 +937,11 @@ public class TcpSendingMessageHandlerTests {
final AtomicBoolean done = new AtomicBoolean();
Executors.newSingleThreadExecutor().execute(new Runnable() {
public void run() {
int i = 0;
try {
ServerSocket server = ServerSocketFactory.getDefault().createServerSocket(port);
latch.countDown();
Socket socket = server.accept();
int i = 0;
while (true) {
ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
Object in = null;
@@ -962,7 +962,7 @@ public class TcpSendingMessageHandlerTests {
oos.writeObject("Reply" + (++i));
}
} catch (Exception e) {
if (!done.get()) {
if (i == 0) {
e.printStackTrace();
}
}

View File

@@ -22,7 +22,7 @@ import static org.junit.Assert.fail;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.net.SocketException;
import javax.net.SocketFactory;
@@ -139,7 +139,7 @@ public class SOLingerTests {
}
try {
Socket socket = SocketFactory.getDefault().createSocket("localhost", port);
socket.setSoTimeout(200);
socket.setSoTimeout(10000);
String test = "Test\r\n";
socket.getOutputStream().write(test.getBytes());
byte[] buff = new byte[test.length() + 5];
@@ -149,7 +149,7 @@ public class SOLingerTests {
n = socket.getInputStream().read();
fail("Expected IOException");
} catch (IOException ioe) {
assertTrue(ioe instanceof SocketTimeoutException);
assertTrue(ioe instanceof SocketException);
}
} catch (Exception e) {
e.printStackTrace();

View File

@@ -131,7 +131,7 @@ public class SocketTestUtils {
private static void writeByte(OutputStream os, int b, boolean noDelay) throws Exception {
os.write(b);
logger.debug("Wrote 0x" + Integer.toHexString(b));
logger.trace("Wrote 0x" + Integer.toHexString(b));
if (noDelay) {
return;
}