time for more tests
This commit is contained in:
parent
8e607dd243
commit
bade31ef40
|
@ -63,7 +63,7 @@ public class LocalApplicationProxy implements Closeable {
|
||||||
THREAD_FACTORY.newThread(() -> {
|
THREAD_FACTORY.newThread(() -> {
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
try {
|
try {
|
||||||
while (relayCommandCounter.get() < 4) {
|
while (relayCommandCounter.get() < 4 && !isTimeForApplicationToConnect(context, start)) {
|
||||||
sleep(context.gaugePokingPeriod());
|
sleep(context.gaugePokingPeriod());
|
||||||
byte[] commandPacket = GetOutputsCommand.createRequest();
|
byte[] commandPacket = GetOutputsCommand.createRequest();
|
||||||
|
|
||||||
|
@ -73,6 +73,12 @@ public class LocalApplicationProxy implements Closeable {
|
||||||
authenticatorToProxyStream.readPacket();
|
authenticatorToProxyStream.readPacket();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isTimeForApplicationToConnect(context, start) && relayCommandCounter.get() < 4) {
|
||||||
|
// we should not keep controller blocker, time to auto-disconnect
|
||||||
|
authenticatorToProxyStream.close();
|
||||||
|
}
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("Gauge poker", e);
|
log.error("Gauge poker", e);
|
||||||
}
|
}
|
||||||
|
@ -85,6 +91,10 @@ public class LocalApplicationProxy implements Closeable {
|
||||||
return serverHolder;
|
return serverHolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isTimeForApplicationToConnect(LocalApplicationProxyContext context, long start) {
|
||||||
|
return System.currentTimeMillis() - start > context.startUpIdle();
|
||||||
|
}
|
||||||
|
|
||||||
public static void sendHello(IoStream authenticatorToProxyStream, ApplicationRequest applicationRequest) throws IOException {
|
public static void sendHello(IoStream authenticatorToProxyStream, ApplicationRequest applicationRequest) throws IOException {
|
||||||
log.info("Pushing " + applicationRequest);
|
log.info("Pushing " + applicationRequest);
|
||||||
// right from connection push session authentication data
|
// right from connection push session authentication data
|
||||||
|
|
|
@ -54,7 +54,7 @@ public class LocalApplicationProxyTest {
|
||||||
ApplicationRequest applicationRequest = new ApplicationRequest(sessionDetails, createTestUserResolver().apply(TEST_TOKEN_1));
|
ApplicationRequest applicationRequest = new ApplicationRequest(sessionDetails, createTestUserResolver().apply(TEST_TOKEN_1));
|
||||||
|
|
||||||
CountDownLatch disconnected = new CountDownLatch(1);
|
CountDownLatch disconnected = new CountDownLatch(1);
|
||||||
LocalApplicationProxy.startAndRun(context, applicationRequest, -1, () -> disconnected.countDown(), LocalApplicationProxy.ConnectionListener.VOID);
|
LocalApplicationProxy.startAndRun(context, applicationRequest, -1, disconnected::countDown, LocalApplicationProxy.ConnectionListener.VOID);
|
||||||
|
|
||||||
assertTrue(disconnected.await(30, TimeUnit.SECONDS));
|
assertTrue(disconnected.await(30, TimeUnit.SECONDS));
|
||||||
mockBackend.close();
|
mockBackend.close();
|
||||||
|
@ -73,7 +73,7 @@ public class LocalApplicationProxyTest {
|
||||||
|
|
||||||
HelloCommand.getHelloResponse(applicationClientStream.getDataBuffer());
|
HelloCommand.getHelloResponse(applicationClientStream.getDataBuffer());
|
||||||
|
|
||||||
while (gaugePokes.getCount() > 0) {
|
while (!socket.isClosed()) {
|
||||||
BinaryProtocolServer.Packet packet = applicationClientStream.readPacket();
|
BinaryProtocolServer.Packet packet = applicationClientStream.readPacket();
|
||||||
System.out.println("Got packet " + findCommand(packet.getPacket()[0]));
|
System.out.println("Got packet " + findCommand(packet.getPacket()[0]));
|
||||||
|
|
||||||
|
@ -94,14 +94,14 @@ public class LocalApplicationProxyTest {
|
||||||
SessionDetails sessionDetails = TestHelper.createTestSession(TEST_TOKEN_1, Fields.TS_SIGNATURE);
|
SessionDetails sessionDetails = TestHelper.createTestSession(TEST_TOKEN_1, Fields.TS_SIGNATURE);
|
||||||
ApplicationRequest applicationRequest = new ApplicationRequest(sessionDetails, createTestUserResolver().apply(TEST_TOKEN_1));
|
ApplicationRequest applicationRequest = new ApplicationRequest(sessionDetails, createTestUserResolver().apply(TEST_TOKEN_1));
|
||||||
|
|
||||||
LocalApplicationProxy.startAndRun(context, applicationRequest, -1, TcpIoStream.DisconnectListener.VOID, LocalApplicationProxy.ConnectionListener.VOID);
|
CountDownLatch disconnected = new CountDownLatch(1);
|
||||||
|
LocalApplicationProxy.startAndRun(context, applicationRequest, -1, disconnected::countDown, LocalApplicationProxy.ConnectionListener.VOID);
|
||||||
|
|
||||||
// wait for three output requests to take place
|
// wait for three output requests to take place
|
||||||
assertTrue(gaugePokes.await(30, TimeUnit.SECONDS));
|
assertTrue("gaugePokes", gaugePokes.await(30, TimeUnit.SECONDS));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// but there must be a disconnect after some time
|
||||||
|
assertTrue("disconnected", disconnected.await(30, TimeUnit.SECONDS));
|
||||||
|
|
||||||
mockBackend.close();
|
mockBackend.close();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue