/**
 * Copyright (c) 2011 Yahoo! Inc. All rights reserved.
 *
 * 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. See accompanying LICENSE file.
 */

package com.yahoo.omid;

import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * 
 * This class contains functionality that is useful for the Omid tests.
 * 
 * @author Francisco Perez-Sorrosal - fperez@yahoo-inc.com
 *
 */
public class TestUtils {
	private static final Log LOG = LogFactory.getLog(TestUtils.class);

	public static void waitForSocketListening(String host, int port,
			int sleepTimeMillis) throws UnknownHostException, IOException,
			InterruptedException {
		while (true) {
			Socket sock = null;
			try {
				sock = new Socket(host, port);
			} catch (IOException e) {
				// ignore as this is expected
				Thread.sleep(sleepTimeMillis);
				continue;
			} finally {
				if (sock != null) {
					sock.close();
				}
			}
			LOG.info("Host " + host + ":" + port + " is up");
			break;
		}
	}

	public static void waitForSocketNotListening(String host, int port,
			int sleepTimeMillis) throws UnknownHostException, IOException,
			InterruptedException {
		while (true) {
			Socket sock = null;
			try {
				sock = new Socket(host, port);
			} catch (IOException e) {
				// ignore as this is expected
				break;
			} finally {
				if (sock != null) {
					sock.close();
				}
			}
			Thread.sleep(sleepTimeMillis);
			LOG.info("Host " + host + ":" + port + " is up");
		}
	}

}

@@ -936,70 +936,8 @@
  * %0A
- * @author Francisco Perez-Sorrosal - fperez@yahoo-inc.com%0A *%0A
  */%0A
@@ -961,17 +961,20 @@
 Utils %7B%0A
-%09
+    
 private 
@@ -1033,17 +1033,20 @@
 lass);%0A%0A
-%09
+    
 public s
@@ -1094,35 +1094,44 @@
 host, int port,%0A
-%09%09%09
+            
 int sleepTimeMil
@@ -1169,35 +1169,44 @@
 n, IOException,%0A
-%09%09%09
+            
 InterruptedExcep
@@ -1204,34 +1204,40 @@
 ptedException %7B%0A
-%09%09
+        
 while (true) %7B%0A%09
@@ -1227,35 +1227,44 @@
  while (true) %7B%0A
-%09%09%09
+            
 Socket sock = nu
@@ -1263,37 +1263,58 @@
 ock = null;%0A
-%09%09%09try %7B%0A%09%09%09%09
+            try %7B%0A                
 sock = new S
@@ -1324,35 +1324,44 @@
 et(host, port);%0A
-%09%09%09
+            
 %7D catch (IOExcep
@@ -1362,36 +1362,48 @@
 OException e) %7B%0A
-%09%09%09%09
+                
 // ignore as thi
@@ -1416,20 +1416,32 @@
 xpected%0A
-%09%09%09%09
+                
 Thread.s
@@ -1467,94 +1467,172 @@
 s);%0A
-%09%09%09%09continue;%0A%09%09%09%7D finally %7B%0A%09%09%09%09if (sock != null) %7B%0A%09%09%09%09%09sock.close();%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%09
+                continue;%0A            %7D finally %7B%0A                if (sock != null) %7B%0A                    sock.close();%0A                %7D%0A            %7D%0A            
 LOG.
@@ -1681,27 +1681,48 @@
 %22);%0A
-%09%09%09break;%0A%09%09%7D%0A%09%7D%0A%0A%09
+            break;%0A        %7D%0A    %7D%0A%0A    
 publ
@@ -1785,19 +1785,28 @@
 t port,%0A
-%09%09%09
+            
 int slee
@@ -1860,19 +1860,28 @@
 eption,%0A
-%09%09%09
+            
 Interrup
@@ -1895,18 +1895,24 @@
 ption %7B%0A
-%09%09
+        
 while (t
@@ -1918,19 +1918,28 @@
 true) %7B%0A
-%09%09%09
+            
 Socket s
@@ -1954,21 +1954,42 @@
 ll;%0A
-%09%09%09try %7B%0A%09%09%09%09
+            try %7B%0A                
 sock
@@ -2015,19 +2015,28 @@
  port);%0A
-%09%09%09
+            
 %7D catch 
@@ -2053,20 +2053,32 @@
 on e) %7B%0A
-%09%09%09%09
+                
 // ignor
@@ -2103,91 +2103,169 @@
 ted%0A
-%09%09%09%09break;%0A%09%09%09%7D finally %7B%0A%09%09%09%09if (sock != null) %7B%0A%09%09%09%09%09sock.close();%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%09
+                break;%0A            %7D finally %7B%0A                if (sock != null) %7B%0A                    sock.close();%0A                %7D%0A            %7D%0A            
 Thre
@@ -2295,11 +2295,20 @@
 s);%0A
-%09%09%09
+            
 LOG.
@@ -2357,13 +2357,22 @@
 %22);%0A
-%09%09%7D%0A%09
+        %7D%0A    
 %7D%0A%0A%7D

Use of 4 spaces instead of tabs. Author removed