Generate a large stream for testing

David V

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?

peter.petrov

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Cannot stream large files

From Dev

Generate large file and send it

From Dev

Stream generate at fixed rate

From Dev

Unit Testing Coverage and testing large components

From Dev

Unit Testing Coverage and testing large components

From Dev

Proper Unit testing with large projects

From Dev

Testing FCN on large image sizes

From Dev

Integration testing a function with a stream writer

From Dev

Integration testing a function with a stream writer

From Dev

Process large JSON stream with jq

From Dev

Flink Generate Dynamic Stream from GenericRecord Stream

From Dev

Generate a large number of the same byte

From Dev

Algorithm for testing inequality of ordered large collections

From Dev

Testing a Large Application with Multiple UI Maps

From Dev

JUnit Testing for attribute values within in Stream

From Dev

HTTP client to generate traffic for testing Flume

From Dev

Automate Testing Web Forms That Generate Reports

From Dev

Generic way to generate random struct for testing

From Java

Spring WebClient: How to stream large byte[] to file?

From Dev

Stream out large datatable to excel file

From Dev

Stream and unzip large csv file with ruby

From Dev

Count the occurrence of each element in large data stream

From Dev

How to stream in and manipulate a large data file in python

From Dev

Spring Cloud Stream Kafka Record Too Large

From Dev

How to stream large files through Kafka?

From Dev

Spring WebClient: How to stream large byte[] to file?

From Dev

How to Stream Through Large Amounts of Twitter Data?

From Dev

Count the occurrence of each element in large data stream

From Dev

How to stream several large files to jetty

Related Related

HotTag

Archive