I’m stuck on Stage #Send Correlation ID #nv3
I referred to code examples and implemented similar way.
Here are my logs:
include relevant logs here (please make sure to keep the backticks around this!)
[compile] [INFO] Scanning for projects...
[compile] [INFO]
[compile] [INFO] -----------------< io.codecrafters:codecrafters-kafka >-----------------
[compile] [INFO] Building codecrafters-kafka 1.0
[compile] [INFO] from pom.xml
[compile] [INFO] --------------------------------[ jar ]---------------------------------
[compile] [INFO]
[compile] [INFO] --- resources:3.3.1:resources (default-resources) @ codecrafters-kafka ---
[compile] [INFO] skip non existing resourceDirectory /app/src/main/resources
[compile] [INFO]
[compile] [INFO] --- compiler:3.13.0:compile (default-compile) @ codecrafters-kafka ---
[compile] [INFO] Recompiling the module because of changed source code.
[compile] [INFO] Compiling 1 source file with javac [debug target 23] to target/classes
[compile] [INFO]
[compile] [INFO] --- resources:3.3.1:testResources (default-testResources) @ codecrafters-kafka ---
[compile] [INFO] skip non existing resourceDirectory /app/src/test/resources
[compile] [INFO]
[compile] [INFO] --- compiler:3.13.0:testCompile (default-testCompile) @ codecrafters-kafka ---
[compile] [INFO] No sources to compile
[compile] [INFO]
[compile] [INFO] --- surefire:3.2.5:test (default-test) @ codecrafters-kafka ---
[compile] [INFO] No tests to run.
[compile] [INFO]
[compile] [INFO] --- jar:3.4.1:jar (default-jar) @ codecrafters-kafka ---
[compile] [INFO] Building jar: /app/target/codecrafters-kafka-1.0.jar
[compile] [INFO]
[compile] [INFO] --- assembly:3.7.1:single (make-assembly) @ codecrafters-kafka ---
[compile] [INFO] Building jar: /tmp/codecrafters-build-kafka-java/codecrafters-kafka.jar
[compile] [WARNING] Configuration option 'appendAssemblyId' is set to false.
[compile] Instead of attaching the assembly file: /tmp/codecrafters-build-kafka-java/codecrafters-kafka.jar, it will become the file for main project artifact.
[compile] NOTE: If multiple descriptors or descriptor-formats are provided for this project, the value of this file will be non-deterministic!
[compile] [WARNING] Replacing pre-existing project main-artifact file: /app/target/codecrafters-kafka-1.0.jar
[compile] with assembly file: /tmp/codecrafters-build-kafka-java/codecrafters-kafka.jar
[compile] [INFO] ------------------------------------------------------------------------
[compile] [INFO] BUILD SUCCESS
[compile] [INFO] ------------------------------------------------------------------------
[compile] [INFO] Total time: 2.519 s
[compile] [INFO] Finished at: 2024-11-29T01:11:19Z
[compile] [INFO] ------------------------------------------------------------------------
[compile] Moved ./.codecrafters/run.sh → ./your_program.sh
[compile] Compilation successful.
[tester::#NV3] Running tests for Stage #NV3 (Send Correlation ID)
[tester::#NV3] $ ./your_program.sh /tmp/server.properties
[your_program] Logs from your program will appear here!
[tester::#NV3] Sending "ApiVersions" (version: 4) request (Correlation id: 7)
[tester::#NV3] [Decoder] Received:
[tester::#NV3] [Decoder] Hex (bytes 0--1) | ASCII
[tester::#NV3] [Decoder] ------------------------------------------------+------------------
[tester::#NV3] [Decoder] |
[tester::#NV3] [Decoder] ^ ^
[tester::#NV3] [Decoder] Error: Expected int32 length to be 4 bytes, got 0 bytes
[tester::#NV3] [Decoder] Context:
[tester::#NV3] [Decoder] - response
[tester::#NV3] [Decoder] - message length
[tester::#NV3] [Decoder] - INT32
[tester::#NV3] [Decoder]
[tester::#NV3] [Decoder] Test failed (try setting 'debug: true' in your codecrafters.yml to see more details)
And here’s a snippet of my code:
public static void main(String[] args){
// You can use print statements as follows for debugging, they'll be visible when running tests.
System.err.println("Logs from your program will appear here!");
// Uncomment this block to pass the first stage
ServerSocket serverSocket = null;
Socket clientSocket = null;
int port = 9092;
try {
serverSocket = new ServerSocket(port);
// Since the tester restarts your program quite often, setting SO_REUSEADDR
// ensures that we don't run into 'Address already in use' errors
serverSocket.setReuseAddress(true);
// Wait for connection from client.
clientSocket = serverSocket.accept();
OutputStream out = clientSocket.getOutputStream();
out.write(new byte[] {0, 1, 2, 3});
out.write(new byte[] {0, 0, 0, 7});
} catch (IOException e) {
System.out.println("IOException: " + e.getMessage());
} finally {
try {
if (clientSocket != null) {
clientSocket.close();
}
} catch (IOException e) {
System.out.println("IOException: " + e.getMessage());
}
}
}