Skip to content

Commit 31d24a6

Browse files
CesarCoelhoclaude
andcommitted
Exercise >2 GB Blob encode/decode in LargeBlobTest
Enable the previously @ignore'd probe and run it over fixed binary (FixedBinaryEncoder/Decoder), so it exercises a full 3 GB Blob round-trip rather than documenting the limitation. Extract the random-file generation into a reusable public static generateRandomFile(File, long) helper that writes in fixed-size chunks, so other tests can reuse it and generation never holds the whole file in memory. The test still guards on available heap/disk and skips (via assumeTrue) when they are insufficient. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 6335001 commit 31d24a6

1 file changed

Lines changed: 26 additions & 15 deletions

File tree

testbeds/testbed-encoders/src/test/java/esa/mo/mal/encoders/LargeBlobTest.java

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@
2828
import java.io.File;
2929
import java.io.FileInputStream;
3030
import java.io.FileOutputStream;
31+
import java.io.IOException;
3132
import java.io.InputStream;
3233
import java.io.OutputStream;
3334
import java.util.Random;
3435
import org.ccsds.moims.mo.mal.structures.Blob;
3536
import org.ccsds.moims.mo.mal.structures.Element;
3637
import static org.junit.Assume.assumeTrue;
37-
import org.junit.Ignore;
3838
import org.junit.Test;
3939

4040
/**
@@ -45,9 +45,6 @@ public class LargeBlobTest {
4545

4646
private static final long SIZE = 3L * 1024 * 1024 * 1024; // 3 GB (on purpose > 2 GB)
4747

48-
@Ignore("A Blob larger than 2 GB cannot yet be encoded (the length prefix is a "
49-
+ "32-bit field); this probe is expected to fail until that is addressed. "
50-
+ "Enable it manually to reproduce the limitation.")
5148
@Test
5249
public void encodeThenDecode3GBBlob() throws Exception {
5350
File dir = new File("target/large-blob-test");
@@ -81,17 +78,7 @@ public void encodeThenDecode3GBBlob() throws Exception {
8178
try {
8279
// 1. Generate a 3 GB file with random content
8380
System.out.println("[1] Generating " + SIZE + " byte random file...");
84-
byte[] chunk = new byte[8 * 1024 * 1024];
85-
Random rnd = new Random(42);
86-
long written = 0;
87-
try (OutputStream os = new BufferedOutputStream(new FileOutputStream(srcFile))) {
88-
while (written < SIZE) {
89-
rnd.nextBytes(chunk);
90-
int toWrite = (int) Math.min(chunk.length, SIZE - written);
91-
os.write(chunk, 0, toWrite);
92-
written += toWrite;
93-
}
94-
}
81+
generateRandomFile(srcFile, SIZE);
9582
System.out.println(" File generated: " + srcFile.length() + " bytes");
9683

9784
// 2. Create a Blob with it (file-based: a byte[] cannot hold 3 GB)
@@ -122,4 +109,28 @@ public void encodeThenDecode3GBBlob() throws Exception {
122109
dir.delete();
123110
}
124111
}
112+
113+
/**
114+
* Generates a file of the given size filled with deterministic pseudo-random
115+
* bytes. The content is written in fixed-size chunks so the generation itself
116+
* never holds the whole file in memory, allowing sizes larger than the heap.
117+
* Reusable by any test that needs a large file.
118+
*
119+
* @param file the file to (over)write.
120+
* @param size the number of bytes to write.
121+
* @throws IOException if the file could not be written.
122+
*/
123+
public static void generateRandomFile(File file, long size) throws IOException {
124+
byte[] chunk = new byte[8 * 1024 * 1024];
125+
Random rnd = new Random(42);
126+
long written = 0;
127+
try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) {
128+
while (written < size) {
129+
rnd.nextBytes(chunk);
130+
int toWrite = (int) Math.min(chunk.length, size - written);
131+
os.write(chunk, 0, toWrite);
132+
written += toWrite;
133+
}
134+
}
135+
}
125136
}

0 commit comments

Comments
 (0)