@@ -41,7 +41,7 @@ | |||
<!-- Atmosphere versions --> | |||
<!-- Note that this should be kept in sync with the class Constants --> | |||
<atmosphere.runtime.version>2.2.9.vaadin2</atmosphere.runtime.version> | |||
<atmosphere.runtime.version>2.2.13.vaadin1</atmosphere.runtime.version> | |||
<atmosphere.js.version>2.2.13.vaadin5</atmosphere.js.version> | |||
<!-- Dependency unpack directory --> |
@@ -66,7 +66,7 @@ public interface Constants { | |||
+ "================================================================="; | |||
// Keep the version number in sync with pom.xml | |||
static final String REQUIRED_ATMOSPHERE_RUNTIME_VERSION = "2.2.9.vaadin2"; | |||
static final String REQUIRED_ATMOSPHERE_RUNTIME_VERSION = "2.2.13.vaadin1"; | |||
static final String INVALID_ATMOSPHERE_VERSION_WARNING = "\n" | |||
+ "=================================================================\n" |
@@ -181,11 +181,6 @@ | |||
<version>1.3</version> | |||
<scope>test</scope> | |||
</dependency> | |||
<dependency> | |||
<groupId>com.jcraft</groupId> | |||
<artifactId>jsch</artifactId> | |||
<version>0.1.52</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>commons-codec</groupId> | |||
<artifactId>commons-codec</artifactId> |
@@ -7,7 +7,7 @@ import org.openqa.selenium.WebDriver; | |||
import org.openqa.selenium.WebElement; | |||
import org.openqa.selenium.support.ui.ExpectedCondition; | |||
import com.jcraft.jsch.JSchException; | |||
import java.io.IOException; | |||
import com.vaadin.testbench.elements.ButtonElement; | |||
import com.vaadin.testbench.parallel.TestCategory; | |||
import com.vaadin.tests.tb3.MultiBrowserTestWithProxy; | |||
@@ -16,7 +16,7 @@ import com.vaadin.tests.tb3.MultiBrowserTestWithProxy; | |||
public class ReconnectDialogUITest extends MultiBrowserTestWithProxy { | |||
@Test | |||
public void reconnectTogglesBodyStyle() throws JSchException { | |||
public void reconnectTogglesBodyStyle() throws IOException { | |||
openTestURL(); | |||
getButton().click(); | |||
disconnectProxy(); | |||
@@ -33,7 +33,7 @@ public class ReconnectDialogUITest extends MultiBrowserTestWithProxy { | |||
} | |||
@Test | |||
public void reconnectDialogShownAndDisappears() throws JSchException { | |||
public void reconnectDialogShownAndDisappears() throws IOException { | |||
openTestURL(); | |||
getButton().click(); | |||
Assert.assertEquals("1. Hello from the server", getLogRow(0)); |
@@ -2,6 +2,7 @@ package com.vaadin.tests.push; | |||
import org.junit.Test; | |||
import org.openqa.selenium.By; | |||
import org.openqa.selenium.NoSuchElementException; | |||
import org.openqa.selenium.WebDriver; | |||
import org.openqa.selenium.WebElement; | |||
import org.openqa.selenium.support.ui.ExpectedCondition; | |||
@@ -74,8 +75,12 @@ public abstract class BasicPushTest extends MultiBrowserTest { | |||
@Override | |||
public Boolean apply(WebDriver input) { | |||
return BasicPushTest | |||
.getClientCounter(BasicPushTest.this) == expectedValue; | |||
try { | |||
return BasicPushTest | |||
.getClientCounter(BasicPushTest.this) == expectedValue; | |||
} catch (NoSuchElementException e) { | |||
return false; | |||
} | |||
} | |||
}, 10); | |||
} |
@@ -1,14 +1,15 @@ | |||
package com.vaadin.tests.push; | |||
import org.junit.Test; | |||
import org.openqa.selenium.By; | |||
import org.openqa.selenium.NoSuchElementException; | |||
import org.openqa.selenium.WebDriver; | |||
import org.openqa.selenium.WebElement; | |||
import org.openqa.selenium.support.ui.ExpectedCondition; | |||
import com.jcraft.jsch.JSchException; | |||
import com.vaadin.tests.tb3.MultiBrowserTestWithProxy; | |||
import java.io.IOException; | |||
public abstract class ReconnectTest extends MultiBrowserTestWithProxy { | |||
@Override | |||
@@ -26,7 +27,7 @@ public abstract class ReconnectTest extends MultiBrowserTestWithProxy { | |||
} | |||
@Test | |||
public void messageIsQueuedOnDisconnect() throws JSchException { | |||
public void messageIsQueuedOnDisconnect() throws IOException { | |||
disconnectProxy(); | |||
clickButtonAndWaitForTwoReconnectAttempts(); | |||
@@ -37,7 +38,7 @@ public abstract class ReconnectTest extends MultiBrowserTestWithProxy { | |||
@Test | |||
public void messageIsNotSentBeforeConnectionIsEstablished() | |||
throws JSchException, InterruptedException { | |||
throws IOException { | |||
disconnectProxy(); | |||
waitForNextReconnectionAttempt(); | |||
@@ -68,7 +69,7 @@ public abstract class ReconnectTest extends MultiBrowserTestWithProxy { | |||
waitForDebugMessage("Reopening push connection"); | |||
} | |||
private void connectAndVerifyConnectionEstablished() throws JSchException { | |||
private void connectAndVerifyConnectionEstablished() throws IOException { | |||
connectProxy(); | |||
waitUntilServerCounterChanges(); | |||
} | |||
@@ -83,8 +84,12 @@ public abstract class ReconnectTest extends MultiBrowserTestWithProxy { | |||
@Override | |||
public Boolean apply(WebDriver input) { | |||
return BasicPushTest | |||
.getServerCounter(ReconnectTest.this) > counter; | |||
try { | |||
return BasicPushTest | |||
.getServerCounter(ReconnectTest.this) > counter; | |||
} catch (NoSuchElementException e) { | |||
return false; | |||
} | |||
} | |||
}, 30); | |||
} | |||
@@ -94,8 +99,12 @@ public abstract class ReconnectTest extends MultiBrowserTestWithProxy { | |||
@Override | |||
public Boolean apply(WebDriver input) { | |||
return BasicPushTest | |||
.getClientCounter(ReconnectTest.this) == expectedValue; | |||
try { | |||
return BasicPushTest | |||
.getClientCounter(ReconnectTest.this) == expectedValue; | |||
} catch (NoSuchElementException e) { | |||
return false; | |||
} | |||
} | |||
}, 5); | |||
} |
@@ -1,26 +1,18 @@ | |||
package com.vaadin.tests.tb3; | |||
import java.io.File; | |||
import java.util.concurrent.atomic.AtomicInteger; | |||
import org.junit.After; | |||
import com.jcraft.jsch.JSch; | |||
import com.jcraft.jsch.JSchException; | |||
import com.jcraft.jsch.Session; | |||
import java.io.IOException; | |||
import com.vaadin.testbench.parallel.TestCategory; | |||
@TestCategory("push") | |||
public abstract class MultiBrowserTestWithProxy extends MultiBrowserTest { | |||
private static AtomicInteger availablePort = new AtomicInteger(2000); | |||
private Session proxySession; | |||
private SimpleProxy proxySession; | |||
private Integer proxyPort = null; | |||
private JSch jsch; | |||
private static String sshDir = System.getProperty("user.home") + "/.ssh/"; | |||
private String[] publicKeys = new String[] { | |||
System.getProperty("sshkey.file"), sshDir + "id_rsa", | |||
sshDir + "id_dsa", sshDir + "id_rsa2" }; | |||
@Override | |||
public void setup() throws Exception { | |||
@@ -61,7 +53,7 @@ public abstract class MultiBrowserTestWithProxy extends MultiBrowserTest { | |||
/** | |||
* Ensure the proxy is active. Does nothing if the proxy is already active. | |||
*/ | |||
protected void connectProxy() throws JSchException { | |||
protected void connectProxy() throws IOException { | |||
if (proxySession != null) { | |||
return; | |||
} | |||
@@ -71,7 +63,7 @@ public abstract class MultiBrowserTestWithProxy extends MultiBrowserTest { | |||
try { | |||
createProxy(getProxyPort()); | |||
break; | |||
} catch (JSchException e) { | |||
} catch (IOException e) { | |||
try { | |||
sleep(500); | |||
} catch (InterruptedException e1) { | |||
@@ -84,26 +76,9 @@ public abstract class MultiBrowserTestWithProxy extends MultiBrowserTest { | |||
} | |||
} | |||
private void createProxy(int proxyPort) throws JSchException { | |||
if (jsch == null) { | |||
jsch = new JSch(); | |||
String keyFile = null; | |||
for (String publicKey : publicKeys) { | |||
if (publicKey != null) { | |||
if (new File(publicKey).exists()) { | |||
keyFile = publicKey; | |||
break; | |||
} | |||
} | |||
} | |||
jsch.addIdentity(keyFile); | |||
} | |||
proxySession = jsch.getSession("localhost"); | |||
proxySession.setConfig("StrictHostKeyChecking", "no"); | |||
proxySession.setPortForwardingL("0.0.0.0", proxyPort, | |||
super.getDeploymentHostname(), super.getDeploymentPort()); | |||
proxySession.connect(); | |||
private void createProxy(int proxyPort) throws IOException { | |||
proxySession = new SimpleProxy(proxyPort, getDeploymentHostname(), getDeploymentPort()); | |||
proxySession.start(); | |||
} | |||
@Override |
@@ -0,0 +1,101 @@ | |||
package com.vaadin.tests.tb3; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.io.OutputStream; | |||
import java.net.InetAddress; | |||
import java.net.ServerSocket; | |||
import java.net.Socket; | |||
import java.net.SocketException; | |||
import java.util.Queue; | |||
import java.util.concurrent.ConcurrentLinkedQueue; | |||
public class SimpleProxy extends Thread { | |||
private final ThreadGroup proxyThreads; | |||
private final Queue<Socket> sockets = new ConcurrentLinkedQueue<Socket>(); | |||
private final ServerSocket serverSocket; | |||
private final String remoteHost; | |||
private final int remotePort; | |||
public SimpleProxy(int localPort, String remoteHost, int remotePort) throws IOException { | |||
super(new ThreadGroup("proxy " + localPort), "server"); | |||
this.remoteHost = remoteHost; | |||
this.remotePort = remotePort; | |||
proxyThreads = getThreadGroup(); | |||
serverSocket = new ServerSocket(localPort, 100, | |||
InetAddress.getByName("0.0.0.0")); | |||
setDaemon(true); | |||
} | |||
@Override | |||
public void run() { | |||
try { | |||
while (!isInterrupted()) { | |||
try { | |||
Socket proxySocket = serverSocket.accept(); | |||
sockets.add(proxySocket); | |||
Socket remoteSocket = new Socket(remoteHost, remotePort); | |||
sockets.add(remoteSocket); | |||
new CopySocket(proxyThreads, proxySocket, remoteSocket).start(); | |||
new CopySocket(proxyThreads, remoteSocket, proxySocket).start(); | |||
} catch (IOException e) { | |||
throw new RuntimeException(e); | |||
} | |||
} | |||
} finally { | |||
disconnect(); | |||
} | |||
} | |||
public void disconnect() { | |||
proxyThreads.interrupt(); | |||
for (Socket socket : sockets) { | |||
try { | |||
socket.close(); | |||
} catch (IOException ignored) { | |||
} | |||
} | |||
try { | |||
serverSocket.close(); | |||
} catch (IOException ignored) { | |||
} | |||
} | |||
private class CopySocket extends Thread { | |||
private final InputStream inputStream; | |||
private final OutputStream outputStream; | |||
private CopySocket(ThreadGroup proxyThreads, Socket srcSocket, Socket dstSocket) throws IOException { | |||
super(proxyThreads, "proxy worker"); | |||
setDaemon(true); | |||
inputStream = srcSocket.getInputStream(); | |||
outputStream = dstSocket.getOutputStream(); | |||
} | |||
@Override | |||
public void run() { | |||
try { | |||
for (int b; (b = inputStream.read()) >= 0; ) { | |||
outputStream.write(b); | |||
} | |||
} catch (SocketException ignored) { | |||
} catch (IOException e) { | |||
e.printStackTrace(); | |||
} finally { | |||
try { | |||
inputStream.close(); | |||
} catch (IOException ignored) { | |||
} | |||
try { | |||
outputStream.close(); | |||
} catch (IOException ignored) { | |||
} | |||
} | |||
} | |||
} | |||
} |