time for more tests

This commit is contained in:
rusefi 2020-07-25 22:35:10 -04:00
parent a7961de5cd
commit 240b647595
5 changed files with 49 additions and 15 deletions

View File

@ -35,23 +35,21 @@ public class LocalApplicationProxy implements Closeable {
/** /**
* @param context * @param context
* @param serverPortForRemoteUsers port on which rusEFI proxy accepts authenticator connections
* @param applicationRequest remote session we want to connect to * @param applicationRequest remote session we want to connect to
* @param localApplicationPort local port we would bind for TunerStudio to connect to
* @param jsonHttpPort * @param jsonHttpPort
* @param disconnectListener * @param disconnectListener
* @param connectionListener * @param connectionListener
*/ */
public static ServerSocketReference startAndRun(LocalApplicationProxyContext context, int serverPortForRemoteUsers, ApplicationRequest applicationRequest, int localApplicationPort, int jsonHttpPort, TcpIoStream.DisconnectListener disconnectListener, ConnectionListener connectionListener) throws IOException { public static ServerSocketReference startAndRun(LocalApplicationProxyContext context, ApplicationRequest applicationRequest, int jsonHttpPort, TcpIoStream.DisconnectListener disconnectListener, ConnectionListener connectionListener) throws IOException {
String version = context.executeGet(ProxyClient.getHttpAddress(jsonHttpPort) + ProxyClient.VERSION_PATH); String version = context.executeGet(ProxyClient.getHttpAddress(jsonHttpPort) + ProxyClient.VERSION_PATH);
log.info("Server says version=" + version); log.info("Server says version=" + version);
if (!version.contains(ProxyClient.BACKEND_VERSION)) if (!version.contains(ProxyClient.BACKEND_VERSION))
throw new IOException("Unexpected backend version " + version + " while we want " + ProxyClient.BACKEND_VERSION); throw new IOException("Unexpected backend version " + version + " while we want " + ProxyClient.BACKEND_VERSION);
IoStream authenticatorToProxyStream = new TcpIoStream("authenticatorToProxyStream ", rusEFISSLContext.getSSLSocket(HttpUtil.RUSEFI_PROXY_HOSTNAME, serverPortForRemoteUsers), disconnectListener); IoStream authenticatorToProxyStream = new TcpIoStream("authenticatorToProxyStream ", rusEFISSLContext.getSSLSocket(HttpUtil.RUSEFI_PROXY_HOSTNAME, context.serverPortForRemoteApplications()), disconnectListener);
LocalApplicationProxy.sendHello(authenticatorToProxyStream, applicationRequest); LocalApplicationProxy.sendHello(authenticatorToProxyStream, applicationRequest);
ServerSocketReference serverHolder = BinaryProtocolProxy.createProxy(authenticatorToProxyStream, localApplicationPort); ServerSocketReference serverHolder = BinaryProtocolProxy.createProxy(authenticatorToProxyStream, context.authenticatorPort());
LocalApplicationProxy localApplicationProxy = new LocalApplicationProxy(applicationRequest, serverHolder, authenticatorToProxyStream); LocalApplicationProxy localApplicationProxy = new LocalApplicationProxy(applicationRequest, serverHolder, authenticatorToProxyStream);
connectionListener.onConnected(localApplicationProxy); connectionListener.onConnected(localApplicationProxy);
return serverHolder; return serverHolder;

View File

@ -4,4 +4,14 @@ import java.io.IOException;
public interface LocalApplicationProxyContext { public interface LocalApplicationProxyContext {
String executeGet(String url) throws IOException; String executeGet(String url) throws IOException;
/**
* port on which rusEFI proxy accepts authenticator connections
*/
int serverPortForRemoteApplications();
/**
* local port on which authenticator accepts connections from Tuner Studio
*/
int authenticatorPort();
} }

View File

@ -4,9 +4,14 @@ import com.rusefi.tools.online.HttpUtil;
import java.io.IOException; import java.io.IOException;
public class LocalApplicationProxyContextImpl implements LocalApplicationProxyContext { public abstract class LocalApplicationProxyContextImpl implements LocalApplicationProxyContext {
@Override @Override
public String executeGet(String url) throws IOException { public String executeGet(String url) throws IOException {
return HttpUtil.executeGet(url); return HttpUtil.executeGet(url);
} }
@Override
public int serverPortForRemoteApplications() {
return LocalApplicationProxy.SERVER_PORT_FOR_APPLICATIONS;
}
} }

View File

@ -9,8 +9,9 @@ import com.rusefi.io.LinkManager;
import com.rusefi.io.tcp.TcpIoStream; import com.rusefi.io.tcp.TcpIoStream;
import com.rusefi.proxy.NetworkConnector; import com.rusefi.proxy.NetworkConnector;
import com.rusefi.proxy.client.LocalApplicationProxy; import com.rusefi.proxy.client.LocalApplicationProxy;
import com.rusefi.proxy.client.LocalApplicationProxyContextImpl; import com.rusefi.proxy.client.LocalApplicationProxyContext;
import com.rusefi.server.*; import com.rusefi.server.*;
import com.rusefi.tools.online.HttpUtil;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -40,6 +41,24 @@ public class FullServerTest {
int value = 241; int value = 241;
int userId = 7; int userId = 7;
LocalApplicationProxyContext localApplicationProxyContext = new LocalApplicationProxyContext() {
@Override
public String executeGet(String url) throws IOException {
return HttpUtil.executeGet(url);
}
@Override
public int serverPortForRemoteApplications() {
return 7003;
}
@Override
public int authenticatorPort() {
return 7004;
}
};
CountDownLatch controllerRegistered = new CountDownLatch(1); CountDownLatch controllerRegistered = new CountDownLatch(1);
CountDownLatch applicationClosed = new CountDownLatch(1); CountDownLatch applicationClosed = new CountDownLatch(1);
@ -60,12 +79,11 @@ public class FullServerTest {
} }
}; LinkManager clientManager = new LinkManager()) { }; LinkManager clientManager = new LinkManager()) {
int serverPortForControllers = 7001; int serverPortForControllers = 7001;
int serverPortForRemoteUsers = 7003;
// first start backend server // first start backend server
BackendTestHelper.runControllerConnectorBlocking(backend, serverPortForControllers); BackendTestHelper.runControllerConnectorBlocking(backend, serverPortForControllers);
BackendTestHelper.runApplicationConnectorBlocking(backend, serverPortForRemoteUsers); BackendTestHelper.runApplicationConnectorBlocking(backend, localApplicationProxyContext.serverPortForRemoteApplications());
// create virtual controller to which "rusEFI network connector" connects to // create virtual controller to which "rusEFI network connector" connects to
int controllerPort = 7002; int controllerPort = 7002;
@ -83,8 +101,7 @@ public class FullServerTest {
ApplicationRequest applicationRequest = new ApplicationRequest(authenticatorSessionDetails, userDetailsResolver.apply(MockRusEfiDevice.TEST_TOKEN_1)); ApplicationRequest applicationRequest = new ApplicationRequest(authenticatorSessionDetails, userDetailsResolver.apply(MockRusEfiDevice.TEST_TOKEN_1));
// start authenticator // start authenticator
int authenticatorPort = 7004; // local port on which authenticator accepts connections from Tuner Studio LocalApplicationProxy.startAndRun(localApplicationProxyContext, applicationRequest, httpPort,
LocalApplicationProxy.startAndRun(new LocalApplicationProxyContextImpl(), serverPortForRemoteUsers, applicationRequest, authenticatorPort, httpPort,
TcpIoStream.DisconnectListener.VOID, TcpIoStream.DisconnectListener.VOID,
LocalApplicationProxy.ConnectionListener.VOID); LocalApplicationProxy.ConnectionListener.VOID);
@ -92,7 +109,7 @@ public class FullServerTest {
CountDownLatch connectionEstablishedCountDownLatch = new CountDownLatch(1); CountDownLatch connectionEstablishedCountDownLatch = new CountDownLatch(1);
// connect to proxy and read virtual controller through it // connect to proxy and read virtual controller through it
clientManager.startAndConnect(TestHelper.LOCALHOST + ":" + authenticatorPort, new ConnectionStateListener() { clientManager.startAndConnect(TestHelper.LOCALHOST + ":" + localApplicationProxyContext.authenticatorPort(), new ConnectionStateListener() {
@Override @Override
public void onConnectionEstablished() { public void onConnectionEstablished() {
connectionEstablishedCountDownLatch.countDown(); connectionEstablishedCountDownLatch.countDown();

View File

@ -222,11 +222,15 @@ public class RemoteTab {
serverHolder.close(); serverHolder.close();
}); });
LocalApplicationProxyContextImpl context = new LocalApplicationProxyContextImpl() {
@Override
public int authenticatorPort() {
return Integer.parseInt(getLocalPort());
}
};
ServerSocketReference serverHolder = LocalApplicationProxy.startAndRun( ServerSocketReference serverHolder = LocalApplicationProxy.startAndRun(
new LocalApplicationProxyContextImpl(), context,
LocalApplicationProxy.SERVER_PORT_FOR_APPLICATIONS,
applicationRequest, applicationRequest,
Integer.parseInt(getLocalPort()),
HttpUtil.PROXY_JSON_API_HTTP_PORT, disconnectListener, connectionListener); HttpUtil.PROXY_JSON_API_HTTP_PORT, disconnectListener, connectionListener);
serverHolderAtomicReference.set(serverHolder); serverHolderAtomicReference.set(serverHolder);
} catch (IOException e) { } catch (IOException e) {