Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.ezcode.codetest.application.submission.dto.event;

import org.ezcode.codetest.domain.submission.exception.SubmissionException;
import org.ezcode.codetest.domain.submission.exception.code.SubmissionExceptionCode;

public record SubmissionErrorEvent(

String sessionKey,

SubmissionExceptionCode code

) {
public SubmissionErrorEvent(String sessionKey, Throwable t) {
this(sessionKey, resolveCode(t));
}

private static SubmissionExceptionCode resolveCode(Throwable t) {
if (t instanceof SubmissionException se) {
return (SubmissionExceptionCode) se.getResponseCode();
}
return SubmissionExceptionCode.UNKNOWN_ERROR;
}
Comment on lines +17 to +22
Copy link

@coderabbitai coderabbitai bot Jun 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

안전하지 않은 캐스팅을 수정해주세요.

19번 라인의 (SubmissionExceptionCode) se.getResponseCode() 캐스팅이 안전하지 않습니다. getResponseCode()SubmissionExceptionCode를 반환한다는 보장이 없어 ClassCastException이 발생할 수 있습니다.

다음과 같이 안전한 캐스팅으로 수정하는 것을 권장합니다:

-    private static SubmissionExceptionCode  resolveCode(Throwable t) {
+    private static SubmissionExceptionCode resolveCode(Throwable t) {
         if (t instanceof SubmissionException se) {
-            return (SubmissionExceptionCode) se.getResponseCode();
+            var responseCode = se.getResponseCode();
+            return responseCode instanceof SubmissionExceptionCode ? 
+                (SubmissionExceptionCode) responseCode : SubmissionExceptionCode.UNKNOWN_ERROR;
         }
         return SubmissionExceptionCode.UNKNOWN_ERROR;
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
private static SubmissionExceptionCode resolveCode(Throwable t) {
if (t instanceof SubmissionException se) {
return (SubmissionExceptionCode) se.getResponseCode();
}
return SubmissionExceptionCode.UNKNOWN_ERROR;
}
private static SubmissionExceptionCode resolveCode(Throwable t) {
if (t instanceof SubmissionException se) {
var responseCode = se.getResponseCode();
return responseCode instanceof SubmissionExceptionCode ?
(SubmissionExceptionCode) responseCode : SubmissionExceptionCode.UNKNOWN_ERROR;
}
return SubmissionExceptionCode.UNKNOWN_ERROR;
}
🤖 Prompt for AI Agents
In
src/main/java/org/ezcode/codetest/application/submission/dto/event/SubmissionErrorEvent.java
lines 17 to 22, the cast on line 19 from se.getResponseCode() to
SubmissionExceptionCode is unsafe and may cause ClassCastException. To fix this,
avoid direct casting and instead check if the returned object is an instance of
SubmissionExceptionCode before casting, or modify the method to return
SubmissionExceptionCode directly if possible, ensuring type safety.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

나중에 SubmissionException으로 JudgeClient에서 다 랩핑해서 넘길 거야

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thezz9 아, 그렇다면 현재 코드는 그대로 두시고 향후 JudgeClient에서 모든 예외를 SubmissionException으로 래핑해서 넘겨주시면 이 캐스팅 문제가 자연스럽게 해결되겠네요! 👍


✏️ Learnings added
Learnt from: thezz9
PR: ezcode-my/backend#98
File: src/main/java/org/ezcode/codetest/application/submission/dto/event/SubmissionErrorEvent.java:17-22
Timestamp: 2025-06-25T01:24:30.754Z
Learning: JudgeClient에서 모든 예외를 SubmissionException으로 래핑해서 넘길 계획이므로, SubmissionErrorEvent.resolveCode() 메서드의 캐스팅은 안전할 예정임.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.ezcode.codetest.application.submission.dto.event;

import org.ezcode.codetest.application.submission.dto.event.payload.SubmissionFinalResultPayload;

public record SubmissionJudgingFinishedEvent(

String sessionKey,

SubmissionFinalResultPayload payload

) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.ezcode.codetest.application.submission.dto.event;

import org.ezcode.codetest.application.submission.dto.event.payload.TestcaseResultPayload;

public record TestcaseEvaluatedEvent(

String sessionKey,

TestcaseResultPayload payload

) {
public static TestcaseEvaluatedEvent of(String sessionKey, TestcaseResultPayload payload) {
return new TestcaseEvaluatedEvent(
sessionKey,
payload
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.ezcode.codetest.application.submission.dto.event;

import java.util.List;

import org.ezcode.codetest.application.submission.dto.event.payload.InitTestcaseListPayload;

public record TestcaseListInitializedEvent(

String sessionKey,

List<InitTestcaseListPayload> payload

) {
public static TestcaseListInitializedEvent from(String sessionKey, List<InitTestcaseListPayload> payload) {
return new TestcaseListInitializedEvent(sessionKey, payload);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.ezcode.codetest.application.submission.dto.event.payload;

import java.util.List;
import java.util.stream.IntStream;

import org.ezcode.codetest.domain.problem.model.ProblemInfo;
import org.ezcode.codetest.domain.problem.model.entity.Testcase;

public record InitTestcaseListPayload(

int seqId,

String input,

String expectedOutput,

String status

) {
public static List<InitTestcaseListPayload> from(ProblemInfo info) {
return IntStream.rangeClosed(1, info.getTestcaseCount())
.mapToObj(seq -> {
Testcase tc = info.testcaseList().get(seq - 1);
return new InitTestcaseListPayload(
seq,
tc.getInput(),
tc.getOutput(),
"채점 중"
);
})
.toList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.ezcode.codetest.application.submission.dto.event.payload;

import lombok.Getter;

@Getter
public class SubmissionFinalResultPayload {

private final int totalCount;

private final int passedCount;

private final boolean isCorrect;

private final String message;

public SubmissionFinalResultPayload(int totalCount, int passedCount, String message) {
this.totalCount = totalCount;
this.passedCount = passedCount;
this.isCorrect = totalCount == passedCount;
this.message = message;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.ezcode.codetest.application.submission.dto.event.payload;

import org.ezcode.codetest.application.submission.model.JudgeResult;
import org.ezcode.codetest.domain.submission.dto.AnswerEvaluation;

public record TestcaseResultPayload(

int seqId,

boolean isPassed,

String actualOutput,

long executionTime,

long memoryUsage,

String message

) {
public static TestcaseResultPayload fromEvaluation(int seqId, JudgeResult result, AnswerEvaluation evaluation) {
return new TestcaseResultPayload(
seqId,
evaluation.isPassed(),
result.actualOutput(),
result.executionTime(),
result.memoryUsage(),
result.message());
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public record SubmissionDetailResponse(
String message,

@Schema(description = "실행 시간 (s)", example = "0.129")
Double executionTime,
Long executionTime,

@Schema(description = "메모리 사용량 (KB)", example = "12196")
Long memoryUsage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public record JudgeResult(

String actualOutput,

double executionTime,
long executionTime,

long memoryUsage,

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.ezcode.codetest.application.submission.model;

import org.ezcode.codetest.application.submission.dto.response.submission.FinalResultResponse;
import org.ezcode.codetest.application.submission.dto.event.payload.SubmissionFinalResultPayload;
import org.ezcode.codetest.domain.submission.model.SubmissionAggregator;

import java.util.concurrent.CountDownLatch;
Expand Down Expand Up @@ -33,8 +33,8 @@ public static SubmissionContext initialize(int totalTestcaseCount) {
);
}

public FinalResultResponse toFinalResult(int totalTestcaseCount) {
return new FinalResultResponse(
public SubmissionFinalResultPayload toFinalResult(int totalTestcaseCount) {
return new SubmissionFinalResultPayload(
totalTestcaseCount,
this.getPassedCount(),
this.getCurrentMessage()
Expand All @@ -53,10 +53,6 @@ public int getPassedCount() {
return this.passedCount.get();
}

public int getProcessedCount() {
return this.processedCount.get();
}

public String getCurrentMessage() {
return this.message.get();
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.ezcode.codetest.application.submission.port;

import org.ezcode.codetest.domain.submission.model.entity.UserProblemResult;

public interface ProblemEventService {

void publishProblemSolveEvent(UserProblemResult event);

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.ezcode.codetest.application.submission.port;

import org.ezcode.codetest.infrastructure.event.dto.SubmissionMessage;
import org.ezcode.codetest.infrastructure.event.dto.submission.SubmissionMessage;

public interface QueueProducer {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.ezcode.codetest.application.submission.port;

import org.ezcode.codetest.application.submission.dto.event.SubmissionErrorEvent;
import org.ezcode.codetest.application.submission.dto.event.SubmissionJudgingFinishedEvent;
import org.ezcode.codetest.application.submission.dto.event.TestcaseListInitializedEvent;
import org.ezcode.codetest.application.submission.dto.event.TestcaseEvaluatedEvent;

public interface SubmissionEventService {

void publishInitTestcases(TestcaseListInitializedEvent event);

void publishTestcaseUpdate(TestcaseEvaluatedEvent event);

void publishFinalResult(SubmissionJudgingFinishedEvent event);

void publishSubmissionError(SubmissionErrorEvent event);
}
Loading