mirror of https://github.com/rusefi/rusefi-1.git
testConnectionFailed
This commit is contained in:
parent
06fb6185ba
commit
e5a51c97fb
|
@ -132,6 +132,7 @@ public class BinaryProtocolServer implements BinaryProtocolCommands {
|
|||
} else if (command == Fields.TS_BURN_COMMAND) {
|
||||
stream.sendPacket(new byte[]{TS_RESPONSE_BURN_OK}, logger);
|
||||
} else if (command == Fields.TS_GET_COMPOSITE_BUFFER_DONE_DIFFERENTLY) {
|
||||
System.err.println("NOT IMPLEMENTED TS_GET_COMPOSITE_BUFFER_DONE_DIFFERENTLY relay");
|
||||
// todo: relay command
|
||||
stream.sendPacket(TS_OK.getBytes(), logger);
|
||||
} else if (command == Fields.TS_OUTPUT_COMMAND) {
|
||||
|
@ -146,6 +147,10 @@ public class BinaryProtocolServer implements BinaryProtocolCommands {
|
|||
if (currentOutputs != null)
|
||||
System.arraycopy(currentOutputs, 1 + offset, response, 1, count);
|
||||
stream.sendPacket(response, logger);
|
||||
} else if (command == Fields.TS_GET_TEXT) {
|
||||
// todo: relay command
|
||||
System.err.println("NOT IMPLEMENTED TS_GET_TEXT relay");
|
||||
stream.sendPacket(TS_OK.getBytes(), logger);
|
||||
} else {
|
||||
unknownCommands.incrementAndGet();
|
||||
new IllegalStateException().printStackTrace();
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
package com.rusefi.io;
|
||||
|
||||
import com.opensr5.ConfigurationImage;
|
||||
import com.opensr5.Logger;
|
||||
import com.opensr5.ini.field.ScalarIniField;
|
||||
import com.rusefi.FileLog;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocolState;
|
||||
import com.rusefi.config.Field;
|
||||
import com.rusefi.config.generated.Fields;
|
||||
import com.rusefi.io.ConnectionStateListener;
|
||||
import com.rusefi.io.LinkConnector;
|
||||
import com.rusefi.io.LinkManager;
|
||||
import com.rusefi.io.tcp.BinaryProtocolServer;
|
||||
import com.rusefi.io.tcp.TcpConnector;
|
||||
import com.rusefi.tune.xml.Constant;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.Test;
|
||||
|
@ -19,10 +15,37 @@ import java.util.concurrent.CountDownLatch;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class TcpCommunicationIntegrationTest {
|
||||
private static final Logger LOGGER = Logger.CONSOLE;
|
||||
|
||||
// todo: implement & test TCP connector restart!
|
||||
@Test
|
||||
public void testConnect() throws InterruptedException {
|
||||
public void testConnectionFailed() throws InterruptedException {
|
||||
int port = 6101;
|
||||
|
||||
CountDownLatch failedCountDownLatch = new CountDownLatch(1);
|
||||
|
||||
LinkManager clientManager = new LinkManager(LOGGER);
|
||||
clientManager.startAndConnect(Integer.toString(port), new ConnectionStateListener() {
|
||||
@Override
|
||||
public void onConnectionEstablished() {
|
||||
System.out.println("Established");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectionFailed() {
|
||||
System.out.println("onConnectionFailed");
|
||||
failedCountDownLatch.countDown();
|
||||
}
|
||||
});
|
||||
|
||||
assertTrue(failedCountDownLatch.await(30, TimeUnit.SECONDS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConnectAndTransmitImageOverTcpIp() throws InterruptedException {
|
||||
ConfigurationImage ci = prepareImage(239);
|
||||
|
||||
int port = 6100;
|
||||
|
@ -31,20 +54,20 @@ public class TcpCommunicationIntegrationTest {
|
|||
state.setController(ci);
|
||||
state.setCurrentOutputs(new byte[1 + Fields.TS_OUTPUT_SIZE]);
|
||||
|
||||
LinkManager linkManager = new LinkManager(FileLog.LOGGER);
|
||||
LinkManager linkManager = new LinkManager(LOGGER);
|
||||
linkManager.setConnector(LinkConnector.getDetachedConnector(state));
|
||||
BinaryProtocolServer server = new BinaryProtocolServer(FileLog.LOGGER);
|
||||
BinaryProtocolServer server = new BinaryProtocolServer(LOGGER);
|
||||
server.start(linkManager, port);
|
||||
|
||||
CountDownLatch countDownLatch = new CountDownLatch(1);
|
||||
CountDownLatch connectionEstablishedCountDownLatch = new CountDownLatch(1);
|
||||
|
||||
// todo: remove CONFIGURATION_RUSEFI_BINARY or nicer API to disable local file load
|
||||
|
||||
LinkManager clientManager = new LinkManager(FileLog.LOGGER);
|
||||
LinkManager clientManager = new LinkManager(LOGGER);
|
||||
clientManager.startAndConnect(Integer.toString(port), new ConnectionStateListener() {
|
||||
@Override
|
||||
public void onConnectionEstablished() {
|
||||
countDownLatch.countDown();
|
||||
connectionEstablishedCountDownLatch.countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -52,7 +75,7 @@ public class TcpCommunicationIntegrationTest {
|
|||
System.out.println("Failed");
|
||||
}
|
||||
});
|
||||
countDownLatch.await(30, TimeUnit.SECONDS);
|
||||
assertTrue(connectionEstablishedCountDownLatch.await(30, TimeUnit.SECONDS));
|
||||
assertEquals(0, server.unknownCommands.get());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue