proxy progress - WOW TDD totally works
This commit is contained in:
parent
ebb86a05d5
commit
7e4a1223bb
|
@ -21,6 +21,7 @@ import java.util.concurrent.TimeUnit;
|
|||
import static com.rusefi.TestHelper.createIniField;
|
||||
import static com.rusefi.TestHelper.prepareImage;
|
||||
import static com.rusefi.Timeouts.READ_IMAGE_TIMEOUT;
|
||||
import static com.rusefi.Timeouts.SECOND;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
@ -40,15 +41,23 @@ public class FullServerTest {
|
|||
int userId = 7;
|
||||
|
||||
CountDownLatch controllerRegistered = new CountDownLatch(1);
|
||||
CountDownLatch applicationClosed = new CountDownLatch(1);
|
||||
|
||||
UserDetailsResolver userDetailsResolver = authToken -> new UserDetails(authToken.substring(0, 5), userId);
|
||||
int httpPort = 8003;
|
||||
try (Backend backend = new Backend(userDetailsResolver, httpPort, logger) {
|
||||
int applicationTimeout = 7 * SECOND;
|
||||
try (Backend backend = new Backend(userDetailsResolver, httpPort, logger, applicationTimeout) {
|
||||
@Override
|
||||
protected void onRegister(ControllerConnectionState controllerConnectionState) {
|
||||
super.onRegister(controllerConnectionState);
|
||||
controllerRegistered.countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void close(ApplicationConnectionState applicationConnectionState) {
|
||||
super.close(applicationConnectionState);
|
||||
applicationClosed.countDown();
|
||||
}
|
||||
}; LinkManager clientManager = new LinkManager(logger)) {
|
||||
int serverPortForControllers = 7001;
|
||||
int serverPortForRemoteUsers = 7003;
|
||||
|
@ -100,7 +109,14 @@ public class FullServerTest {
|
|||
String clientValue = iniField.getValue(clientImage);
|
||||
assertEquals(Double.toString(value), clientValue);
|
||||
|
||||
assertEquals(1, backend.getApplications().size());
|
||||
assertEquals(1, applicationClosed.getCount());
|
||||
|
||||
// now let's test that application connector would be terminated by server due to inactivity
|
||||
System.out.println("Sleeping twice the application timeout");
|
||||
assertTrue(applicationClosed.await(2 * applicationTimeout, TimeUnit.MILLISECONDS));
|
||||
|
||||
assertEquals("applications size", 0, backend.getApplications().size());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
package com.rusefi;
|
||||
|
||||
import com.opensr5.ConfigurationImage;
|
||||
import com.opensr5.Logger;
|
||||
import com.rusefi.config.generated.Fields;
|
||||
import com.rusefi.io.IoStream;
|
||||
import com.rusefi.io.commands.HelloCommand;
|
||||
import com.rusefi.proxy.NetworkConnector;
|
||||
import com.rusefi.server.*;
|
||||
import com.rusefi.tools.online.HttpUtil;
|
||||
import com.rusefi.tools.online.ProxyClient;
|
||||
|
@ -20,7 +18,6 @@ import java.util.List;
|
|||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.rusefi.Timeouts.READ_IMAGE_TIMEOUT;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
@ -99,6 +96,8 @@ public class ServerTest {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
covered by FullServerTest
|
||||
@Test
|
||||
public void testApplicationTimeout() throws InterruptedException, IOException {
|
||||
int serverPortForRemoteUsers = 6999;
|
||||
|
@ -137,6 +136,7 @@ public class ServerTest {
|
|||
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void testInvalidApplicationRequest() throws InterruptedException, IOException {
|
||||
|
|
|
@ -177,7 +177,7 @@ public class Backend implements Closeable {
|
|||
}, serverPortForApplications, "ApplicationServer", serverSocketCreationCallback, BinaryProtocolServer.SECURE_SOCKET_FACTORY);
|
||||
}
|
||||
|
||||
private void close(ApplicationConnectionState applicationConnectionState) {
|
||||
protected void close(ApplicationConnectionState applicationConnectionState) {
|
||||
if (applicationConnectionState != null)
|
||||
applicationConnectionState.close();
|
||||
onDisconnectApplication(applicationConnectionState);
|
||||
|
@ -186,7 +186,7 @@ public class Backend implements Closeable {
|
|||
protected void onDisconnectApplication(ApplicationConnectionState applicationConnectionState) {
|
||||
if (applicationConnectionState != null) {
|
||||
synchronized (lock) {
|
||||
applications.add(applicationConnectionState);
|
||||
applications.remove(applicationConnectionState);
|
||||
}
|
||||
}
|
||||
logger.info("Disconnecting application");
|
||||
|
@ -255,6 +255,10 @@ public class Backend implements Closeable {
|
|||
return userDetailsResolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* we do not push anything into connected applications so we have to run a clean-up loop
|
||||
* that's different from controllers since we periodically pull outputs from controllers which allows us to detect disconnects
|
||||
*/
|
||||
private void runCleanup() {
|
||||
List<ApplicationConnectionState> inactiveApplications = new ArrayList<>();
|
||||
|
||||
|
|
Loading…
Reference in New Issue