From 74189942f436b86579d33b5abbac384be08cd92b Mon Sep 17 00:00:00 2001 From: Ilayaperumal Gopinathan Date: Wed, 22 Jun 2016 19:01:09 +0530 Subject: [PATCH] Remove RabbitTestSupport class --- .../test/junit/rabbit/RabbitTestSupport.java | 166 ------------------ 1 file changed, 166 deletions(-) delete mode 100644 spring-cloud-stream-test-support-internal/src/main/java/org/springframework/cloud/stream/test/junit/rabbit/RabbitTestSupport.java diff --git a/spring-cloud-stream-test-support-internal/src/main/java/org/springframework/cloud/stream/test/junit/rabbit/RabbitTestSupport.java b/spring-cloud-stream-test-support-internal/src/main/java/org/springframework/cloud/stream/test/junit/rabbit/RabbitTestSupport.java deleted file mode 100644 index 1de2403c8..000000000 --- a/spring-cloud-stream-test-support-internal/src/main/java/org/springframework/cloud/stream/test/junit/rabbit/RabbitTestSupport.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright 2015 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.stream.test.junit.rabbit; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.ServerSocket; -import java.net.Socket; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -import javax.net.ServerSocketFactory; -import javax.net.SocketFactory; - -import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; -import org.springframework.cloud.stream.test.junit.AbstractExternalResourceTestSupport; - -/** - * JUnit {@link org.junit.Rule} that detects the fact that RabbitMQ is available on localhost. - * - * @author Mark Fisher - * @author Gary Russell - * @author Eric Bottard - */ -public class RabbitTestSupport extends AbstractExternalResourceTestSupport { - - private final boolean management; - - public RabbitTestSupport() { - this(false); - } - - public RabbitTestSupport(boolean management) { - super("RABBIT"); - this.management = management; - } - - @Override - protected void obtainResource() throws Exception { - resource = new CachingConnectionFactory("localhost"); - resource.createConnection().close(); - if (management) { - Socket socket = SocketFactory.getDefault().createSocket("localhost", 15672); - socket.close(); - } - } - - @Override - protected void cleanupResource() throws Exception { - resource.destroy(); - } - - /** - * Test class to allow testing deferred entity declarations when RabbitMQ is down. - * - */ - public static class RabbitProxy { - - private final int port; - - private final ExecutorService serverExec = Executors.newSingleThreadExecutor(); - - private final ExecutorService socketExec = Executors.newCachedThreadPool(); - - private volatile ServerSocket serverSocket; - - public RabbitProxy() throws IOException { - ServerSocket serverSocket = ServerSocketFactory.getDefault().createServerSocket(0); - this.port = serverSocket.getLocalPort(); - serverSocket.close(); - } - - public int getPort() { - return this.port; - } - - public void start() throws IOException { - this.serverSocket = ServerSocketFactory.getDefault().createServerSocket(this.port); - this.serverExec.execute(new Runnable() { - - @Override - public void run() { - try { - while (true) { - final Socket socket = serverSocket.accept(); - socketExec.execute(new Runnable() { - - @Override - public void run() { - try { - final Socket rabbitSocket = SocketFactory.getDefault().createSocket("localhost", - 5672); - socketExec.execute(new Runnable() { - - @Override - public void run() { - try { - InputStream is = rabbitSocket.getInputStream(); - OutputStream os = socket.getOutputStream(); - int c; - while ((c = is.read()) >= 0) { - os.write(c); - } - } - catch (IOException e) { - try { - socket.close(); - rabbitSocket.close(); - } - catch (IOException e1) { - } - } - } - }); - InputStream is = socket.getInputStream(); - OutputStream os = rabbitSocket.getOutputStream(); - int c; - while ((c = is.read()) >= 0) { - os.write(c); - } - } - catch (IOException e) { - try { - socket.close(); - } - catch (IOException e1) { - } - } - } - - }); - } - } - catch (IOException e) { - try { - serverSocket.close(); - } - catch (IOException e1) { - } - } - } - }); - } - - public void stop() throws IOException { - this.serverSocket.close(); - } - - } - -}