package cd.casic.server;

import cd.casic.ci.process.engine.manager.LoggerManager;
import jakarta.annotation.Resource;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.core5.http.HttpResponse;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

@SpringBootTest(classes = {OpsServerApplication.class})
@ActiveProfiles("local")
public class SSETest {
    @Resource
    LoggerManager loggerManager;
    @Test
    public void subscribe(){
        loggerManager.subscribe("716299524330622976",null);
    }
    @Test
    public void shuimuSSE() throws IOException {
        try (CloseableHttpClient client = HttpClients.createDefault()) {
            HttpGet request = new HttpGet("http://175.6.27.155:10200/api/driverGeneration/progress?uuid=6");
            request.addHeader("Accept", "text/event-stream");
            request.addHeader("Authorization", "Bearer xj76K1VJBMrKnCXAzTdPJUCp4B4");

            try (CloseableHttpResponse response = client.execute(request)) {
                BufferedReader reader = new BufferedReader(
                        new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
                String line;
                while ((line = reader.readLine()) != null) {
                    System.out.println("收到: " + line);
                }
            }
        }
    }

}
