jeudi 27 août 2020

How to test a recursive function [closed]

I'm in the trouble that I have a recursive function which calls a Http request. The Problem is that the Function needs to have a delay of 1 second otherwise I would get a 429 respons. Because the function is trieng to collect a long list of links it takes a lot of time and I'm not sure if it works as I expected it to do. I don't want to test it by just starting the programm and wait a long time until it maybe finished. This would take a long time especially when I ended up in an endless recursion :P

public List<String> getAllLinks(String url) throws IOException, InterruptedException {
    TimeUnit.MILLISECONDS.sleep(1000);
    List<String> links = this.getLinks(this.readPage(url));
    System.out.println(links);
    if(links.isEmpty()) return Collections.EMPTY_LIST;

    int size = links.size();
    for(int i=0;i<size;i++){
        List<String> tmp = getAllLinks(links.get(i) + "/child?expand=page.body.VIEW&limit=300");
        if(!tmp.isEmpty())
            links.addAll(tmp);

    }

    return links;
}

Aucun commentaire:

Enregistrer un commentaire