reducing code duplication
This commit is contained in:
parent
342c80d270
commit
76334822b3
|
@ -55,16 +55,8 @@ public class FullServerTest {
|
||||||
|
|
||||||
|
|
||||||
// first start backend server
|
// first start backend server
|
||||||
CountDownLatch controllerServerCreated = new CountDownLatch(1);
|
TestHelper.runControllerConnectorBlocking(backend, serverPortForControllers);
|
||||||
CountDownLatch applicationServerCreated = new CountDownLatch(1);
|
TestHelper.runApplicationConnectorBlocking(backend, serverPortForRemoteUsers);
|
||||||
|
|
||||||
backend.runControllerConnector(serverPortForControllers, parameter -> controllerServerCreated.countDown());
|
|
||||||
|
|
||||||
backend.runApplicationConnector(serverPortForRemoteUsers, parameter -> applicationServerCreated.countDown());
|
|
||||||
|
|
||||||
assertTrue(controllerServerCreated.await(READ_IMAGE_TIMEOUT, TimeUnit.MILLISECONDS));
|
|
||||||
assertTrue(applicationServerCreated.await(READ_IMAGE_TIMEOUT, TimeUnit.MILLISECONDS));
|
|
||||||
|
|
||||||
|
|
||||||
// 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;
|
||||||
|
|
|
@ -8,6 +8,7 @@ import com.rusefi.server.*;
|
||||||
import com.rusefi.tools.online.HttpUtil;
|
import com.rusefi.tools.online.HttpUtil;
|
||||||
import com.rusefi.tools.online.ProxyClient;
|
import com.rusefi.tools.online.ProxyClient;
|
||||||
import com.rusefi.tools.online.PublicSession;
|
import com.rusefi.tools.online.PublicSession;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -17,7 +18,6 @@ import java.util.List;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static com.rusefi.Timeouts.READ_IMAGE_TIMEOUT;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
@ -42,10 +42,9 @@ public class ServerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testControllerSessionTimeout() throws InterruptedException, IOException {
|
public void testControllerSessionStartupTimeTimeout() throws InterruptedException, IOException {
|
||||||
int serverPortForControllers = 7000;
|
int serverPortForControllers = 7000;
|
||||||
int httpPort = 8000;
|
int httpPort = 8000;
|
||||||
UserDetailsResolver userDetailsResolver = authToken -> new UserDetails(authToken.substring(0, 5), authToken.charAt(6));
|
|
||||||
|
|
||||||
CountDownLatch serverCreated = new CountDownLatch(1);
|
CountDownLatch serverCreated = new CountDownLatch(1);
|
||||||
CountDownLatch allClientsDisconnected = new CountDownLatch(1);
|
CountDownLatch allClientsDisconnected = new CountDownLatch(1);
|
||||||
|
@ -54,7 +53,7 @@ public class ServerTest {
|
||||||
CountDownLatch allConnected = new CountDownLatch(1);
|
CountDownLatch allConnected = new CountDownLatch(1);
|
||||||
|
|
||||||
|
|
||||||
try (Backend backend = new Backend(userDetailsResolver, httpPort, logger) {
|
try (Backend backend = new Backend(createTestUserResolver(), httpPort, logger) {
|
||||||
@Override
|
@Override
|
||||||
public void register(ControllerConnectionState clientConnectionState) {
|
public void register(ControllerConnectionState clientConnectionState) {
|
||||||
super.register(clientConnectionState);
|
super.register(clientConnectionState);
|
||||||
|
@ -97,13 +96,27 @@ public class ServerTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testApplicationTimeout() throws InterruptedException {
|
||||||
|
int serverPortForRemoteUsers = 6999;
|
||||||
|
int serverPortForControllers = 6997;
|
||||||
|
int httpPort = 6998;
|
||||||
|
|
||||||
|
try (Backend backend = new Backend(createTestUserResolver(), httpPort, logger)) {
|
||||||
|
|
||||||
|
TestHelper.runApplicationConnectorBlocking(backend, serverPortForRemoteUsers);
|
||||||
|
|
||||||
|
TestHelper.runControllerConnectorBlocking(backend, serverPortForControllers);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInvalidApplicationRequest() throws InterruptedException, IOException {
|
public void testInvalidApplicationRequest() throws InterruptedException, IOException {
|
||||||
UserDetailsResolver userDetailsResolver = authToken -> new UserDetails(authToken.substring(0, 5), authToken.charAt(6));
|
|
||||||
int httpPort = 8001;
|
int httpPort = 8001;
|
||||||
int serverPortForRemoteUsers = 6801;
|
int serverPortForRemoteUsers = 6801;
|
||||||
CountDownLatch disconnectedCountDownLatch = new CountDownLatch(1);
|
CountDownLatch disconnectedCountDownLatch = new CountDownLatch(1);
|
||||||
try (Backend backend = new Backend(userDetailsResolver, httpPort, logger) {
|
try (Backend backend = new Backend(createTestUserResolver(), httpPort, logger) {
|
||||||
@Override
|
@Override
|
||||||
protected void onDisconnectApplication() {
|
protected void onDisconnectApplication() {
|
||||||
super.onDisconnectApplication();
|
super.onDisconnectApplication();
|
||||||
|
@ -111,9 +124,7 @@ public class ServerTest {
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
CountDownLatch applicationServerCreated = new CountDownLatch(1);
|
TestHelper.runApplicationConnectorBlocking(backend, serverPortForRemoteUsers);
|
||||||
backend.runApplicationConnector(serverPortForRemoteUsers, parameter -> applicationServerCreated.countDown());
|
|
||||||
assertTrue(applicationServerCreated.await(READ_IMAGE_TIMEOUT, TimeUnit.MILLISECONDS));
|
|
||||||
|
|
||||||
// start authenticator
|
// start authenticator
|
||||||
IoStream authenticatorToProxyStream = TestHelper.secureConnectToLocalhost(serverPortForRemoteUsers, logger);
|
IoStream authenticatorToProxyStream = TestHelper.secureConnectToLocalhost(serverPortForRemoteUsers, logger);
|
||||||
|
@ -123,16 +134,20 @@ public class ServerTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static UserDetailsResolver createTestUserResolver() {
|
||||||
|
return authToken -> new UserDetails(authToken.substring(0, 5), authToken.charAt(6));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAuthenticatorRequestUnknownSession() throws InterruptedException, IOException {
|
public void testAuthenticatorRequestUnknownSession() throws InterruptedException, IOException {
|
||||||
int serverPortForRemoteUsers = 6800;
|
int serverPortForRemoteUsers = 6800;
|
||||||
|
|
||||||
UserDetailsResolver userDetailsResolver = authToken -> new UserDetails(authToken.substring(0, 5), authToken.charAt(6));
|
|
||||||
int httpPort = 8002;
|
int httpPort = 8002;
|
||||||
|
|
||||||
CountDownLatch disconnectedCountDownLatch = new CountDownLatch(1);
|
CountDownLatch disconnectedCountDownLatch = new CountDownLatch(1);
|
||||||
|
|
||||||
try (Backend backend = new Backend(userDetailsResolver, httpPort, logger) {
|
try (Backend backend = new Backend(createTestUserResolver(), httpPort, logger) {
|
||||||
@Override
|
@Override
|
||||||
protected void onDisconnectApplication() {
|
protected void onDisconnectApplication() {
|
||||||
super.onDisconnectApplication();
|
super.onDisconnectApplication();
|
||||||
|
@ -140,9 +155,7 @@ public class ServerTest {
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
CountDownLatch applicationServerCreated = new CountDownLatch(1);
|
TestHelper.runApplicationConnectorBlocking(backend, serverPortForRemoteUsers);
|
||||||
backend.runApplicationConnector(serverPortForRemoteUsers, parameter -> applicationServerCreated.countDown());
|
|
||||||
assertTrue(applicationServerCreated.await(READ_IMAGE_TIMEOUT, TimeUnit.MILLISECONDS));
|
|
||||||
|
|
||||||
SessionDetails sessionDetails = MockRusEfiDevice.createTestSession(MockRusEfiDevice.TEST_TOKEN_1, Fields.TS_SIGNATURE);
|
SessionDetails sessionDetails = MockRusEfiDevice.createTestSession(MockRusEfiDevice.TEST_TOKEN_1, Fields.TS_SIGNATURE);
|
||||||
ApplicationRequest applicationRequest = new ApplicationRequest(sessionDetails, 123);
|
ApplicationRequest applicationRequest = new ApplicationRequest(sessionDetails, 123);
|
||||||
|
|
|
@ -11,6 +11,7 @@ import com.rusefi.io.LinkConnector;
|
||||||
import com.rusefi.io.LinkManager;
|
import com.rusefi.io.LinkManager;
|
||||||
import com.rusefi.io.tcp.BinaryProtocolServer;
|
import com.rusefi.io.tcp.BinaryProtocolServer;
|
||||||
import com.rusefi.io.tcp.TcpIoStream;
|
import com.rusefi.io.tcp.TcpIoStream;
|
||||||
|
import com.rusefi.server.Backend;
|
||||||
import com.rusefi.server.rusEFISSLContext;
|
import com.rusefi.server.rusEFISSLContext;
|
||||||
import com.rusefi.tune.xml.Constant;
|
import com.rusefi.tune.xml.Constant;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
@ -80,4 +81,16 @@ public class TestHelper {
|
||||||
assertTrue(controllerCreated.await(READ_IMAGE_TIMEOUT, TimeUnit.MILLISECONDS));
|
assertTrue(controllerCreated.await(READ_IMAGE_TIMEOUT, TimeUnit.MILLISECONDS));
|
||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void runApplicationConnectorBlocking(Backend backend, int serverPortForRemoteUsers) throws InterruptedException {
|
||||||
|
CountDownLatch applicationServerCreated = new CountDownLatch(1);
|
||||||
|
backend.runApplicationConnector(serverPortForRemoteUsers, parameter -> applicationServerCreated.countDown());
|
||||||
|
assertTrue(applicationServerCreated.await(READ_IMAGE_TIMEOUT, TimeUnit.MILLISECONDS));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void runControllerConnectorBlocking(Backend backend, int serverPortForControllers) throws InterruptedException {
|
||||||
|
CountDownLatch controllerServerCreated = new CountDownLatch(1);
|
||||||
|
backend.runControllerConnector(serverPortForControllers, parameter -> controllerServerCreated.countDown());
|
||||||
|
assertTrue(controllerServerCreated.await(READ_IMAGE_TIMEOUT, TimeUnit.MILLISECONDS));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue