1
0
mirror of https://github.com/mik3y/usb-serial-for-android.git synced 2026-08-13 01:13:06 +00:00

01. Refactored SerialInputOutputManager (#615)

Used separate threads for reading and writing, enhancing concurrency and performance.

Note: before was possible to start `SerialInputOutputManager` with `Executors.newSingleThreadExecutor().submit(ioManager)`. Now you have to use `ioManager.start()`
This commit is contained in:
Dmitry Kaukov
2025-01-29 07:26:09 +11:00
committed by GitHub
parent 2673407f1d
commit 9911e141a7
5 changed files with 160 additions and 161 deletions
@@ -34,18 +34,19 @@ public class SerialInputOutputManagerTest {
CommonUsbSerialPort port = mock(CommonUsbSerialPort.class);
when(port.getReadEndpoint()).thenReturn(readEndpoint);
when(port.read(new byte[16], 0)).thenReturn(1);
when(port.isOpen()).thenReturn(true);
SerialInputOutputManager manager = new SerialInputOutputManager(port);
manager.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);
ExceptionListener exceptionListener = new ExceptionListener();
manager.setListener(exceptionListener);
manager.run();
manager.runRead();
assertEquals(RuntimeException.class, exceptionListener.e.getClass());
assertEquals("exception1", exceptionListener.e.getMessage());
ErrorListener errorListener = new ErrorListener();
manager.setListener(errorListener);
manager.run();
manager.runRead();
assertEquals(Exception.class, errorListener.e.getClass());
assertEquals("java.lang.UnknownError: error1", errorListener.e.getMessage());
assertEquals(UnknownError.class, errorListener.e.getCause().getClass());