epugh commented on code in PR #4264:
URL: https://github.com/apache/solr/pull/4264#discussion_r3106076100


##########
solr/core/src/test/org/apache/solr/handler/configsets/GetConfigSetFileAPITest.java:
##########
@@ -126,10 +135,70 @@ public void testEmptyFileReturnsEmptyContent() throws 
Exception {
     createConfigSetWithFile(configSetName, filePath, "");
 
     final var api = new GetConfigSetFile(mockCoreContainer, null, null);
-    final ConfigSetFileContentsResponse response = 
api.getConfigSetFile(configSetName, filePath);
+    final StreamingOutput streamingOutput = 
api.getConfigSetFile(configSetName, filePath);
+
+    assertNotNull(streamingOutput);
+
+    // Read the streamed bytes
+    ByteArrayOutputStream baos = new ByteArrayOutputStream();
+    streamingOutput.write(baos);
+
+    assertEquals(0, baos.size());
+  }
+
+  @Test
+  public void testBinaryFilePreservedWithStreamingOutput() throws Exception {
+    // This test demonstrates that binary files are now correctly handled
+    // by returning raw bytes via StreamingOutput instead of UTF-8 String.
+    final String configSetName = "binarytest";
+    final String filePath = "logo.png";
+
+    // Create a file with binary data simulating a small PNG image header
+    // PNG signature: 89 50 4E 47 0D 0A 1A 0A (first 8 bytes of any PNG)
+    // Plus some additional binary data that would corrupt as UTF-8
+    byte[] binaryData =
+        new byte[] {
+          (byte) 0x89,
+          0x50,
+          0x4E,
+          0x47,
+          0x0D,
+          0x0A,
+          0x1A,
+          0x0A, // PNG signature
+          (byte) 0xFF,
+          (byte) 0xFE,
+          0x00,
+          0x01,
+          (byte) 0x80,
+          (byte) 0xDE,
+          (byte) 0xAD,
+          (byte) 0xBE,
+          (byte) 0xEF // Binary data
+        };
+
+    Path configDir = configSetBase.resolve(configSetName);
+    Files.createDirectories(configDir);
+    Files.write(configDir.resolve(filePath), binaryData);
+
+    final var api = new GetConfigSetFile(mockCoreContainer, null, null);
+    final StreamingOutput streamingOutput = 
api.getConfigSetFile(configSetName, filePath);
+
+    assertNotNull(streamingOutput);
+
+    // Read the streamed bytes
+    ByteArrayOutputStream baos = new ByteArrayOutputStream();
+    streamingOutput.write(baos);
+    byte[] responseBytes = baos.toByteArray();
+
+    // SUCCESS: Binary data is preserved exactly!
+    assertArrayEquals(
+        "Binary file content should be preserved byte-for-byte", binaryData, 
responseBytes);
 
-    assertNotNull(response);
-    assertEquals(filePath, response.path);
-    assertEquals("", response.content);
+    // Verify PNG signature is intact
+    assertEquals((byte) 0x89, responseBytes[0]);

Review Comment:
   yeah, I kind of wondered...    It was sort of cool to see that we are able 
to look at specfici bytes to make sure the full roundtripping worked...   but i 
also know adding tests is adding more work to review.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to