zyx 2 년 전
부모
커밋
bbbaa64b4f
2개의 변경된 파일10개의 추가작업 그리고 3개의 파일을 삭제
  1. 2 1
      src/main/java/com/sxtvs/api/chatgpt/service/ChatGptService.java
  2. 8 2
      src/test/java/com/sxtvs/ChatgptApplicationTests.java

+ 2 - 1
src/main/java/com/sxtvs/api/chatgpt/service/ChatGptService.java

@@ -22,6 +22,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.SynchronousQueue;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 import java.util.stream.Collectors;
@@ -56,7 +57,7 @@ public class ChatGptService {
                 .collect(Collectors.joining("\n")));
         var params = objectMapper.writeValueAsString(paramsDto);
         logger.info("request", params, "dto", objectMapper.writeValueAsString(dto));
-        var token = queue.poll();
+        var token = queue.poll(1, TimeUnit.DAYS);
         String result;
         try {
             var httpPost = new HttpPost("https://api.openai.com/v1/completions");

+ 8 - 2
src/test/java/com/sxtvs/ChatgptApplicationTests.java

@@ -3,11 +3,17 @@ package com.sxtvs;
 import org.junit.jupiter.api.Test;
 import org.springframework.boot.test.context.SpringBootTest;
 
-@SpringBootTest
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+
 class ChatgptApplicationTests {
 
     @Test
-    void contextLoads() {
+    void contextLoads() throws InterruptedException {
+        ArrayBlockingQueue<String> queue = new ArrayBlockingQueue<>(1);
+        var poll = queue.poll(1, TimeUnit.DAYS);
+        System.out.println(poll);
     }
 
 }