TcpCommunicationIntegrationTest
This commit is contained in:
parent
e204e64316
commit
6008159238
|
@ -100,8 +100,7 @@ public class BinaryProtocolServer implements BinaryProtocolCommands {
|
|||
if (crc != IoHelper.getCrc32(packet))
|
||||
throw new IllegalStateException("CRC mismatch");
|
||||
|
||||
|
||||
TcpIoStream stream = new TcpIoStream(linkManager, clientSocket.getInputStream(), clientSocket.getOutputStream());
|
||||
TcpIoStream stream = new TcpIoStream(linkManager, clientSocket);
|
||||
if (command == COMMAND_HELLO) {
|
||||
stream.sendPacket((TS_OK + Fields.TS_SIGNATURE).getBytes(), FileLog.LOGGER);
|
||||
} else if (command == COMMAND_PROTOCOL) {
|
||||
|
|
|
@ -96,13 +96,11 @@ public class TcpConnector implements LinkConnector {
|
|||
@Override
|
||||
public void connectAndReadConfiguration(ConnectionStateListener listener) {
|
||||
FileLog.MAIN.logLine("Connecting to host=" + hostname + "/port=" + port);
|
||||
OutputStream os;
|
||||
BufferedInputStream stream;
|
||||
TcpIoStream tcpIoStream;
|
||||
|
||||
try {
|
||||
Socket socket = new Socket(hostname, port);
|
||||
os = socket.getOutputStream();
|
||||
stream = new BufferedInputStream(socket.getInputStream());
|
||||
// ioStream = new TcpIoStream(os, stream);
|
||||
tcpIoStream = new TcpIoStream(linkManager, socket);
|
||||
} catch (IOException e) {
|
||||
listener.onConnectionFailed();
|
||||
FileLog.MAIN.logLine("Failed to connect to " + hostname + "/port=" + port);
|
||||
|
@ -124,7 +122,7 @@ public class TcpConnector implements LinkConnector {
|
|||
};
|
||||
// ioStream.setInputListener(listener1);
|
||||
|
||||
bp = new BinaryProtocol(linkManager, FileLog.LOGGER, new TcpIoStream(linkManager, stream, os));
|
||||
bp = new BinaryProtocol(linkManager, FileLog.LOGGER, tcpIoStream);
|
||||
|
||||
boolean result = bp.connectAndReadConfiguration(listener1);
|
||||
if (result) {
|
||||
|
|
|
@ -5,9 +5,11 @@ import com.opensr5.io.DataListener;
|
|||
import com.rusefi.io.IoStream;
|
||||
import com.rusefi.io.LinkManager;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.Socket;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
|
@ -20,6 +22,10 @@ public class TcpIoStream implements IoStream {
|
|||
private final LinkManager linkManager;
|
||||
private boolean isClosed;
|
||||
|
||||
public TcpIoStream(LinkManager linkManager, Socket socket) throws IOException {
|
||||
this(linkManager, new BufferedInputStream(socket.getInputStream()), socket.getOutputStream());
|
||||
}
|
||||
|
||||
public TcpIoStream(LinkManager linkManager, InputStream input, OutputStream output) {
|
||||
this.linkManager = linkManager;
|
||||
if (input == null)
|
||||
|
|
|
@ -18,7 +18,7 @@ class BinaryProtocolServerSandbox {
|
|||
public static void main(String[] args) {
|
||||
LinkManager linkManager = new LinkManager();
|
||||
TcpIoStream stream = new TcpIoStream(linkManager, new ByteArrayInputStream(new byte[0]), new ByteArrayOutputStream());
|
||||
BinaryProtocol bp = new BinaryProtocol(linkManager, FileLog.LOGGER, (IoStream) stream);
|
||||
BinaryProtocol bp = new BinaryProtocol(linkManager, FileLog.LOGGER, stream);
|
||||
linkManager.setConnector(new LinkConnector() {
|
||||
@Override
|
||||
public void connectAndReadConfiguration(ConnectionStateListener listener) {
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package com.rusefi.io.test;
|
||||
|
||||
import com.opensr5.ConfigurationImage;
|
||||
import com.opensr5.ini.field.ScalarIniField;
|
||||
import com.rusefi.config.Field;
|
||||
import com.rusefi.config.generated.Fields;
|
||||
import com.rusefi.tune.xml.Constant;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TcpCommunicationIntegrationTest {
|
||||
@Test
|
||||
public void testConnect() {
|
||||
ConfigurationImage ci = new ConfigurationImage(Fields.TOTAL_CONFIG_SIZE);
|
||||
|
||||
Field field = Fields.CYLINDERSCOUNT;
|
||||
|
||||
ScalarIniField scalarIniField = new ScalarIniField(field.getName(), field.getOffset(), "", field.getType(), 1);
|
||||
int input = 239;
|
||||
scalarIniField.setValue(ci, new Constant(field.getName(), "", Integer.toString(input)));
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue