We have a web service where we upload files and want to write an integration test for uploading a somewhat large file. The testing process needs to generate the file (I don't want to add some larger file to source control).
I'm looking to generate a stream of about 50 MB to upload. The data itself does not much matter. I tried this with an in-memory object and that was fairly easy, but I was running out of memory.
The integration tests are written in Groovy, so we can use Groovy or Java APIs to generate the data. How can we generate a random stream for uploading without keeping it in memory the whole time?
Here is a simple program which generates a 50 MB text file with random content.
import java.io.PrintWriter;
import java.util.Random;
public class Test004 {
public static void main(String[] args) throws Exception {
PrintWriter pw = new PrintWriter("c:/test123.txt");
Random rnd = new Random();
for (int i=0; i<50*1024*1024; i++){
pw.write('a' + rnd.nextInt(10));
}
pw.flush();
pw.close();
}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments