Pending-Name-21 / screen

A graphical user interface written in rust. It renders data provided by Sockets
0 stars 0 forks source link

Task 228/refactor socket client #9

Closed luiggymamani closed 2 days ago

luiggymamani commented 5 days ago

US Refactor socket client for screen based on the latest architecture

US 216

TASK 228

Description

I refactored the input device monitor module from the screen based on the new architecture and used SOLID principles to make this module scalable. I also added test coverage.

What did I do?

How did I do it?

Why did I do it?

To adapt the old implementation with the new architecture and in case there is another change it can be done without modifying the existing modules, but rather adding implementations and changing the dependency injection for these new implementations.

Type of Change

Pull Request Checklist

How to test?

Running the unit tests:

The client socket tests use a server socket running in another thread and these fail when executed together with the other modules, for this reason they must be executed isolating it:

  1. Run all the tests except those of the client socket:

    cargo test --package screen --lib -- input_device_monitor -- --ignored --show-output
  2. Run the socket client tests:

    cargo test --package screen --lib -- --test-threads=1 input_device_monitor --ignored --show-output

    Running the frontend library server socket and screen client socket

  3. Clone the frontend library (this branch "task-207/input-intermediate" for now until the hotfix is ​​made)

  4. Add this unit test inside the "SocketServerTest" test and run:

    @Test
    public void runSocketServer() {
        KeyboardEventManager keyboardEventManager = new KeyboardEventManager();
        MouseEventManager mouseEventManager = new MouseEventManager();
        Receiver receiver = new Receiver();
        receiver.addBuffer(keyboardEventManager);
        receiver.addBuffer(mouseEventManager);
        AtomicBoolean atomicBoolean = new AtomicBoolean(true);
        Thread thread = startServer(receiver, atomicBoolean);
        try {
            thread.join();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
  5. Run the screen client socket running:

    cargo run

    You will be able to see the communication and if you want to see more details you can debug the socket server: Screenshot from 2024-06-30 14-09-17 Screenshot from 2024-06-30 14-10-22